Skip to content

Commit

Permalink
Merge pull request #9 from grap/16.0-ref-account_invoice_triple_disco…
Browse files Browse the repository at this point in the history
…unt-manage-create

[FIX] account_invoice_triple_discount: Manage Correct creation of account move lines, where 'discount' field is set
  • Loading branch information
grindtildeath authored Jun 28, 2024
2 parents 64605a2 + 03c2e1e commit 675b466
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions account_invoice_triple_discount/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ def _inverse_discount(self):
line.discount2 = 0
line.discount3 = 0

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get("discount") and not vals.get("discount1"):
vals["discount1"] = vals.pop("discount")
return super().create(vals_list)

def _get_aggregated_multiple_discounts(self, discounts):
"""
Returns the aggregate discount corresponding to any number of discounts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def setUpClass(cls):
cls.env.user.groups_id += cls.env.ref("product.group_discount_per_so_line")
cls.Account = cls.env["account.account"]
cls.AccountMove = cls.env["account.move"]
cls.AccountMoveLine = cls.env["account.move.line"]
cls.AccountTax = cls.env["account.tax"]
cls.Partner = cls.env["res.partner"]
cls.Journal = cls.env["account.journal"]
Expand Down Expand Up @@ -205,6 +206,30 @@ def test_08_write_on_main_discount(self):
self.assertEqual(invoice_line1.discount3, 0.0)
self.assertEqual(invoice_line1.price_subtotal, 500.0)

def test_09_wreate_with_main_discount(self):
"""
Tests if creating a invoice line with main discount field
set correctly discount1, discount2 and discount3
"""
invoice = self.create_simple_invoice(0)

invoice_line2 = self.AccountMoveLine.create(
{
"move_id": invoice.id,
"name": "Line With Main Discount",
"quantity": 1,
"price_unit": 1000,
"discount": 10,
"tax_ids": [],
}
)

# 1000 * 0.9
self.assertEqual(invoice_line2.price_subtotal, 900.0)
self.assertEqual(invoice_line2.discount1, 10.0)
self.assertEqual(invoice_line2.discount2, 0.0)
self.assertEqual(invoice_line2.discount3, 0.0)

def test_tax_compute_with_lock_date(self):
# Check that the tax computation works even if the lock date is set
invoice = self.create_simple_invoice(0)
Expand Down

0 comments on commit 675b466

Please sign in to comment.