Skip to Content
Menu
This question has been flagged
3 Replies
4163 Views

On my invoices, I want to print the amount_total without discount additionally to the one with discount.

I guess I have to add two fields: one in account.invoice.line like price_total_nodiscount and one in
account.invoice like amount_total_nodiscount. Now I need help where to calculate and fill the fields! 

It's V11 community

Avatar
Discard
Best Answer

Hi,

create a new module which depends of the module 'account', add the following python code in it, and install the module.

I let you to create signed fields corresponding to fields I created (note I don't test this code, but should work)

from odoo import api, fields, models


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):
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.invoice.line"

@api.one
@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')

Regards

Avatar
Discard
Best Answer

Hi,

How to do it for odoo 14?

Avatar
Discard
Author

Just in case you still need this: there's a module available, which provides the relevant field (amount without discount):

https://github.com/OCA/account-invoicing/tree/14.0/account_invoice_discount_display_amount

Now you can put "price_total_no_discount" in your report!

hth ;-)

Author Best Answer

Thanks for the answer - It's working!

Avatar
Discard

Hi, effectively for other fields which are using the the same function in invoice and line, this parameter is by default set to False, remove compute_sudo parameter in 2 fields I created, update the module, if you have again the warning, set in 2 fields I created compute_sudo=False

Good week end

set in 2 fields I created compute_sudo=False and update the module

Author

just removed it and got rid of the Warning - Merci bien!

I corrected my answer, if all is good, you can validated my answer

tchuss