Allow custom default taxes required in each invoice line (#2)

#163790
This commit is contained in:
nan-tic-dev 2023-12-13 15:55:50 +01:00 committed by GitHub
parent a0fa9b47ff
commit 64670de12d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -1,12 +1,10 @@
# This file is part account_invoice_taxes_required module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.pool import Pool, PoolMeta
from trytond.i18n import gettext
from trytond.exceptions import UserError
__all__ = ['Invoice', 'InvoiceLine']
from trytond.model import fields
class Invoice(metaclass=PoolMeta):
@ -15,6 +13,7 @@ class Invoice(metaclass=PoolMeta):
@classmethod
def validate(cls, invoices):
InvoiceLine = Pool().get('account.invoice.line')
super(Invoice, cls).validate(invoices)
for invoice in invoices:
InvoiceLine.validate(invoice.lines)
@ -22,6 +21,11 @@ class Invoice(metaclass=PoolMeta):
class InvoiceLine(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
taxes_required = fields.Boolean('Taxes Required', readonly=True)
@classmethod
def default_taxes_required(cls):
return True
@classmethod
def validate(cls, lines):
@ -30,8 +34,10 @@ class InvoiceLine(metaclass=PoolMeta):
line.check_tax_required()
def check_tax_required(self):
if not self.invoice or self.invoice.state in ('draft', 'cancelled') or \
self.type != 'line':
if (not self.invoice
or not self.taxes_required
or self.invoice.state in ('draft', 'cancelled')
or self.type != 'line'):
return
if not self.taxes:
raise UserError(gettext(

View File

@ -102,6 +102,8 @@ Create invoice Without Taxes::
>>> line.description = 'Test'
>>> line.quantity = 1
>>> line.unit_price = Decimal(20)
>>> line.taxes_required == True
True
>>> invoice.untaxed_amount
Decimal('220.00')
>>> invoice.tax_amount