1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
for ($o=0, $n=$count_products; $o<$n; $o++) {
//******************************************
// research invoice_id by origin invoice
//***************************************
// ====> mettre en relation avec la B2B
$ids = $OSCOM_ODOO->odooSearch('default_code', '=', $order->products[$o]['model'], 'product.template');
// **********************************
// read id products odoo
// **********************************
$field_list = array('default_code',
'id'
);
$Qodoo_products_id = $OSCOM_ODOO->readOdoo($ids, $field_list, 'product.template');
$odoo_products_id = $Qodoo_products_id[0][id];
// **********************************
// tax
// **********************************
/*
(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update the linked record with id = ID (write *values* on it)
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID) link to existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)
Example: [(6, 0, [8, 5, 6, 4])] sets the many2many to ids [8, 5, 6, 4]
*/
$QProductsTax = $OSCOM_PDO->prepare('select products_tax
from :table_orders_products
where orders_id = :orders_id
and products_id = :products_id
');
$QProductsTax->bindInt(':orders_id', (int)$insert_id);
$QProductsTax->bindValue(':products_id', $order->products[$o]['id']);
$QProductsTax->execute();
$products_tax = $QProductsTax->fetch();
$products_tax = round($products_tax, 2);
//******************************************
// research tax_id by amount tax
//***************************************
$ids = $OSCOM_ODOO->odooSearch('amount', 'like', $products_tax, 'account.tax');
// **********************************
// read id in account.tax
// **********************************
$field_list = array('id');
$QodooProductsTaxId = $OSCOM_ODOO->readOdoo($ids, $field_list, 'account.tax');
$odoo_products_tax_id = $QodooProductsTaxId[0][id];
$tax = array(new xmlrpcval(
array(
new xmlrpcval(6, "int"),// 6 : id link
new xmlrpcval(0, "int"),
new xmlrpcval(array(new xmlrpcval($odoo_products_tax_id, "int")),"array")
),"array"
)
);
// **********************************
// Write a new line concerning the invoice
// **********************************
$values = array (
"order_id" => new xmlrpcval($invoice_id, "int"),
"product_id" => new xmlrpcval($odoo_products_id, "int"),
"company_id" => new xmlrpcval($company_id, "int"),
"name" => new xmlrpcval($order->products[$o]['name'], "string"),
"price_unit" => new xmlrpcval($order->products[$o]['final_price'],"double"),
"product_uom_qty" => new xmlrpcval($order->products[$o]['qty'], 'int'),
"tax_id" => new xmlrpcval($tax, 'array'),
);
$OSCOM_ODOO->createOdoo($values, "sale.order.line");
} //end for |
Partager