Merge lp:~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase into lp:~purchase-core-editors/purchase-wkfl/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Needs review
Proposed branch: lp:~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase
Merge into: lp:~purchase-core-editors/purchase-wkfl/7.0
Diff against target: 159 lines (+66/-38)
2 files modified
mrp_smart_purchase/__openerp__.py (+19/-8)
mrp_smart_purchase/mrp_smart_purchase.py (+47/-30)
To merge this branch: bzr merge lp:~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Resubmitting
Review via email: mp+213295@code.launchpad.net

Commit message

Portage of module mrp_smart_purchase to v7

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

This project is now hosted on https://github.com/OCA/purchase-workflow. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting

Unmerged revisions

31. By Yannick Vaucher @ Camptocamp on 2014-03-28

Portage of module mrp_smart_purchase to v7

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mrp_smart_purchase/__openerp__.py'
2--- mrp_smart_purchase/__openerp__.py 2013-02-08 16:17:30 +0000
3+++ mrp_smart_purchase/__openerp__.py 2014-03-28 16:15:30 +0000
4@@ -20,18 +20,29 @@
5 ##############################################################################
6 {'name' : 'Smart MRP Purchase based on supplier price',
7 'version' : '0.2',
8+ 'category': 'MRP',
9 'author' : 'Camptocamp',
10 'maintainer': 'Camptocamp',
11- 'category': 'version',
12- 'complexity': "normal", # easy, normal, expert
13+ 'complexity': 'normal',
14 'depends' : ['mrp', 'product', 'purchase'],
15- 'description': """This Module will try to get the lower price for given quantity in PO""",
16+ 'description': """
17+Smart MRP Purchase based on supplier price
18+==========================================
19+
20+This module will try to get the lowest price for given quantity in a
21+Purchase Order
22+
23+
24+ Contributors:
25+ -------------
26+
27+ * Nicolas Bessi <nicolas.bessi@camptocamp.com>
28+
29+""",
30 'website': 'http://www.camptocamp.com',
31- 'init_xml': [],
32- 'update_xml': [],
33- 'demo_xml': [],
34- 'tests': [],
35- 'installable': False,
36+ 'data': [],
37+ 'test': [],
38+ 'installable': True,
39 'auto_install': False,
40 'license': 'AGPL-3',
41 'application': True}
42
43=== modified file 'mrp_smart_purchase/mrp_smart_purchase.py'
44--- mrp_smart_purchase/mrp_smart_purchase.py 2012-07-24 12:27:35 +0000
45+++ mrp_smart_purchase/mrp_smart_purchase.py 2014-03-28 16:15:30 +0000
46@@ -20,26 +20,33 @@
47 ##############################################################################
48 from openerp.osv.orm import Model
49
50+
51 class MrpProcurement(Model):
52- """Mrp Procurement we override action_po assing to get the cheapest supplier,
53- if you want to change priority parameters just change the _supplier_to_tuple function
54- TODO remove hack if merge proposal accepted look in action_po_assing for details"""
55+ """Mrp Procurement we override action_po assing to get the cheapest
56+ supplier, if you want to change priority parameters just change the
57+ _supplier_to_tuple function
58+
59+ TODO remove hack by making a merge proposal
60+ look in action_po_assign for details"""
61
62 _inherit = "procurement.order"
63
64- def action_po_assign(self, cursor, uid, ids, context=None):
65- context = context or {}
66- # stack is prduct id : qty
67- # this is a hack beacause make_po hase no function
68+ def action_po_assign(self, cr, uid, ids, context=None):
69+ if context is None:
70+ context = {}
71+ # stack is product id : qty
72+ # this is a hack because make_po has no function
73 # get supplier so I pass requiered data in context
74- # I know that sucks but OpenEPR wont change this function in stable relase
75- # Merge proposal for trunkis running
76+ # I know that sucks but OpenERP won't change this function in stable
77+ # release
78 context['smart_mrp_stack'] = {}
79- for proc in self.browse(cursor, uid, ids, context):
80+ for proc in self.browse(cr, uid, ids, context=context):
81 context['smart_mrp_stack'][proc.product_id.id] = proc.product_qty
82- res = super(MrpProcurement, self).action_po_assign(cursor, uid, ids, context=context)
83+ res = super(MrpProcurement, self
84+ ).action_po_assign(cr, uid, ids, context=context)
85 return res
86
87+
88 class ProductTemplate(Model):
89 """ We overrride the get_main_supplier function
90 that is used to retrieve supplier in function fields"""
91@@ -47,39 +54,49 @@
92 _name = "product.template"
93 _inherit = "product.template"
94
95-
96- def _supplier_to_tuple(self, cursor, uid, supplier_id, price, product_id):
97+ def _supplier_to_tuple(self, cr, uid, supplier_id, price, product_id,
98+ context=None):
99 """ Generate an tuple that can be sorted """
100- # This is not the most performat way but it allows easy overriding
101- # the faster solution will be to populate a mapping hash in _get_main_product_supplier
102- info_obj = self.pool.get('product.supplierinfo')
103- info_id = info_obj.search(cursor, uid, [('product_id', '=', product_id),
104- ('name', '=', supplier_id)], order='sequence')[0]
105- info = info_obj.browse(cursor, uid, info_id)
106+ # This is not the most performant way but it allows easy overriding
107+ # the faster solution will be to populate a mapping hash in
108+ # _get_main_product_supplier
109+ info_obj = self.pool['product.supplierinfo']
110+ info_id = info_obj.search(cr, uid,
111+ [('product_id', '=', product_id),
112+ ('name', '=', supplier_id)],
113+ order='sequence',
114+ context=context)[0]
115+ info = info_obj.browse(cr, uid, info_id, context=context)
116 res_tuple = (price, info.delay, info.sequence or 10000, info.id)
117 return res_tuple
118-
119
120- def _get_main_product_supplier(self, cursor, uid, product, context=None):
121+ def _get_main_product_supplier(self, cr, uid, product, context=None):
122 """Determines the main (best) product supplier for ``product``,
123 using smart_mrp_stack in context to determine qty else it uses sequence
124 """
125- info_obj = self.pool.get('product.supplierinfo')
126- context = context or {}
127- smart_mrp_stack = context.get('smart_mrp_stack', {})
128+ if context is None:
129+ context = {}
130+ info_obj = self.pool['product.supplierinfo']
131+ smart_mrp_stack = context.get('smart_mrp_stack', {})
132 if product.id in smart_mrp_stack:
133 ## we look for best prices based on supplier info
134- sellers = product.seller_ids
135+ sellers = product.seller_ids
136 supplier_ids = [x.name.id for x in sellers]
137 qty = smart_mrp_stack.get(product.id, 1)
138- best_prices_persupplier = info_obj.price_get(cursor, uid, supplier_ids,
139- product.id, qty, context=context)
140+ best_prices_persupplier = info_obj.price_get(
141+ cr, uid, supplier_ids,
142+ product.id, qty, context=context)
143 #Assmuption to sort price is more important than delay
144 final_choice = []
145 for supp, price in best_prices_persupplier.items():
146- final_choice.append(self._supplier_to_tuple(cursor, uid, supp, price, product.id))
147+ final_choice.append(self._supplier_to_tuple(cr, uid, supp,
148+ price, product.id,
149+ context=context))
150 final_choice.sort()
151- return info_obj.browse(cursor, uid, final_choice[0][3])
152+ return info_obj.browse(cr, uid, final_choice[0][3],
153+ context=context)
154 else:
155- return super(ProductTemplate, self)._get_main_product_supplier(cursor, uid, product, context)
156+ return super(ProductTemplate, self
157+ )._get_main_product_supplier(cr, uid, product,
158+ context=context)
159 return False

Subscribers

People subscribed via source and target branches