Merge lp:~openerp-dev/openobject-addons/6.0-bug-783496-pso into lp:openobject-addons/6.0

Proposed by Priyesh (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/6.0-bug-783496-pso
Merge into: lp:openobject-addons/6.0
Diff against target: 233 lines (+66/-44)
3 files modified
account_voucher/account_voucher.py (+48/-26)
account_voucher/voucher_payment_receipt_view.xml (+14/-14)
account_voucher/voucher_sales_purchase_view.xml (+4/-4)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.0-bug-783496-pso
Reviewer Review Type Date Requested Status
Thomas Winteler (Win-Soft) (community) Approve
Leonardo Pistone (community) Approve
qdp (OpenERP) Pending
Olivier Dony (Odoo) Pending
OpenERP Core Team Pending
Review via email: mp+61917@code.launchpad.net

Description of the change

Hello,

Fixed https://bugs.launchpad.net/openobject-addons/+bug/783496
Improved onchange_partner_id method of voucher
Passed voucher lines in onchange_partner_id method

Thanks,
pso

To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote :

We tested this with a clone of the DB from our customer that made the OPW request. It seems OK to us.

Thanks!

review: Approve
Revision history for this message
Thomas Winteler (Win-Soft) (thomi) wrote :

As Leonardo writes, we have tested that on customers instance and it worked as it should. Only one thing maybe should be handled as a enhancement ;)
See my comment: https://bugs.launchpad.net/openobject-addons/+bug/783496/comments/6

review: Approve
Revision history for this message
Priyesh (OpenERP) (pso-openerp) wrote :

Leonardo and Thomas,

Thanks for the feedback.

We are investing more for a best suitable approach as a fix.

However, the enhancement you listed here is not really a blocking one.

Thanks.

Unmerged revisions

4590. By Priyesh (OpenERP)

