跳至內容
選單
此問題已被標幟
2 回覆
4996 瀏覽次數

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
1月 24
14499
3
3月 15
8624
1
4月 19
4828
0
4月 18
2873
3
9月 17
5326