Merge lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-change-carrier into lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-options-yvr

Proposed by Guewen Baconnier @ Camptocamp
Status: Merged
Merged at revision: 18
Proposed branch: lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-change-carrier
Merge into: lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-options-yvr
Diff against target: 44 lines (+37/-0)
1 file modified
delivery_carrier_label_dispatch/picking_dispatch.py (+37/-0)
To merge this branch: bzr merge lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-change-carrier
Reviewer Review Type Date Requested Status
Leonardo Pistone code review Approve
Yannick Vaucher @ Camptocamp Pending
Review via email: mp+208364@code.launchpad.net

Description of the change

Keep the options in sync with the carrier

To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote :

lgtm

review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'delivery_carrier_label_dispatch/picking_dispatch.py'
2--- delivery_carrier_label_dispatch/picking_dispatch.py 2014-01-17 15:52:29 +0000
3+++ delivery_carrier_label_dispatch/picking_dispatch.py 2014-02-26 13:23:27 +0000
4@@ -105,3 +105,40 @@
5 context=context)
6 res.update(default_value)
7 return res
8+
9+ def _values_with_carrier_options(self, cr, uid, values, context=None):
10+ values = values.copy()
11+ carrier_id = values.get('carrier_id')
12+ option_ids = values.get('option_ids')
13+ if carrier_id and not option_ids:
14+ res = self.carrier_id_change(cr, uid, [], carrier_id,
15+ context=context)
16+ option_ids = res.get('value', {}).get('option_ids')
17+ if option_ids:
18+ values.update(option_ids=[(6, 0, option_ids)])
19+ return values
20+
21+ def write(self, cr, uid, ids, values, context=None):
22+ """ Set the default options when the delivery method is changed.
23+
24+ So we are sure that the options are always in line with the
25+ current delivery method.
26+
27+ """
28+ values = self._values_with_carrier_options(cr, uid, values,
29+ context=context)
30+ return super(PickingDispatch, self).\
31+ write(cr, uid, ids, values, context=context)
32+
33+ def create(self, cr, uid, values, context=None):
34+ """ Set the default options when the delivery method is set on creation
35+
36+ So we are sure that the options are always in line with the
37+ current delivery method.
38+
39+ """
40+ values = self._values_with_carrier_options(cr, uid, values,
41+ context=context)
42+ dispatch_id = super(PickingDispatch, self).\
43+ create(cr, uid, values, context=context)
44+ return dispatch_id

Subscribers

People subscribed via source and target branches

to all changes: