简体   繁体   中英

Odoo PHP API and Laradoo - how to save many2many many2one and selection fields

Could someone please provide a simple example of the usage for dealing with Odoo's one2many, many2many and selection fields when using Laradoo (or ripcord)?

Specifically how one would use them with create() and update(). In Python, it seems as if these are dealt with using special tuple commands however for PHP documentation seems very hard to find for these types of things and it would be extremely helpful.

For illustrative purposes in my particular project, I haven't been able to figure out how to relate a CRM lead tag to a lead during the creation process using Laradoo:

$id = $odoo->create('crm.lead', [
    'type'          => 'lead',
    'priority'      => 0, <-- what do we pass here for this selection field?
    'name'          => 'Example',
    'contact_name'  => 'John Doe',
    'phone'         => '555-555-5555',
    'email_from'    => 'example@domain.com',
    'description'   => 'Just some text.',
    'tag_ids'       => [1], <-- What do we pass here for this one2many field?
]);

In the example above when trying to set the priority selection field to an int other than 0 fails and when trying to pass an array of tag_ids (1 is valid tag id in my project), the lead remains untagged.

First of all selection field values are just string values that need to be part of the field defined selection values.

The values for relational fields like Onetomany and Many2many are ruled by the command formated values that you could read at:

https://github.com/odoo/odoo/blob/11.0/odoo/models.py#L3020-L3055

For the php api usage with ripcord you could set the tag_ids field value like:

$id = $odoo->create('crm.lead', [
    'type'          => 'lead',
    'priority'      => '0',
    'name'          => 'Example',
    'contact_name'  => 'John Doe',
    'phone'         => '555-555-5555',
    'email_from'    => 'example@domain.com',
    'description'   => 'Just some text.',
    'tag_ids'       => array(array(4,1)),
]);

This translate as that 1 is the id of a known and already existing crm.lead.tag that you could link to the m2m tag_ids field using the command 4. This could also be expressed using command 6 to link multiple ids on the same command value:

'tag_ids' => array(array(6,0,array(1,2,3))),

where using command 4 it will be:

'tag_ids' => array(array(4,1), array(4,2), array(4,3)),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM