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

Hi,

I created a "total cost" field which depends on the costs of my product lines.

The total cost updates correctly the first time but if I change a quantity or add a product it does not update


the code :

for record in self:

    cost_total = 0.0

    for line in record.order_line:  

        cost_total += line.x_studio_cot_total

    record['x_studio_float_field_3vq_1hkehadjt'] = cost_total

아바타
취소
베스트 답변

Hi, 
Try this code:from odoo import fields, models, api

class YourModel(models.Model):
    _name = 'your.model'

    x_studio_float_field_3vq_1hkehadjt = fields.Float(compute='_compute_total_cost', store=True)

    @api.depends('order_line.x_studio_cot_total')
    def _compute_total_cost(self):
        for record in self:
            record.x_studio_float_field_3vq_1hkehadjt = sum(line.x_studio_cot_total for line in record.order_line)


Hope it helps

아바타
취소
작성자 베스트 답변

THANKS !


Your comment helped me,


Here is my final solution


아바타
취소
관련 게시물 답글 화면 활동
1
2월 25
646
7
12월 24
5808
2
8월 24
957
0
7월 24
699
1
3월 24
608