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

View file

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