153 lines
6.1 KiB
Python
153 lines
6.1 KiB
Python
# The COPYRIGHT file at the top level of this repository contains the full
|
|
# copyright notices and license terms.
|
|
from trytond.model import fields
|
|
from trytond.pool import PoolMeta
|
|
from trytond.pyson import Eval
|
|
from trytond.transaction import Transaction
|
|
from trytond.tools import cached_property
|
|
from .aeat import (BOOK_KEY, OPERATION_KEY, SEND_SPECIAL_REGIME_KEY,
|
|
RECEIVE_SPECIAL_REGIME_KEY, IVA_SUBJECTED, EXEMPTION_CAUSE,
|
|
IVA_NOT_SUBJECTED)
|
|
|
|
|
|
__all__ = ['Configuration', 'TemplateTax', 'Tax']
|
|
|
|
|
|
class Configuration(metaclass=PoolMeta):
|
|
__name__ = 'account.configuration'
|
|
aeat_pending_sii = fields.Boolean('AEAT Pending SII',
|
|
help='Automatically generate AEAT Pending SII reports by cron')
|
|
aeat_pending_sii_send = fields.Boolean('AEAT Pending SII Send',
|
|
states={
|
|
'invisible': ~Eval('aeat_pending_sii', False),
|
|
}, depends=['aeat_pending_sii'],
|
|
help='Automatically send AEAT Pending SII reports by cron')
|
|
aeat_received_sii = fields.Boolean('AEAT Received SII',
|
|
help='Automatically generate AEAT Received SII reports by cron')
|
|
aeat_received_sii_send = fields.Boolean('AEAT Received SII Send',
|
|
states={
|
|
'invisible': ~Eval('aeat_received_sii', False),
|
|
}, depends=['aeat_received_sii'],
|
|
help='Automatically send AEAT Received SII reports by cron')
|
|
max_sii_lines = fields.Integer('Max SII lines', help='Indicates the '
|
|
'maximum number of invoices to be included in each SII book.',
|
|
domain=['OR',
|
|
[('max_sii_lines', '=', None)],
|
|
[('max_sii_lines', '>', 0)]])
|
|
sii_reagyp_invoice_paid = fields.Boolean('Load SII REAGYP when paid',
|
|
help='Load REAGYP invoices on SII book only when they are paid')
|
|
|
|
@staticmethod
|
|
def default_aeat_pending_sii():
|
|
return False
|
|
|
|
@staticmethod
|
|
def default_aeat_received_sii():
|
|
return False
|
|
|
|
@staticmethod
|
|
def default_aeat_pending_sii_send():
|
|
return False
|
|
|
|
@staticmethod
|
|
def default_aeat_received_sii_send():
|
|
return False
|
|
|
|
|
|
class TemplateTax(metaclass=PoolMeta):
|
|
__name__ = 'account.tax.template'
|
|
|
|
sii_book_key = fields.Selection(BOOK_KEY, 'Book Key')
|
|
sii_operation_key = fields.Selection(OPERATION_KEY, 'SII Operation Key')
|
|
sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key')
|
|
sii_received_key = fields.Selection(RECEIVE_SPECIAL_REGIME_KEY,
|
|
'Received Key')
|
|
sii_subjected_key = fields.Selection(IVA_SUBJECTED, 'Subjected Key')
|
|
sii_exemption_cause = fields.Selection(EXEMPTION_CAUSE, 'Exemption Cause')
|
|
sii_not_subjected_key = fields.Selection(IVA_NOT_SUBJECTED,
|
|
'Not Subjected Key')
|
|
tax_used = fields.Boolean('Used in Tax')
|
|
invoice_used = fields.Boolean('Used in invoice Total')
|
|
|
|
@classmethod
|
|
def __register__(cls, module_name):
|
|
cursor = Transaction().connection.cursor()
|
|
table = cls.__table_handler__(module_name)
|
|
sql_table = cls.__table__()
|
|
|
|
exist_sii_excemption_key = table.column_exist('sii_excemption_key')
|
|
exist_sii_intracomunity_key = table.column_exist('sii_intracomunity_key')
|
|
|
|
super(TemplateTax, cls).__register__(module_name)
|
|
|
|
if exist_sii_excemption_key:
|
|
# Don't use UPDATE FROM because SQLite nor MySQL support it.
|
|
cursor.execute(*sql_table.update([sql_table.sii_exemption_cause],
|
|
[sql_table.sii_excemption_key])),
|
|
table.drop_column('sii_excemption_key')
|
|
|
|
if exist_sii_intracomunity_key:
|
|
table.drop_column('sii_intracomunity_key')
|
|
|
|
def _get_tax_value(self, tax=None):
|
|
res = super(TemplateTax, self)._get_tax_value(tax)
|
|
for field in ('sii_book_key', 'sii_operation_key', 'sii_issued_key',
|
|
'sii_subjected_key', 'sii_exemption_cause', 'sii_received_key',
|
|
'tax_used', 'invoice_used'):
|
|
|
|
if not tax or getattr(tax, field) != getattr(self, field):
|
|
res[field] = getattr(self, field)
|
|
|
|
return res
|
|
|
|
|
|
class Tax(metaclass=PoolMeta):
|
|
__name__ = 'account.tax'
|
|
|
|
sii_book_key = fields.Selection(BOOK_KEY, 'Book Key')
|
|
sii_operation_key = fields.Selection(OPERATION_KEY, 'SII Operation Key')
|
|
sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key')
|
|
sii_received_key = fields.Selection(RECEIVE_SPECIAL_REGIME_KEY,
|
|
'Received Key')
|
|
sii_subjected_key = fields.Selection(IVA_SUBJECTED, 'Subjected Key')
|
|
sii_not_subjected_key = fields.Selection(IVA_NOT_SUBJECTED,
|
|
'Not Subjected Key')
|
|
sii_exemption_cause = fields.Selection(EXEMPTION_CAUSE, 'Exemption Cause')
|
|
tax_used = fields.Boolean('Used in Tax')
|
|
invoice_used = fields.Boolean('Used in invoice Total')
|
|
recargo_equivalencia = fields.Boolean('Recargo Equivalencia',
|
|
help='Indicates if the tax is Recargo de Equivalencia')
|
|
recargo_equivalencia_related_tax = fields.Many2One(
|
|
'account.tax', 'Recargo Equivalencia Related Tax',
|
|
domain=[
|
|
('recargo_equivalencia', '=', True),
|
|
('company', '=', Eval('company', -1)),
|
|
], depends=['recargo_equivalencia', 'company'],
|
|
help='The possible Recargo Equivalencia related to this tax')
|
|
deducible = fields.Boolean('Deducible',
|
|
help='Indicates if the tax is deductible')
|
|
|
|
@classmethod
|
|
def __register__(cls, module_name):
|
|
cursor = Transaction().connection.cursor()
|
|
table = cls.__table_handler__(module_name)
|
|
sql_table = cls.__table__()
|
|
|
|
exist_sii_excemption_key = table.column_exist('sii_excemption_key')
|
|
exist_sii_intracomunity_key = table.column_exist('sii_intracomunity_key')
|
|
|
|
super(Tax, cls).__register__(module_name)
|
|
|
|
if exist_sii_excemption_key:
|
|
# Don't use UPDATE FROM because SQLite nor MySQL support it.
|
|
cursor.execute(*sql_table.update([sql_table.sii_exemption_cause],
|
|
[sql_table.sii_excemption_key])),
|
|
table.drop_column('sii_excemption_key')
|
|
|
|
if exist_sii_intracomunity_key:
|
|
table.drop_column('sii_intracomunity_key')
|
|
|
|
@staticmethod
|
|
def default_deducible():
|
|
return True
|