Odoo validate invoice from code

筅森魡賤 提交于 2019-12-06 14:08:09

问题


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()


回答1:


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.




回答2:


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

a.signal_workflow('invoice_open')


来源:https://stackoverflow.com/questions/35375213/odoo-validate-invoice-from-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!