[FIX] mrp_repair : Creation of invoices corrected from repairs with fees
authorJay (OpenERP) <jvo@tinyerp.com>
Wed, 1 Sep 2010 08:28:29 +0000 (13:58 +0530)
committerJay (OpenERP) <jvo@tinyerp.com>
Wed, 1 Sep 2010 08:28:29 +0000 (13:58 +0530)
lp bug: https://launchpad.net/bugs/619078 fixed

bzr revid: jvo@tinyerp.com-20100901082829-n2k3yl7qpxghaxl9

addons/mrp_repair/mrp_repair.py

index cea46cc..19c2774 100644 (file)
@@ -260,7 +260,7 @@ class mrp_repair(osv.osv):
             if repair.state in ('draft','cancel') or repair.invoice_id:
                 continue
             if not (repair.partner_id.id and repair.partner_invoice_id.id):
-                raise osv.except_osv(_('No partner !'),_('You have to select a partner in the repair form !'))
+                raise osv.except_osv(_('No partner !'),_('You have to select a partner and invoicing address in the repair form !'))
             comment=repair.quotation_notes
             if (repair.invoice_method != 'none'):
                 if group and repair.partner_invoice_id.id in invoices_group:
@@ -298,7 +298,7 @@ class mrp_repair(osv.osv):
                             name = repair.name + '-' + operation.name
                         else:
                             name = operation.name
-
+                        
                         if operation.product_id.property_account_income:
                             account_id = operation.product_id.property_account_income
                         elif operation.product_id.categ_id.property_account_income_categ:
@@ -306,7 +306,7 @@ class mrp_repair(osv.osv):
                         else:
                             raise osv.except_osv(_('Error !'), _('No account defined for product "%s".') % operation.product_id.name )
 
-                        invoice_line_id=self.pool.get('account.invoice.line').create(cr, uid, {
+                        invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, {
                             'invoice_id': inv_id,
                             'name': name,
                             'origin':repair.name,
@@ -325,11 +325,19 @@ class mrp_repair(osv.osv):
                             name = repair.name + '-' + fee.name
                         else:
                             name = fee.name
-                        invoice_fee_id=self.pool.get('account.invoice.line').create(cr, uid, {
+                        if not fee.product_id:
+                            raise osv.except_osv(_('Warning !'), _('No product defined on Fees!'))
+                        if fee.product_id.property_account_income:
+                            account_id = fee.product_id.property_account_income
+                        elif fee.product_id.categ_id.property_account_income_categ:
+                            account_id = fee.product_id.categ_id.property_account_income_categ.id
+                        else:
+                            raise osv.except_osv(_('Error !'), _('No account defined for product "%s".') % fee.product_id.name)
+                        invoice_fee_id = self.pool.get('account.invoice.line').create(cr, uid, {
                             'invoice_id': inv_id,
                             'name': name,
                             'origin':repair.name,
-                            'account_id': a,
+                            'account_id': account_id,
                             'quantity': fee.product_uom_qty,
                             'invoice_line_tax_id': [(6,0,[x.id for x in fee.tax_id])],
                             'uos_id': fee.product_uom.id,