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
1=== modified file 'base_delivery_carrier_label/stock.py'
2--- base_delivery_carrier_label/stock.py 2014-01-15 13:13:55 +0000
3+++ base_delivery_carrier_label/stock.py 2014-02-26 13:32:24 +0000
4@@ -161,21 +161,39 @@
5 res.update(default_value)
6 return res
7
8- def create(self, cr, uid, values, context=None):
9- """ Trigger carrier_id_change on create
10-
11- To ensure options are setted on the basis of carrier_id copied from
12- Sale order or defined by default.
13-
14- """
15+ def _values_with_carrier_options(self, cr, uid, values, context=None):
16+ values = values.copy()
17 carrier_id = values.get('carrier_id')
18- if carrier_id:
19- picking_obj = self.pool.get('stock.picking')
20- res = picking_obj.carrier_id_change(cr, uid, [], carrier_id,
21- context=context)
22+ option_ids = values.get('option_ids')
23+ if carrier_id and not option_ids:
24+ res = self.carrier_id_change(cr, uid, [], carrier_id,
25+ context=context)
26 option_ids = res.get('value', {}).get('option_ids')
27 if option_ids:
28 values.update(option_ids=[(6, 0, option_ids)])
29+ return values
30+
31+ def write(self, cr, uid, ids, values, context=None):
32+ """ Set the default options when the delivery method is changed.
33+
34+ So we are sure that the options are always in line with the
35+ current delivery method.
36+
37+ """
38+ values = self._values_with_carrier_options(cr, uid, values,
39+ context=context)
40+ return super(stock_picking, self).\
41+ write(cr, uid, ids, values, context=context)
42+
43+ def create(self, cr, uid, values, context=None):
44+ """ Trigger carrier_id_change on create
45+
46+ To ensure options are setted on the basis of carrier_id copied from
47+ Sale order or defined by default.
48+
49+ """
50+ values = self._values_with_carrier_options(cr, uid, values,
51+ context=context)
52 picking_id = super(stock_picking, self
53 ).create(cr, uid, values, context=context)
54 return picking_id
55@@ -229,6 +247,33 @@
56 option_ids, carrier_id,
57 context=context)
58
59+ def write(self, cr, uid, ids, values, context=None):
60+ """ Set the default options when the delivery method is changed.
61+
62+ So we are sure that the options are always in line with the
63+ current delivery method.
64+
65+ """
66+ picking_obj = self.pool['stock.picking']
67+ values = picking_obj._values_with_carrier_options(cr, uid, values,
68+ context=context)
69+ return super(stock_picking_in, self).\
70+ write(cr, uid, ids, values, context=context)
71+
72+ def create(self, cr, uid, values, context=None):
73+ """ Trigger carrier_id_change on create
74+
75+ To ensure options are setted on the basis of carrier_id copied from
76+ Sale order or defined by default.
77+
78+ """
79+ picking_obj = self.pool['stock.picking']
80+ values = picking_obj._values_with_carrier_options(cr, uid, values,
81+ context=context)
82+ picking_id = super(stock_picking_in, self
83+ ).create(cr, uid, values, context=context)
84+ return picking_id
85+
86
87 class stock_picking_out(orm.Model):
88 """ Add what isn't inherited from stock.picking """
89@@ -275,6 +320,33 @@
90 option_ids, carrier_id,
91 context=context)
92
93+ def write(self, cr, uid, ids, values, context=None):
94+ """ Set the default options when the delivery method is changed.
95+
96+ So we are sure that the options are always in line with the
97+ current delivery method.
98+
99+ """
100+ picking_obj = self.pool['stock.picking']
101+ values = picking_obj._values_with_carrier_options(cr, uid, values,
102+ context=context)
103+ return super(stock_picking_out, self).\
104+ write(cr, uid, ids, values, context=context)
105+
106+ def create(self, cr, uid, values, context=None):
107+ """ Trigger carrier_id_change on create
108+
109+ To ensure options are setted on the basis of carrier_id copied from
110+ Sale order or defined by default.
111+
112+ """
113+ picking_obj = self.pool['stock.picking']
114+ values = picking_obj._values_with_carrier_options(cr, uid, values,
115+ context=context)
116+ picking_id = super(stock_picking_out, self
117+ ).create(cr, uid, values, context=context)
118+ return picking_id
119+
120
121 class ShippingLabel(orm.Model):
122 """ Child class of ir attachment to identify which are labels """

Subscribers

People subscribed via source and target branches