This question has been flagged
Hello everyone,
 I have two models product_template  and sale_order_line.
In the product_template template I have some fields that are characteristic
of this product this field calls product characteristic

class productCharacteristcs (models.Model):
   _inherit = 'product.template'
   caractheristic_product = fields.Many2many (comodel_name = 'caracteristic.product.')
In my model sale_order_line there is this same field, but now it is 
related to another table, which may or may not be different for each sale. 
saleProductCharacteristcs (models.Model):
   _inherit = 'sale.order.line
   sale_caractheristic_product = fields.Many2many (comodel_name = 'sale.caracteristic.product.')

I would like the event onchange to automatically populate sale.order.line but 
based on the product information and change as i like

I found information like this: self.update ({ 'attendance_line': [(0, 0, {values})], }) But I tried here and unfortunately it was unsuccessful


Avatar
Discard
Best Answer

Hi, if I understand you correctly, you can try the below:

You already in sale.order.line model and you want to use onchange for sale_caractheristic_product field to populate sale line data

So you can use the below:

@api.onchange('sale_caractheristic_product ')
def _onchange_sale_caractheristic_product (self):
//Do you check here to retrieve the required data //Set values to sale line  
self.product_id = 
self.product_uom_qty =
..
etc
Avatar
Discard
Author

Hi, unffortily wont work.

What i want to do is, grab product caracteristics and use it on sale_product_caracteristc,.

If i change sale_product_caracterist i wont it change on product_caracteristcs.

You will use something like that:

self.update({'move_line_ids': [(0, 0, {

'product_id': self.product1.id,

'product_uom_id': self.uom_unit.id,

'qty_done': 2,

'product_uom_qty': 0,

'lot_id': False,

'package_id': False,

'result_package_id': False,

'location_id': move1.location_id.id,

'location_dest_id': move1.location_dest_id.id,

})]})

Author

Hi, that was perfect.. but i need one last help :/

I'm trying insert multiples lines, when i use a for, like

for x in move_line_ids:

It will just show the last line, the cursor pass over the first,secound, etc, but only show the last one.

Some Tip?

Yes, it will show only the last one so you have to have a loop and append all line into list and then assigned it to your ids in update method as below:

You can do something like this:

update = []

for record in data.order_line:

update.append((0, 0, {

'product_id': record.product_id.id,

'product_uom': record.product_uom.id,

'order_id': record.order_id.id,

'name': record.name,

'product_qty': record.product_uom_qty,

'price_unit': record.price_unit,

'taxes_id': False,

'product_subtotal': record.price_subtotal,

'analytic_account_id': record.order_id.analytic_account_id.id,

}))

self.update({'new_order_line_ids': update})

Author

Last 2 question i promisse...

If a field, integer, its not show in the many2many table widget, it wont be update corret? even if i got:

update.append((0, 0, {

'product_id': record.product_id.id, -- Show field in the table

'numeric_field': record.product_id.numeric_field.id, -- Not show field in the widget table

}))

If inside the order_line_id i got a field many2one i wont be able to update that to?

update.append((0, 0, {

'product_id': record.product_id.id,

'attributes': record.product_id.ids, -- this field is many2many

}))

Even if this case i use something like

'attributes': ((0,0{'id':1})),

I promisse i will compile every information and make a anser in the end :P