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

I want to automatically fill a table when another table is filled by user.
here's the problem : 

I have different products for rent (let's say cars), each product have different stock/quantity.

I want to develop a method that if a user/admin adds a new "Car Model" with 'stock = N' the method adds N new rows of data for each car.
the reason i need them to be stored separately is because each car has it's own attributes e.g. how many times has it been rented, need repair or not, damaged or not, etc.....

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Thanks so mush that was helpful
I did the following and it worked

#this code is inside Car Model's class
#Overriding create
@api.model
def create(self, vals):
    res = super(CarModel, self).create(vals)
    for i in range(vals["stock"]):
        super(rc.RentCar, self.env['rent.car']).create({
            'model_id': res.id,
            'car_ref' : "%s_%s" %(res.ref,i+1),
            'name' : "%s #%s" %(res.name,i+1)
        })
    return res

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

Hi,

You can apply your logic by overriding the create and write method of the first model.

For overriding the create method, see: https://www.youtube.com/watch?v=_-fs_NBeOLI

Thanks

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ม.ค. 24
14362
Database list method in openerp แก้ไขแล้ว
3
มี.ค. 15
8565
1
เม.ย. 19
4745
0
เม.ย. 18
2827
3
ก.ย. 17
5232