Skip to content

Commit

Permalink
[FIX] sale_product_pack: Update Price Action
Browse files Browse the repository at this point in the history
Resolves an issue in the "Update Prices" action for packs.
When update the pricelist, ignore all the "cero" lines, this
is the components of packs "Detailed: Totalized in main product" or
"Detailed - Ignored".

We only want to update component lines if the parent pack is
"Detailed - Detailed per component".

Also keep in the so line the component discount settled in the parent
pack settings.
  • Loading branch information
bruno-zanotti committed Dec 26, 2023
1 parent 8183160 commit d5143b1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
16 changes: 4 additions & 12 deletions sale_product_pack/models/product_pack_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,14 @@ def get_sale_order_line_vals(self, line, order):
sol._onchange_product_id_warning()
vals = sol._convert_to_write(sol._cache)
pack_price_types = {"totalized", "ignored"}
sale_discount = 0.0
if line.product_id.pack_component_price == "detailed":
sale_discount = 100.0 - (
(100.0 - sol.discount) * (100.0 - self.sale_discount) / 100.0
)
elif (
if (
line.product_id.pack_type == "detailed"
and line.product_id.pack_component_price in pack_price_types
):
vals["price_unit"] = 0.0
vals.update(
{
"discount": sale_discount,
"name": "{}{}".format("> " * (line.pack_depth + 1), sol.name),
}
)

vals["name"] = "{}{}".format("> " * (line.pack_depth + 1), sol.name)

return vals

def price_compute(
Expand Down
13 changes: 4 additions & 9 deletions sale_product_pack/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ def write(self, vals):

def _get_update_prices_lines(self):
res = super()._get_update_prices_lines()
result = self.order_line.browse()
index = 0
while index < len(res):
line = res[index]
result |= line
index += 1
if line.product_id.pack_ok and line.pack_type == "detailed":
index += len(line.product_id.pack_line_ids)
return result
return res.filtered(
lambda line: not line.pack_parent_line_id
or line.pack_parent_line_id.pack_component_price == "detailed"
)
18 changes: 18 additions & 0 deletions sale_product_pack/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@ def action_open_parent_pack_product_view(self):
"view_mode": "tree,form",
"domain": domain,
}

def _get_pack_line_discount(self):
"""returns the discount settled in the parent pack lines"""
self.ensure_one()
discount = 0.0
if self.pack_parent_line_id.pack_component_price == "detailed":
for pack_line in self.pack_parent_line_id.product_id.pack_line_ids:
if pack_line.product_id == self.product_id:
discount = pack_line.sale_discount
break
return discount

@api.depends("product_id", "product_uom", "product_uom_qty")
def _compute_discount(self):
res = super()._compute_discount()
for pack_line in self.filtered("pack_parent_line_id"):
pack_line.discount = pack_line._get_pack_line_discount()
return res
2 changes: 1 addition & 1 deletion sale_product_pack/tests/test_sale_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_create_components_price_order_line(self):
self.assertAlmostEqual(line.price_subtotal, 27.68)
self.assertEqual(
(self.sale_order.order_line - line).mapped("price_subtotal"),
[1755.0, 22.5, 885.0],
[1579.5, 20.25, 796.5],
)

def test_create_ignored_price_order_line(self):
Expand Down
2 changes: 1 addition & 1 deletion sale_product_pack/views/product_pack_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<field name="pack_modifiable" invisible="True" />
<field name="pack_parent_line_id" invisible="True" />
<button
string="Parent Pack is not modifiable"
string="Locked"
name="action_open_parent_pack_product_view"
type="object"
attrs="{'invisible': ['|', ('pack_parent_line_id', '=', False), ('pack_modifiable', '=', True)]}"
Expand Down

0 comments on commit d5143b1

Please sign in to comment.