Odoo validate invoice from code

2019-04-16 07:34发布

I creating an invoice from another model, and want to get validated not draft But internal number and total are not generated with my 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()

I also try adding a.action_number()

2条回答
霸刀☆藐视天下
2楼-- · 2019-04-16 08:16

validate button sends a signal to a workflow, you just need to send the same signal:

a.signal_workflow('invoice_open')
查看更多
叼着烟拽天下
3楼-- · 2019-04-16 08:28

This code should work for you:

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)

You can check by calling all above methods and let me know.

查看更多
登录 后发表回答