This question has been flagged
3569 Views

I have create on_change method on one2many field and set value in another one2many fields. Now First I have add two line in one2many and another one2many set then we saved. Saved successfully.But issue is now we update record and add another line(means Third line) so onchange method call and set another one2many fields unlink old two line and set new one. I need updated line set in third one.not old remove.I hope you understand.

    new_values = []
    res = {}
    self_rec  = self.browse(cr,uid,ids)[0]
    if data_sheet_sales_id:       
        for row in data_sheet_sales_id:
             product = self.pool.get('product.product').browse(cr, uid, row[2]['up_lighting_type'])
             new_values.append((0,0,{
                              'location': row[2]['location'] or False,
                               'partner_name': self_rec.saver_name.id,
                               'up_lighting_type': row[2]['up_lighting_type'],
                               'qty_original': row[2]['qty_original'],
                               'qty_upgraded': row[2]['qty_upgraded'],
                               'hours_per_year': row[2]['hours_per_year'],
                               'unit_cost': product.list_price or 0.00,
                               'install_cost': product.installation_cost or 0.00,
                               'total_supply_ins': product.product_cost + product.installation_cost,
                               'control_sys1_original':row[2]['control_sys1_original'],
                               'control_sys2_original':row[2]['control_sys2_original'],
                               'up_control_sys1':row[2]['up_control_sys1'],
                               'up_control_sys2':row[2]['up_control_sys2'],
                               'max_min_discnt': product.max_min_discount or 0.00, 
                }))

    return {'value':{'sales_quotation_id':[{
                            'name': self_rec.saver_name.id,
                            'date_order': datetime.date.today().strftime('%Y-%m-%d'),
                            'order_line': new_values
                    }],

        }}
Avatar
Discard