changeset f253b2351a87 in modules/account_invoice:default
details:
https://hg.tryton.org/modules/account_invoice?cmd=changeset&node=f253b2351a87
description:
Create base tax line for manual taxes
issue10429
review340811002
diffstat:
CHANGELOG | 2 +
invoice.py | 13 ++++-
tests/scenario_invoice_manual_tax.rst | 87 +++++++++++++++++++++++++++++++++++
tests/test_account_invoice.py | 4 +
4 files changed, 105 insertions(+), 1 deletions(-)
diffs (150 lines):
diff -r 6c7795997567 -r f253b2351a87 CHANGELOG
--- a/CHANGELOG Mon May 03 15:47:26 2021 +0200
+++ b/CHANGELOG Thu May 20 10:20:41 2021 +0200
@@ -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 -r 6c7795997567 -r f253b2351a87 invoice.py
--- a/invoice.py Mon May 03 15:47:26 2021 +0200
+++ b/invoice.py Thu May 20 10:20:41 2021 +0200
@@ -2648,10 +2648,13 @@
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 @@
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 -r 6c7795997567 -r f253b2351a87 tests/scenario_invoice_manual_tax.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_invoice_manual_tax.rst Thu May 20 10:20:41 2021 +0200
@@ -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 -r 6c7795997567 -r f253b2351a87 tests/test_account_invoice.py
--- a/tests/test_account_invoice.py Mon May 03 15:47:26 2021 +0200
+++ b/tests/test_account_invoice.py Thu May 20 10:20:41 2021 +0200
@@ -315,4 +315,8 @@
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