Skip to content

Commit c214bce

Browse files
author
ilo
committed
[18.0] Migrate delivery_carrier_label_batch
1 parent 2cdf842 commit c214bce

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

delivery_carrier_label_batch/__manifest__.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
33
{
44
"name": "Carrier labels - Stock Batch Picking (link)",
5-
"version": "14.0.1.1.1",
5+
"version": "18.0.1.1.1",
66
"author": "Camptocamp,Odoo Community Association (OCA)",
77
"maintainer": "Camptocamp",
88
"category": "Carrier",
99
"complexity": "normal",
10-
"depends": ["base_delivery_carrier_label", "stock_picking_batch_extended"],
10+
"depends": [
11+
# "base_delivery_carrier_label",
12+
"delivery_carrier_option",
13+
"delivery_carrier_package_info",
14+
# OCA/stock-logistics-workflow
15+
"stock_picking_batch_extended"
16+
],
1117
"website": "https://github.com/OCA/delivery-carrier",
1218
"data": [
1319
"data/ir.config_parameter.xml",

delivery_carrier_label_batch/models/stock_batch_picking.py

+20-26
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ class StockBatchPicking(models.Model):
1212

1313
_inherit = "stock.picking.batch"
1414

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)
2018
def action_set_options(self):
2119
"""Apply options to picking of the batch
2220
@@ -35,20 +33,22 @@ def _get_options_to_add(self, carrier=None):
3533
options = carrier.available_option_ids
3634
return options.filtered(lambda rec: rec.mandatory or rec.by_default)
3735

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):
4138
if self.carrier_id:
4239
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()
5252

5353
@api.onchange("option_ids")
5454
def option_ids_change(self):
@@ -58,15 +58,14 @@ def option_ids_change(self):
5858
for available_option in self.carrier_id.available_option_ids:
5959
if available_option.mandatory and available_option not in self.option_ids:
6060
res["warning"] = {
61-
"title": _("User Error !"),
61+
"title": _("User Error!"),
6262
"message": _(
6363
"You can not remove a mandatory option."
6464
"\nPlease reset options to default."
6565
),
6666
}
67-
# Due to https://github.com/odoo/odoo/issues/2693 we cannot
6867
# reset options
69-
# self.option_ids = self._get_options_to_add()
68+
self.option_ids = self._get_options_to_add()
7069
return res
7170

7271
def _values_with_carrier_options(self, values):
@@ -111,11 +110,6 @@ def purge_tracking_references(self):
111110
packs = move_lines.result_package_id.filtered(lambda p: p.parcel_tracking)
112111
if packs:
113112
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)])
120114
if pickings:
121115
pickings.write({"carrier_tracking_ref": False})

delivery_carrier_label_batch/views/stock_batch_picking.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<page name="carrier" string="Carrier Info">
1313
<separator string="Delivery" />
1414
<group>
15-
<field name="carrier_id" />
15+
<field name="carrier_id" readonly="state == 'done'"/>
1616
</group>
1717
<separator string="Options" />
1818
<field name="option_ids" nolabel="1" />

0 commit comments

Comments
 (0)