mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]l10n_es_SII: and refactoring pms documents
This commit is contained in:
2
pms_l10n_es_SII/models/__init__.py
Normal file
2
pms_l10n_es_SII/models/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import res_partner_id_category
|
||||
from . import res_partner
|
||||
69
pms_l10n_es_SII/models/res_partner.py
Normal file
69
pms_l10n_es_SII/models/res_partner.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = "res.partner"
|
||||
|
||||
vat = fields.Char(
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_vat",
|
||||
)
|
||||
aeat_identification_type = fields.Selection(
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_aeat_identification_type",
|
||||
)
|
||||
aeat_identification = fields.Char(
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_aeat_identification",
|
||||
)
|
||||
|
||||
@api.depends(
|
||||
"id_numbers",
|
||||
"id_numbers.category_id",
|
||||
"id_numbers.category_id.aeat_identification_type",
|
||||
)
|
||||
def _compute_aeat_identification_type(self):
|
||||
if hasattr(super(), "_compute_aeat_identification_type"):
|
||||
super()._compute_aeat_identification_type()
|
||||
for record in self:
|
||||
# Passport ("03"), Residential cert. ("04") and Another document ("05")
|
||||
# are setted in aeat identificacion type.
|
||||
# NIF/VAT ("02") are setted in partner vat field compute
|
||||
document = record.id_numbers.filtered(
|
||||
lambda i: i.category_id.aeat_identification_type in ["03", "05", "06"]
|
||||
)
|
||||
if document and not record.vat:
|
||||
record.aeat_identification_type = document[
|
||||
0
|
||||
].category_id.aeat_identification_type
|
||||
elif not record.aeat_identification_type or record.vat:
|
||||
record.aeat_identification_type = False
|
||||
|
||||
@api.depends("id_numbers", "id_numbers.name")
|
||||
def _compute_aeat_identification(self):
|
||||
if hasattr(super(), "_compute_aeat_identification"):
|
||||
super()._compute_aeat_identification()
|
||||
for record in self:
|
||||
document = record.id_numbers.filtered(
|
||||
lambda i: i.category_id.aeat_identification_type in ["03", "05", "06"]
|
||||
)
|
||||
if document:
|
||||
record.aeat_identification = document[0].name
|
||||
elif not record.aeat_identification:
|
||||
record.aeat_identification = False
|
||||
|
||||
@api.depends("id_numbers", "id_numbers.name")
|
||||
def _compute_vat(self):
|
||||
if hasattr(super(), "_compute_vat"):
|
||||
super()._compute_vat()
|
||||
for record in self:
|
||||
vat = record.id_numbers.filtered(
|
||||
lambda i: i.category_id.aeat_identification_type == "02"
|
||||
)
|
||||
if vat:
|
||||
record.vat = vat[0].name
|
||||
elif not record.vat:
|
||||
record.vat = False
|
||||
26
pms_l10n_es_SII/models/res_partner_id_category.py
Normal file
26
pms_l10n_es_SII/models/res_partner_id_category.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResPartnerIdCategory(models.Model):
|
||||
_inherit = "res.partner.id_category"
|
||||
|
||||
aeat_identification_type = fields.Selection(
|
||||
string="AEAT Identification type equivalent",
|
||||
help=(
|
||||
"Used to specify an identification type to send to SII. Normally for "
|
||||
"sending national and export invoices to SII where the customer country "
|
||||
"is not Spain, it would calculate an identification type of 04 if the VAT "
|
||||
"field is filled and 06 if it was not. This field is to specify "
|
||||
"types of 03 through 05, in the event that the customer doesn't identify "
|
||||
"with a foreign VAT and instead with their passport "
|
||||
"or residential certificate. If there is no value it will work as before."
|
||||
),
|
||||
selection=[
|
||||
("02", "NIF - VAT"),
|
||||
("03", "Passport"),
|
||||
("04", "Official document from the original country"),
|
||||
("05", "Residential certificate"),
|
||||
("06", "Another document"),
|
||||
("07", "Not registered on census"),
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user