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
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py 2012-10-08 12:17:45 +0000
+++ account/account_invoice.py 2012-10-11 04:55:26 +0000
@@ -645,7 +645,7 @@
645 res[r[0]].append( r[1] )645 res[r[0]].append( r[1] )
646 return res646 return res
647647
648 def copy(self, cr, uid, id, default=None, context=None):648 def copy_data(self, cr, uid, id, default=None, context=None):
649 default = default or {}649 default = default or {}
650 default.update({650 default.update({
651 'state':'draft',651 'state':'draft',
@@ -664,7 +664,7 @@
664 default.update({664 default.update({
665 'date_due':False665 'date_due':False
666 })666 })
667 return super(account_invoice, self).copy(cr, uid, id, default, context)667 return super(account_invoice, self).copy_data(cr, uid, id, default, context)
668668
669 def test_paid(self, cr, uid, ids, *args):669 def test_paid(self, cr, uid, ids, *args):
670 res = self.move_line_id_payment_get(cr, uid, ids)670 res = self.move_line_id_payment_get(cr, uid, ids)
@@ -1124,26 +1124,12 @@
1124 ids = self.search(cr, user, [('name',operator,name)] + args, limit=limit, context=context)1124 ids = self.search(cr, user, [('name',operator,name)] + args, limit=limit, context=context)
1125 return self.name_get(cr, user, ids, context)1125 return self.name_get(cr, user, ids, context)
11261126
1127 def _refund_cleanup_lines(self, cr, uid, lines):
1128 for line in lines:
1129 del line['id']
1130 del line['invoice_id']
1131 for field in ('company_id', 'partner_id', 'account_id', 'product_id',
1132 'uos_id', 'account_analytic_id', 'tax_code_id', 'base_code_id'):
1133 if line.get(field):
1134 line[field] = line[field][0]
1135 if 'invoice_line_tax_id' in line:
1136 line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
1137 return map(lambda x: (0,0,x), lines)
1138
1139 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):1127 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
1140 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'])
1141 obj_invoice_line = self.pool.get('account.invoice.line')
1142 obj_invoice_tax = self.pool.get('account.invoice.tax')
1143 obj_journal = self.pool.get('account.journal')1128 obj_journal = self.pool.get('account.journal')
1129
1130 invoices = [self.copy_data(cr, uid, id) for id in ids]
1144 new_ids = []1131 new_ids = []
1145 for invoice in invoices:1132 for invoice in invoices:
1146 del invoice['id']
11471133
1148 type_dict = {1134 type_dict = {
1149 'out_invoice': 'out_refund', # Customer Invoice1135 'out_invoice': 'out_refund', # Customer Invoice
@@ -1152,12 +1138,6 @@
1152 'in_refund': 'in_invoice', # Supplier Refund1138 'in_refund': 'in_invoice', # Supplier Refund
1153 }1139 }
11541140
1155 invoice_lines = obj_invoice_line.read(cr, uid, invoice['invoice_line'])
1156 invoice_lines = self._refund_cleanup_lines(cr, uid, invoice_lines)
1157
1158 tax_lines = obj_invoice_tax.read(cr, uid, invoice['tax_line'])
1159 tax_lines = filter(lambda l: l['manual'], tax_lines)
1160 tax_lines = self._refund_cleanup_lines(cr, uid, tax_lines)
1161 if journal_id:1141 if journal_id:
1162 refund_journal_ids = [journal_id]1142 refund_journal_ids = [journal_id]
1163 elif invoice['type'] == 'in_invoice':1143 elif invoice['type'] == 'in_invoice':
@@ -1172,9 +1152,9 @@
1172 'date_invoice': date,1152 'date_invoice': date,
1173 'state': 'draft',1153 'state': 'draft',
1174 'number': False,1154 'number': False,
1175 'invoice_line': invoice_lines,1155 'invoice_line': invoice['invoice_line'],
1176 'tax_line': tax_lines,1156 'tax_line': invoice['tax_line'],
1177 'journal_id': refund_journal_ids1157 'journal_id': refund_journal_ids and refund_journal_ids[0] or False
1178 })1158 })
1179 if period_id:1159 if period_id:
1180 invoice.update({1160 invoice.update({
@@ -1184,10 +1164,6 @@
1184 invoice.update({1164 invoice.update({
1185 'name': description,1165 'name': description,
1186 })1166 })
1187 # take the id part of the tuple returned for many2one fields
1188 for field in ('partner_id', 'company_id',
1189 'account_id', 'currency_id', 'payment_term', 'journal_id'):
1190 invoice[field] = invoice[field] and invoice[field][0]
1191 # create the new invoice1167 # create the new invoice
1192 new_ids.append(self.create(cr, uid, invoice))1168 new_ids.append(self.create(cr, uid, invoice))
11931169
@@ -1373,7 +1349,7 @@
1373 'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),1349 'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),
1374 'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),1350 'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
1375 'company_id': fields.related('invoice_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),1351 'company_id': fields.related('invoice_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
1376 'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True)1352 'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True),
1377 }1353 }
13781354
1379 def _default_account_id(self, cr, uid, context=None):1355 def _default_account_id(self, cr, uid, context=None):
13801356
=== modified file 'account/wizard/account_invoice_refund.py'
--- account/wizard/account_invoice_refund.py 2012-09-30 17:02:56 +0000
+++ account/wizard/account_invoice_refund.py 2012-10-11 04:55:26 +0000
@@ -91,8 +91,6 @@
91 mod_obj = self.pool.get('ir.model.data')91 mod_obj = self.pool.get('ir.model.data')
92 act_obj = self.pool.get('ir.actions.act_window')92 act_obj = self.pool.get('ir.actions.act_window')
93 wf_service = netsvc.LocalService('workflow')93 wf_service = netsvc.LocalService('workflow')
94 inv_tax_obj = self.pool.get('account.invoice.tax')
95 inv_line_obj = self.pool.get('account.invoice.line')
96 res_users_obj = self.pool.get('res.users')94 res_users_obj = self.pool.get('res.users')
97 if context is None:95 if context is None:
98 context = {}96 context = {}
@@ -174,32 +172,17 @@
174 writeoff_acc_id=inv.account_id.id172 writeoff_acc_id=inv.account_id.id
175 )173 )
176 if mode == 'modify':174 if mode == 'modify':
177 invoice = inv_obj.read(cr, uid, [inv.id],175 invoice = inv_obj.copy_data(cr, uid, inv.id, context=context)
178 ['name', 'type', 'number', 'reference',
179 'comment', 'date_due', 'partner_id',
180 'partner_insite', 'partner_contact',
181 'partner_ref', 'payment_term', 'account_id',
182 'currency_id', 'invoice_line', 'tax_line',
183 'journal_id', 'period_id'], context=context)
184 invoice = invoice[0]
185 del invoice['id']
186 invoice_lines = inv_line_obj.read(cr, uid, invoice['invoice_line'], context=context)
187 invoice_lines = inv_obj._refund_cleanup_lines(cr, uid, invoice_lines)
188 tax_lines = inv_tax_obj.read(cr, uid, invoice['tax_line'], context=context)
189 tax_lines = inv_obj._refund_cleanup_lines(cr, uid, tax_lines)
190 invoice.update({176 invoice.update({
191 'type': inv.type,177 'type': inv.type,
192 'date_invoice': date,178 'date_invoice': date,
193 'state': 'draft',179 'state': 'draft',
194 'number': False,180 'number': False,
195 'invoice_line': invoice_lines,181 'invoice_line': invoice['invoice_line'],
196 'tax_line': tax_lines,182 'tax_line': invoice['tax_line'],
197 'period_id': period,183 'period_id': period,
198 'name': description184 'name': description
199 })185 })
200 for field in ('partner_id', 'account_id', 'currency_id',
201 'payment_term', 'journal_id'):
202 invoice[field] = invoice[field] and invoice[field][0]
203 inv_id = inv_obj.create(cr, uid, invoice, {})186 inv_id = inv_obj.create(cr, uid, invoice, {})
204 if inv.payment_term.id:187 if inv.payment_term.id:
205 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)188 data = inv_obj.onchange_payment_term_date_invoice(cr, uid, [inv_id], inv.payment_term.id, date)
206189
=== modified file 'account_anglo_saxon/invoice.py'
--- account_anglo_saxon/invoice.py 2012-03-06 05:58:47 +0000
+++ account_anglo_saxon/invoice.py 2012-10-11 04:55:26 +0000
@@ -1,8 +1,8 @@
1##############################################################################1##############################################################################
2# 2#
3# OpenERP, Open Source Management Solution3# OpenERP, Open Source Management Solution
4# Copyright (C) 4# Copyright (C)
5# 2004-2010 Tiny SPRL (<http://tiny.be>). 5# 2004-2010 Tiny SPRL (<http://tiny.be>).
6# 2009-2010 Veritos (http://veritos.nl).6# 2009-2010 Veritos (http://veritos.nl).
7# All Rights Reserved7# All Rights Reserved
8#8#
@@ -17,7 +17,7 @@
17# GNU Affero General Public License for more details.17# GNU Affero General Public License for more details.
18#18#
19# You should have received a copy of the GNU Affero General Public License19# You should have received a copy of the GNU Affero General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>. 20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21#21#
22##############################################################################22##############################################################################
2323
@@ -162,23 +162,23 @@
162class account_invoice(osv.osv):162class account_invoice(osv.osv):
163 _inherit = "account.invoice"163 _inherit = "account.invoice"
164164
165 def _refund_cleanup_lines(self, cr, uid, lines):165 def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
166 for line in lines:166 product_obj = self.pool.get('product.product')
167 inv_id = line['invoice_id']167 fiscal_pos_obj = self.pool.get('account.fiscal.position')
168 inv_obj = self.browse(cr, uid, inv_id[0])168 inv_line_obj = self.pool.get('account.invoice.line')
169 if inv_obj.type == 'in_invoice':169
170 if line.get('product_id',False):170 for invoice in self.browse(cr, uid, ids):
171 product_obj = self.pool.get('product.product').browse(cr, uid, line['product_id'][0])171 if invoice.type == 'in_invoice':
172 oa = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id172 for line in invoice.invoice_line:
173 if not oa:173 if line.product_id:
174 oa = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id174 product = product_obj.browse(cr, uid, line.product_id.id)
175 if oa:175 stock_output_acc = product.property_stock_account_output and product.property_stock_account_output.id
176 fpos = inv_obj.fiscal_position or False176 if not stock_output_acc:
177 a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, oa)177 stock_output_acc = product.categ_id.property_stock_account_output_categ and product.categ_id.property_stock_account_output_categ.id
178 account_data = self.pool.get('account.account').read(cr, uid, [a], ['name'])[0]178 if stock_output_acc:
179 line.update({'account_id': (account_data['id'],account_data['name'])})179 fpos = invoice.fiscal_position or False
180 res = super(account_invoice,self)._refund_cleanup_lines(cr, uid, lines)180 inv_line_obj.write(cr, uid, [line.id], {'account_id': fiscal_pos_obj.map_account(cr, uid, fpos, stock_output_acc)})
181 return res181 return super(account_invoice, self).refund(cr, uid, ids, date, period_id, description, journal_id)
182182
183account_invoice()183account_invoice()
184# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:184# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches

to all changes: