odoo one2many default not set

后端 未结 1 714
予麋鹿
予麋鹿 2021-02-06 16:19

I wrote a wizard which form view should show a one2many field with rows taken from context[\'active_ids\'].

I set the one2many default correctly, but when the f

相关标签:
1条回答
  • 2021-02-06 16:50

    The problem may be there :

    res['details'] = **[(6, False, dws)]**
    

    Your details field is a One2many field, [(6,0, [IDS])] are for Many2many. In your case, you don't need to assign anything to the details fields ; it's a One2many, so it's automatic as you already created the corresponding Many2one record (dw).

    Little reminder from the doc :

    • For Many2many

    For a many2many field, a list of tuples is expected. Here is the list of tuple that are accepted, with the corresponding semantics

    (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]

    • And One2many :

    (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)

    Example: [(0, 0, {'field_name':field_value_record1, ...}), (0, 0, {'field_name':field_value_record2, ...})]

    Also, try to follow odoo guidelines for Many2One/One2many fields if you want your code to be easily understandable by other people :

    One2Many and Many2Many fields should always have _ids as suffix (example: sale_order_line_ids)

    Many2One fields should have _id as suffix (example : partner_id, user_id, ...)

    0 讨论(0)
提交回复
热议问题