Reputation: 932
I'm developing a ruby application which sends some commands to Odoo via XMLRCP API. I've been able to create a sale order in this whay
def execute_odoo_command(odoo_model, odoo_command, values)
@models.execute_kw(ODOO_DB, @uid, ODOO_PASSWORD, odoo_model, odoo_command, values)
end
def create_order_sale
order_reference = "SO #{@reference_code}_#{@customer_odoo_id}"
values = {
currency_id: 1,
date_order: Date.today.to_s,
name: order_reference,
payment_term: 1,
partner_id: @customer_odoo_id
}
order_id = execute_odoo_command('sale.order', 'create', [values])
create_sale_order_lines(order_id)
execute_odoo_command('sale.order', 'action_confirm', [order_id])
end
Now, I would launch the invoice creation. I have found a way to do it like this
execute_odoo_command('account.invoice', 'create', [invoice_values(order_reference)])
But, even if the invoice is created, the sale order is stil "open" and I can create another invoice from the Odoo interface clicking on "Create Invoice" button (which is obviously wrong). Is there any way to simulate that action via API?
The debug mode does not show any method in the tooltip.
Any suggestion is appreciated, thank you!
Upvotes: 1
Views: 1575
Reputation: 932
For future googlers. The solution is that I'm using an old API version. the right command call is this one
def create_invoice_from_sale_order(sale_order_id)
sale_order_to_invoice_data = [sale_order_id, {context: {active_ids: sale_order_id}}]
@odoo_rpc_client.execute_odoo_command('sale.order', 'action_invoice_create', sale_order_to_invoice_data)
end
Upvotes: 3