Merge lp:~openerp-dev/openobject-addons/6.1-opw-577100-rgo into lp:openobject-addons/6.1

Proposed by Ravi Gohil (OpenERP)
Status: Approved
Approved by: Vinay Rana (OpenERP)
Approved revision: 6961
Proposed branch: lp:~openerp-dev/openobject-addons/6.1-opw-577100-rgo
Merge into: lp:openobject-addons/6.1
Diff against target: 99 lines (+41/-3)
3 files modified
account_voucher/account_voucher.py (+38/-0)
account_voucher/account_voucher_view.xml (+1/-1)
account_voucher/voucher_sales_purchase_view.xml (+2/-2)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.1-opw-577100-rgo
Reviewer Review Type Date Requested Status
Vinay Rana (OpenERP) (community) Approve
Naresh(OpenERP) Pending
Review via email: mp+120981@code.launchpad.net

Description of the change

Hello,

Validating the voucher after adding/altering Tax Amount in Sale Receipt/Purchase Receipt/Journal Voucher forms results in unbalanced journal items.

Steps to reproduce:
1) Create a record for Sale Receipt, add lines and select a Tax,
2) Alter the tax amount and validate the voucher,

You will have unbalanced entries in 'Journal Items' tab.

This fix will create a new tax entry with tax difference amount and will be correctly calculated for Chart of Taxes and Chart of Accounts. I also added an onchange() on tax_amount field as any change made to tax_amount should be reflected in total amount.

Please review the fix.

Thanks.

To post a comment you must log in.
Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

The provided solution will adjust the amount which is passed externally in the tax field text.
This solution fixes the issue.

review: Approve
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

Hello,

This bug was qualified as Confirmed on Trunk (means still existing and reproducible). A Merge Proposal for trunk was created to fix it. Here is the link to follow the MP on Launchpad https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-opw-577100-port-mma/+merge/137189 and be informed once it's been merged in trunk: ... If this Merge Proposal could not be merged in v6.1 at the release of v7.0, it will be closed.

Thanks,
Naresh Soni

Unmerged revisions

6961. By Ravi Gohil (OpenERP)

