From 5b6a13bb4c4494dccb2fcc6076b79b0d14e8dd0d Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Thu, 20 May 2021 10:20:41 +0200 Subject: [PATCH] Create base tax line for manual taxes issue10429 review340811002 --- CHANGELOG | 2 + invoice.py | 13 +++- tests/scenario_invoice_manual_tax.rst | 87 +++++++++++++++++++++++++++ tests/test_account_invoice.py | 4 ++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 tests/scenario_invoice_manual_tax.rst diff --git a/CHANGELOG b/CHANGELOG index cff47f88b6..74e88a368c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Create base tax line for manual taxes + Version 6.0.0 - 2021-05-03 * Bug fixes (see mercurial logs for details) * Allow using debt accounts on supplier invoices diff --git a/invoice.py b/invoice.py index 87d625853f..0be24f3635 100644 --- a/invoice.py +++ b/invoice.py @@ -2648,10 +2648,13 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView): with Transaction().set_context(date=self.invoice.currency_date): amount = Currency.compute(self.invoice.currency, self.amount, self.invoice.company.currency) + base = Currency.compute(self.invoice.currency, self.base, + self.invoice.company.currency) line.amount_second_currency = self.amount line.second_currency = self.invoice.currency else: amount = self.amount + base = self.base line.amount_second_currency = None line.second_currency = None if amount >= 0: @@ -2673,11 +2676,19 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView): line.party = self.invoice.party line.origin = self if self.tax: + tax_lines = [] tax_line = TaxLine() tax_line.amount = amount tax_line.type = 'tax' tax_line.tax = self.tax - line.tax_lines = [tax_line] + tax_lines.append(tax_line) + if self.manual: + tax_line = TaxLine() + tax_line.amount = base + tax_line.type = 'base' + tax_line.tax = self.tax + tax_lines.append(tax_line) + line.tax_lines = tax_lines return [line] def _credit(self): diff --git a/tests/scenario_invoice_manual_tax.rst b/tests/scenario_invoice_manual_tax.rst new file mode 100644 index 0000000000..79fe6ce244 --- /dev/null +++ b/tests/scenario_invoice_manual_tax.rst @@ -0,0 +1,87 @@ +================== +Invoice Manual Tax +================== + +Imports:: + + >>> import datetime as dt + >>> from decimal import Decimal + >>> from proteus import Model + >>> from trytond.tests.tools import activate_modules + >>> from trytond.modules.company.tests.tools import ( + ... create_company, get_company) + >>> from trytond.modules.account.tests.tools import ( + ... create_fiscalyear, create_chart, get_accounts, create_tax, + ... create_tax_code) + >>> from trytond.modules.account_invoice.tests.tools import ( + ... set_fiscalyear_invoice_sequences) + >>> today = dt.date.today() + +Activate modules:: + + >>> config = activate_modules('account_invoice') + + >>> Invoice = Model.get('account.invoice') + >>> Party = Model.get('party.party') + >>> TaxCode = Model.get('account.tax.code') + +Create company:: + + >>> _ = create_company() + >>> company = get_company() + +Create fiscal year:: + + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear(company)) + >>> fiscalyear.click('create_period') + >>> period_ids = [p.id for p in fiscalyear.periods] + +Create chart of accounts:: + + >>> _ = create_chart(company) + >>> accounts = get_accounts(company) + +Create tax:: + + >>> tax = create_tax(Decimal('.10')) + >>> tax.save() + >>> invoice_base_code = create_tax_code(tax, 'base', 'invoice') + >>> invoice_base_code.save() + >>> invoice_tax_code = create_tax_code(tax, 'tax', 'invoice') + >>> invoice_tax_code.save() + +Create party:: + + >>> party = Party(name="Party") + >>> party.save() + +Post a supplier invoice with manual taxes:: + + >>> invoice = Invoice(type='in') + >>> invoice.party = party + >>> invoice.invoice_date = today + >>> tax_line = invoice.taxes.new() + >>> bool(tax_line.manual) + True + >>> tax_line.tax = tax + >>> tax_line.base = Decimal('100') + >>> tax_line.amount + Decimal('10.00') + >>> invoice.untaxed_amount, invoice.tax_amount, invoice.total_amount + (Decimal('0.00'), Decimal('10.00'), Decimal('10.00')) + +Post invoice and check tax codes:: + + >>> invoice.click('post') + >>> invoice.untaxed_amount, invoice.tax_amount, invoice.total_amount + (Decimal('0.00'), Decimal('10.00'), Decimal('10.00')) + + >>> with config.set_context(periods=period_ids): + ... invoice_base_code = TaxCode(invoice_base_code.id) + ... invoice_base_code.amount + Decimal('100.00') + >>> with config.set_context(periods=period_ids): + ... invoice_tax_code = TaxCode(invoice_tax_code.id) + ... invoice_tax_code.amount + Decimal('10.00') diff --git a/tests/test_account_invoice.py b/tests/test_account_invoice.py index f6092fffbe..0f493e0ff3 100644 --- a/tests/test_account_invoice.py +++ b/tests/test_account_invoice.py @@ -315,4 +315,8 @@ def suite(): tearDown=doctest_teardown, encoding='utf-8', checker=doctest_checker, optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + suite.addTests(doctest.DocFileSuite('scenario_invoice_manual_tax.rst', + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) return suite