← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier into lp:carriers-deliveries

 

Guewen Baconnier @ Camptocamp has proposed merging lp:~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier into lp:carriers-deliveries.

Requested reviews:
  Stock and Logistic Core Editors (stock-logistic-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier/+merge/208367

The options are strongly related to the selected carrier.
When the carrier is modified by a user from the views, the onchange set the correct options, that the user might modify.
However, when the carrier is modified directly from a write / create (and the call does not set the according options), we must ensure that the correct options for the carrier are set.
-- 
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier/+merge/208367
Your team Stock and Logistic Core Editors is requested to review the proposed merge of lp:~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier into lp:carriers-deliveries.
=== modified file 'base_delivery_carrier_label/stock.py'
--- base_delivery_carrier_label/stock.py	2014-01-15 13:13:55 +0000
+++ base_delivery_carrier_label/stock.py	2014-02-26 13:32:24 +0000
@@ -161,21 +161,39 @@
                 res.update(default_value)
         return res
 
-    def create(self, cr, uid, values, context=None):
-        """ Trigger carrier_id_change on create
-
-        To ensure options are setted on the basis of carrier_id copied from
-        Sale order or defined by default.
-
-        """
+    def _values_with_carrier_options(self, cr, uid, values, context=None):
+        values = values.copy()
         carrier_id = values.get('carrier_id')
-        if carrier_id:
-            picking_obj = self.pool.get('stock.picking')
-            res = picking_obj.carrier_id_change(cr, uid, [], carrier_id,
-                                                context=context)
+        option_ids = values.get('option_ids')
+        if carrier_id and not option_ids:
+            res = self.carrier_id_change(cr, uid, [], carrier_id,
+                                         context=context)
             option_ids = res.get('value', {}).get('option_ids')
             if option_ids:
                 values.update(option_ids=[(6, 0, option_ids)])
+        return values
+
+    def write(self, cr, uid, ids, values, context=None):
+        """ Set the default options when the delivery method is changed.
+
+        So we are sure that the options are always in line with the
+        current delivery method.
+
+        """
+        values = self._values_with_carrier_options(cr, uid, values,
+                                                   context=context)
+        return super(stock_picking, self).\
+            write(cr, uid, ids, values, context=context)
+
+    def create(self, cr, uid, values, context=None):
+        """ Trigger carrier_id_change on create
+
+        To ensure options are setted on the basis of carrier_id copied from
+        Sale order or defined by default.
+
+        """
+        values = self._values_with_carrier_options(cr, uid, values,
+                                                   context=context)
         picking_id = super(stock_picking, self
                     ).create(cr, uid, values, context=context)
         return picking_id
@@ -229,6 +247,33 @@
                                              option_ids, carrier_id,
                                              context=context)
 
+    def write(self, cr, uid, ids, values, context=None):
+        """ Set the default options when the delivery method is changed.
+
+        So we are sure that the options are always in line with the
+        current delivery method.
+
+        """
+        picking_obj = self.pool['stock.picking']
+        values = picking_obj._values_with_carrier_options(cr, uid, values,
+                                                          context=context)
+        return super(stock_picking_in, self).\
+            write(cr, uid, ids, values, context=context)
+
+    def create(self, cr, uid, values, context=None):
+        """ Trigger carrier_id_change on create
+
+        To ensure options are setted on the basis of carrier_id copied from
+        Sale order or defined by default.
+
+        """
+        picking_obj = self.pool['stock.picking']
+        values = picking_obj._values_with_carrier_options(cr, uid, values,
+                                                          context=context)
+        picking_id = super(stock_picking_in, self
+                    ).create(cr, uid, values, context=context)
+        return picking_id
+
 
 class stock_picking_out(orm.Model):
     """ Add what isn't inherited from stock.picking """
@@ -275,6 +320,33 @@
                                              option_ids, carrier_id,
                                              context=context)
 
+    def write(self, cr, uid, ids, values, context=None):
+        """ Set the default options when the delivery method is changed.
+
+        So we are sure that the options are always in line with the
+        current delivery method.
+
+        """
+        picking_obj = self.pool['stock.picking']
+        values = picking_obj._values_with_carrier_options(cr, uid, values,
+                                                          context=context)
+        return super(stock_picking_out, self).\
+            write(cr, uid, ids, values, context=context)
+
+    def create(self, cr, uid, values, context=None):
+        """ Trigger carrier_id_change on create
+
+        To ensure options are setted on the basis of carrier_id copied from
+        Sale order or defined by default.
+
+        """
+        picking_obj = self.pool['stock.picking']
+        values = picking_obj._values_with_carrier_options(cr, uid, values,
+                                                          context=context)
+        picking_id = super(stock_picking_out, self
+                    ).create(cr, uid, values, context=context)
+        return picking_id
+
 
 class ShippingLabel(orm.Model):
     """ Child class of ir attachment to identify which are labels """


Follow ups