Divyesh Makwana(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-896462-mdi into 
lp:openobject-addons.

Requested reviews:
  Divyesh Makwana(OpenERP) (mdi-openerp)
  Mustufa Rangwala (Open ERP) (mra-tinyerp)
  Purnendu Singh (OpenERP) (psi-tinyerp)
  Raphael Collet (OpenERP) (rco-openerp)
  qdp (OpenERP) (qdp)
  Moisés López - http://www.vauxoo.com (moylop260)
Related bugs:
  Bug #896462 in OpenERP Addons: "[trunk & 6.0] [account] [wizard 
account.invoice.refund] Invoice refund wizard make error with other relational 
fields"
  https://bugs.launchpad.net/openobject-addons/+bug/896462

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-896462-mdi/+merge/84734

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)
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-896462-mdi/+merge/84734
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-896462-mdi.
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py	2012-09-05 07:31:34 +0000
+++ account/account_invoice.py	2012-09-10 06:49:24 +0000
@@ -1114,26 +1114,15 @@
             ids = self.search(cr, user, [('name',operator,name)] + args, limit=limit, context=context)
         return self.name_get(cr, user, ids, context)
 
-    def _refund_cleanup_lines(self, cr, uid, lines):
-        for line in lines:
-            del line['id']
-            del line['invoice_id']
-            for field in ('company_id', 'partner_id', 'account_id', 'product_id',
-                          'uos_id', 'account_analytic_id', 'tax_code_id', 'base_code_id'):
-                if line.get(field):
-                    line[field] = line[field][0]
-            if 'invoice_line_tax_id' in line:
-                line['invoice_line_tax_id'] = [(6,0, line.get('invoice_line_tax_id', [])) ]
-        return map(lambda x: (0,0,x), lines)
-
     def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
-        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'])
         obj_invoice_line = self.pool.get('account.invoice.line')
         obj_invoice_tax = self.pool.get('account.invoice.tax')
         obj_journal = self.pool.get('account.journal')
+        invoices = []
+        for id in ids:
+            invoices.append(self.copy_data(cr, uid, id))
         new_ids = []
         for invoice in invoices:
-            del invoice['id']
 
             type_dict = {
                 'out_invoice': 'out_refund', # Customer Invoice
@@ -1142,12 +1131,6 @@
                 'in_refund': 'in_invoice',   # Supplier Refund
             }
 
-            invoice_lines = obj_invoice_line.read(cr, uid, invoice['invoice_line'])
-            invoice_lines = self._refund_cleanup_lines(cr, uid, invoice_lines)
-
-            tax_lines = obj_invoice_tax.read(cr, uid, invoice['tax_line'])
-            tax_lines = filter(lambda l: l['manual'], tax_lines)
-            tax_lines = self._refund_cleanup_lines(cr, uid, tax_lines)
             if journal_id:
                 refund_journal_ids = [journal_id]
             elif invoice['type'] == 'in_invoice':
@@ -1162,9 +1145,9 @@
                 'date_invoice': date,
                 'state': 'draft',
                 'number': False,
