Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
3200 Lượt xem

Hi,

In sale.order i have a field similar to order_line(of model sale.order.line). I wrote an onchange function of order_line for writing values into the new one2many field, the data appended successfully to the new field but during the time of saving the document the order line of both field gets doubled.

my new field

new_order_line = fields.One2many('sale.order.line', 'order_id', string='Order Lines',
states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True,
auto_join=True)

my onchange function

@api.onchange('order_line')
@api.depends('order_line')
def _onchange_order_line(self):
line_list = [(5, 0, 0)]
for order_line in self.order_line:
vals = (0, 0, {
'product_id': order_line.product_id.id,
'name': order_line.name,
'analytic_tag_ids': order_line.analytic_tag_ids.ids,
'product_uom_qty': order_line.product_uom_qty,
'product_uom': order_line.product_uom.id,
'price_unit': order_line.price_unit,
'discount': order_line.discount,
'tax_id': order_line.tax_id.ids,
'price_subtotal': order_line.price_subtotal,
'price_total': order_line.price_total,
'currency_id': order_line.currency_id.id,
})
line_list.append(vals)
self.update({'new_order_line': line_list})

This happens while saving the record(Initially i have only one order line, after saving it turns to two)

Screenshot_2020-02-05 SO009 - Odoo.png

 Thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

According to your question your new field have same model of the existing order_line(sale.order.line), so when we save the record the data will automatically get updated into your new field(new_order_line) and in your case there are two functions are working to update the values to the new field one is write and other is onchange function. So for solving this issue i think you have to remove the onchange function or you have to define a new model for the newly created one2many field.

Regards

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

thanks for the replay, i forgot to check the case of write function.i removed the onchange function , now only one line is occuring after saving.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 4 20
2313
2
thg 12 19
2732
0
thg 6 22
1766
1
thg 12 19
7289
3
thg 11 23
16334