İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
15963 Görünümler

I will insert some lines to _compute_amount method. How can I do this?My Odoo version is 11

Original Method:

    @api.one

    @api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount', 'tax_line_ids.amount_rounding',

                 'currency_id', 'company_id', 'date_invoice', 'type')

    def _compute_amount(self):

        round_curr = self.currency_id.round

        self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line_ids)

        self.amount_tax = sum(round_curr(line.amount_total) for line in self.tax_line_ids)

        self.amount_total = self.amount_untaxed + self.amount_tax

        amount_total_company_signed = self.amount_total

        amount_untaxed_signed = self.amount_untaxed

        if self.currency_id and self.company_id and self.currency_id != self.company_id.currency_id:

            currency_id = self.currency_id.with_context(date=self.date_invoice)

            amount_total_company_signed = currency_id.compute(self.amount_total, self.company_id.currency_id)

            amount_untaxed_signed = currency_id.compute(self.amount_untaxed, self.company_id.currency_id)

        sign = self.type in ['in_refund', 'out_refund'] and -1 or 1

        self.amount_total_company_signed = amount_total_company_signed * sign

        self.amount_total_signed = self.amount_total * sign

        self.amount_untaxed_signed = amount_untaxed_signed * sign

Avatar
Vazgeç

Override Odoo methods using super(): https://goo.gl/4BkizH

En İyi Yanıt

Hi,

You can do two things, either you can super the existing function or you can rewrite the entire function as a new one.


class AccountInvoice(models.Model):
_inherit = "account.invoice"

def _compute_amount(self):
res = super(AccountInvoice, self)._compute_amount()
# do the things here
return res

As shown above, you can Super the _compute_amount method in account.invoice.

Or you can rewrite the entire function as per the need by inherting the model

class AccountInvoice(models.Model):
_inherit = "account.invoice"

@api.one
@api.depends('invoice_line_ids.price_subtotal', 'tax_line_ids.amount', 'tax_line_ids.amount_rounding',
'currency_id', 'company_id', 'date_invoice', 'type')
def _compute_amount(self):
# change the function as per the need


Thanks

Avatar
Vazgeç
Üretici

So thanks, It was helpful to me

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 18
6646
1
Mar 24
4839
2
Şub 24
15415
1
Ara 22
4929
2
Ara 22
14348