Pages

Showing posts with label V5. Show all posts
Showing posts with label V5. Show all posts

Friday, October 22, 2010

OpenERP on_change: bunch of parameters vs dictionaries

def product_uom_change(self, cursor, user, ids, pricelist, product, qty=0,
            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
            lang=False, update_tax=True, date_order=False):
        res = self.product_id_change(cursor, user, ids, pricelist, product,
                qty=qty, uom=uom, qty_uos=qty_uos, uos=uos, name=name,
                partner_id=partner_id, lang=lang, update_tax=update_tax,
                date_order=date_order)
        if 'product_uom' in res['value']:
            del res['value']['product_uom']
        if not uom:
            res['value']['price_unit'] = 0.0
        return res

Look at this on_change, 15 parameters and calling another one with 14 parameters. This is too much, a good idea will be to use dictionaries:


def product_uom_change(self, cursor, user, ids, params, context=None):
        res = self.product_id_change(cursor, user, ids, params, context=context)
        if 'product_uom' in res['value']:
            del res['value']['product_uom']
        if not params['uom']:
            res['value']['price_unit'] = 0.0
        return res

PS: Here I have also a context parameter, OpenERP and his CEO Fabien Pinckaers forget it frequently.

Friday, October 15, 2010

base_contact module, heaven or hell?

Well, a lot of companies when they saw the partners (without the base_contact), they think that they need contacts separated from the addresses. In 70% of the cases they don't need it really but if they need it you think directly... base_contact... but this module is hell or heaven?

Just comment it!

Good reading for the CEO of OpenERP:
http://eu.wiley.com/WileyCDA/WileyTitle/productCd-0470178450,descCd-description.html

Thursday, October 14, 2010

Code obfuscation

From http://twitter.com/cedrickrier/status/27248865483

dict = {}
        for object in result:
            k2 = {}
            for id,fnct in result[object].items():
                k2.setdefault(tuple(fnct), [])
                k2[tuple(fnct)].append(id)
            for fnct,id in k2.items():
                dict.setdefault(fncts[fnct[0]][4],[])
                dict[fncts[fnct[0]][4]].append((fncts[fnct[0]][4],object,id,map(lambda x: fncts[x][1], fnct)))

http://bazaar.launchpad.net/~openerp/openobject-server/trunk/annotate/head:/bin/osv/orm.py#L3777

Code obfuscation...

Wednesday, October 13, 2010

Projects in OpenERP V5 Part 2

Code coming from the project module:

class project_work(osv.osv):
    _name = "project.task.work"
    _description = "Task Work"
    _columns = {
        'name': fields.char('Work summary', size=128),
        'date': fields.datetime('Date'),
        'task_id': fields.many2one('project.task', 'Task', ondelete='cascade', required=True),
        'hours': fields.float('Time Spent'),
        'user_id': fields.many2one('res.users', 'Done by', required=True),
    }

...

Using hours instead of a unit of measure and a value or defining in the application like in Tryton (http://www.tryton.org) what 1 day, 1 week, 1 month and 1 year of work means that your are obliged to encode hours in your time sheet...


Projects in OpenERP V5 Part 1

Code coming from the project module:

class project_work(osv.osv):
    _name = "project.task.work"
    _description = "Task Work"
    _columns = {
        'name': fields.char('Work summary', size=128),
        'date': fields.datetime('Date'),
        'task_id': fields.many2one('project.task', 'Task', ondelete='cascade', required=True),
        'hours': fields.float('Time Spent'),
        'user_id': fields.many2one('res.users', 'Done by', required=True),
    }

...

In this code, you can see that in the project work you have a user_id but It will be more interesting to link the employee (from the hr module).

Here is the problem:
You have a company with a lot of external consultants, you don't want them as users but you need to encode the time spent by these external consultants on your project to invoice your customer...