the amount_change method defined on account_invoice_tax is not perfect and can be improved.

Registered by qdp (OpenERP)

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........................................base.............amount...........tax code amount (visible in form view only)
Marchandises Déductibles 21% (1)........100.................21.........................21
Marchandises Déductibles 21% (2)........100................-21.........................21
Marchandises Déductibles 21% (3)........100...................0...........................0

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

Related branches

Sprints

Whiteboard

the following patch implements the second option. It may be reused for improving trunk.

=== modified file 'account/account_invoice_view.xml'
--- account/account_invoice_view.xml 2009-01-28 15:14:06 +0000
+++ account/account_invoice_view.xml 2009-02-06 13:23:24 +0000
@@ -104,6 +104,7 @@
                     <field name="base_amount"/>
                     <field name="tax_code_id"/>
                     <field name="tax_amount"/>
+ <field name="tax_sign"/>
                 </form>
             </field>
         </record>

=== modified file 'account/invoice.py'
--- account/invoice.py 2009-02-05 07:05:49 +0000
+++ account/invoice.py 2009-02-06 13:32:24 +0000
@@ -1095,16 +1095,19 @@
         'base_amount': fields.float('Base Code Amount', digits=(16,2)),
         'tax_code_id': fields.many2one('account.tax.code', 'Tax Code', help="The tax basis of the tax declaration."),
         'tax_amount': fields.float('Tax Code Amount', digits=(16,2)),
+ 'tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1."),
     }
     def base_change(self, cr, uid, ids, base):
         return {'value': {'base_amount':base}}
     def amount_change(self, cr, uid, ids, amount):
- return {'value': {'tax_amount':amount}}
+ sign = self.browse(cr, uid, ids[0]).tax_sign
+ return {'value': {'tax_amount':amount*sign}}
     _order = 'sequence'
     _defaults = {
         'manual': lambda *a: 1,
         'base_amount': lambda *a: 0.0,
         'tax_amount': lambda *a: 0.0,
+ 'tax_sign': lambda *a: 1,
     }
     def compute(self, cr, uid, invoice_id, context={}):
         tax_grouped = {}
@@ -1129,6 +1132,7 @@
                     val['tax_code_id'] = tax['tax_code_id']
                     val['base_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['base'] * tax['base_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')})
                     val['tax_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['amount'] * tax['tax_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')})
+ val['tax_sign'] = tax['tax_sign']
                     val['account_id'] = tax['account_collected_id'] or line.account_id.id
                 else:
                     val['base_code_id'] = tax['ref_base_code_id']
@@ -1136,6 +1140,7 @@
                     val['base_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['base'] * tax['ref_base_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')})
                     val['tax_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['amount'] * tax['ref_tax_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')})
                     val['account_id'] = tax['account_paid_id'] or line.account_id.id
+ val['tax_sign'] = tax['ref_tax_sign']

                 key = (val['tax_code_id'], val['base_code_id'], val['account_id'])
                 if not key in tax_grouped:

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.