Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
13929 มุมมอง

Hi,


I have created a One2Many table on Quotations to display information of different cargo companies, such as their price and delivery date:


class SaleOrder(models.Model):
_inherit = "sale.order"

cargo_line = fields.One2many('cargo.order.line', 'cargo_id', 'Cargos', readonly=True, context={'active_test': False})

class CargoOrderLine(models.Model):
_name = 'cargo.order.line'

cargo_id = fields.Many2one('sale.order', string='Cargo Reference', required=True, ondelete='cascade', index=True, copy=False)

company = fields.Text(string='Company')
price = fields.Float('Peso Unit', digits='2', default=0.00)
ref_number = fields.Text(string='Reference Number')
delay = fields.Text(string='Delivery date')

Note: I'm not sure if this is the correct way of doing it, but it worked


I have also made a custom function that estimates the cargo prices and returns a dictionary containing company, price, ref_number and delay


My question: How do I write these values into the cargo_line (One2Many) field?


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You can write values into the one2many field as follows:

self.field_name = [(0,0,{'field_o2m1':value, 'field_o2m2': value}), (0,0,{'field_o2m1':value, 'field_o2m2': value})]


See the sample of setting default value for one2many field in odoo: 

https://www.youtube.com/watch?v=BSL4iOHZ-Rc


Thanks

อวตาร
ละทิ้ง
ผู้เขียน

It works, but after inserting the values I must refresh the page (F5) to see the values. Is there a way to auto-refresh the one2many table?

Hi Hugo you dont need to refresh the page, but put the code that Niyas give above inside iteration (for loop) instead. Because at the end of the loop, the page will refreshed by the system itself.

คำตอบที่ดีที่สุด
self.cargo_line = [(0,0,{
    'company':value, 
    'price': value, 
    'ref_number': value
    }
)]
อวตาร
ละทิ้ง
ผู้เขียน

It works, but after inserting the values I must refresh the page (F5) to see the values. Is there a way to auto-refresh the one2many table?

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ธ.ค. 22
5638
how to override create or write method แก้ไขแล้ว
3
ก.ค. 17
11846
1
มี.ค. 15
4703
1
มิ.ย. 22
13476
4
ต.ค. 20
8297