Improve manual edition of invoice tax lines
review396005
This commit is contained in:
+50
-2
@@ -1970,7 +1970,9 @@ class InvoiceTax(ModelSQL, ModelView):
|
||||
base = fields.Numeric('Base', required=True,
|
||||
digits=(16, Eval('_parent_invoice', {}).get('currency_digits', 2)))
|
||||
amount = fields.Numeric('Amount', required=True,
|
||||
digits=(16, Eval('_parent_invoice', {}).get('currency_digits', 2)))
|
||||
digits=(16, Eval('_parent_invoice', {}).get('currency_digits', 2)),
|
||||
on_change_with=['tax', 'base', 'amount', 'manual'],
|
||||
depends=['tax', 'base', 'manual'])
|
||||
manual = fields.Boolean('Manual')
|
||||
base_code = fields.Many2One('account.tax.code', 'Base Code',
|
||||
domain=[
|
||||
@@ -1982,7 +1984,13 @@ class InvoiceTax(ModelSQL, ModelView):
|
||||
('company', '=', Eval('_parent_invoice', {}).get('company', 0)),
|
||||
])
|
||||
tax_sign = fields.Numeric('Tax Sign', digits=(2, 0), required=True)
|
||||
tax = fields.Many2One('account.tax', 'Tax')
|
||||
tax = fields.Many2One('account.tax', 'Tax',
|
||||
states={
|
||||
'readonly': ~Eval('manual', False),
|
||||
},
|
||||
on_change=['tax', '_parent_invoice.party',
|
||||
'_parent_invoice.type'],
|
||||
depends=['manual'])
|
||||
|
||||
def __init__(self):
|
||||
super(InvoiceTax, self).__init__()
|
||||
@@ -2023,6 +2031,46 @@ class InvoiceTax(ModelSQL, ModelView):
|
||||
def default_tax_sign(self):
|
||||
return Decimal('1')
|
||||
|
||||
def on_change_tax(self, values):
|
||||
pool = Pool()
|
||||
tax_obj = pool.get('account.tax')
|
||||
invoice_obj = pool.get('account.invoice')
|
||||
changes = {}
|
||||
if values.get('tax'):
|
||||
invoice_values = dict(
|
||||
(f[16:], v) for f, v in values.iteritems()
|
||||
if f.startswith('_parent_invoice.'))
|
||||
context = invoice_obj.get_tax_context(invoice_values)
|
||||
with Transaction().set_context(**context):
|
||||
tax = tax_obj.browse(values['tax'])
|
||||
changes['description'] = tax.description
|
||||
invoice_type = values.get('_parent_invoice.type', 'out_invoice')
|
||||
if invoice_type in ('out_invoice', 'in_invoice'):
|
||||
changes['base_code'] = tax.invoice_base_code.id
|
||||
changes['base_sign'] = tax.invoice_base_sign
|
||||
changes['tax_code'] = tax.invoice_tax_code.id
|
||||
changes['tax_sign'] = tax.invoice_tax_sign
|
||||
changes['account'] = tax.invoice_account.id
|
||||
else:
|
||||
changes['base_code'] = tax.credit_note_base_code.id
|
||||
changes['base_sign'] = tax.credit_note_base_sign
|
||||
changes['tax_code'] = tax.credit_note_tax_code.id
|
||||
changes['tax_sign'] = tax.credit_note_tax_sign
|
||||
changes['account'] = tax.credit_note_account.id
|
||||
return changes
|
||||
|
||||
def on_change_with_amount(self, values):
|
||||
pool = Pool()
|
||||
tax_obj = pool.get('account.tax')
|
||||
if values.get('tax') and values.get('manual', False):
|
||||
tax_id = values['tax']
|
||||
base = values.get('base') or Decimal(0)
|
||||
for tax in tax_obj.compute([tax_id], base, 1):
|
||||
if (tax['tax'].id == tax_id
|
||||
and tax['base'] == values.get('base')):
|
||||
return tax['amount']
|
||||
return values.get('amount')
|
||||
|
||||
def check_modify(self, ids):
|
||||
'''
|
||||
Check if the taxes can be modified
|
||||
|
||||
+4
-2
@@ -655,6 +655,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<form string="Invoice Tax">
|
||||
<label name="invoice"/>
|
||||
<field name="invoice" colspan="3"/>
|
||||
<label name="tax"/>
|
||||
<field name="tax" colspan="3"/>
|
||||
<label name="description"/>
|
||||
<field name="description"/>
|
||||
<label name="sequence"/>
|
||||
@@ -677,7 +679,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<label name="base_sign"/>
|
||||
<field name="base_sign"/>
|
||||
</group>
|
||||
<field name="tax" colspan="4" invisible="1"/>
|
||||
</form>
|
||||
]]>
|
||||
</field>
|
||||
@@ -690,12 +691,12 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<![CDATA[
|
||||
<tree string="Invoice Taxes">
|
||||
<field name="invoice"/>
|
||||
<field name="tax"/>
|
||||
<field name="description"/>
|
||||
<field name="account"/>
|
||||
<field name="manual"/>
|
||||
<field name="base"/>
|
||||
<field name="amount"/>
|
||||
<field name="tax" tree_invisible="1"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
@@ -718,6 +719,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<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"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user