Remove tax code from invoice tax

issue6013
review41941002
This commit is contained in:
Cédric Krier
2018-03-25 23:34:44 +02:00
parent 7b14095c22
commit d56a461bfa
6 changed files with 64 additions and 125 deletions
+25 -76
View File
@@ -560,10 +560,8 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
if tax.manual:
self.tax_amount += tax.amount or Decimal('0.0')
continue
key = (tax.base_code.id if tax.base_code else None, tax.base_sign,
tax.tax_code.id if tax.tax_code else None, tax.tax_sign,
tax.account.id if tax.account else None,
tax.tax.id if tax.tax else None)
tax_id = tax.tax.id if tax.tax else None
key = (tax.account.id, tax_id)
if (key not in computed_taxes) or (key in tax_keys):
taxes.remove(tax)
continue
@@ -903,12 +901,8 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
for tax in invoice.taxes:
if tax.manual:
continue
base_code_id = tax.base_code.id if tax.base_code else None
tax_code_id = tax.tax_code.id if tax.tax_code else None
tax_id = tax.tax.id if tax.tax else None
key = (base_code_id, tax.base_sign,
tax_code_id, tax.tax_sign,
tax.account.id, tax_id)
key = (tax.account.id, tax_id)
if (key not in computed_taxes) or (key in tax_keys):
if exception:
cls.raise_user_error('missing_tax_line',
@@ -1898,12 +1892,8 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
for tax in self.invoice.taxes:
if tax.manual:
continue
base_code_id = tax.base_code.id if tax.base_code else None
tax_code_id = tax.tax_code.id if tax.tax_code else None
tax_id = tax.tax.id if tax.tax else None
key = (base_code_id, tax.base_sign,
tax_code_id, tax.tax_sign,
tax.account.id, tax_id)
key = (tax.account.id, tax_id)
if key in taxes_keys:
taxes.append(tax.id)
return taxes
@@ -2107,22 +2097,17 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
return tax_lines
taxes = self._get_taxes().values()
for tax in taxes:
if tax['base'] >= 0:
base_code = tax['base_code']
amount = tax['base'] * tax['base_sign']
else:
base_code = tax['base_code']
amount = tax['base'] * tax['base_sign']
if base_code:
with Transaction().set_context(
date=self.invoice.currency_date):
amount = Currency.compute(self.invoice.currency,
amount, self.invoice.company.currency)
tax_line = TaxLine()
tax_line.code = base_code
tax_line.amount = amount
tax_line.tax = tax['tax']
tax_lines.append(tax_line)
amount = tax['base']
with Transaction().set_context(
date=self.invoice.currency_date):
amount = Currency.compute(
self.invoice.currency, amount,
self.invoice.company.currency)
tax_line = TaxLine()
tax_line.amount = amount
tax_line.type = 'base'
tax_line.tax = tax['tax']
tax_lines.append(tax_line)
return tax_lines
def get_move_lines(self):
@@ -2228,20 +2213,6 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
states=_states,
depends=['tax', 'base', 'manual'] + _depends)
manual = fields.Boolean('Manual', states=_states, depends=_depends)
base_code = fields.Many2One('account.tax.code', 'Base Code',
domain=[
('company', '=', Eval('_parent_invoice', {}).get('company', 0)),
],
states=_states, depends=_depends)
base_sign = fields.Numeric('Base Sign', digits=(2, 0), required=True,
states=_states, depends=_depends)
tax_code = fields.Many2One('account.tax.code', 'Tax Code',
domain=[
('company', '=', Eval('_parent_invoice', {}).get('company', 0)),
],
states=_states, depends=_depends)
tax_sign = fields.Numeric('Tax Sign', digits=(2, 0), required=True,
states=_states, depends=_depends)
tax = fields.Many2One('account.tax', 'Tax',
ondelete='RESTRICT',
domain=[
@@ -2264,14 +2235,6 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
'"%(invoice)s" because it is posted or paid.'),
'create': ('You can not add tax to invoice '
'"%(invoice)s" because it is posted, paid or canceled.'),
'invalid_base_code_company': ('You can not create invoice '
'"%(invoice)s" on company "%(invoice_company)s" '
'using base tax code "%(base_code)s" from company '
'"%(base_code_company)s".'),
'invalid_tax_code_company': ('You can not create invoice '
'"%(invoice)s" on company "%(invoice_company)s" using tax '
'code "%(tax_code)s" from company '
'"%(tax_code_company)s".'),
})
@classmethod
@@ -2284,6 +2247,10 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
# Migration from 4.6: drop base_sign and tax_sign
table.not_null_action('base_sign', action='remove')
table.not_null_action('tax_sign', action='remove')
@staticmethod
def default_base():
return Decimal('0.0')
@@ -2296,14 +2263,6 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
def default_manual():
return True
@staticmethod
def default_base_sign():
return Decimal('1')
@staticmethod
def default_tax_sign():
return Decimal('1')
@fields.depends('invoice', '_parent_invoice.state')
def on_change_with_invoice_state(self, name=None):
if self.invoice:
@@ -2322,16 +2281,8 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
tax = Tax(self.tax.id)
self.description = tax.description
if self.base >= 0:
self.base_code = tax.invoice_base_code
self.base_sign = tax.invoice_base_sign
self.tax_code = tax.invoice_tax_code
self.tax_sign = tax.invoice_tax_sign
self.account = tax.invoice_account
else:
self.base_code = tax.credit_note_base_code
self.base_sign = tax.credit_note_base_sign
self.tax_code = tax.credit_note_tax_code
self.tax_sign = tax.credit_note_tax_sign
self.account = tax.credit_note_account
@fields.depends('tax', 'base', 'amount', 'manual', 'invoice',
@@ -2435,12 +2386,11 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
line.account = self.account
if self.account.party_required:
line.party = self.invoice.party
if self.tax_code:
tax_line = TaxLine()
tax_line.code = self.tax_code
tax_line.amount = amount * self.tax_sign
tax_line.tax = self.tax
line.tax_lines = [tax_line]
tax_line = TaxLine()
tax_line.amount = amount
tax_line.type = 'tax'
tax_line.tax = self.tax
line.tax_lines = [tax_line]
return [line]
def _credit(self):
@@ -2451,8 +2401,7 @@ class InvoiceTax(sequence_ordered(), ModelSQL, ModelView):
line.base = -self.base
line.amount = -self.amount
for field in ('description', 'sequence', 'manual', 'base_sign',
'tax_sign', 'account', 'base_code', 'tax_code', 'tax'):
for field in ['description', 'sequence', 'manual', 'account', 'tax']:
setattr(line, field, getattr(self, field))
return line
+18 -14
View File
@@ -12,7 +12,7 @@ Imports::
>>> 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, set_tax_code
... create_chart, get_accounts, create_tax, create_tax_code
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> today = datetime.date.today()
@@ -51,12 +51,16 @@ Create chart of accounts::
Create tax::
>>> TaxCode = Model.get('account.tax.code')
>>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax = create_tax(Decimal('.10'))
>>> tax.save()
>>> invoice_base_code = tax.invoice_base_code
>>> invoice_tax_code = tax.invoice_tax_code
>>> credit_note_base_code = tax.credit_note_base_code
>>> credit_note_tax_code = tax.credit_note_tax_code
>>> 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()
>>> credit_note_base_code = create_tax_code(tax, 'base', 'credit')
>>> credit_note_base_code.save()
>>> credit_note_tax_code = create_tax_code(tax, 'tax', 'credit')
>>> credit_note_tax_code.save()
Set Cash journal::
@@ -172,19 +176,19 @@ Post invoice::
Decimal('20.00')
>>> with config.set_context(periods=period_ids):
... invoice_base_code = TaxCode(invoice_base_code.id)
... invoice_base_code.sum
... invoice_base_code.amount
Decimal('200.00')
>>> with config.set_context(periods=period_ids):
... invoice_tax_code = TaxCode(invoice_tax_code.id)
... invoice_tax_code.sum
... invoice_tax_code.amount
Decimal('20.00')
>>> with config.set_context(periods=period_ids):
... credit_note_base_code = TaxCode(credit_note_base_code.id)
... credit_note_base_code.sum
... credit_note_base_code.amount
Decimal('0.00')
>>> with config.set_context(periods=period_ids):
... credit_note_tax_code = TaxCode(credit_note_tax_code.id)
... credit_note_tax_code.sum
... credit_note_tax_code.amount
Decimal('0.00')
Credit invoice with refund::
@@ -214,19 +218,19 @@ Credit invoice with refund::
Decimal('20.00')
>>> with config.set_context(periods=period_ids):
... invoice_base_code = TaxCode(invoice_base_code.id)
... invoice_base_code.sum
... invoice_base_code.amount
Decimal('200.00')
>>> with config.set_context(periods=period_ids):
... invoice_tax_code = TaxCode(invoice_tax_code.id)
... invoice_tax_code.sum
... invoice_tax_code.amount
Decimal('20.00')
>>> with config.set_context(periods=period_ids):
... credit_note_base_code = TaxCode(credit_note_base_code.id)
... credit_note_base_code.sum
... credit_note_base_code.amount
Decimal('200.00')
>>> with config.set_context(periods=period_ids):
... credit_note_tax_code = TaxCode(credit_note_tax_code.id)
... credit_note_tax_code.sum
... credit_note_tax_code.amount
Decimal('20.00')
Pay invoice::
@@ -14,7 +14,7 @@ Imports::
>>> 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, set_tax_code
... create_chart, get_accounts, create_tax
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> today = datetime.date.today()
@@ -58,12 +58,8 @@ Create chart of accounts::
Create tax::
>>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax = create_tax(Decimal('.10'))
>>> tax.save()
>>> invoice_base_code = tax.invoice_base_code
>>> invoice_tax_code = tax.invoice_tax_code
>>> credit_note_base_code = tax.credit_note_base_code
>>> credit_note_tax_code = tax.credit_note_tax_code
Set Cash journal::
@@ -163,7 +159,7 @@ Pay the invoice with rate change::
Create negative tax::
>>> negative_tax = set_tax_code(create_tax(Decimal('-.10')))
>>> negative_tax = create_tax(Decimal('-.10'))
>>> negative_tax.save()
Create invoice with alternate currency and negative taxes::
+14 -10
View File
@@ -12,7 +12,7 @@ Imports::
>>> 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, set_tax_code
... create_chart, get_accounts, create_tax, create_tax_code
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> today = datetime.date.today()
@@ -45,12 +45,16 @@ Create chart of accounts::
Create tax::
>>> TaxCode = Model.get('account.tax.code')
>>> tax = set_tax_code(create_tax(Decimal('.10')))
>>> tax = create_tax(Decimal('.10'))
>>> tax.save()
>>> invoice_base_code = tax.invoice_base_code
>>> invoice_tax_code = tax.invoice_tax_code
>>> credit_note_base_code = tax.credit_note_base_code
>>> credit_note_tax_code = tax.credit_note_tax_code
>>> 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()
>>> credit_note_base_code = create_tax_code(tax, 'base', 'credit')
>>> credit_note_base_code.save()
>>> credit_note_tax_code = create_tax_code(tax, 'tax', 'credit')
>>> credit_note_tax_code.save()
Create party::
@@ -149,19 +153,19 @@ Create invoice::
Decimal('0.00')
>>> with config.set_context(periods=period_ids):
... invoice_base_code = TaxCode(invoice_base_code.id)
... invoice_base_code.sum
... 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.sum
... invoice_tax_code.amount
Decimal('10.00')
>>> with config.set_context(periods=period_ids):
... credit_note_base_code = TaxCode(credit_note_base_code.id)
... credit_note_base_code.sum
... credit_note_base_code.amount
Decimal('0.00')
>>> with config.set_context(periods=period_ids):
... credit_note_tax_code = TaxCode(credit_note_tax_code.id)
... credit_note_tax_code.sum
... credit_note_tax_code.amount
Decimal('0.00')
Credit invoice::
+4 -14
View File
@@ -14,20 +14,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="account"/>
<label name="manual"/>
<field name="manual"/>
<group col="6" colspan="4" string="Tax Code" id="tax_code">
<label name="base"/>
<field name="base"/>
<label name="base_code"/>
<field name="base_code"/>
<label name="base_sign"/>
<field name="base_sign"/>
<label name="amount"/>
<field name="amount"/>
<label name="tax_code"/>
<field name="tax_code"/>
<label name="tax_sign"/>
<field name="tax_sign"/>
</group>
<label name="base"/>
<field name="base"/>
<label name="amount"/>
<field name="amount"/>
<separator name="legal_notice" colspan="4"/>
<field name="legal_notice" colspan="4"/>
</form>
-4
View File
@@ -7,10 +7,6 @@ this repository contains the full copyright notices and license terms. -->
<field name="amount" expand="1"/>
<field name="sequence" tree_invisible="1"/>
<field name="manual" tree_invisible="1"/>
<field name="base_code" tree_invisible="1"/>
<field name="base_sign" tree_invisible="1"/>
<field name="tax_code" tree_invisible="1"/>
<field name="tax_sign" tree_invisible="1"/>
<field name="account" tree_invisible="1"/>
<field name="tax" tree_invisible="1"/>
<field name="legal_notice" tree_invisible="1"/>