the amount_change method defined on account_invoice_tax is not perfect and can be improved.
This method does simply complete the tax_amount field by the entered value into the amount field. The problem is that it doesn't take in consideration the signs of this field.
For example, let's create a supplier invoice of total cost 100€, and with one product costing 100€ with the tax "Marchandises Déductibles 21%" (this tax is included in the l10n_be module).
This tax is somehow special because it creates 3 tax lines like this:
tax description.
Marchandises Déductibles 21% (1)....
Marchandises Déductibles 21% (2)....
Marchandises Déductibles 21% (3)....
I hereby am only interested about the entry number 2. As you can see the amount is -21 and the tax amount is 21. That's ok but if i need to change this amount (because of a rounding problem for example), if i set the amount to -22, the tax amount will be set to -22 too, instead of 22! It happens because the onchange defined doesn't take in consideration the sign defined on the tax...
So to improve this onchange, we need first to add the missing information. There are 2 ways:
*either add a new field many2one on account_invoice_tax that refer to the account_Tax that created the account_invoice_tax
*either copy the values of base_sign and tax_sign (or ref_base_sign and ref_tax_sign is it's a refund) into 2 new fields in account_invoice_tax
Thanks
Blueprint information
- Status:
- Not started
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- New
- Series goal:
- None
- Implementation:
- Unknown
- Milestone target:
- None
- Started by
- Completed by
Related branches
Related bugs
Sprints
Whiteboard
the following patch implements the second option. It may be reused for improving trunk.
=== modified file 'account/
--- account/
+++ account/
@@ -104,6 +104,7 @@
+ <field name="tax_sign"/>
</record>
=== modified file 'account/
--- account/invoice.py 2009-02-05 07:05:49 +0000
+++ account/invoice.py 2009-02-06 13:32:24 +0000
@@ -1095,16 +1095,19 @@
+ 'tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1."),
}
def base_change(self, cr, uid, ids, base):
return {'value': {'base_
def amount_change(self, cr, uid, ids, amount):
- return {'value': {'tax_amount'
+ sign = self.browse(cr, uid, ids[0]).tax_sign
+ return {'value': {'tax_amount'
_order = 'sequence'
_defaults = {
'manual': lambda *a: 1,
+ 'tax_sign': lambda *a: 1,
}
def compute(self, cr, uid, invoice_id, context={}):
@@ -1129,6 +1132,7 @@
+ val['tax_sign'] = tax['tax_sign']
@@ -1136,6 +1140,7 @@
+ val['tax_sign'] = tax['ref_tax_sign']
if not key in tax_grouped: