Skip to Content
Menu
This question has been flagged
1 Reply
1157 Views

How to caculate amount_total without discount additionally in invoice in odoo 14?


Avatar
Discard
Author

Hi,

from odoo import api, fields, models

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

@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):
super(AccountInvoice, self)._compute_amount()
self.amount_total_no_discount = sum(self.invoice_line_ids.mapped('price_subtotal_no_discount'))

amount_total_no_discount = fields.Monetary(string='Total without discount', store=True, readonly=True,
compute='_compute_amount')

class AccountInvoiceLine(models.Model):
_inherit = "account.move.line"

@api.depends('price_unit', 'discount', 'invoice_line_tax_ids', 'quantity', 'product_id', 'invoice_id.partner_id',
'invoice_id.currency_id', 'invoice_id.company_id','invoice_id.date_invoice', 'invoice_id.date')
def _compute_price(self):
super(AccountInvoiceLine, self)._compute_price()
if self.invoice_line_tax_ids:
taxes = self.invoice_line_tax_ids.compute_all(self.price_unit, self.invoice_id.currency_id, self.quantity,
product=self.product_id, partner=self.invoice_id.partner_id)
self.price_subtotal_no_discount = taxes['total_included']
else:
self.price_subtotal_no_discount = self.price_unit * self.quantity

price_subtotal_no_discount = fields.Monetary(string='Amount without discount', store=True, readonly=True,
compute='_compute_price')

This code don't work on odoo14.

How to edit it for working on odoo 14?

Thank's

Author

please help me!


Best Answer

Hi,

You can inherit the _compute_amount function that computes the value to amount_total field and make necessary changes.

Thanks

Avatar
Discard