I am trying in Odoo v8 to create an invoice and its invoice lines using PHP.
However, when creating an invoice line I need to population invoice_line_tax_id which is a many2many field.
I have tried to read this page but I cannot figure it out : https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write
Here is how I create an invoice line
$result = $models->execute_kw($db, $uid, $password,
'account.invoice.line', 'create',
array(array(
'invoice_id'=> 15,
'product_id'=> 2,
'quantity'=> 1,
'name'=> 'Abonnement standard' ,
'price_unit' => 50 ,
'invoice_line_tax_id' => array( 0 , false , array( 2 ) )
)));
I have the following error in return :
string 'Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 75, in xmlrpc_return
result = openerp.http.dispatch_rpc(service, method, params)
File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
result = dispatch(method, params)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
res = fn(db, uid, *params)
File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", li'... (length=2004)
If I just put the invoice_line_tax_id this way :
'invoice_line_tax_id' => array( 0 , false , 2 )
It works but no tax is inserted.
Any idea how to make this work ?
Thanks in advance.
For me, it worked this way:
'invoice_line_tax_id'=>array(array(4, $tax_id,false))
I used 4 option because the tax is already created.
I think the other array is necessary because in documentation said:
This format is a list of triplets executed sequentially
For those (like me) who struggle with odoo 10 :
Assuming your tax_id 1 exist in account_tax, correct syntax is invoice_line_tax_ids (note the final s) :
'invoice_line_tax_ids'=> [[4,[1],false]]
Related
I'm looking to find a smarty variable that displays the base price from a product that has combinations. Those combinations may or may not affect the base price. I was able to find the the $combinations variable that contains the array of combinations which contains the "impact on price" price, but for some reason in the debug window I cannot find the base/root price before the combination's impact on price.
Anyone know if this variable is being served by default, and if not, how I would be able to add it?
Thanks so much.
Try with :
$prod = new Product($id_product);
echo $prod->price;
Regards
Maybe this will help: use getPriceStatic method.
So, in /controllers/ProductController.php
under around lines 231 and 234
$productPrice = $this->product->getPrice(true, null, 6);
$productPricet = $this->product->getPriceStatic($this->product->id, false, null, 2, null, false, false, 1, false, null, null, null, $this->specificPrice);
and in line ~365 assign it to array
$this->context->smarty->assign(array(
'priceDisplay' => $priceDisplay,
'productPriceWithoutReduction' => $productPriceWithoutReduction,
'customizationFields' => $customization_fields,
'id_customization' => empty($customization_datas) ? null : $customization_datas[0]['id_customization'],
'accessories' => $accessories,
'product' => $product_for_template,
'displayUnitPrice' => (!empty($this->product->unity) && $this->product->unit_price_ratio > 0.000000) ? true : false,
'product_manufacturer' => $productManufacturer,
'manufacturer_image_url' => $manufacturerImageUrl,
'product_brand_url' => $productBrandUrl,
'productPricet' => $productPricet,
));
and then in .tpl file in your theme
{$productPricet}
Edit: tested it, does not work wery well - you get exactly the same as in workaround below... - sorry.
Simple workaround is to use formatted {$productPriceWithoutReduction} in tpl file -> will display base attribute price and won't change during attribute change.
i am creating backup using codigniter library "dbutil" and i have fields in my mysql database which having datatype bit when using below given code
public function run_backup()
{
$filename="MembersPro_database_$this->curr_date.sql";
$filepath="application/upload/DatabaseBackup/$filename";
$dbfilepath="MembersPro/application/upload/DatabaseBackup/$filename";
$prefs = array(
'ignore' => array(), // List of tables to omit from the backup
'format' => 'sql', // gzip, zip, txt
'filename' =>$filepath, // File name - NEEDED ONLY WITH ZIP FILES
'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file
'add_insert' => TRUE,
"foreign_key_checks" =>FALSE
/* 'newline' => "\n",*/
// Newline character used in backup file
);
$backup="CREATE DATABASE IF NOT EXISTS `MembersManagmentSystem`; USE `MembersManagmentSystem` ";
$backup .= $this->dbutil->backup($prefs);
if(!write_file($filepath, $backup))
{
echo "Error";die;
}
else
{
$_SESSION['sucessmsgbackup']="true";
}
$this->insert_into_datbase($filename,$dbfilepath);
redirect("ViewDatabaseBackup");
}
getting wrong output insert query
INSERT INTO `User` (`userId`, `userRoleId`,`userActive`, `userIsDelete`) VALUES ('20000046', '20001','1', '0');
in above given query "userActive" and "userIsDelete" fields having datatype "bit" and the query create by DbUtil library is treating it as string so i am getting warning error in mysql
"out of range column value"
Read Here Why you should not use BIT columns in MySQL
Issue reported Here in Github
Look into folder and modify core classes so that it will not escape, for example for mysqli driver
system/database/drivers/mysqli
https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/drivers/mysqli/mysqli_utility.php#L159
and find file mysqli_utility.php
locate line
$is_int[$i] = in_array(strtolower($field->type),
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
TRUE);
Type numbers
numerics
-------------
BIT: 16
TINYINT: 1
BOOL: 1
SMALLINT: 2
MEDIUMINT: 9
INTEGER: 3
BIGINT: 8
SERIAL: 8
FLOAT: 4
DOUBLE: 5
DECIMAL: 246
NUMERIC: 246
FIXED: 246
and add your datatype to above array like below
$is_int[$i] = in_array($field->type,
array(16, 1, 2, 9, 3, 8),
TRUE);
I would like to use the highchart plugin in cakephp. I installed it and I can run all the demos that come with the plugin.
I would like to use it in my own controller and took one of the examples as an implementation guide.
If I have the following code in my controller it does NOT work, i.e. highchart does not display any of the input values.
$resultStatistics = $this->Statistic->find("all", $params = array( 'fields' => 'new_students_total','recursive' => -1) );
$chartData1 = array();
$chartData1 = Hash::extract($resultStatistics, '{n}.Statistic.new_students_total');
// $chartData1 = array(0=>5, 1=>5, 2=>4, 3=>4);
$this->print_r2($chartData1);
$chartName = 'Evolution of Actual Number of Students';
$mychart = $this->Highcharts->create($chartName, 'line');
$this->Highcharts->setChartParams($chartName, array(
'renderTo' => 'linewrapper', // div to display chart inside
'chartWidth' => 600,
'chartHeight' => 500,
'chartMarginTop' => 60,
'chartMarginLeft' => 90,
'xAxisCategories' => array('Jan', 'Feb', 'Mar', 'Apr'),
// autostep options
// 'enableAutoStep' => TRUE
)
);
$series1 = $this->Highcharts->addChartSeries();
$series1->addName('ABC')
->addData($chartData1);
$mychart->addSeries($series1);
$this->set(compact('chartName'));
The result from the database query is a simple array with 4 integer values.
But if I uncomment the line 4, “$chartData1 = array(0=>5, 1=>5, 2=>4, 3=>4);”, basically defining the values of the array manually it DOES WORK and a linechart is drawn. I use Cakephp 2.4.3 and PHP 5.6
I can't seem to figure out the difference between the "mysql" version of the array $chartData1 and the "manual defined" version of $chartData1. What am I missing?
After lots of checking I eventually found the problem. The Cake plug in helper expects integer (or reals) in the chartData1 array. So simple adding the following lines:
foreach ($resultStatistics as $result) {
$chartData[] = (int) $result['Statistic']['new_students_total'];
}
at last solved my problem.
Thank anyway for your help
I have lots of records in a collection. They are indexed with a binary uuid :
db.users.find().limit(1);
[{ "_id": ..., "guid": BinData(2,"EAAAANR56IodpE3xhYLtfugc7SY="), otherdata }]
If I query from the CLI, I can retrieve the records:
db.users.find({ "guid": BinData(2,"EAAAANR56IodpE3xhYLtfugc7SY=") });
[{ "_id": ..., "guid": BinData(2,"EAAAANR56IodpE3xhYLtfugc7SY="), otherdata }]
If I want to do the same thing from PHP, the query returns nothing:
$client->db->setProfilingLevel(2);
$res = $client->db->users->find(array('guid' => new MongoBinData($bin_data, 2)));
$res->next(); // perform the query
echo $res->count(); // display 0
Of course I have tested the $bin_data variable hold the right value.
If I look at mongo's logs,
Thu Jan 10 18:05:06 [conn1] query db.users query: { guid: BinData } ntoreturn:0 ntoskip:0 nscanned:0 keyUpdates:0 locks(micros) r:14807 nreturned:0 reslen:20 14ms
the scanned value is 0 ! This means it does not even scan the collection for results ?
Any clue ?
Edit I have set the profiling level to 2, it does change anything. I can see authentication in the logs but still no query.
Edit2 Added log line.
I must admit I am confused myself. I ran:
$mongo = new Mongo();
$db = $mongo->mydb;
$col = $db->gjgjgj->insert(
array( "guid" => new MongoBinData("EAAAANR56IodpE3xhYLtfugc7SY=", 2) )
);
var_dump($col);
$cur = $db->gjgjgj->find(
array( "guid" => new MongoBinData("EAAAANR56IodpE3xhYLtfugc7SY=", 2) )
);
var_dump(iterator_to_array($cur));
And my output was:
boolean true
array
'50ef0bc96803fa0b04000000' =>
array
'_id' =>
object(MongoId)[7]
public '$id' => string '50ef0bc96803fa0b04000000' (length=24)
'guid' =>
object(MongoBinData)[9]
public 'bin' => string 'EAAAANR56IodpE3xhYLtfugc7SY=' (length=28)
public 'type' => int 2
Can you tell us what PHP driver version this is?
Can you also post your entire script that can reproduce this?
Edit
Of course running count() after running a next() on the cursor works for me too.
Mongo doesn't log all queries by default. Only slow queries (usually taking more than 100 milliseconds) are logged. Also check out docs on profiling.
You can use mongoDB profiling from php to see what is happining there
http://php.net/manual/en/mongodb.setprofilinglevel.php
$this->command(array('profile' => 2))
What I want:
fetch some documents
for every document, set a field:
change it, if it exists
add it, if it doesn't
What I do:
// fresh data
print_r(iterator_to_array($collection->find()->limit(2)));
// query
$docs = $collection->find()->limit(2);
// fetch
foreach ( $docs AS $id => $doc ) {
// update
$collection->update(array('_id' => $doc['_id']), array(
'$set' => array(
'existing_field' => 'x',
'new_field' => 'y',
),
), array('multiple' => false));
}
// verify
print_r(iterator_to_array($collection->find()->limit(2)));
Why doesn't that do anything? The existing field isn't changed and the new field isn't added. Is the condition maybe wrong??
PS. The full code (with a lot of junk in between): http://pastebin.com/CNfCVxex
lines 33 - 37 -- fresh data
lines 63 - 76 -- query, fetch & update
lines 79 - 80 -- verify
Not familiar with the driver you are using here, but from your description you can achieve what you want in a single database hit, no need to fetch/loop/update..
The $set operator will insert or update a field depending on whether it exists or not.
db.Collection.update({}, { $set : { "myfield" : "x" } }, false, true)
The above would set the 'myfield' field in all documents in the collection to 'x', or if it already exists it would change the value to 'x'. Is that what you want to achieve?
I suspect you need to convert the string $doc['_id'] back to a MongoId by using new MongoId. See the example at the bottom of this page: http://www.php.net/manual/en/class.mongoid.php