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

Hi! 


I'm trying to get a field for the sale order balance. We invoice a reservation in advance, and then before we give the service we ask for the second payment.

For the sake of not paying unnecesary taxes for unpayed invoices, we only invoice when we get the money.


I was trying to get a field with the balance of a sale, this is: 

Ammount_Total of the sale - Payed invoices. 


I tryed creating a new field in the debug. The field in the sale.order I was trying to do was: 


from odoo import models, fields, api


class SaleOrder(models.Model):

    _inherit = 'sale.order'


    balance = fields.Monetary(

        string='Balance',

        compute='_compute_balance',

        store=True,

        readonly=True,

        currency_field='currency_id',

        help="Balance of the sale order."

    )


    @api.depends('amount_total', 'invoice_ids.state', 'invoice_ids.amount_total')

    def _compute_balance(self):

        for order in self:

            paid_amount = sum(inv.amount_total for inv in order.invoice_ids.filtered(lambda inv: inv.state == 'paid'))

            order.balance = order.amount_total - paid_amount



Is there something I'm missing?


Thank you!

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

Thank you!

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

You need payment status = "paid" not invoice status.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 25
1393
4
thg 2 24
12926
sale / delivery Đã xử lý
1
thg 1 24
1920
0
thg 5 23
2201
4
thg 4 23
42530