Skip to content

Commit

Permalink
Merge PR #201 into 18.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Jan 31, 2025
2 parents edc63a6 + 0f52bd0 commit 233c855
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sale_product_pack/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ def _get_pack_line_discount(self):
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
discount = 100.0 - (
(100.0 - self.discount)
* (100.0 - pack_line.sale_discount)
/ 100.0
)
break
return discount

Expand Down
34 changes: 34 additions & 0 deletions sale_product_pack/tests/test_sale_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,37 @@ def test_create_several_lines_03(self):
self.assertEqual(sequence_tp, self.sale_order.order_line[2].sequence)
self.assertEqual(sequence_tp, self.sale_order.order_line[3].sequence)
self.assertEqual(self.sale_order.order_line[4].product_id, product)

def test_compute_discount_for_detailed_packs(self):
group_discount = self.env.ref("sale.group_discount_per_so_line")
self.env.user.write({"groups_id": [(4, group_discount.id)]})
product_pack = self.env.ref("product_pack.product_pack_cpu_detailed_components")
sale_order = self.env["sale.order"].create(
{
"partner_id": self.env.ref("base.res_partner_12").id,
"pricelist_id": self.discount_pricelist.id,
"order_line": [
(
0,
0,
{
"product_id": product_pack.id,
"product_uom_qty": 1,
"pack_component_price": "detailed",
},
)
],
}
)
sale_order.action_update_prices()
pack_lines = sale_order.order_line.filtered(
lambda line: line.pack_parent_line_id
)
self.assertEqual(
len(pack_lines), 3, "Expected 3 lines for the components of the pack."
)
self.assertEqual(
pack_lines.mapped("discount"),
[19, 19, 10],
"Discounts for the pack lines are not calculated correctly.",
)

0 comments on commit 233c855

Please sign in to comment.