Merge lp:~openerp-dev/openobject-addons/trunk-bug-896462-mdi into lp:openobject-addons

Proposed by DJ Patel (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-896462-mdi
Merge into: lp:openobject-addons
Diff against target: 211 lines (+32/-73)
3 files modified
account/account_invoice.py (+8/-32)
account/wizard/account_invoice_refund.py (+3/-20)
account_anglo_saxon/invoice.py (+21/-21)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-896462-mdi
Reviewer Review Type Date Requested Status
DJ Patel (OpenERP) (community) Needs Resubmitting
Mustufa Rangwala (Open ERP) (community) Needs Fixing
Moisés López - http://www.vauxoo.com (community) Approve
Raphael Collet (OpenERP) (community) Needs Information
Purnendu Singh (OpenERP) (community) Needs Fixing
qdp (OpenERP) Pending
Review via email: mp+84734@code.launchpad.net

Description of the change

Hello Sir,

I have fix the issue: https://bugs.launchpad.net/openobject-addons/+bug/896462 "[trunk & 6.0] [account] [wizard account.invoice.refund] Invoice refund wizard make error with other relational fields".

Thanks and Regards,

Divyesh Makwana(MDI)

To post a comment you must log in.
Revision history for this message
Purnendu Singh (OpenERP) (purnendu-singh) wrote :

hello Divyesh,

Your patch will not work in case of multiple invoice lines because of this
9 - 'invoice_line': invoice_lines,
90 - 'tax_line': tax_lines,
91 + 'invoice_line': inv_list[0],
92 + 'tax_line': tax_list[0],

it will also crash when tax_list is a blank list e.g:[]

Thanks
Purnendu singh

review: Needs Fixing
Revision history for this message
DJ Patel (OpenERP) (mdi-openerp) wrote :

Hello Sir,

I have improved the code as per your suggestion.

Thanks and Regards,

Divyesh Makwana(MDI)

review: Needs Resubmitting
Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

Getting rid of _refund_cleanup_lines is a good, since it is badly defined.
However, small change added by account_anglo_saxon is completely removed.
Is this correct?

review: Needs Information
Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote :

Tested done!

review: Approve
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

I think Raphael Collect point is correct, once we remove the _refund_cleanup_lines from anglo_saxon module the functionality provided by that method will be completely hide.

Please check and fix it.

Thanks,
Mustufa (mra)

review: Needs Fixing
Revision history for this message
DJ Patel (OpenERP) (mdi-openerp) wrote :

Hello Sir,

I use copy_data() to duplicate and modify an existing record properly instead of the strange stuff done in refund().

So refund() should be based on a call to copy_data() on the invoice, and not manual steps like that.

I totally removed _refund_cleanup_lines() function from 'account' and 'account_anglo_saxon'.

In order to not hide the functionality provided by 'account_anglo_saxon' module i override the 'refund' method.

Thanks,
Divyesh

review: Needs Resubmitting
5849. By DJ Patel (OpenERP)

[FIX] account, account_anglo_saxon : Improved the code.

5850. By DJ Patel (OpenERP)

[FIX] account : Improved the code.

5851. By DJ Patel (OpenERP)

[FIX] account : Improved the code.

5852. By DJ Patel (OpenERP)

[IMP] account_anglo_saxon : Improved the code.

5853. By DJ Patel (OpenERP)

[IMP] account_anglo_saxon : Improved the code.

5854. By DJ Patel (OpenERP)

[IMP] account_anglo_saxon : Improved the code.

5855. By DJ Patel (OpenERP)

[IMP] account : Improved the code.

Revision history for this message
DJ Patel (OpenERP) (mdi-openerp) wrote :

Now, we can totally get rid of _refund_cleanup_lines.

5856. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5857. By DJ Patel (OpenERP)

[IMP] account : Override the 'copy_data' instead of 'copy' orm method.

5858. By DJ Patel (OpenERP)

[IMP] account_anglo_saxon : Improved the code.

5859. By DJ Patel (OpenERP)

[IMP] account_anglo_saxon : Improved the code.

5860. By DJ Patel (OpenERP)

[IMP] account_anglo_saxon : Improved the code.

5861. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5862. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5863. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5864. By DJ Patel (OpenERP)

[REM] account : Removed unused object references.

5865. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5866. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5867. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5868. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5869. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5870. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5871. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5872. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5873. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5874. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5875. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5876. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5877. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5878. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5879. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5880. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5881. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5882. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

Unmerged revisions

5882. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5881. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5880. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5879. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5878. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5877. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5876. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5875. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5874. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

5873. By DJ Patel (OpenERP)

[Merge] Merge with main addons.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_invoice.py'
2--- account/account_invoice.py 2012-10-08 12:17:45 +0000
3+++ account/account_invoice.py 2012-10-11 04:55:26 +0000
4@@ -645,7 +645,7 @@
5 res[r[0]].append( r[1] )
6 return res
7
8- def copy(self, cr, uid, id, default=None, context=None):
9+ def copy_data(self, cr, uid, id, default=None, context=None):
10 default = default or {}
11 default.update({
12 'state':'draft',
13@@ -664,7 +664,7 @@
14 default.update({
15 'date_due':False
16 })
17- return super(account_invoice, self).copy(cr, uid, id, default, context)
18+ return super(account_invoice, self).copy_data(cr, uid, id, default, context)
19
20 def test_paid(self, cr, uid, ids, *args):
21 res = self.move_line_id_payment_get(cr, uid, ids)
22@@ -1124,26 +1124,12 @@
23 ids = self.search(cr, user, [('name',operator,name)] + args, limit=limit, context=context)
24 return self.name_get(cr, user, ids, context)
25
26- def _refund_cleanup_lines(self, cr, uid, lines):
27- for line in lines:
28- del line['id']
29- del line['invoice_id']
30- for field in ('company_id', 'partner_id', 'account_id', 'product_id',
31- 'uos_id', 'account_analytic_id', 'tax_code_id', 'base_code_id'):
32- if line.get(field):
33- line[field] = line[field][0]
34- if 'invoice_line_tax_id' in line:
35- line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
36- return map(lambda x: (0,0,x), lines)
37-
38 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
39- invoices = self.read(cr, uid, ids, ['name', 'type', 'number', 'reference', 'comment', 'date_due', 'partner_id', 'partner_contact', 'partner_insite', 'partner_ref', 'payment_term', 'account_id', 'currency_id', 'invoice_line', 'tax_line', 'journal_id', 'company_id'])
40- obj_invoice_line = self.pool.get('account.invoice.line')
41- obj_invoice_tax = self.pool.get('account.invoice.tax')
42 obj_journal = self.pool.get('account.journal')
43+
44+ invoices = [self.copy_data(cr, uid, id) for id in ids]
45 new_ids = []
46 for invoice in invoices:
47- del invoice['id']
48
49 type_dict = {
50 'out_invoice': 'out_refund', # Customer Invoice
51@@ -1152,12 +1138,6 @@
52 'in_refund': 'in_invoice', # Supplier Refund
53 }
54
55- invoice_lines = obj_invoice_line.read(cr, uid, invoice['invoice_line'])
56- invoice_lines = self._refund_cleanup_lines(cr, uid, invoice_lines)
57-
58- tax_lines = obj_invoice_tax.read(cr, uid, invoice['tax_line'])
59- tax_lines = filter(lambda l: l['manual'], tax_lines)
60- tax_lines = self._refund_cleanup_lines(cr, uid, tax_lines)
61 if journal_id:
62 refund_journal_ids = [journal_id]
63 elif invoice['type'] == 'in_invoice':
64@@ -1172,9 +1152,9 @@
65 'date_invoice': date,
66 'state': 'draft',
67 'number': False,
68- 'invoice_line': invoice_lines,
69- 'tax_line': tax_lines,
70- 'journal_id': refund_journal_ids
71+ 'invoice_line': invoice['invoice_line'],
72+ 'tax_line': invoice['tax_line'],
73+ 'journal_id': refund_journal_ids and refund_journal_ids[0] or False
74 })
75 if period_id:
76 invoice.update({
77@@ -1184,10 +1164,6 @@
78 invoice.update({
79 'name': description,
80 })
81- # take the id part of the tuple returned for many2one fields
82- for field in ('partner_id', 'company_id',
83- 'account_id', 'currency_id', 'payment_term', 'journal_id'):
84- invoice[field] = invoice[field] and invoice[field][0]
85 # create the new invoice
86 new_ids.append(self.create(cr, uid, invoice))
87
88@@ -1373,7 +1349,7 @@
89 'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),
90 'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
91 'company_id': fields.related('invoice_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
92- 'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True)
93+ 'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True),
94 }
95
96 def _default_account_id(self, cr, uid, context=None):
97
98=== modified file 'account/wizard/account_invoice_refund.py'
99--- account/wizard/account_invoice_refund.py 2012-09-30 17:02:56 +0000
100+++ account/wizard/account_invoice_refund.py 2012-10-11 04:55:26 +0000
101@@ -91,8 +91,6 @@
102 mod_obj = self.pool.get('ir.model.data')
103 act_obj = self.pool.get('ir.actions.act_window')
104 wf_service = netsvc.LocalService('workflow')
105- inv_tax_obj = self.pool.get('account.invoice.tax')
106- inv_line_obj = self.pool.get('account.invoice.line')
107 res_users_obj = self.pool.get('res.users')
108 if context is None:
109 context = {}
110@@ -174,32 +172,17 @@
111 writeoff_acc_id=inv.account_id.id
112 )
113 if mode == 'modify':
114- invoice = inv_obj.read(cr, uid, [inv.id],
115- ['name', 'type', 'number', 'reference',
116- 'comment', 'date_due', 'partner_id',
117- 'partner_insite', 'partner_contact',
118- 'partner_ref', 'payment_term', 'account_id',
119- 'currency_id', 'invoice_line', 'tax_line',
120- 'journal_id', 'period_id'], context=context)
121- invoice = invoice[0]
122- del invoice['id']
123- invoice_lines = inv_line_obj.read(cr, uid, invoice['invoice_line'], context=context)
124- invoice_lines = inv_obj._refund_cleanup_lines(cr, uid, invoice_lines)
125- tax_lines = inv_tax_obj.read(cr, uid, invoice['tax_line'], context=context)
126- tax_lines = inv_obj._refund_cleanup_lines(cr, uid, tax_lines)
127+ invoice = inv_obj.copy_data(cr, uid, inv.id, context=context)
128 invoice.update({
129 'type': inv.type,
130 'date_invoice': date,
131 'state': 'draft',
132 'number': False,
133- 'invoice_line': invoice_lines,
134- 'tax_line': tax_lines,
135+ 'invoice_line': invoice['invoice_line'],
136+ 'tax_line': invoice['tax_line'],
137 'period_id': period,
138 'name': description
139 })
140- for field in ('partner_id', 'account_id', 'currency_id',
141- 'payment_term', 'journal_id'):
142- invoice[field] = invoice[field] and invoice[field][0]
143 inv_id = inv_obj.create(cr, uid, invoice, {})
144 if inv.payment_term.id:
145 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
146
147=== modified file 'account_anglo_saxon/invoice.py'
148--- account_anglo_saxon/invoice.py 2012-03-06 05:58:47 +0000
149+++ account_anglo_saxon/invoice.py 2012-10-11 04:55:26 +0000
150@@ -1,8 +1,8 @@
151 ##############################################################################
152-#
153+#
154 # OpenERP, Open Source Management Solution
155-# Copyright (C)
156-# 2004-2010 Tiny SPRL (<http://tiny.be>).
157+# Copyright (C)
158+# 2004-2010 Tiny SPRL (<http://tiny.be>).
159 # 2009-2010 Veritos (http://veritos.nl).
160 # All Rights Reserved
161 #
162@@ -17,7 +17,7 @@
163 # GNU Affero General Public License for more details.
164 #
165 # You should have received a copy of the GNU Affero General Public License
166-# along with this program. If not, see <http://www.gnu.org/licenses/>.
167+# along with this program. If not, see <http://www.gnu.org/licenses/>.
168 #
169 ##############################################################################
170
171@@ -162,23 +162,23 @@
172 class account_invoice(osv.osv):
173 _inherit = "account.invoice"
174
175- def _refund_cleanup_lines(self, cr, uid, lines):
176- for line in lines:
177- inv_id = line['invoice_id']
178- inv_obj = self.browse(cr, uid, inv_id[0])
179- if inv_obj.type == 'in_invoice':
180- if line.get('product_id',False):
181- product_obj = self.pool.get('product.product').browse(cr, uid, line['product_id'][0])
182- oa = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id
183- if not oa:
184- oa = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id
185- if oa:
186- fpos = inv_obj.fiscal_position or False
187- a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, oa)
188- account_data = self.pool.get('account.account').read(cr, uid, [a], ['name'])[0]
189- line.update({'account_id': (account_data['id'],account_data['name'])})
190- res = super(account_invoice,self)._refund_cleanup_lines(cr, uid, lines)
191- return res
192+ def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
193+ product_obj = self.pool.get('product.product')
194+ fiscal_pos_obj = self.pool.get('account.fiscal.position')
195+ inv_line_obj = self.pool.get('account.invoice.line')
196+
197+ for invoice in self.browse(cr, uid, ids):
198+ if invoice.type == 'in_invoice':
199+ for line in invoice.invoice_line:
200+ if line.product_id:
201+ product = product_obj.browse(cr, uid, line.product_id.id)
202+ stock_output_acc = product.property_stock_account_output and product.property_stock_account_output.id
203+ if not stock_output_acc:
204+ stock_output_acc = product.categ_id.property_stock_account_output_categ and product.categ_id.property_stock_account_output_categ.id
205+ if stock_output_acc:
206+ fpos = invoice.fiscal_position or False
207+ inv_line_obj.write(cr, uid, [line.id], {'account_id': fiscal_pos_obj.map_account(cr, uid, fpos, stock_output_acc)})
208+ return super(account_invoice, self).refund(cr, uid, ids, date, period_id, description, journal_id)
209
210 account_invoice()
211 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches

to all changes: