0
votes

I am trying to modify an OpenERP addon called mrp_bom_history to get default values from the existing bom lines as default value.

I have made a _read_line method to return a list of bom_line ids similar to how to initialize a default one2many fields in OpenERP, but I get an 'Record not correctly loaded' exception, and I am having trouble figuring out why.

Python code from save_bom_history.py:

class save_bom_history(osv.osv_memory):
    def _read_line(self,cr,uid,context=None):
        bom = self.pool.get('mrp.bom').browse(cr,uid,context['active_id'])
        result = []
        for lines in bom.bom_lines:
            result.append(lines.id)
        return result

    _name       = "save.bom.history"
    _columns    = {
                   'name'           : fields.char('Name'),
                   'cut_off_date'   : fields.date('Cut-off Date'),
                   'new_bom_ids'    : fields.one2many('save.bom.history.line','\
wizard_id','New Bill of Material'),
                   }

    _defaults   = {
                   'name'           : "History",
                   'cut_off_date'   : time.strftime('%Y-%m-%d'),
                   'new_bom_ids'    : _read_line,
                  }
2
The object save.bom.history.line, is it a wizard?yannicksoldati
Save_bom_history is a wizard with a name field and a cut-off-date field and then it has a new_bom_ids line that contains product name, product quantity, unit of meassure, valid from, valid to.MortenS
Save.bom.history.line is also a wizard used to add a product to the BoM. The data from the lines created by the save_bom_history_line wizard is used when the new BoM is created. So it is embedded into the save.bom.history wizard.MortenS

2 Answers

0
votes

One2many and Many2many use a special "commands" format to manipulate the set of records stored in/associated with the field.

Try this:

result.append((0, 0, lines.id))
0
votes

I made it work by returning a tuple instead of just the id

        for lines in bom.bom_lines:
        line_data = {
                         'name'             : lines.name,
                         'date_start'       : lines.date_start,
                         'date_stop'        : time.strftime('%Y-%m-%d'),
                         'product_qty'      : lines.product_qty,
                         'product_id'       : lines.product_id and lines.product_id.id or False,
                         'product_uom'      : lines.product_uom and lines.product_uom.id or False,
                         'bom_id'           : bom and bom.id or False,
                         }
        result.append((0,0,line_data))
    return result