Scusate, questo è il mio codice:
def create_invoice(self, cr, uid, ids, context=None):
wf_service = netsvc.LocalService('workflow')
if context is None:
context = {}
ctx = context.copy()
ctx['_partial_invoice'] = {}
so_line_obj = self.pool['sale.order.line']
so_obj = self.pool['sale.order']
order_lines = {}
for wiz in self.browse(cr, uid, ids, context=context):
for line in wiz.line_ids:
if line.price_unit == 0:
return self.write(cr, uid, ids, {'state': 'done'}, context=context)
sale_order = line.sale_order_line_id.order_id
if line.price_unit > (line.order_qty * line.prod_original_quantity - line.qty_invoiced):
raise orm.except_orm(_('Incorrect Data'),
_("Errore! L'importo inserito non è corretto"))
if sale_order.id not in order_lines:
# order_lines[sale_order.id] = [line.sale_order_line_id.id]
order_lines[sale_order.id] = []
order_lines[sale_order.id].append(line.sale_order_line_id.id)
ctx['_partial_invoice'][line.sale_order_line_id.id] = line.price_unit #line.quantity *
for order_id in order_lines:
line_ids = order_lines[order_id]
invoice_line_ids = so_line_obj.invoice_line_create(cr,
uid,
line_ids,
context=ctx)
order = so_obj.browse(cr, uid, order_id, context=context)
invoice_id = so_obj._make_invoice(cr, uid,
order,
invoice_line_ids,
context=ctx)
_logger.info('created invoice %d', invoice_id)
if all(line.invoiced for line in order.order_line):
wf_service.trg_validate(uid, 'sale.order', order.id, 'manual_invoice', cr)
if context.get('open_invoices', False):
return self.open_invoices(cr, uid, ids, invoice_id, context=context)
return {'type': 'ir.actions.act_window_close'}
def open_invoices(self, cr, uid, ids, invoice_ids, context=None):
""" open a view on one of the given invoice_ids """
ir_model_data = self.pool.get('ir.model.data')
form_res = ir_model_data.get_object_reference(cr, uid, 'account', 'invoice_form')
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',
'view_mode': 'form,tree',
'res_model': 'account.invoice',
'res_id': invoice_ids,
'view_id': False,
'views': [(form_id, 'form'), (tree_id, 'tree')],
'context': {'type': 'out_invoice'},
'type': 'ir.actions.act_window',
}
Perchè SE line.price_unit è uguale a 0 non mi segna l'ordine come Fatturato?
Perchè quando creo la fattura e lancio la funzione open_invoices (la quale credo dovrebbe mandarmi direttamente sulla pag della fattura) non fa niente?
Chiedo gentilmente il vostro aiuto!
Grazie