Skip to content

Commit

Permalink
[FIXUP] no taxes on call off lines
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Dec 17, 2024
1 parent a4bb856 commit dff351c
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
11 changes: 11 additions & 0 deletions sale_order_blanket_order/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,17 @@ def _prepare_procurement_values(self, group_id=False):
res["call_off_sale_line_id"] = call_off_sale_line_id
return res

def _compute_tax_id(self):
# Overload to consider the call-off order lines in the computation
# For these lines we don't want to apply taxes. If we don't enforce
# the tax_id to False, we could end up with an amount to invoice
# if a fixed price is set on linked taxes. All the invoicing is done
# on the blanket order line including the taxes.
call_off_lines = self.filtered(lambda l: l.order_type == "call_off")
other_lines = self - call_off_lines
call_off_lines.tax_id = False
return super(SaleOrderLine, other_lines)._compute_tax_id()

def _compute_qty_at_date(self):
# Overload to consider the call-off order lines in the computation
# For these lines we take the values computed on the corresponding
Expand Down
28 changes: 25 additions & 3 deletions sale_order_blanket_order/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,36 @@ def setUpClass(cls):
- Create a normal sale order with 2 lines.
"""
super().setUpClass()
# create a flat tax
cls.tax_fixed = cls.env["account.tax"].create(
{
"sequence": 10,
"name": "Tax 10.0 (Fixed)",
"amount": 10.0,
"amount_type": "fixed",
"include_base_amount": True,
}
)
cls.product_1 = cls.env["product.product"].create(
{"name": "Product 1", "type": "product"}
{
"name": "Product 1",
"type": "product",
"taxes_id": [Command.link(cls.tax_fixed.id)],
}
)
cls.product_2 = cls.env["product.product"].create(
{"name": "Product 2", "type": "product"}
{
"name": "Product 2",
"type": "product",
"taxes_id": [Command.link(cls.tax_fixed.id)],
}
)
cls.product_3 = cls.env["product.product"].create(
{"name": "Product 3", "type": "product"}
{
"name": "Product 3",
"type": "product",
"taxes_id": [Command.link(cls.tax_fixed.id)],
}
)
cls._set_qty_in_loc_only(cls.product_1, 1000)
cls._set_qty_in_loc_only(cls.product_2, 2000)
Expand Down
3 changes: 3 additions & 0 deletions sale_order_blanket_order/tests/test_sale_call_off_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def test_order_line_attributes(self):
"forecast_expected_date": blanket_line.forecast_expected_date,
"free_qty_today": blanket_line.free_qty_today,
"qty_available_today": blanket_line.qty_available_today,
"price_tax": 0.0,
"price_total": 0.0,
"tax_id": [],
}
],
)
Expand Down
17 changes: 17 additions & 0 deletions sale_order_blanket_order/tests/test_sale_normal_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ def test_call_off_auto_create(self):
self.assertEqual(len(order.order_line), 1)
self.assertEqual(order.order_line.product_id, self.product_3)
self.assertEqual(len(new_order.order_line), 1)
self.assertRecordValues(
new_order.order_line,
[
{
"product_id": self.product_1.id,
"product_uom_qty": 1.0,
"price_unit": 0.0,
"qty_to_deliver": 0.0,
"qty_to_invoice": 0.0,
"qty_delivered": 0.0,
"price_tax": 0.0,
"price_total": 0.0,
"tax_id": [],
}
],
)

self.assertEqual(new_order.order_line.product_id, self.product_1)
self.assertEqual(new_order.order_line.product_uom_qty, 1)
blanket_lines = self.blanket_so.order_line.filtered(
Expand Down

0 comments on commit dff351c

Please sign in to comment.