Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
4940 Näkymät

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.....

Avatar
Hylkää
Tekijä Paras vastaus

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

Avatar
Hylkää
Paras vastaus

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

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
tammik. 24
14406
3
maalisk. 15
8581
1
huhtik. 19
4782
0
huhtik. 18
2841
3
syysk. 17
5266