콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
5012 화면

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
14509
3
3월 15
8624
1
4월 19
4829
0
4월 18
2876
3
9월 17
5336