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

Hi,

In my custom module I have created one wizard in that I fetched order_lines I want to calculate the the sum of cost and display that value in another field in the same wizard. (https://i.imgur.com/eQ2ZkRB.png)

Could you please help me to achieve this.

Thanks in advance!

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

Hi,

You can check how the computation works in sale order. You can see the total amount is computing from the sale.order.lines. Just see the below code and adjust accordingly to your case.

Check this to see how to write compute field in Odoo: How to Write Compute Field and its Function in Odoo12

In Sales,

amount_total = fields.Monetary(string='Total', compute='_amount_all', track_visibility='always')

Compute Function:

@api.depends('order_line.price_total')
def _amount_all(self):
"""
Compute the total amounts of the SO.
"""
for order in self:
amount_untaxed = amount_tax = 0.0
for line in order.order_line:
amount_untaxed += line.price_subtotal
# FORWARDPORT UP TO 10.0
if order.company_id.tax_calculation_rounding_method == 'round_globally':
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = line.tax_id.compute_all(price, line.order_id.currency_id, line.product_uom_qty, product=line.product_id, partner=order.partner_shipping_id)
amount_tax += sum(t.get('amount', 0.0) for t in taxes.get('taxes', []))
else:
amount_tax += line.price_tax
order.update({
'amount_total': amount_untaxed + amount_tax,
})


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you Niyas for your help!

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 20
5867
1
thg 9 19
6317
2
thg 9 23
4355
2
thg 9 22
4192
0
thg 1 21
2969