-                'invoice_line': invoice_lines,
-                'tax_line': tax_lines,
-                'journal_id': refund_journal_ids
+                'invoice_line': invoice['invoice_line'],
+                'tax_line': invoice['tax_line'],
+                'journal_id': refund_journal_ids and refund_journal_ids[0] or False
             })
             if period_id:
                 invoice.update({
@@ -1174,10 +1157,6 @@
                 invoice.update({
                     'name': description,
                 })
-            # take the id part of the tuple returned for many2one fields
-            for field in ('partner_id', 'company_id',
-                    'account_id', 'currency_id', 'payment_term', 'journal_id'):
-                invoice[field] = invoice[field] and invoice[field][0]
             # create the new invoice
             new_ids.append(self.create(cr, uid, invoice))
 
@@ -1360,7 +1339,7 @@
         'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),
         'account_analytic_id':  fields.many2one('account.analytic.account', 'Analytic Account'),
         'company_id': fields.related('invoice_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
-        'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True)
+        'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True),
     }
 
     def _default_account_id(self, cr, uid, ids, context=None):

=== modified file 'account/wizard/account_invoice_refund.py'
--- account/wizard/account_invoice_refund.py	2012-08-07 11:31:37 +0000
+++ account/wizard/account_invoice_refund.py	2012-09-10 06:49:24 +0000
@@ -184,16 +184,20 @@
                         invoice = invoice[0]
                         del invoice['id']
                         invoice_lines = inv_line_obj.read(cr, uid, invoice['invoice_line'], context=context)
-                        invoice_lines = inv_obj._refund_cleanup_lines(cr, uid, invoice_lines)
+                        inv_list = []
+                        for inv_line in invoice_lines:
+                            inv_list.append(inv_line_obj.copy_data(cr, uid, inv_line['id']))
                         tax_lines = inv_tax_obj.read(cr, uid, invoice['tax_line'], context=context)
-                        tax_lines = inv_obj._refund_cleanup_lines(cr, uid, tax_lines)
+                        tax_list = []
+                        for tax_line in tax_lines:
+                            tax_list.append(inv_tax_obj.copy_data(cr, uid, tax_line['id']))
                         invoice.update({
                             'type': inv.type,
                             'date_invoice': date,
                             'state': 'draft',
                             'number': False,
-                            'invoice_line': invoice_lines,
-                            'tax_line': tax_lines,
+                            'invoice_line': map(lambda x: (0,0,x), inv_list),
+                            'tax_line': map(lambda x: (0,0,x), tax_list),
                             'period_id': period,
                             'name': description
                         })

=== 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-09-10 06:49:24 +0000
@@ -1,8 +1,8 @@
 ##############################################################################
-#    
+#
 #    OpenERP, Open Source Management Solution
-#    Copyright (C) 
-#    2004-2010 Tiny SPRL (<http://tiny.be>). 
+#    Copyright (C)
+#    2004-2010 Tiny SPRL (<http://tiny.be>).
 #    2009-2010 Veritos (http://veritos.nl).
 #    All Rights Reserved
 #
@@ -17,7 +17,7 @@
 #    GNU Affero General Public License for more details.
 #
 #    You should have received a copy of the GNU Affero General Public License
-#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
@@ -162,22 +162,25 @@
 class account_invoice(osv.osv):
     _inherit = "account.invoice"
 
-    def _refund_cleanup_lines(self, cr, uid, lines):
-        for line in lines:
-            inv_id = line['invoice_id']
-            inv_obj = self.browse(cr, uid, inv_id[0])
-            if inv_obj.type == 'in_invoice':
-                if line.get('product_id',False):
-                    product_obj = self.pool.get('product.product').browse(cr, uid, line['product_id'][0])
-                    oa = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id
-                    if not oa:
-                        oa = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id
-                    if oa:
-                        fpos = inv_obj.fiscal_position or False
-                        a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, oa)
-                        account_data = self.pool.get('account.account').read(cr, uid, [a], ['name'])[0]
-                        line.update({'account_id': (account_data['id'],account_data['name'])})
-        res = super(account_invoice,self)._refund_cleanup_lines(cr, uid, lines)
+    def refund(self, cr, uid, ids, date=None, period_id=None, description=None, journal_id=None):
+        invoices = []
+        for id in ids:
+            invoices.append(self.copy_data(cr, uid, id))
+        for invoice in invoices:
+            lines = map(lambda x: x[2], invoice['invoice_line'])
+            for line in lines:
+                if invoice['type'] == 'in_invoice':
+                    if 'product_id' in line:
+                        product_obj = self.pool.get('product.product').browse(cr, uid, line['product_id'])
+                        oa = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id
+                        if not oa:
+                            oa = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id
+                        if oa:
+                            fpos = invoice['fiscal_position'] or False
+                            a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, oa)
+                            account_data = self.pool.get('account.account').read(cr, uid, [a], ['name'])[0]
+                            line.update({'account_id': account_data['id']})
+        res = super(account_invoice, self).refund(cr, uid, ids, date, period_id, description, journal_id)
         return res
 
 account_invoice()

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to