Debian Codegraph @

addons/l10n_es_edi_verifactu/models/res_company.py

raw symbols SCIP
1 from odoo import _, fields, models
2
3
4 class ResCompany(models.Model):
5 _inherit = 'res.company'
6
7 l10n_es_edi_verifactu_certificate_ids = fields.One2many(
8 string="Veri*Factu Certificates",
9 comodel_name='certificate.certificate',
10 inverse_name='company_id',
11 )
12 l10n_es_edi_verifactu_required = fields.Boolean(
13 string="Enable Veri*Factu",
14 copy=False,
15 )
16 l10n_es_edi_verifactu_test_environment = fields.Boolean(
17 string="Veri*Factu Test Environment",
18 default=True,
19 copy=False,
20 )
21 l10n_es_edi_verifactu_chain_sequence_id = fields.Many2one(
22 comodel_name='ir.sequence',
23 string="Veri*Factu Document Chain Sequence",
24 readonly=True,
25 copy=False,
26 )
27 l10n_es_edi_verifactu_next_batch_time = fields.Datetime(
28 string="Veri*Factu Next Batch Time",
29 readonly=True,
30 copy=False,
31 help="The Datetime at which the next submission to the AEAT can be made.",
32 )
33 l10n_es_edi_verifactu_special_vat_regime = fields.Selection(
34 string="Veri*Factu VAT Regime",
35 selection=[
36 ('simplified', "Simplified Regime"),
37 ('reagyp', "REAGYP (Special Regime for Agriculture, Livestock and Fisheries)"),
38 ('recargo', "Recargo de Equivalencia"),
39 ],
40 help="Leave empty for the normal regimen.",
41 )
42
43 def _l10n_es_edi_verifactu_get_endpoints(self):
44 """
45 For the SOAP endpoints see:
46 https://prewww2.aeat.es/static_files/common/internet/dep/aplicaciones/es/aeat/tikeV1.0/cont/ws/SistemaFacturacion.wsdl
47 """
48 self.ensure_one()
49 wsdl_base = {
50 'url': 'https://prewww2.aeat.es/static_files/common/internet/dep/aplicaciones/es/aeat/tikeV1.0/cont/ws/SistemaFacturacion.wsdl',
51 'service': 'sfVerifactu',
52 'registration': 'RegFactuSistemaFacturacion',
53 'port': None,
54 }
55 if self.l10n_es_edi_verifactu_test_environment:
56 endpoints = {
57 'wsdl': wsdl_base | {'port': 'SistemaVerifactuPruebas'},
58 'verifactu': 'https://prewww1.aeat.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP',
59 'QR': 'https://prewww2.aeat.es/wlpl/TIKE-CONT/ValidarQR',
60 }
61 else:
62 endpoints = {
63 'wsdl': wsdl_base | {'port': 'SistemaVerifactu'},
64 'verifactu': 'https://www1.agenciatributaria.gob.es/wlpl/TIKE-CONT/ws/SistemaFacturacion/VerifactuSOAP',
65 'QR': 'https://www2.agenciatributaria.gob.es/wlpl/TIKE-CONT/ValidarQR'
66 }
67 return endpoints
68
69 def _l10n_es_edi_verifactu_get_certificate(self):
70 self.ensure_one()
71 return self.env['certificate.certificate'].search(
72 [('company_id', '=', self.id), ('scope', '=', 'verifactu')],
73 order='date_end desc',
74 limit=1,
75 )
76
77 def _l10n_es_edi_verifactu_get_chain_sequence(self):
78 self.ensure_one()
79 if not self.l10n_es_edi_verifactu_chain_sequence_id:
80 self_sudo = self.sudo()
81 self_sudo.l10n_es_edi_verifactu_chain_sequence_id = self_sudo.env['ir.sequence'].create({
82 'name': _("Veri*Factu Document Sequence for company %(name)s (%(id)s)", name=self.name, id=self.id),
83 'code': f'l10n_es_edi_verifactu.document.{self.id}',
84 'implementation': 'no_gap',
85 'company_id': self.id,
86 })
87 return self.l10n_es_edi_verifactu_chain_sequence_id
88
89 def _l10n_es_edi_verifactu_get_last_document(self):
90 self.ensure_one()
91 return self.env['l10n_es_edi_verifactu.document'].search(
92 [
93 ('chain_index', '!=', False),
94 ('company_id', '=', self.id),
95 ],
96 order='chain_index DESC',
97 limit=1,
98 )