[FIX] sale: invoicing several sale order lines in batch was not correctly working (only the first order was triggered and opened) + small refactoring
bzr revid: qdp-launchpad@openerp.com-20130326170202-d2fhez9sz04zionw
This commit is contained in:
@@ -26,6 +26,7 @@ from openerp import netsvc
|
||||
class sale_order_line_make_invoice(osv.osv_memory):
|
||||
_name = "sale.order.line.make.invoice"
|
||||
_description = "Sale OrderLine Make_invoice"
|
||||
|
||||
def make_invoices(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
To make invoices.
|
||||
@@ -83,33 +84,29 @@ class sale_order_line_make_invoice(osv.osv_memory):
|
||||
wf_service = netsvc.LocalService('workflow')
|
||||
for line in sales_order_line_obj.browse(cr, uid, context.get('active_ids', []), context=context):
|
||||
if (not line.invoiced) and (line.state not in ('draft', 'cancel')):
|
||||
if not line.order_id.id in invoices:
|
||||
invoices[line.order_id.id] = []
|
||||
line_id = sales_order_line_obj.invoice_line_create(cr, uid,
|
||||
[line.id])
|
||||
if not line.order_id in invoices:
|
||||
invoices[line.order_id] = []
|
||||
line_id = sales_order_line_obj.invoice_line_create(cr, uid, [line.id])
|
||||
for lid in line_id:
|
||||
invoices[line.order_id.id].append((line, lid))
|
||||
for result in invoices.values():
|
||||
order = result[0][0].order_id
|
||||
il = map(lambda x: x[1], result)
|
||||
invoices[line.order_id].append(lid)
|
||||
for order, il in invoices.items():
|
||||
res = make_invoice(order, il)
|
||||
cr.execute('INSERT INTO sale_order_invoice_rel \
|
||||
(order_id,invoice_id) values (%s,%s)', (order.id, res))
|
||||
|
||||
flag = True
|
||||
data_sale = sales_order_obj.browse(cr, uid, line.order_id.id, context=context)
|
||||
data_sale = sales_order_obj.browse(cr, uid, order.id, context=context)
|
||||
for line in data_sale.order_line:
|
||||
if not line.invoiced:
|
||||
flag = False
|
||||
break
|
||||
if flag:
|
||||
wf_service.trg_validate(uid, 'sale.order', line.order_id.id, 'manual_invoice', cr)
|
||||
sales_order_obj.write(cr, uid, [line.order_id.id], {'state': 'progress'})
|
||||
wf_service.trg_validate(uid, 'sale.order', order.id, 'manual_invoice', cr)
|
||||
sales_order_obj.write(cr, uid, [order.id], {'state': 'progress'})
|
||||
|
||||
if not invoices:
|
||||
raise osv.except_osv(_('Warning!'), _('Invoice cannot be created for this Sales Order Line due to one of the following reasons:\n1.The state of this sales order line is either "draft" or "cancel"!\n2.The Sales Order Line is Invoiced!'))
|
||||
if context.get('open_invoices', False):
|
||||
return self.open_invoices( cr, uid, ids, res, context=context)
|
||||
return self.open_invoices(cr, uid, ids, res, context=context)
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def open_invoices(self, cr, uid, ids, invoice_ids, context=None):
|
||||
@@ -119,7 +116,7 @@ class sale_order_line_make_invoice(osv.osv_memory):
|
||||
form_id = form_res and form_res[1] or False
|
||||
tree_res = ir_model_data.get_object_reference(cr, uid, 'account', 'invoice_tree')
|
||||
tree_id = tree_res and tree_res[1] or False
|
||||
|
||||
|
||||
return {
|
||||
'name': _('Invoice'),
|
||||
'view_type': 'form',
|
||||
|
||||
Reference in New Issue
Block a user