Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] account_payment_term_extension: Display correct amounts in journal items when using foreign currency #780

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions account_payment_term_extension/models/account_payment_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def _compute_terms(
# FIXME: Find an inheritable way of doing this
self.ensure_one()
company_currency = company.currency_id
foreign_currency = company_currency != currency
tax_amount_left = tax_amount
tax_amount_currency_left = tax_amount_currency
untaxed_amount_left = untaxed_amount
Expand All @@ -243,6 +244,8 @@ def _compute_terms(
total_amount_currency = remaining_amount_currency = (
tax_amount_currency + untaxed_amount_currency
)
if foreign_currency:
total_amount, total_amount_currency = total_amount_currency, total_amount
result = []
precision_digits = currency.decimal_places
company_precision_digits = company_currency.decimal_places
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def setUpClass(cls):
cls.payment_term_model = cls.env["account.payment.term"]
cls.invoice_model = cls.env["account.move"]
cls.partner = cls.env["res.partner"].create({"name": "Test Partner"})
cls.foreign_partner = cls.env["res.partner"].create(
{"name": "Test Foreign Partner", "country_id": cls.env.ref("base.es").id}
)
cls.product = cls.env["product.product"].create({"name": "Test product"})
cls.foreign_currency = cls.env["res.currency"].search([("name", "=", "EUR")])
cls.payment_term_0_day_5 = cls.payment_term_model.create(
{
"name": "Normal payment in day 5",
Expand Down Expand Up @@ -136,6 +140,32 @@ def setUpClass(cls):
],
}
)
cls.advance_60days = cls.payment_term_model.create(
{
"name": "30% Now, Balance 60 Days",
"active": True,
"line_ids": [
(
0,
0,
{
"value": "percent",
"value_amount": 30.0,
"days": 0,
},
),
(
0,
0,
{
"value": "balance",
"value_amount": 0.0,
"days": 60,
},
),
],
}
)
cls.tax = cls.env["account.tax"].create(
{
"name": "Test tax",
Expand All @@ -146,14 +176,24 @@ def setUpClass(cls):
)

def _create_invoice(
self, payment_term, date, quantity, price_unit, move_type="in_invoice"
self,
payment_term,
date,
quantity,
price_unit,
move_type="in_invoice",
foreing_partner=False,
):
invoice_form = Form(
self.invoice_model.with_context(default_move_type=move_type)
)
invoice_form.partner_id = self.partner
invoice_form.partner_id = (
self.partner if not foreing_partner else self.foreign_partner
)
invoice_form.invoice_payment_term_id = payment_term
invoice_form.invoice_date = date
if foreing_partner:
invoice_form.currency_id = self.foreign_currency
with invoice_form.invoice_line_ids.new() as line_form:
line_form.product_id = self.product
line_form.quantity = quantity
Expand Down Expand Up @@ -328,3 +368,30 @@ def test_decode_payment_days(self):
self.assertEqual(expected_days, model._decode_payment_days("5, 10"))
self.assertEqual(expected_days, model._decode_payment_days("5 - 10"))
self.assertEqual(expected_days, model._decode_payment_days("5 10"))

def test_invoice_advance_60days_payment_term(self):
invoice = self._create_invoice(
self.advance_60days, fields.Date.today(), 1, 900, foreing_partner=True
)
conversion_rate = self.env["res.currency"]._get_conversion_rate(
invoice.currency_id,
invoice.company_id.currency_id,
invoice.company_id,
invoice.date,
)
invoice.action_post()
self.assertNotEqual(invoice.currency_id, invoice.company_id.currency_id)
first_amount_original_currency = invoice.currency_id.round(
invoice.amount_total * 0.3
)
second_amount_original_currency = invoice.currency_id.round(
invoice.amount_total - first_amount_original_currency
)
expected_first_amount = invoice.currency_id.round(
first_amount_original_currency * conversion_rate
)
expected_second_amount = invoice.currency_id.round(
second_amount_original_currency * conversion_rate
)
self.assertEqual(invoice.line_ids[1].credit, expected_first_amount)
self.assertEqual(invoice.line_ids[2].credit, expected_second_amount)
Loading