mirror of
https://gitlab.com/datalifeit/trytond-aeat_sii
synced 2023-12-13 20:30:37 +01:00
add sii key on taxes and method to load on invoices
This commit is contained in:
parent
652bd4fa6d
commit
a46f9ad5be
9 changed files with 2725 additions and 46 deletions
|
@ -7,18 +7,19 @@ from . import aeat
|
|||
from . import party
|
||||
from . import company
|
||||
from . import load_pkcs12
|
||||
from . import account
|
||||
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
account.TemplateTax,
|
||||
account.Tax,
|
||||
party.Party,
|
||||
company.Company,
|
||||
invoice.Invoice,
|
||||
load_pkcs12.LoadPKCS12Start,
|
||||
aeat.SIIReport,
|
||||
aeat.SIIReportLine,
|
||||
aeat.IssuedTrytonInvoiceMapper,
|
||||
aeat.RecievedTrytonInvoiceMapper,
|
||||
module='aeat_sii', type_='model')
|
||||
Pool.register(
|
||||
load_pkcs12.LoadPKCS12,
|
||||
|
|
54
account.py
Normal file
54
account.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.model import ModelSQL, ModelView, fields
|
||||
from trytond.wizard import Wizard, StateView, StateTransition, Button
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, And, Bool
|
||||
from trytond.transaction import Transaction
|
||||
from .aeat import (OPERATION_KEY, BOOK_KEY, SEND_SPECIAL_REGIME_KEY,
|
||||
RECEIVE_SPECIAL_REGIME_KEY, AEAT_INVOICE_STATE, IVA_SUBJECTED,
|
||||
EXCEMPTION_CAUSE, INTRACOMUNITARY_TYPE)
|
||||
|
||||
|
||||
__all__ = ['TemplateTax', 'Tax']
|
||||
|
||||
|
||||
class TemplateTax:
|
||||
__name__ = 'account.tax.template'
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
sii_book_key = fields.Selection(BOOK_KEY, 'Book Key')
|
||||
sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key')
|
||||
sii_received_key = fields.Selection(RECEIVE_SPECIAL_REGIME_KEY,
|
||||
'Received Key')
|
||||
sii_intracomunity_key = fields.Selection(INTRACOMUNITARY_TYPE,
|
||||
'Intracommunity Key')
|
||||
sii_subjected_key = fields.Selection(IVA_SUBJECTED, 'Subjected Key')
|
||||
sii_excemption_key = fields.Selection(EXCEMPTION_CAUSE, 'Excemption Key')
|
||||
|
||||
def _get_tax_value(self, tax=None):
|
||||
res = super(TemplateTax, self)._get_tax_value(tax)
|
||||
print "res:", res
|
||||
for field in ('sii_book_key', 'sii_issued_key', 'sii_subjected_key',
|
||||
'sii_excemption_key', 'sii_received_key',
|
||||
'sii_intracomunity_key'):
|
||||
|
||||
if not tax or getattr(tax, field) != getattr(self, field):
|
||||
print "A:", field, getattr(self, field)
|
||||
res[field] = getattr(self, field)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
class Tax:
|
||||
__name__ = 'account.tax'
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
sii_book_key = fields.Selection(BOOK_KEY, 'Book Key')
|
||||
sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key')
|
||||
sii_received_key = fields.Selection(RECEIVE_SPECIAL_REGIME_KEY,
|
||||
'Received Key')
|
||||
sii_intracomunity_key = fields.Selection(INTRACOMUNITARY_TYPE,
|
||||
'Intracommunity Key')
|
||||
sii_subjected_key = fields.Selection(IVA_SUBJECTED, 'Subjected Key')
|
||||
sii_excemption_key = fields.Selection(EXCEMPTION_CAUSE, 'Excemption Key')
|
17
account.xml
Normal file
17
account.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="aeat_sii_tax_form_view">
|
||||
<field name="model">account.tax</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit" ref="account.tax_view_form"/>
|
||||
<field name="name">tax_form</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="aeat_sii_template_tax_form_view">
|
||||
<field name="model">account.tax.template</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit" ref="account.tax_template_view_form"/>
|
||||
<field name="name">template_tax_form</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
8
aeat.py
8
aeat.py
|
@ -76,6 +76,7 @@ PARTY_IDENTIFIER_TYPE = [
|
|||
|
||||
|
||||
SEND_SPECIAL_REGIME_KEY = [ # L3.1
|
||||
(None, ''),
|
||||
('01', 'Common System Operation'),
|
||||
('02', 'Export'),
|
||||
('03', 'Operations to which the special arrangements for\n'
|
||||
|
@ -105,6 +106,7 @@ SEND_SPECIAL_REGIME_KEY = [ # L3.1
|
|||
]
|
||||
|
||||
RECEIVE_SPECIAL_REGIME_KEY = [
|
||||
(None, ''),
|
||||
('01', 'Common system operation'),
|
||||
('02', 'Operations by which employers '
|
||||
'satisfy REAGYP compensation'),
|
||||
|
@ -162,12 +164,16 @@ PROPERTY_STATE = [ # L6
|
|||
|
||||
# L7 - Iva Subjected
|
||||
IVA_SUBJECTED = [
|
||||
(None, ''),
|
||||
('S1', 'Subjected - Not Excempt'),
|
||||
('S2', 'Subjected - Not Excempt , Inv. Suj. Pass')
|
||||
('S2', 'Subjected - Not Excempt , Inv. Suj. Pass'),
|
||||
('S3', 'Subjected - Not Excempt , With and Withot Inv. Suj. Pass')
|
||||
|
||||
]
|
||||
|
||||
# L9 - Excemption cause
|
||||
EXCEMPTION_CAUSE = [
|
||||
(None, ''),
|
||||
('E1', 'Excempt. Article 20'),
|
||||
('E2', 'Excempt. Article 21'),
|
||||
('E3', 'Excempt. Article 22'),
|
||||
|
|
2570
aeatsii.xml
Normal file
2570
aeatsii.xml
Normal file
File diff suppressed because it is too large
Load diff
70
invoice.py
70
invoice.py
|
@ -7,6 +7,7 @@ from trytond.pyson import Eval
|
|||
from trytond.transaction import Transaction
|
||||
|
||||
from sql.aggregate import Max
|
||||
|
||||
from .aeat import (
|
||||
OPERATION_KEY, BOOK_KEY, SEND_SPECIAL_REGIME_KEY,
|
||||
RECEIVE_SPECIAL_REGIME_KEY, AEAT_INVOICE_STATE, IVA_SUBJECTED,
|
||||
|
@ -24,21 +25,21 @@ class Invoice:
|
|||
'SII Book Key')
|
||||
sii_operation_key = fields.Selection([(None, ''), ] + OPERATION_KEY,
|
||||
'SII Operation Key')
|
||||
sii_issued_key = fields.Selection([(None, ''), ] + SEND_SPECIAL_REGIME_KEY,
|
||||
sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY,
|
||||
'SII Issued Key',
|
||||
states={
|
||||
'invisible': ~Eval('type').in_(['out_invoice', 'out_credit_note']),
|
||||
})
|
||||
sii_received_key = fields.Selection([(None, ''), ] +
|
||||
RECEIVE_SPECIAL_REGIME_KEY, 'SII Recived Key',
|
||||
sii_received_key = fields.Selection(RECEIVE_SPECIAL_REGIME_KEY,
|
||||
'SII Recived Key',
|
||||
states={
|
||||
'invisible': Eval('type').in_(['out_invoice', 'out_credit_note']),
|
||||
})
|
||||
sii_subjected = fields.Selection([(None, '')] + IVA_SUBJECTED, 'Subjected')
|
||||
sii_excemption_cause = fields.Selection([(None, '')] + EXCEMPTION_CAUSE,
|
||||
sii_subjected = fields.Selection(IVA_SUBJECTED, 'Subjected')
|
||||
sii_excemption_cause = fields.Selection(EXCEMPTION_CAUSE,
|
||||
'Excemption Cause')
|
||||
sii_intracomunity_key = fields.Selection([(None, ''), ] +
|
||||
INTRACOMUNITARY_TYPE, 'SII Intracommunity Key',
|
||||
sii_intracomunity_key = fields.Selection(INTRACOMUNITARY_TYPE,
|
||||
'SII Intracommunity Key',
|
||||
states={
|
||||
'invisible': ~Eval('sii_book_key').in_(['U']),
|
||||
}
|
||||
|
@ -55,40 +56,6 @@ class Invoice:
|
|||
'sii_received_key', 'sii_issued_key', 'sii_subjected',
|
||||
'sii_excemption_cause', 'sii_intracomunity_key']
|
||||
|
||||
@staticmethod
|
||||
def default_sii_book_key():
|
||||
type_ = Transaction().context.get('type', 'out_invoice')
|
||||
book_key = 'E'
|
||||
if type_ and type_ == 'in_invoice':
|
||||
book_key = 'R'
|
||||
|
||||
return book_key
|
||||
|
||||
@staticmethod
|
||||
def default_sii_subjected():
|
||||
return 'S1'
|
||||
|
||||
@staticmethod
|
||||
def default_sii_issued_key():
|
||||
type_ = Transaction().context.get('type', 'out_invoice')
|
||||
if type_ == 'out_invoice':
|
||||
return '01'
|
||||
return 'None'
|
||||
|
||||
@staticmethod
|
||||
def default_sii_received_key():
|
||||
type_ = Transaction().context.get('type', 'out_invoice')
|
||||
if type_ == 'in_invoice':
|
||||
return '01'
|
||||
return 'None'
|
||||
|
||||
@staticmethod
|
||||
def default_sii_operation_key():
|
||||
type_ = Transaction().context.get('type', 'out_invoice')
|
||||
if type_ in ('in_credit_note', 'out_credit_note'):
|
||||
return 'R1'
|
||||
return 'F1'
|
||||
|
||||
@classmethod
|
||||
def search_sii_state(cls, name, clause):
|
||||
pool = Pool()
|
||||
|
@ -112,8 +79,6 @@ class Invoice:
|
|||
clause2 = [tuple(('state',)) + tuple(clause[1:])] + \
|
||||
[('id', 'in', lines)]
|
||||
|
||||
print "clause2:", clause2
|
||||
|
||||
res_lines = SIILines.search(clause2)
|
||||
return [('id', 'in', [x.invoice.id for x in res_lines])]
|
||||
|
||||
|
@ -151,3 +116,22 @@ class Invoice:
|
|||
|
||||
res['sii_operation_key'] = 'R4'
|
||||
return res
|
||||
|
||||
@fields.depends('sii_book_key', 'sii_issued_key', 'sii_received_key',
|
||||
'sii_subjected', 'sii_excemption_cause', 'sii_intracomunity_key')
|
||||
def _on_change_lines_taxes(self):
|
||||
res = super(Invoice, self)._on_change_lines_taxes()
|
||||
for field in ('sii_book_key', 'sii_issued_key', 'sii_received_key',
|
||||
'sii_subjected', 'sii_excemption_cause',
|
||||
'sii_intracomunity_key'):
|
||||
if getattr(self, field):
|
||||
return res
|
||||
|
||||
tax = self.taxes and self.taxes[0]
|
||||
if not tax:
|
||||
return res
|
||||
for field in ('sii_book_key', 'sii_issued_key', 'sii_received_key',
|
||||
'sii_subjected', 'sii_excemption_cause',
|
||||
'sii_intracomunity_key'):
|
||||
res[field] = getattr(tax, field)
|
||||
return res
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
[tryton]
|
||||
version=4.0
|
||||
depends:
|
||||
account_es
|
||||
account_chart_speedup
|
||||
account_invoice
|
||||
xml:
|
||||
account.xml
|
||||
aeat.xml
|
||||
invoice.xml
|
||||
party.xml
|
||||
company.xml
|
||||
load_pkcs12.xml
|
||||
aeatsii.xml
|
||||
|
|
22
view/tax_form.xml
Normal file
22
view/tax_form.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--The COPYRIGHT file at the top level of this repository
|
||||
contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id="code"]" position="after">
|
||||
<page string="AEAT SII" id="aeatsii">
|
||||
<label name="sii_book_key"/>
|
||||
<field name="sii_book_key"/>
|
||||
<label name="sii_issued_key"/>
|
||||
<field name="sii_issued_key"/>
|
||||
<label name="sii_received_key"/>
|
||||
<field name="sii_received_key"/>
|
||||
<label name="sii_intracomunity_key"/>
|
||||
<field name="sii_intracomunity_key"/>
|
||||
|
||||
<label name="sii_subjected_key"/>
|
||||
<field name="sii_subjected_key"/>
|
||||
<label name="sii_excemption_key"/>
|
||||
<field name="sii_excemption_key"/>
|
||||
</page>
|
||||
</xpath>
|
||||
</data>
|
21
view/template_tax_form.xml
Normal file
21
view/template_tax_form.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--The COPYRIGHT file at the top level of this repository
|
||||
contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath expr="/form/notebook/page[@id="code"]" position="after">
|
||||
<page string="AEAT sii" id="aeatsii">
|
||||
<label name="sii_book_key"/>
|
||||
<field name="sii_book_key"/>
|
||||
<label name="sii_issued_key"/>
|
||||
<field name="sii_issued_key"/>
|
||||
<label name="sii_received_key"/>
|
||||
<field name="sii_received_key"/>
|
||||
<label name="sii_intracomunity_key"/>
|
||||
<field name="sii_intracomunity_key"/>
|
||||
<label name="sii_subjected_key"/>
|
||||
<field name="sii_subjected_key"/>
|
||||
<label name="sii_excemption_key"/>
|
||||
<field name="sii_excemption_key"/>
|
||||
</page>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in a new issue