2018-01-10 15:10:02 +01:00
|
|
|
# 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.
|
2013-12-04 12:23:38 +01:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
2019-03-31 08:51:18 +02:00
|
|
|
from trytond.i18n import gettext
|
|
|
|
from trytond.exceptions import UserError
|
2023-12-13 15:55:50 +01:00
|
|
|
from trytond.model import fields
|
2012-08-27 12:07:17 +02:00
|
|
|
|
2013-07-02 16:16:32 +02:00
|
|
|
|
2018-08-24 12:17:27 +02:00
|
|
|
class Invoice(metaclass=PoolMeta):
|
2013-12-04 12:23:38 +01:00
|
|
|
__name__ = 'account.invoice'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def validate(cls, invoices):
|
|
|
|
InvoiceLine = Pool().get('account.invoice.line')
|
2023-12-13 15:55:50 +01:00
|
|
|
|
2013-12-04 12:23:38 +01:00
|
|
|
super(Invoice, cls).validate(invoices)
|
|
|
|
for invoice in invoices:
|
|
|
|
InvoiceLine.validate(invoice.lines)
|
|
|
|
|
|
|
|
|
2018-08-24 12:17:27 +02:00
|
|
|
class InvoiceLine(metaclass=PoolMeta):
|
2012-10-17 12:44:55 +02:00
|
|
|
__name__ = 'account.invoice.line'
|
2023-12-13 15:55:50 +01:00
|
|
|
taxes_required = fields.Boolean('Taxes Required', readonly=True)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def default_taxes_required(cls):
|
|
|
|
return True
|
2012-08-27 12:07:17 +02:00
|
|
|
|
2013-07-02 16:16:32 +02:00
|
|
|
@classmethod
|
|
|
|
def validate(cls, lines):
|
|
|
|
super(InvoiceLine, cls).validate(lines)
|
|
|
|
for line in lines:
|
|
|
|
line.check_tax_required()
|
|
|
|
|
2012-10-17 12:44:55 +02:00
|
|
|
def check_tax_required(self):
|
2023-12-13 15:55:50 +01:00
|
|
|
if (not self.invoice
|
|
|
|
or not self.taxes_required
|
|
|
|
or self.invoice.state in ('draft', 'cancelled')
|
|
|
|
or self.type != 'line'):
|
2013-11-24 23:52:25 +01:00
|
|
|
return
|
2012-10-17 12:44:55 +02:00
|
|
|
if not self.taxes:
|
2019-03-31 08:51:18 +02:00
|
|
|
raise UserError(gettext(
|
|
|
|
'account_invoice_taxes_required.tax_required',
|
2021-03-19 16:05:08 +01:00
|
|
|
line=self.rec_name.split(' @ ')[0],
|
|
|
|
invoice=(self.invoice.id if self.invoice else '')))
|