[FIX] account_voucher: Adding/Altering Tax Amount manually resulting into unbalanced Journal Items: (Maintenance Case : 577100)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_voucher/account_voucher.py'
2--- account_voucher/account_voucher.py 2012-08-21 12:23:47 +0000
3+++ account_voucher/account_voucher.py 2012-08-23 12:53:09 +0000
4@@ -1016,6 +1016,7 @@
5 voucher_brw = self.pool.get('account.voucher').browse(cr, uid, voucher_id, context)
6 ctx = context.copy()
7 ctx.update({'date': voucher_brw.date})
8+ voucher_total = 0.0
9 for line in voucher_brw.line_ids:
10 #create one move line per voucher line where amount is not 0.0
11 if not line.amount:
12@@ -1090,6 +1091,8 @@
13 foreign_currency_diff = sign * line.move_line_id.amount_residual_currency + amount_currency
14
15 move_line['amount_currency'] = amount_currency
16+ tax_amount_line = move_line.copy()
17+ voucher_total += line.amount
18 voucher_line = move_line_obj.create(cr, uid, move_line)
19 rec_ids = [voucher_line, line.move_line_id.id]
20
21@@ -1122,8 +1125,43 @@
22 if line.move_line_id.id:
23 rec_lst_ids.append(rec_ids)
24
25+ tax_amount_diff = 0.0
26+ if voucher_brw.tax_id:
27+ taxed_amount = tax_obj.compute_all(cr, uid, [voucher_brw.tax_id], voucher_total, 1.00, force_excluded=True).get('taxes')[0]['amount']
28+ tax_amount_diff = voucher_brw.tax_amount - taxed_amount
29+ if tax_amount_diff:
30+ credit = tax_amount_line.get('credit') and tax_amount_diff or 0.0
31+ debit = tax_amount_line.get('debit') and tax_amount_diff or 0.0
32+ tax_amount = voucher_brw.tax_id.tax_sign * abs(tax_amount_diff)
33+ if credit:
34+ debit = credit<0 and abs(credit)
35+ if debit:
36+ tax_amount = -1 * voucher_brw.tax_id.tax_sign * abs(tax_amount_diff)
37+ credit = 0.0
38+ else:
39+ credit = debit<0 and abs(debit)
40+ if credit:
41+ tax_amount = -1 * voucher_brw.tax_id.tax_sign * abs(tax_amount_diff)
42+ debit = 0.0
43+ tax_amount_line.update(account_tax_id=False,
44+ account_id=voucher_brw.tax_id.account_collected_id.id or tax_amount_line['account_id'],
45+ credit=credit,
46+ debit=debit,
47+ name=_('Tax difference for ') + voucher_brw.tax_id.name,
48+ tax_code_id=voucher_brw.tax_id.tax_code_id.id,
49+ tax_amount=tax_amount)
50+ move_line_obj.create(cr, uid, tax_amount_line, context=context)
51+
52 return (tot_line, rec_lst_ids)
53
54+ def onchange_tax(self, cr, uid, ids, tax_amount, line_ids, tax_id, partner_id=False, context=None):
55+ if not tax_id:
56+ return {}
57+ else:
58+ values = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id=partner_id, context=context)['value']
59+ total_amount = values['amount'] - values['tax_amount'] + tax_amount
60+ return {'value': {'amount': total_amount}}
61+
62 def writeoff_move_line_get(self, cr, uid, voucher_id, line_total, move_id, name, company_currency, current_currency, context=None):
63 '''
64 Set a dict to be use to create the writeoff move line.
65
66=== modified file 'account_voucher/account_voucher_view.xml'
67--- account_voucher/account_voucher_view.xml 2012-01-31 13:36:57 +0000
68+++ account_voucher/account_voucher_view.xml 2012-08-23 12:53:09 +0000
69@@ -74,7 +74,7 @@
70 </group>
71 <group col="4" colspan="1" attrs="{'invisible':[('type','in',['payment', 'receipt', False])]}">
72 <separator string="Total" colspan="4"/>
73- <field name="tax_id" on_change="onchange_price(line_ids, tax_id, partner_id)" widget="selection"/><field name="tax_amount" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" groups="base.group_extended" string="Compute Tax" attrs="{'invisible': [('state','!=','draft')]}"/>
74+ <field name="tax_id" on_change="onchange_price(line_ids, tax_id, partner_id)" widget="selection"/><field name="tax_amount" on_change="onchange_tax(tax_amount, line_ids, tax_id, partner_id)" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" groups="base.group_extended" string="Compute Tax" attrs="{'invisible': [('state','!=','draft')]}"/>
75 <label colspan="1" string=""/><field name="amount" string="Total"/>
76 </group>
77 </group>
78
79=== modified file 'account_voucher/voucher_sales_purchase_view.xml'
80--- account_voucher/voucher_sales_purchase_view.xml 2012-01-31 13:36:57 +0000
81+++ account_voucher/voucher_sales_purchase_view.xml 2012-08-23 12:53:09 +0000
82@@ -121,7 +121,7 @@
83 </group>
84 <group col="4" colspan="1">
85 <separator string="Total" colspan="4"/>
86- <field name="tax_id" on_change="onchange_price(line_cr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('sale','all')), ('parent_id', '=', False)]"/><field name="tax_amount" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" groups="base.group_extended" string="Compute Tax" attrs="{'invisible': [('state','!=','draft')]}"/>
87+ <field name="tax_id" on_change="onchange_price(line_cr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('sale','all')), ('parent_id', '=', False)]"/><field name="tax_amount" on_change="onchange_tax(tax_amount, line_cr_ids, tax_id, partner_id)" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" groups="base.group_extended" string="Compute Tax" attrs="{'invisible': [('state','!=','draft')]}"/>
88 <label string="" colspan="1"/><field name="amount" string="Total"/>
89 </group>
90 </group>
91@@ -242,7 +242,7 @@
92 </group>
93 <group col="4" colspan="1">
94 <separator string="Total" colspan="4"/>
95- <field name="tax_id" on_change="onchange_price(line_dr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('purchase','all')), ('parent_id', '=', False)]"/><field name="tax_amount" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" string="Compute Tax" groups="base.group_extended" attrs="{'invisible': [('state','!=','draft')]}"/>
96+ <field name="tax_id" on_change="onchange_price(line_dr_ids, tax_id, partner_id)" widget="selection" domain="[('type_tax_use','in',('purchase','all')), ('parent_id', '=', False)]"/><field name="tax_amount" on_change="onchange_tax(tax_amount, line_dr_ids, tax_id, partner_id)" nolabel="1"/><button type="object" icon="terp-stock_format-scientific" name="compute_tax" string="Compute Tax" groups="base.group_extended" attrs="{'invisible': [('state','!=','draft')]}"/>
97 <label string="" colspan="1"/><field name="amount" string="Total"/>
98 </group>
99 </group>