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

I have a model (like purchase.order) and it has a field One2Many to model line (like  purchase.order.line) I want to get these lines before saving the model. Can anyone help me please?

아바타
취소
베스트 답변

Hello Mouna Cherrad, for above given scenario,  you can use a compute field and calculate the values from the rows, It will be similar like purchase order's Total(amount_total) field.
for example:

quantity_total = fields.Integer(string='Quantity', compute='_quantity_total')

@api.depends('order_line.quantity')
def _quantity_total(self):
    for order in self:
        order.quantity_total = sum(order.mapped('order_line.quantity'))

아바타
취소
베스트 답변

Please give more details about what do you want to achieve. You mean before save the record, You can get them in create method from vals. You can override create method and you can get the order_line (one2many) from vals and do what ever you want and then call super method of create/write.

아바타
취소
작성자

Hello Waleed, thank you for your answer.
Yes, the scenario is as follows:
I have a field quantity in the model that should be the sum of the quantities in the rows , so when adding a new line I want to get all the quantities in the lines above even if they are not saved to propose the next quantity of the new line (the difference between the quantity in the model and the sum of the quantities in the lines). I hope it is more clear

@Atul Patel Give you the write answer.