Review: Needs Fixing

The code is correct, but obscure.  I would like to clarify and simplify it.

By the way, searching for a project's name (diff line 18) when you have its id 
is bogus!

First, line.product_id and procurement.product_id should be the same, right?  
So I suggest to first check for the product's associated project, i.e., 
procurement.product_id.project_id.  If it doesn't exist, then check for the 
sales order's associated project.  I suggest the following code to determine 
project_id:

        # project_id = the product's associated project if it exists,
        #              the sales order's associated project otherwise
        if procurement.product_id.project_id:
            project_id = procurement.product_id.project_id.id
        else:
            project_id = False
            line_ids = line_pool.search(cr, uid , [('procurement_id', '=', 
procurement.id)])
            for line in line_pool.browse(cr, uid, line_ids):
                if line.order_id.project_id:
                    project_id = line.order_id.project_id.id
                    break

I think it should be 100% equivalent, and to me it's more penetrable (specially 
with the comment).

What do you think?  Isn't it better (and more efficient, by the way)?

Thanks,
Raphael

-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-821261-jam/+merge/71321
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-821261-jam.

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to