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

​So I have a field which is being computed:

price_subtotal = fields.Monetary(compute='_compute_amount', string='Subtotal', readonly=True, store=True)


I have used the logger to make sure the fields are being computed on the fly however they aren't updating in the field view?

Edit: compute function
@api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id')
def _compute_amount(self):
for line in self:
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = line.tax_id.compute_all(price, line.quote_id.currency_id, line.product_uom_qty, product=line.product_id, partner=line.quote_id.partner_shipping_id)
line.update({
'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
'price_total': taxes['total_included'],
'price_subtotal': taxes['total_excluded'],
})
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
  • The only solution is to set store=False

EDIT: Actually there is a simple solution to achieve what we want: 

  • Computed field: store=False; make it invisible in the view.

  • Create a related field with store=True, related to the computed_field


Ảnh đại diện
Huỷ bỏ

Should work well

I tried with the computed field with store=False & field present but invisible in the view and it seems to be enough.

I think that the important point is to have the @api.depends fields present in the view otherwize my impression is that the odoo js client ignores them

Tác giả Câu trả lời hay nhất

Added the compute function


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

Can you please attach the compute function. Then it would be easy to suggest a solution. 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 3 17
4933
1
thg 5 23
1797
1
thg 4 15
4423
2
thg 2 24
2587
2
thg 7 22
6230