I'm trying to integrate an third party application with odoo, the application should create the order and confirm it, to generate the invoice, the order creation works perfectly, when executing the create_invoices nothing shows and no errors appears.
require_once('ripcord/ripcord.php');
$url = "http://127.0.0.1:8069";
$db = "odoo";
$password = "";
$username = "";
$common = ripcord::client("$url/xmlrpc/2/common");
$uid = $common->authenticate($db, $username, $password, array());
$models = ripcord::client("$url/xmlrpc/2/object");
$order_data = array(
'partner_id' => 12, // Customer ID
'date_order' => date('Y-m-d'), // Order Date
// 'pricelist_id' => 1, // Price List ID
'state' => 'draft', // Order Status (draft)
'order_line' => array(array(0, 0, array( // Order Line Items
'product_id' => 2, // Product ID
'name' => 'Product Name', // Product Name
'product_uom_qty' => 5.00, // Quantity of Product
'price_unit' => 10.00, // Unit Price of Product
)))
);
$order_id = $models->execute_kw($db, $uid, $password, 'sale.order', 'create', array($order_data));
// Confirm Order and Create Invoice
if ($order_id) {
$confirmOrder = $models->execute_kw($db, $uid, $password, 'sale.order', 'action_confirm', array($order_id));
if ($confirmOrder) {
$invoiceCreate = $models->execute_kw(
$db,
$uid,
$password,
'sale.advance.payment.inv',
'create_invoices',
array(
'sale_order_ids' =>
array(
0 =>
array(
0 => 6,
1 => false,
2 =>
array(
0 => $order_id,
),
),
),
'advance_payment_method' => 'delivered',
'deduct_down_payments' => true,
'product_id' => false,
'fixed_amount' => 0,
'amount' => 0,
'deposit_account_id' => false,
'deposit_taxes_id' =>
array(
0 =>
array(
0 => 6,
1 => false,
2 => array(),
),
),
)
,
array(
"context" => array(
'active_model' => "sale.order",
"allowed_company_ids" => array(1),
'active_id' => $order_id, "active_ids" => array($order_id)
)
)
);
if ($invoiceCreate) {
echo "Order and Invoice #$invoiceCreate for Order #$order_id created successfully!\n";
} else {
echo "Error creating invoice!";
}
} else {
echo "Error confirming order!";
}
} else {
echo "Error creating order!";
}
When calling
create_invoices, Odoo will consider the first parameter as ids, to see the function call details change thelog_leveltodebugYou should see the following debug message:
Odoo will fail to call
create_invoicesfunction.To fix the issue you can call the
createfunction to get a wizard record id then call thecreate_invoicesExample: