This question has been flagged
2 Replies
4789 Views

In v7 i could fill the one2many field with the following code, without creating an entry in the datebase.

from_template = self.pool.get('mrp.eq_routing_template').browse(cr, uid, routing_template, context)

            wclist = []
            #Creates the workcenter.lines and saves them in a list.
            for workcenter in from_template.eq_workcenter_lines:
                wc_vals = {
                    'workcenter_id': workcenter.eq_workcenter_id.id,
                    'name': workcenter.eq_name,
                    'sequence': workcenter.eq_sequence,
                    'cycle_nbr': workcenter.eq_cycle_nbr,
                    'hour_nbr': workcenter.eq_hour_nbr,
                    'note': workcenter.eq_note,
                    }
                wclist.append((wc_vals))
            #Data for the return
            vals_from_template = {
                'name': from_template.eq_name,
                'active': True,
                'code': from_template.eq_code,
                'note': from_template.eq_note,
                'location_id': from_template.eq_location_id.id,
                'workcenter_lines': wclist,
                }
            return {'value': vals_from_template}

When i use this on_change Method with v8 it creates empty lines.

How am I able to do the same in v 8.0?

Avatar
Discard
Best Answer

I think it is a bug in odoo 8.

I now accomplished it by hacking the line 1397 in ./server/openerp/fields.py file

Change 

    if fnames is None:

to

    if fnames is None or len(fnames) == 0:

Avatar
Discard
Best Answer

Artur,

It should be :

return {'value': {'one2many_field_name': [dictionary1, dictionary2]}}

Thanks.

Avatar
Discard