Community mailing list archives

community@mail.odoo.com

Need help for tax sales order xml rpc

by
loic
- 11/24/2014 16:20:41
Hello,

I have two question concerning the tax in sale order line.
Is is possible to help me.

For one products, the script works well but

1/ When I have more products with different taxe, The export does'nt work well, the tax is completly different than my ecommerce  platform.

2/ I sell products but the tax appear insode odoo said me it's purchased.
I have a taxe for sell : 5.5%
I have also a tax for purchase : 5.5%
I think Odoo take the last tax (purchase). It's not the good tax;

How to resolve these two questions ?

thank you



// count number of product
$count_products = sizeof($order->products);

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['products_tax']/100), 3);
// $products_tax = 0.055;
//******************************************
// research tax_id by amount tax
//***************************************


// **********************************
// read id in account.tax
// **********************************

$field_list = array('id',
'amount',
);

$QodooProductsTaxId = $OSCOM_ODOO->readOdoo($ids, $field_list, 'account.tax');
$odoo_products_tax_id = $QodooProductsTaxId[0][id];
$odoo_products_tax_amount = $QodooProductsTaxId[0][amount];

$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"


/* try this but does'nt work or error.

// callFunctionOdoo($relation, $method, $ids, $params) {
// functions
$ids = array($odoo_products_tax_id);
$vals = array(
'part'=>array($odoo_products_tax_id,'int'),
);
$res = $OSCOM_ODOO->callFunctionOdoo('sale.order.line',' onchange_tax_id', $ids, $vals);
// $res_val = $res->structmem('value');

print_r($res);
var_dump($res);
exit;
*/
);






------------------------
Cordialement,
loïc Richard