@@ -12,11 +12,9 @@ class StockBatchPicking(models.Model):
12
12
13
13
_inherit = "stock.picking.batch"
14
14
15
- carrier_id = fields .Many2one (
16
- "delivery.carrier" , "Carrier" , states = {"done" : [("readonly" , True )]}
17
- )
18
- option_ids = fields .Many2many ("delivery.carrier.option" , string = "Options" )
19
-
15
+ carrier_id = fields .Many2one ("delivery.carrier" , "Carrier" )
16
+ option_ids = fields .Many2many ("delivery.carrier.option" , string = "Options" , compute = "_compute_carrier" ,
17
+ store = True , readonly = False )
20
18
def action_set_options (self ):
21
19
"""Apply options to picking of the batch
22
20
@@ -35,20 +33,22 @@ def _get_options_to_add(self, carrier=None):
35
33
options = carrier .available_option_ids
36
34
return options .filtered (lambda rec : rec .mandatory or rec .by_default )
37
35
38
- @api .onchange ("carrier_id" )
39
- def carrier_id_change (self ):
40
- """Inherit this method in your module"""
36
+ @api .onchange ('carrier_id' )
37
+ def _onchange_carrier (self ):
41
38
if self .carrier_id :
42
39
available_options = self .carrier_id .available_option_ids
43
- default_options = self ._get_options_to_add ()
44
- self .option_ids = [(6 , 0 , default_options .ids )]
45
- self .carrier_code = self .carrier_id .code
46
- return {
47
- "domain" : {
48
- "option_ids" : [("id" , "in" , available_options .ids )],
49
- }
50
- }
51
- return {}
40
+ domain = [("id" , "in" , available_options .ids )]
41
+ else :
42
+ domain = []
43
+ return {'domain' : {'option_ids' : domain }}
44
+
45
+ @api .depends ("carrier_id" )
46
+ def _compute_carrier (self ):
47
+ for batch in self :
48
+ if batch .carrier_id :
49
+ default_options = batch ._get_options_to_add ()
50
+ batch .option_ids = [(6 , 0 , default_options .ids )]
51
+ batch ._onchange_carrier ()
52
52
53
53
@api .onchange ("option_ids" )
54
54
def option_ids_change (self ):
@@ -58,15 +58,14 @@ def option_ids_change(self):
58
58
for available_option in self .carrier_id .available_option_ids :
59
59
if available_option .mandatory and available_option not in self .option_ids :
60
60
res ["warning" ] = {
61
- "title" : _ ("User Error !" ),
61
+ "title" : _ ("User Error!" ),
62
62
"message" : _ (
63
63
"You can not remove a mandatory option."
64
64
"\n Please reset options to default."
65
65
),
66
66
}
67
- # Due to https://github.com/odoo/odoo/issues/2693 we cannot
68
67
# reset options
69
- # self.option_ids = self._get_options_to_add()
68
+ self .option_ids = self ._get_options_to_add ()
70
69
return res
71
70
72
71
def _values_with_carrier_options (self , values ):
@@ -111,11 +110,6 @@ def purge_tracking_references(self):
111
110
packs = move_lines .result_package_id .filtered (lambda p : p .parcel_tracking )
112
111
if packs :
113
112
packs .write ({"parcel_tracking" : False })
114
- pickings = self .env ["stock.picking" ].search (
115
- [
116
- ("move_line_ids" , "in" , move_lines .ids ),
117
- ("carrier_tracking_ref" , "!=" , False ),
118
- ]
119
- )
113
+ pickings = self .env ["stock.picking" ].search ([("move_line_ids" , "in" , move_lines .ids ), ("carrier_tracking_ref" , "!=" , False )])
120
114
if pickings :
121
115
pickings .write ({"carrier_tracking_ref" : False })
0 commit comments