← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase into lp:purchase-wkfl

 

Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase into lp:purchase-wkfl.

Commit message:
Portage of module mrp_smart_purchase to v7

Requested reviews:
  Purchase Core Editors (purchase-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase/+merge/213295
-- 
https://code.launchpad.net/~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase/+merge/213295
Your team Purchase Core Editors is requested to review the proposed merge of lp:~camptocamp/purchase-wkfl/7.0-port-mrp_smart_purchase into lp:purchase-wkfl.
=== modified file 'mrp_smart_purchase/__openerp__.py'
--- mrp_smart_purchase/__openerp__.py	2013-02-08 16:17:30 +0000
+++ mrp_smart_purchase/__openerp__.py	2014-03-28 16:15:30 +0000
@@ -20,18 +20,29 @@
 ##############################################################################
 {'name' : 'Smart MRP Purchase based on supplier price',
  'version' : '0.2',
+ 'category': 'MRP',
  'author' : 'Camptocamp',
  'maintainer': 'Camptocamp',
- 'category': 'version',
- 'complexity': "normal",  # easy, normal, expert
+ 'complexity': 'normal',
  'depends' : ['mrp', 'product', 'purchase'],
- 'description': """This Module will try to get the lower price for given quantity in PO""",
+ 'description': """
+Smart MRP Purchase based on supplier price
+==========================================
+
+This module will try to get the lowest price for given quantity in a
+Purchase Order
+
+
+ Contributors:
+ -------------
+
+  * Nicolas Bessi <nicolas.bessi@xxxxxxxxxxxxxx>
+
+""",
  'website': 'http://www.camptocamp.com',
- 'init_xml': [],
- 'update_xml': [],
- 'demo_xml': [],
- 'tests': [],
- 'installable': False,
+ 'data': [],
+ 'test': [],
+ 'installable': True,
  'auto_install': False,
  'license': 'AGPL-3',
  'application': True}

=== modified file 'mrp_smart_purchase/mrp_smart_purchase.py'
--- mrp_smart_purchase/mrp_smart_purchase.py	2012-07-24 12:27:35 +0000
+++ mrp_smart_purchase/mrp_smart_purchase.py	2014-03-28 16:15:30 +0000
@@ -20,26 +20,33 @@
 ##############################################################################
 from openerp.osv.orm import Model
 
+
 class MrpProcurement(Model):
-    """Mrp Procurement we override action_po assing to get the cheapest supplier,
-     if you want to change priority parameters just change the  _supplier_to_tuple function
-    TODO remove hack if merge proposal accepted look in action_po_assing for details"""
+    """Mrp Procurement we override action_po assing to get the cheapest
+    supplier, if you want to change priority parameters just change the
+    _supplier_to_tuple function
+
+    TODO remove hack by making a merge proposal
+    look in action_po_assign for details"""
 
     _inherit = "procurement.order"
 
-    def action_po_assign(self, cursor, uid, ids, context=None):
-        context = context or {}
-        # stack is prduct id : qty
-        # this is a hack beacause make_po hase no function
+    def action_po_assign(self, cr, uid, ids, context=None):
+        if context is None:
+            context = {}
+        # stack is product id : qty
+        # this is a hack because make_po has no function
         # get supplier so I pass requiered data in context
-        # I know that sucks but OpenEPR wont change this function in stable relase
-        # Merge proposal for trunkis running
+        # I know that sucks but OpenERP won't change this function in stable
+        # release
         context['smart_mrp_stack'] = {}
-        for proc in self.browse(cursor, uid, ids, context):
+        for proc in self.browse(cr, uid, ids, context=context):
             context['smart_mrp_stack'][proc.product_id.id] = proc.product_qty
-        res = super(MrpProcurement, self).action_po_assign(cursor, uid, ids, context=context)
+        res = super(MrpProcurement, self
+                    ).action_po_assign(cr, uid, ids, context=context)
         return res
 
+
 class ProductTemplate(Model):
     """ We overrride the get_main_supplier function
     that is used to retrieve supplier in function fields"""
@@ -47,39 +54,49 @@
     _name = "product.template"
     _inherit = "product.template"
 
-
-    def _supplier_to_tuple(self, cursor, uid, supplier_id, price, product_id):
+    def _supplier_to_tuple(self, cr, uid, supplier_id, price, product_id,
+                           context=None):
         """ Generate an tuple that can be sorted """
-        # This is not the most performat way but it allows easy overriding
-        # the faster solution will be to populate a mapping hash in _get_main_product_supplier
-        info_obj = self.pool.get('product.supplierinfo')
-        info_id = info_obj.search(cursor, uid, [('product_id', '=', product_id),
-                                                ('name', '=', supplier_id)], order='sequence')[0]
-        info = info_obj.browse(cursor, uid, info_id)
+        # This is not the most performant way but it allows easy overriding
+        # the faster solution will be to populate a mapping hash in
+        # _get_main_product_supplier
+        info_obj = self.pool['product.supplierinfo']
+        info_id = info_obj.search(cr, uid,
+                                  [('product_id', '=', product_id),
+                                   ('name', '=', supplier_id)],
+                                  order='sequence',
+                                  context=context)[0]
+        info = info_obj.browse(cr, uid, info_id, context=context)
         res_tuple = (price, info.delay, info.sequence or 10000, info.id)
         return res_tuple
-        
 
-    def _get_main_product_supplier(self, cursor, uid, product, context=None):
+    def _get_main_product_supplier(self, cr, uid, product, context=None):
         """Determines the main (best) product supplier for ``product``,
         using smart_mrp_stack in context to determine qty else it uses sequence
         """
-        info_obj = self.pool.get('product.supplierinfo')
-        context = context or {}
-        smart_mrp_stack =  context.get('smart_mrp_stack', {})
+        if context is None:
+            context = {}
+        info_obj = self.pool['product.supplierinfo']
+        smart_mrp_stack = context.get('smart_mrp_stack', {})
         if product.id in smart_mrp_stack:
             ## we look for best prices based on supplier info
-            sellers =  product.seller_ids
+            sellers = product.seller_ids
             supplier_ids = [x.name.id for x in sellers]
             qty = smart_mrp_stack.get(product.id, 1)
-            best_prices_persupplier = info_obj.price_get(cursor, uid, supplier_ids,
-                                                         product.id, qty, context=context)
+            best_prices_persupplier = info_obj.price_get(
+                cr, uid, supplier_ids,
+                product.id, qty, context=context)
             #Assmuption to sort price is more important than delay
             final_choice = []
             for supp, price in best_prices_persupplier.items():
-                final_choice.append(self._supplier_to_tuple(cursor, uid, supp, price, product.id))
+                final_choice.append(self._supplier_to_tuple(cr, uid, supp,
+                                                            price, product.id,
+                                                            context=context))
             final_choice.sort()
-            return info_obj.browse(cursor, uid, final_choice[0][3])
+            return info_obj.browse(cr, uid, final_choice[0][3],
+                                   context=context)
         else:
-            return super(ProductTemplate, self)._get_main_product_supplier(cursor, uid, product, context)
+            return super(ProductTemplate, self
+                         )._get_main_product_supplier(cr, uid, product,
+                                                      context=context)
         return False


References