Merge lp:~akretion-team/openobject-addons/hook-for-purchase-order into lp:openobject-addons

Proposed by Sébastien BEAU - http://www.akretion.com
Status: Merged
Merged at revision: 4959
Proposed branch: lp:~akretion-team/openobject-addons/hook-for-purchase-order
Merge into: lp:openobject-addons
Diff against target: 70 lines (+19/-12)
1 file modified
purchase/purchase.py (+19/-12)
To merge this branch: bzr merge lp:~akretion-team/openobject-addons/hook-for-purchase-order
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Approve
Raphaël Valyi - http://www.akretion.com (community) Approve
Joël Grand-Guillaume @ camptocamp (community) Approve
Review via email: mp+66979@code.launchpad.net

Description of the change

For the module sale_bundle_product http://bazaar.launchpad.net/~openerp-commiter/openobject-addons/extra-6.0/files/head:/sale_bundle_product/
We need to add some field in the line before creating the PO.
I propose a generic merge which allow to modify the purchase order line and to modify the purchase order (needed for brasilian localisation) before creating the PO

Thanks to merge it

To post a comment you must log in.
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

+1 for this merge ! Thanks for your work Sébastien

review: Approve
Revision history for this message
Raphaël Valyi - http://www.akretion.com (rvalyi) wrote :

Hello, I helped Sebastien shaping that merge proposal, so of course I approve it.

BTW, I think we need more of such refactoring where:
1) we split large mehods into smaller overridable ones
2) we give a chance to overriders to change as many things as possible BEFORE writing anything into the database. Currently, there are many places in OpenERP where the multiplication of overriders accross extension modules tend to generate may be 5x too many database access in a given method. So we need more of such refactoring before 6.1 is out. For instance, we will now be happy to override that purchase order generation for the Brazilian localization as we need it; now we will have a clean way to do it too.

review: Approve
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Works for me, well done!

I would add a docstring on the new method to make a little more obvious what it's supposed to do and what are the arguments. Sebastien, if you can add it it'd be great (see recent reviews for guidelines/example of the format, e.g.[1]), otherwise we'll add it after the merge.

Thanks!

[1] https://code.launchpad.net/~openerp-community/openobject-addons/stefan-therp_lp794584/+merge/63872

review: Approve
Revision history for this message
Sébastien BEAU - http://www.akretion.com (sebastien.beau) wrote :

Hi Olivier
I add the doc string, it's ok for you?
Thanks for merging it.
Have a good day

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Yes it's fine like that, thanks!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'purchase/purchase.py'
2--- purchase/purchase.py 2011-07-22 13:00:50 +0000
3+++ purchase/purchase.py 2011-08-24 22:34:31 +0000
4@@ -761,6 +761,17 @@
5 res = res.values()
6 return len(res) and res[0] or 0 #TO CHECK: why workflow is generated error if return not integer value
7
8+ def create_procurement_purchase_order(self, cr, uid, procurement, po_vals, line, context=None):
9+ """ Create the purchase order from the procurement
10+ :params procurement: the procurement object generating the purchase order
11+ :params dict po_vals: the values of the purchase order
12+ :params dict line: the values of the purchase order line
13+ :return: purchase order id
14+ :rtype: int
15+ """
16+ po_vals.update({'order_line': [(0,0,line)]})
17+ return self.pool.get('purchase.order').create(cr, uid, po_vals, context=context)
18+
19 def make_po(self, cr, uid, ids, context=None):
20 """ Make purchase order from procurement
21 @return: New created Purchase Orders procurement wise
22@@ -774,7 +785,6 @@
23 pricelist_obj = self.pool.get('product.pricelist')
24 prod_obj = self.pool.get('product.product')
25 acc_pos_obj = self.pool.get('account.fiscal.position')
26- po_obj = self.pool.get('purchase.order')
27 for procurement in self.browse(cr, uid, ids, context=context):
28 res_id = procurement.move_id.id
29 partner = procurement.product_id.seller_id # Taken Main Supplier of Product of Procurement.
30@@ -799,6 +809,8 @@
31 context.update({'lang': partner.lang, 'partner_id': partner_id})
32
33 product = prod_obj.browse(cr, uid, procurement.product_id.id, context=context)
34+ taxes_ids = procurement.product_id.product_tmpl_id.supplier_taxes_id
35+ taxes = acc_pos_obj.map_tax(cr, uid, partner.property_account_position, taxes_ids)
36
37 line = {
38 'name': product.partner_ref,
39@@ -809,25 +821,20 @@
40 'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
41 'move_dest_id': res_id,
42 'notes': product.description_purchase,
43+ 'taxes_id': [(6,0,taxes)],
44 }
45-
46- taxes_ids = procurement.product_id.product_tmpl_id.supplier_taxes_id
47- taxes = acc_pos_obj.map_tax(cr, uid, partner.property_account_position, taxes_ids)
48- line.update({
49- 'taxes_id': [(6,0,taxes)]
50- })
51- purchase_id = po_obj.create(cr, uid, {
52+
53+ po_vals = {
54 'origin': procurement.origin,
55 'partner_id': partner_id,
56 'partner_address_id': address_id,
57 'location_id': procurement.location_id.id,
58 'pricelist_id': pricelist_id,
59- 'order_line': [(0,0,line)],
60 'company_id': procurement.company_id.id,
61 'fiscal_position': partner.property_account_position and partner.property_account_position.id or False
62- })
63- res[procurement.id] = purchase_id
64- self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': purchase_id})
65+ }
66+ res[procurement.id] = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line, context=context)
67+ self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': res[procurement.id]})
68 return res
69
70 procurement_order()

Subscribers

People subscribed via source and target branches

to all changes: