diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index 741bcf3a526..3c7003e49b0 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -829,12 +829,13 @@ class sale_order_line(osv.osv):
'number_packages': fields.function(_number_packages, method=True, type='integer', string='Number Packages'),
'notes': fields.text('Notes'),
'th_weight': fields.float('Weight', readonly=True, states={'draft':[('readonly',False)]}),
- 'state': fields.selection([('draft', 'Draft'),('confirmed', 'Confirmed'),('done', 'Done'),('cancel', 'Cancelled'),('exception', 'Exception')], 'State', required=True, readonly=True,
+ 'state': fields.selection([('draft', 'Draft'),('confirmed', 'Confirmed'),('done', 'Done'),('cancel', 'Cancelled'),('exception', 'Exception'),('invoiced','Invoiced')], 'State', required=True, readonly=True,
help=' * The \'Draft\' state is set automatically when sale order in draft state. \
\n* The \'Confirmed\' state is set automatically when sale order in confirm state. \
\n* The \'Exception\' state is set automatically when sale order is set as exception. \
\n* The \'Done\' state is set automatically when sale order is set as done. \
- \n* The \'Cancelled\' state is set automatically when user cancel sale order.'),
+ \n* The \'Cancelled\' state is set automatically when user cancel sale order\
+ \n* The \'Invoiced\' state is set automatically when user creates sale order line invoice.'),
'order_partner_id': fields.related('order_id', 'partner_id', type='many2one', relation='res.partner', string='Customer'),
'salesman_id':fields.related('order_id', 'user_id', type='many2one', relation='res.users', string='Salesman'),
'company_id': fields.related('order_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True, states={'draft':[('readonly',False)]}),
@@ -852,11 +853,11 @@ class sale_order_line(osv.osv):
'product_packaging': False
}
- def call_make_invoices(self, cr, uid, ids, context):
+ def create_sale_order_line_invoice(self, cr, uid, ids, context):
line_make_invoice_obj = self.pool.get("sale.order.line.make.invoice")
context.update({'active_ids' : ids,'active_id' : ids})
- invoice_call = line_make_invoice_obj.make_invoices(cr, uid, ids, context)
- return True
+ invoice_id = line_make_invoice_obj.make_invoices(cr, uid, ids, context)
+ return self.write(cr, uid, ids, {'state': 'invoiced'})
def invoice_line_create(self, cr, uid, ids, context=None):
if context is None:
@@ -939,6 +940,10 @@ class sale_order_line(osv.osv):
for line in self.browse(cr, uid, ids, context=context):
if line.invoiced:
raise osv.except_osv(_('Invalid action !'), _('You cannot cancel a sale order line that has already been invoiced !'))
+ if line.order_id.picking_ids:
+ raise osv.except_osv(
+ _('Could not cancel sale order line!'),
+ _('You must first cancel stock move attached to this sale order line.'))
message = _('Sale order line') + " '" + line.name + "' "+_("is cancelled")
self.log(cr, uid, id, message)
return self.write(cr, uid, ids, {'state': 'cancel'})
diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml
index 82bf98032ff..44e75125e31 100644
--- a/addons/sale/sale_view.xml
+++ b/addons/sale/sale_view.xml
@@ -165,10 +165,10 @@
@@ -398,22 +398,19 @@
-
-
+
+ icon="gtk-cancel"/>
+