Skip to Content
Menu
This question has been flagged
1 Reply
3902 Views

I would like to demonstrate how to create Customer Invoices using the API, so do this from within a Scheduled Action that I can run manually. 

How would I do this?


Avatar
Discard
Best Answer

For v15, assuming you have a Customer called "ACME Inc" and an Income Account with code "400000" you could do something like: 

customer_name = "ACME Inc"
invoice_ref = "B65253"
invoice_date = "2022-07-01"
invoice_date_due = "2022-07-31"
invoice_line_note = 'Consulting Services'
invoice_line_account = '400000'
invoice_line_amount = '150'
invoice_line_quantity = 10

customer_in_odoo = env['res.partner'].search([('name','=',customer_name)])

if not customer_in_odoo:
raise UserError("Cannot find Customer!")

invoice_line_account_in_odoo = env['account.account'].search([('code','=',invoice_line_account)])

if not invoice_line_account_in_odoo:
raise UserError("Cannot find Account for the Invoice Line!")

invoice = env['account.move'].create({
'move_type': 'out_invoice',
'invoice_origin': 'External API Demo',
'partner_id': customer_in_odoo.id,
'ref': invoice_ref,
'invoice_date': invoice_date,
'invoice_date_due': invoice_date_due,
'invoice_line_ids': [(0,0,{
'name': invoice_line_note,
'account_id': invoice_line_account_in_odoo.id,
'price_unit': invoice_line_amount,
'quantity': invoice_line_quantity,
})],
})
Avatar
Discard
Related Posts Replies Views Activity
2
Jul 19
3017
0
May 19
3067
1
Jun 17
2479
1
May 16
2253
0
Nov 24
91