[Merge] : branch merged with lp:openobject-addons
[odoo/odoo.git] / addons / sale / wizard / sale_line_invoice.py
index 5ce0ac1..15405f0 100644 (file)
 ##############################################################################
 
 from osv import fields, osv
-from service import web_services
-import wizard
-import netsvc
-import ir
-import pooler
+from tools.translate import _
 
 class sale_order_line_make_invoice(osv.osv_memory):
     _name = "sale.order.line.make.invoice"
@@ -75,7 +71,7 @@ class sale_order_line_make_invoice(osv.osv_memory):
                 'currency_id' : order.pricelist_id.currency_id.id,
                 'comment': order.note,
                 'payment_term': pay_term,
-                'fiscal_position': order.partner_id.property_account_position.id
+                'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
             }
             inv_id = self.pool.get('account.invoice').create(cr, uid, inv)
             return inv_id
@@ -103,6 +99,8 @@ class sale_order_line_make_invoice(osv.osv_memory):
                 wf_service.trg_validate(uid, 'sale.order', line.order_id.id, 'all_lines', cr)
                 sales_order_obj.write(cr,uid,[line.order_id.id],{'state' : 'progress'})
 
+        if not invoices:
+            raise osv.except_osv(_('Warning'),_('Invoice cannot be created for this Sale Order Line due to one of the following reasons:\n1.The state of this sale order line is either "draft" or "cancel"!\n2.The Sale Order Line is Invoiced!'))
         for result in invoices.values():
             order = result[0][0].order_id
             il = map(lambda x: x[1], result)