Skip to content

Commit 5aab4b7

Browse files
committed
[MIG] sale_product_pack: Migration to 19.0 and code review
1 parent 1b614f5 commit 5aab4b7

File tree

4 files changed

+34
-24
lines changed

4 files changed

+34
-24
lines changed

sale_product_pack/models/product_pack_line.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ def get_sale_order_line_vals(self, line, order):
2424
"pack_modifiable": line.product_id.pack_modifiable,
2525
"product_uom_qty": quantity,
2626
}
27-
sol = line.new(line_vals)
28-
vals = sol._convert_to_write(sol._cache)
2927
pack_price_types = {"totalized", "ignored"}
3028
if (
3129
line.product_id.pack_type == "detailed"
3230
and line.product_id.pack_component_price in pack_price_types
3331
):
34-
vals["price_unit"] = 0.0
35-
36-
vals["name"] = f"{'> ' * (line.pack_depth + 1)}{sol.name}"
37-
38-
return vals
32+
line_vals["price_unit"] = 0.0
33+
return line_vals
3934

4035
def _get_pack_line_price(self, pricelist, quantity, uom=None, date=False, **kwargs):
4136
return super()._get_pack_line_price(

sale_product_pack/models/sale_order.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@
77
class SaleOrder(models.Model):
88
_inherit = "sale.order"
99

10-
def copy(self, default=None):
11-
sale_copy = super().copy(default)
12-
for record in self:
13-
# we unlink pack lines that should not be copied
14-
pack_copied_lines = sale_copy.order_line.filtered(
15-
lambda x, order=record: x.pack_parent_line_id.order_id == order
16-
)
17-
if pack_copied_lines:
18-
pack_copied_lines.unlink()
19-
return sale_copy
10+
def _get_copiable_order_lines(self):
11+
self.ensure_one()
12+
res = super()._get_copiable_order_lines()
13+
return res.filtered(
14+
lambda x, order=self: x.pack_parent_line_id.order_id != order
15+
)
2016

2117
@api.onchange("order_line")
2218
def check_pack_line_unlink(self):
@@ -58,6 +54,23 @@ def write(self, vals):
5854
subpacks_to_delete_ids.remove(cmd[1])
5955
for to_delete_id in subpacks_to_delete_ids:
6056
vals["order_line"].append([2, to_delete_id, False])
57+
if to_delete_ids:
58+
# In the case of you modify the list of order lines
59+
# Then you switch the tab of your browser
60+
# That will trigger an invisible write operation
61+
# even if the onchange triggered a raise
62+
line_to_check = self.env["sale.order.line"].search(
63+
[("pack_child_line_ids", "in", to_delete_ids)]
64+
)
65+
for line in line_to_check:
66+
if not line.product_id.pack_modifiable:
67+
raise UserError(
68+
self.env._(
69+
"You cannot delete this line because is part of a pack"
70+
" in this sale order. In order to delete this line you"
71+
" need to delete the pack itself"
72+
)
73+
)
6174
return super().write(vals)
6275

6376
def _get_update_prices_lines(self):

sale_product_pack/models/sale_order_line.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,11 @@ def _compute_discount(self):
166166
for pack_line in self.filtered("pack_parent_line_id"):
167167
pack_line.discount = pack_line._get_pack_line_discount()
168168
return res
169+
170+
def _compute_name(self):
171+
res = super()._compute_name()
172+
for line in self:
173+
parent = line.pack_parent_line_id
174+
if parent.product_id.pack_ok and parent.pack_type == "detailed":
175+
line.name = f"{'> ' * (parent.pack_depth + 1)}{line.name}"
176+
return res

sale_product_pack/pyproject.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
[build-system]
22
requires = ["whool"]
3-
4-
[project]
5-
name = "odoo-addons-oca-product-pak"
6-
version = "19.0.20251027.0"
7-
dependencies = [
8-
"odoo-addon-product_pack @ git+https://github.com/OCA/product-pack.git@refs/pull/223/head#subdirectory=product_pack",
9-
]
3+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)