Skip to content

Commit

Permalink
Merge PR #442 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by dreispt
  • Loading branch information
OCA-git-bot committed Jul 15, 2024
2 parents 19311ad + 680683e commit ff55de4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
3 changes: 2 additions & 1 deletion account_avatax_sale_oca/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def onchange_reset_avatax_amount(self):
"""
for order in self:
order.tax_amount = 0
order.order_line.tax_amt = 0

@api.depends("order_line.price_total", "order_line.product_uom_qty", "tax_amount")
def _compute_amounts(self):
Expand Down Expand Up @@ -293,6 +292,8 @@ def write(self, vals):
result = super(SaleOrder, self).write(vals)
avatax_config = self.env.company.get_avatax_config_company()
for record in self:
if not record.tax_amount:
record.order_line.write({"tax_amt": 0})
if (
avatax_config.sale_calculate_tax
and record.calculate_tax_on_save
Expand Down
1 change: 1 addition & 0 deletions account_avatax_sale_oca/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_sale_order
82 changes: 82 additions & 0 deletions account_avatax_sale_oca/tests/test_sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html


from odoo.fields import Command
from odoo.tests import Form, common


class TestSaleOrder(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env["res.partner"].create(
{
"name": "Test Customer",
}
)
cls.empty_order = cls.env["sale.order"].create(
{
"partner_id": cls.partner.id,
}
)
cls.product = cls.env["product.product"].create({"name": "Super Product"})

def test_sale_order_onchange(self):
"""We found a bug where the price when the decimal accuracy was 5,
the price would be automatically reset to the pricelist price after
saving the order. The reason was a wrong implementation of
onchange_reset_avatax_amount. In this test we demonstrate that
the error does not happen anymore."""
# Change accuracy of product unit of measure
self.env.ref("product.decimal_product_uom").digits = 5
# Enable pricelists
self.env.user.groups_id += self.env.ref("product.group_product_pricelist")
self.pricelist = self.env["product.pricelist"].create(
{
"name": "Test pricelist",
"discount_policy": "without_discount",
"item_ids": [
Command.create(
{
"base": "list_price",
"min_quantity": 6,
"product_id": self.product.id,
"compute_price": "fixed",
"fixed_price": 20,
}
),
],
}
)
so = self.empty_order
so_form = Form(so)
so_form.pricelist_id = self.pricelist
with so_form.order_line.new() as line:
line.product_id = self.product
line.product_uom_qty = 7.0
so_form.save()
with so_form.order_line.new() as line:
line.product_id = self.product
line.product_uom_qty = 7.0
so_form.save()
with Form(so) as so_form:
with so_form.order_line.edit(0) as line0_form:
line0_form.price_unit = 100.00000
with so_form.order_line.edit(1) as line1_form:
line1_form.price_unit = 100.00000
so_form.save()
self.assertEqual(so.tax_amount, 0.0)
self.assertEqual(so.order_line[0].price_unit, 100.00000)
self.assertEqual(so.order_line[0].tax_amt, 0.0)
self.assertEqual(so.order_line[1].price_unit, 100.00000)
self.assertEqual(so.order_line[1].tax_amt, 0.0)
with Form(so) as so_form:
with so_form.order_line.edit(1) as line1_form:
line1_form.price_unit = 200.00000
so_form.save()
self.assertEqual(so.tax_amount, 0.0)
self.assertEqual(so.order_line[0].price_unit, 100.00000)
self.assertEqual(so.order_line[0].tax_amt, 0.0)
self.assertEqual(so.order_line[1].price_unit, 200.00000)
self.assertEqual(so.order_line[1].tax_amt, 0.0)

0 comments on commit ff55de4

Please sign in to comment.