[FIX] account_voucher: Onchange of amount removes all manually added lines

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 2011-05-20 10:29:05 +0000
3+++ account_voucher/account_voucher.py 2011-05-23 06:33:50 +0000
4@@ -393,7 +393,7 @@
5
6 return default
7
8- def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None):
9+ def onchange_partner_id(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, lines_ids=[], context=None):
10 """price
11 Returns a dict that contains new values and context
12
13@@ -412,9 +412,14 @@
14 context_multi_currency.update({'date': date})
15
16 line_pool = self.pool.get('account.voucher.line')
17- line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False
18- if line_ids:
19- line_pool.unlink(cr, uid, line_ids)
20+ flag = False
21+ if lines_ids:
22+ flag = True
23+
24+ if not flag:
25+ line_ids = ids and line_pool.search(cr, uid, [('voucher_id', '=', ids[0])]) or False
26+ if line_ids:
27+ line_pool.unlink(cr, uid, line_ids)
28
29 currency_pool = self.pool.get('res.currency')
30 move_line_pool = self.pool.get('account.move.line')
31@@ -462,15 +467,17 @@
32 total_credit = price or 0.0
33 account_type = 'receivable'
34
35- if not context.get('move_line_ids', False):
36- domain = [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)]
37- if context.get('invoice_id', False):
38- domain.append(('invoice', '=', context['invoice_id']))
39- ids = move_line_pool.search(cr, uid, domain, context=context)
40- else:
41- ids = context['move_line_ids']
42- ids.reverse()
43- moves = move_line_pool.browse(cr, uid, ids, context=context)
44+ moves = []
45+ if not flag:
46+ if not context.get('move_line_ids', False):
47+ domain = [('state','=','valid'), ('account_id.type', '=', account_type), ('reconcile_id', '=', False), ('partner_id', '=', partner_id)]
48+ if context.get('invoice_id', False):
49+ domain.append(('invoice', '=', context['invoice_id']))
50+ ids = move_line_pool.search(cr, uid, domain, context=context)
51+ else:
52+ ids = context['move_line_ids']
53+ ids.reverse()
54+ moves = move_line_pool.browse(cr, uid, ids, context=context)
55
56 company_currency = journal.company_id.currency_id.id
57 if company_currency != currency_id and ttype == 'payment':
58@@ -485,6 +492,7 @@
59 continue
60 total_credit += line.credit or 0.0
61 total_debit += line.debit or 0.0
62+
63 for line in moves:
64 if line.credit and line.reconcile_partial_id and ttype == 'receipt':
65 continue
66@@ -507,26 +515,40 @@
67 amount = min(amount_unreconciled, currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_debit), context=context_multi_currency))
68 rs['amount'] = amount
69 total_debit -= amount
70+ default['value']['line_dr_ids'].append(rs)
71 else:
72 amount = min(amount_unreconciled, currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_credit), context=context_multi_currency))
73 rs['amount'] = amount
74 total_credit -= amount
75-
76+ default['value']['line_cr_ids'].append(rs)
77 default['value']['line_ids'].append(rs)
78- if rs['type'] == 'cr':
79- default['value']['line_cr_ids'].append(rs)
80- else:
81- default['value']['line_dr_ids'].append(rs)
82-
83- if ttype == 'payment' and len(default['value']['line_cr_ids']) > 0:
84- default['value']['pre_line'] = 1
85- elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0:
86- default['value']['pre_line'] = 1
87- default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price)
88+
89+ if flag:
90+ for line in lines_ids:
91+ if line[2]['type'] == 'cr':
92+ amount = min(line[2]['amount_unreconciled'], currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_credit), context=context_multi_currency))
93+ if line[1]:
94+ line_pool.write(cr, uid, [line[1]], {'amount' :amount})
95+ line[2]['amount'] = amount
96+ total_credit -= amount
97+ default['value']['line_cr_ids'].append(line[2])
98+ else:
99+ amount = min(line[2]['amount_unreconciled'], currency_pool.compute(cr, uid, company_currency, currency_id, abs(total_debit), context=context_multi_currency))
100+ if line[1]:
101+ line_pool.write(cr, uid, [line[1]], {'amount' :amount})
102+ line[2]['amount'] = amount
103+ total_debit -= amount
104+ default['value']['line_dr_ids'].append(line[2])
105+
106+ if ttype == 'payment' and len(default['value']['line_cr_ids']) > 0:
107+ default['value']['pre_line'] = 1
108+ elif ttype == 'receipt' and len(default['value']['line_dr_ids']) > 0:
109+ default['value']['pre_line'] = 1
110+ default['value']['writeoff_amount'] = self._compute_writeoff_amount(cr, uid, default['value']['line_dr_ids'], default['value']['line_cr_ids'], price)
111
112 return default
113
114- def onchange_date(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=None):
115+ def onchange_date(self, cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, line_ids, context=None):
116 """
117 @param date: latest value from user input for field date
118 @param args: other arguments
119@@ -534,7 +556,7 @@
120 @return: Returns a dict which contains new values, and context
121 """
122 period_pool = self.pool.get('account.period')
123- res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, context=context)
124+ res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, price, currency_id, ttype, date, line_ids, context=context)
125 pids = period_pool.search(cr, uid, [('date_start', '<=', date), ('date_stop', '>=', date)])
126 if pids:
127 if not 'value' in res:
128
129=== modified file 'account_voucher/voucher_payment_receipt_view.xml'
130--- account_voucher/voucher_payment_receipt_view.xml 2011-05-09 09:20:00 +0000
131+++ account_voucher/voucher_payment_receipt_view.xml 2011-05-23 06:33:50 +0000
132@@ -88,14 +88,14 @@
133 <field name="arch" type="xml">
134 <form string="Bill Payment">
135 <group col="6" colspan="4">
136- <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
137- <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/>
138+ <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
139+ <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)"/>
140 <field name="journal_id"
141 domain="[('type','in',['bank', 'cash'])]"
142 widget="selection" select="1"
143- on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"
144+ on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)"
145 string="Payment Method"/>
146- <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, context)"/>
147+ <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_ids, context)"/>
148 <field name="reference" select="1" string="Payment Ref"/>
149 <field name="name" colspan="2"/>
150 <field name="account_id"
151@@ -151,14 +151,14 @@
152 <field name="arch" type="xml">
153 <form string="Bill Payment">
154 <group col="6" colspan="4">
155- <field name="partner_id" domain="[('supplier','=',True)]" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
156- <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/>
157+ <field name="partner_id" domain="[('supplier','=',True)]" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)" context="{'invoice_currency':currency_id}" string="Supplier"/>
158+ <field name="amount" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)"/>
159 <field name="journal_id"
160 domain="[('type','in',['bank', 'cash'])]"
161 widget="selection" select="1"
162- on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"
163+ on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)"
164 string="Payment Method"/>
165- <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, context)"/>
166+ <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids, context)"/>
167 <field name="reference" select="1" string="Payment Ref"/>
168 <field name="name" colspan="2"/>
169 <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
170@@ -288,23 +288,23 @@
171 <field name="arch" type="xml">
172 <form string="Customer Payment">
173 <group col="6" colspan="4">
174- <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)" string="Customer"/>
175+ <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)" string="Customer"/>
176 <field name="amount"
177 string="Paid Amount"
178- on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"/>
179+ on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)"/>
180 <field name="journal_id"
181 domain="[('type','in',['bank', 'cash'])]"
182 widget="selection" select="1"
183- on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, context)"
184+ on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)"
185 string="Payment Method"/>
186- <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, context)"/>
187+ <field name="date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids, context)"/>
188 <field name="reference" select="1" string="Payment Ref"/>
189 <field name="name" colspan="2"/>
190 <field name="company_id" select="1" widget="selection" groups="base.group_multi_company"/>
191 <field name="account_id"
192 widget="selection"
193 invisible="True"/>
194- <field name="pre_line" invisible="1"/>
195+ <field name="pre_line"/>
196 <field name="type" invisible="True"/>
197 </group>
198 <notebook colspan="4">
199@@ -379,7 +379,7 @@
200 <field name="amount_currency"/>
201 <field name="currency_id"/>
202 </tree>
203- </field>
204+ </field>
205 </page>
206 </notebook>
207 <group col="10" colspan="4">
208
209=== modified file 'account_voucher/voucher_sales_purchase_view.xml'
210--- account_voucher/voucher_sales_purchase_view.xml 2011-03-01 11:49:27 +0000
211+++ account_voucher/voucher_sales_purchase_view.xml 2011-05-23 06:33:50 +0000
212@@ -96,8 +96,8 @@
213 <field name="arch" type="xml">
214 <form string="Sales Receipt">
215 <group col="6" colspan="4">
216- <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)" string="Customer"/>
217- <field name="date" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
218+ <field name="partner_id" required="1" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids)" string="Customer"/>
219+ <field name="date" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_cr_ids)"/>
220 <field name="journal_id" domain="[('type','in',['sale','sale_refund'])]" widget="selection" on_change="onchange_journal(journal_id, line_cr_ids, tax_id, partner_id)"/>
221 <field name="number"/>
222 <field name="name" colspan="2"/>
223@@ -222,8 +222,8 @@
224 <field name="arch" type="xml">
225 <form string="Supplier Voucher">
226 <group col="6" colspan="4">
227- <field name="partner_id" domain="[('supplier','=',True)]" required="1" string="Supplier" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date)"/>
228- <field name="date" string="Bill Date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date)"/>
229+ <field name="partner_id" domain="[('supplier','=',True)]" required="1" string="Supplier" on_change="onchange_partner_id(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids)"/>
230+ <field name="date" string="Bill Date" select="1" on_change="onchange_date(partner_id, journal_id, amount, currency_id, type, date, line_dr_ids)"/>
231 <field name="journal_id" domain="[('type','in',['purchase','purchase_refund'])]" widget="selection" select="1" on_change="onchange_journal(journal_id, line_dr_ids, tax_id, partner_id)"/>
232 <field name="number"/>
233 <field name="name" colspan="2"/>