Odoo 从代码验证发票

Odoo validate invoice from code

我从另一个模型创建发票,并希望得到验证而不是草稿 但是我的代码没有生成内部数字和总数。

invoice_id = self.pool.get('account.invoice').create(cr, uid,{
                                  'partner_id':self.supplier.id,
                                  'name' : 'Faltante mercaderia',
                                  'journal_id': journal_id,
                                  'account_id':account_id,
                                  'type': 'in_refund',
                                    })
self.pool.get('account.invoice.line').create(cr, uid,{
                'invoice_id' : invoice_id,
                'name' : 'Faltante mercaderia %s: %s' %(self.type,self.number),
                'quantity' : self.dif_final,
                'price_unit':self.tarifa_dif / 1000,
            })
a = self.env['account.invoice'].browse([invoice_id])
a.invoice_validate()

我也尝试添加 a.action_number()

此代码应该适合您:

inv_obj = self.pool.get('account.invoice')
inv_obj.button_compute(cr, uid, [invoice_id], context=context, set_total=True)
inv_obj.action_date_assign(cr, uid, invoice_id, context=context)
inv_obj.action_move_create(cr, uid, invoice_id, context=context)
inv_obj.action_number(cr, uid, invoice_id, context=context)
inv_obj.invoice_validate(cr, uid, invoice_id, context=context)

您可以通过调用以上所有方法进行检查并告诉我。

validate 按钮向工作流发送信号,您只需发送相同的信号:

a.signal_workflow('invoice_open')