Error when creating a new entity
Hello, running a basic create test fails.
<?php
require_once 'vendor/autoload.php';
use Ang3\Component\Odoo\Client;
$client = Client::createFromConfig(...);
$recordManager = $client->getRecordManager();
$record_id = $recordManager->create('res.partner', [
'name' => 'John Doe',
'email' => '[email protected]',
]);
echo "Created id: " . $record_id;
?>
Running the script against Odoo 15 Community produces error: "Uncaught Ang3\Component\Odoo\Exception\RemoteException: TypeError: create() takes 2 positional arguments but 3 were given".
odoo.log:
DEBUG odoo15 odoo.api: call res.partner().create('name', 'email')
ERROR odoo15 odoo.http: create() takes 2 positional arguments but 3 were given
Traceback (most recent call last):
File "X:\Odoo\server\odoo\http.py", line 141, in dispatch_rpc
result = dispatch(method, params)
File "X:\Odoo\server\odoo\service\model.py", line 41, in dispatch
res = fn(db, uid, *params)
File "X:\Odoo\server\odoo\service\model.py", line 169, in execute_kw
return execute(db, uid, obj, method, *args, **kw or {})
File "X:\Odoo\server\odoo\service\model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "X:\Odoo\server\odoo\service\model.py", line 176, in execute
res = execute_cr(cr, uid, obj, method, *args, **kw)
File "X:\Odoo\server\odoo\service\model.py", line 160, in execute_cr
result = odoo.api.call_kw(recs, method, args, kw)
File "X:\Odoo\server\odoo\api.py", line 462, in call_kw
result = _call_kw_model_create(method, model, args, kwargs)
File "X:\Odoo\server\odoo\api.py", line 442, in _call_kw_model_create
result = method(recs, *args, **kwargs)
TypeError: create() takes 2 positional arguments but 3 were given
We're running into the same issues on the res.partner repository. @PetrToman did you find any workaround for this?
@Ang3 do you perhaps have an idea on how to work around that? Thanks a lot🙏
@mbardelmeijer Unfortunatelly, I had to postpone my investigations. I suggest to look at other projects - https://github.com/search?q=odoo+php
Found a workaround. The create API calls seem to need the parameter in another array to function correctly.
$record_id = $recordManager->create('res.partner', [
[
'name' => 'John Doe',
'email' => '[email protected]',
],
]);
@mbardelmeijer yes, I can confirm this solution.
Hi,
Thank you for your feedback and the solution.
Sorry, Im really buzy these last months but the version 8.0 is about to be released and this kind of weird cases has been fixed too (tested).
The version 8 will be released before december, 1st 2023. Do not hesitate to make pull request for version 7 if this issue still remaining since last fixes. Or please re-open new issue by referencing this one (for v7).