get amount on line as net-value (even if invoice is gross-mode)

This commit is contained in:
Frederik Jaeckel 2025-06-10 13:45:07 +02:00
parent a5bf930e55
commit 214cbb086f
4 changed files with 85 additions and 3 deletions

View file

@ -10,6 +10,7 @@ from trytond.exceptions import UserError
from trytond.i18n import gettext
from trytond.tools import cached_property
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.modules.product import round_price
@ -160,6 +161,41 @@ class EdocumentMixin(object):
taxname=tax.rec_name))
return tax.unece_code
def get_line_amount(self, line):
""" get amount of current invoice-line,
depends on modegross of invoice, set used-modegross to 'net'
Args:
line (record): model account.invoice.line
"""
if line.modegross == 'net':
return line.amount
elif line.modegross == 'gross':
# get net-amount
# copy from account_invoice/invoice.py:2416-2434
currency = (
line.invoice.currency
if line.invoice else line.currency)
amount = (Decimal(str(line.quantity or 0)) * (
line.unit_price or Decimal(0)))
invoice_type = (
line.invoice.type
if line.invoice else line.invoice_type)
if (invoice_type == 'in'
and line.taxes_deductible_rate is not None
and line.taxes_deductible_rate != 1):
with Transaction().set_context(_deductible_rate=1):
tax_amount = sum(
t['amount'] for t in line._get_taxes().values())
non_deductible_amount = (
tax_amount * (1 - line.taxes_deductible_rate))
amount += non_deductible_amount
if currency:
return currency.round(amount)
return amount
def get_tax_unece_code(self, tax):
while tax:
if tax.unece_code: