Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
2086 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

THANKS !


Your comment helped me,


Here is my final solution


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 2 25
1320
7
thg 12 24
7833
2
thg 8 24
1707
0
thg 7 24
1117
1
thg 3 24
1124