Mariano DAngelo
Mariano DAngelo

Reputation: 940

Odoo validate invoice from code

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

Upvotes: 1

Views: 1399

Answers (2)

Kenly
Kenly

Reputation: 26678

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

a.signal_workflow('invoice_open')

Upvotes: 0

Priyesh Solanki
Priyesh Solanki

Reputation: 707

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.

Upvotes: 1

Related Questions