Merge lp:~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier into lp:~stock-logistic-core-editors/carriers-deliveries/7.0

Proposed by Guewen Baconnier @ Camptocamp
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 11
Merged at revision: 27
Proposed branch: lp:~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier
Merge into: lp:~stock-logistic-core-editors/carriers-deliveries/7.0
Diff against target: 122 lines (+83/-11)
1 file modified
base_delivery_carrier_label/stock.py (+83/-11)
To merge this branch: bzr merge lp:~camptocamp/carriers-deliveries/7.0-base_delivery_carrier_label-change-carrier
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) no test, code review Approve
Yannick Vaucher @ Camptocamp code review, no tests Approve
Review via email: mp+208367@code.launchpad.net

Commit message

Set the default options of the delivery method when it is changed and the options are not set (typically a write from the code or a mass update)

Description of the change

The options are strongly related to the selected carrier. A selected option could have no reason to be on a carrier or another option could be required.

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.

To post a comment you must log in.
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM

review: Approve (code review, no tests)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

A lot of code repretition but no real clean alternative with those out/in/internal stock picking model.

LGTM

Nicolas

review: Approve (no test, code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
161 res.update(default_value)161 res.update(default_value)
162 return res162 return res
163163
164 def create(self, cr, uid, values, context=None):164 def _values_with_carrier_options(self, cr, uid, values, context=None):
165 """ Trigger carrier_id_change on create165 values = values.copy()
166
167 To ensure options are setted on the basis of carrier_id copied from
168 Sale order or defined by default.
169
170 """
171 carrier_id = values.get('carrier_id')166 carrier_id = values.get('carrier_id')
172 if carrier_id:167 option_ids = values.get('option_ids')
173 picking_obj = self.pool.get('stock.picking')168 if carrier_id and not option_ids:
174 res = picking_obj.carrier_id_change(cr, uid, [], carrier_id,169 res = self.carrier_id_change(cr, uid, [], carrier_id,
175 context=context)170 context=context)
176 option_ids = res.get('value', {}).get('option_ids')171 option_ids = res.get('value', {}).get('option_ids')
177 if option_ids:172 if option_ids:
178 values.update(option_ids=[(6, 0, option_ids)])173 values.update(option_ids=[(6, 0, option_ids)])
174 return values
175
176 def write(self, cr, uid, ids, values, context=None):
177 """ Set the default options when the delivery method is changed.
178
179 So we are sure that the options are always in line with the
180 current delivery method.
181
182 """
183 values = self._values_with_carrier_options(cr, uid, values,
184 context=context)
185 return super(stock_picking, self).\
186 write(cr, uid, ids, values, context=context)
187
188 def create(self, cr, uid, values, context=None):
189 """ Trigger carrier_id_change on create
190
191 To ensure options are setted on the basis of carrier_id copied from
192 Sale order or defined by default.
193
194 """
195 values = self._values_with_carrier_options(cr, uid, values,
196 context=context)
179 picking_id = super(stock_picking, self197 picking_id = super(stock_picking, self
180 ).create(cr, uid, values, context=context)198 ).create(cr, uid, values, context=context)
181 return picking_id199 return picking_id
@@ -229,6 +247,33 @@
229 option_ids, carrier_id,247 option_ids, carrier_id,
230 context=context)248 context=context)
231249
250 def write(self, cr, uid, ids, values, context=None):
251 """ Set the default options when the delivery method is changed.
252
253 So we are sure that the options are always in line with the
254 current delivery method.
255
256 """
257 picking_obj = self.pool['stock.picking']
258 values = picking_obj._values_with_carrier_options(cr, uid, values,
259 context=context)
260 return super(stock_picking_in, self).\
261 write(cr, uid, ids, values, context=context)
262
263 def create(self, cr, uid, values, context=None):
264 """ Trigger carrier_id_change on create
265
266 To ensure options are setted on the basis of carrier_id copied from
267 Sale order or defined by default.
268
269 """
270 picking_obj = self.pool['stock.picking']
271 values = picking_obj._values_with_carrier_options(cr, uid, values,
272 context=context)
273 picking_id = super(stock_picking_in, self
274 ).create(cr, uid, values, context=context)
275 return picking_id
276
232277
233class stock_picking_out(orm.Model):278class stock_picking_out(orm.Model):
234 """ Add what isn't inherited from stock.picking """279 """ Add what isn't inherited from stock.picking """
@@ -275,6 +320,33 @@
275 option_ids, carrier_id,320 option_ids, carrier_id,
276 context=context)321 context=context)
277322
323 def write(self, cr, uid, ids, values, context=None):
324 """ Set the default options when the delivery method is changed.
325
326 So we are sure that the options are always in line with the
327 current delivery method.
328
329 """
330 picking_obj = self.pool['stock.picking']
331 values = picking_obj._values_with_carrier_options(cr, uid, values,
332 context=context)
333 return super(stock_picking_out, self).\
334 write(cr, uid, ids, values, context=context)
335
336 def create(self, cr, uid, values, context=None):
337 """ Trigger carrier_id_change on create
338
339 To ensure options are setted on the basis of carrier_id copied from
340 Sale order or defined by default.
341
342 """
343 picking_obj = self.pool['stock.picking']
344 values = picking_obj._values_with_carrier_options(cr, uid, values,
345 context=context)
346 picking_id = super(stock_picking_out, self
347 ).create(cr, uid, values, context=context)
348 return picking_id
349
278350
279class ShippingLabel(orm.Model):351class ShippingLabel(orm.Model):
280 """ Child class of ir attachment to identify which are labels """352 """ Child class of ir attachment to identify which are labels """

Subscribers

People subscribed via source and target branches