Unoo one2many default is not installed
I wrote a wizard that generates a view, should show one2many field with lines taken from the context ['active_ids'].
I am setting the default one2 correctly, but when the form is opened, no lines are displayed.
Did I miss something? (I apologize for the wrong code indentation)
class delivery_wizard(models.TransientModel):
_name = 'as.delivery.wizard'
address = fields.Many2one('res.partner')
details = fields.One2many('as.delivery.detail.wizard', 'delivery')
carrier = fields.Many2one('delivery.carrier')
@api.model
def default_get(self, fields_list):
res = models.TransientModel.default_get(self, fields_list)
ids = self.env.context.get('active_ids', [])
details = self.env['as.delivery.detail'].browse(ids)
dwz = self.env['as.delivery.detail.wizard']
dws = []
for detail in details:
dw = dwz.create({
'production': detail.production_id.id,
'quantity': detail.quantity,
'actual_quantity': detail.quantity,
'enabled': detail.production_id.state == 'done',
'delivery': self.id,
})
dws.append(dw.id)
res['details'] = [(6, False, dws)]
res['address'] = details[0].delivery_id.address_id.id
return res
class delivery_detail_wizard(models.TransientModel):
_name = 'as.delivery.detail.wizard'
production = fields.Many2one('as.production')
quantity = fields.Float()
actual_quantity = fields.Float()
force = fields.Boolean()
enabled = fields.Boolean()
delivery = fields.Many2one('as.delivery.wizard')
source to share
The problem could be there:
res['details'] = **[(6, False, dws)]**
Your data field is the One2many field, [(6,0, [IDS])] for Many2many. In your case, you don't need to assign anything to the information fields; it is One2many, so it is automatic since you already created the corresponding Many2one (dw) record.
- For Many2many
A list of tuples is expected in the many2many field. Here is a list of tuples that are accepted, with appropriate semantics
(0, 0, {values}) reference to a new record to be created with the given value in the dictionary
(1, ID, {values}) update the associated record with id = ID (write values ββon it)
(2, ID) delete and delete the associated entry with id = ID (calls are disconnected by id, which will completely delete the object and link to it as well)
(3, ID) cut the link to the associated record with id = ID (remove the link between the two objects, but do not delete the target object itself)
(4, ID) link to an existing record with id = ID (adds a relationship)
(5) detach all (e.g. use (3, ID) for all related records)
(6, 0, [IDs]) replaces the list of related IDs (for example, using (5) then (4, ID) for each ID in the ID list)
Example: [(6, 0, [8, 5, 6, 4])] sets a set of many objects [8, 5, 6, 4]
- And One2many:
(0, 0, {values}) reference to a new record to be created with the given value in the dictionary
(1, ID, {values}) update the associated record with id = ID (write values ββon it)
(2, ID) delete and delete the associated entry with id = ID (calls are disconnected by id, which will completely delete the object and link to it as well)
Example: [(0, 0, {'field_name': field_value_record1, ...}), (0, 0, {'field_name': field_value_record2, ...})]
Also, try following the odoo guidelines for Many2One / One2many fields if you want your code to be easy for other people to understand:
One2Many and Many2Many fields should always have _ids as a suffix (example: sale_order_line_ids)
Many2One fields must have _id as a suffix (example: partner_id, user_id, ...)
source to share