Skip to content

Commit

Permalink
[FIX]14.0-pms_l10n_es: update vat code country constrain uses documen…
Browse files Browse the repository at this point in the history
…t country instead of country
  • Loading branch information
braisab authored and DarioLodeiros committed Apr 22, 2024
1 parent 8b03f0d commit 048f33a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
25 changes: 22 additions & 3 deletions pms_l10n_es/data/pms_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<field name="name">DNI</field>
<field name="code">D</field>
<field name="country_ids" eval="[(6, 0, [ref('base.es')])]"/>
<field name="priority">10</field>
<field name="validation_code">
letters = {
0: "T",
Expand Down Expand Up @@ -43,6 +44,24 @@ else:
<!-- <field name="has_unique_numbers">True</field>-->
</record>

<record id="document_type_spanish_residence" model="res.partner.id_category">
<field name="name">Spanish Residence permit</field>
<field name="code">N</field>
<field name="priority">30</field>
<field name="country_ids" eval="[(6, 0, [ref('base.es')])]"/>
<field name="validation_code">
permit_first_letter=id_number.name[0:1]
permit_last_letter = id_number.name[
len(id_number.name) - 1 : len(id_number.name)
]
if (permit_first_letter.upper() in ['X','Y']) and id_number.name[1:8].isdigit() and not permit_last_letter.isdigit():
failed = False
else:
failed = True
</field>
<!-- <field name="has_unique_numbers">True</field>-->
</record>

<!-- aeat document type mapped -->
<!-- disabled because this is an override of an existe record in this file -->
<!-- pylint: disable=redundant-modulename-xml -->
Expand All @@ -51,9 +70,9 @@ else:
<field name="aeat_identification_type">02</field>
</record>
<record
id="pms.document_type_spanish_residence"
model="res.partner.id_category"
>
id="pms_l10n_es.document_type_spanish_residence"
model="res.partner.id_category"
>
<field name="aeat_identification_type">05</field>
</record>
<record
Expand Down
19 changes: 10 additions & 9 deletions pms_l10n_es/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ def _missing_document(self, vals, partners=False):
return True
return False

@api.constrains("country_id", "vat")
@api.constrains("id_numbers", "vat")
def update_vat_code_country(self):
if self.env.context.get("ignore_vat_update"):
return
for record in self:
country_id = record.country_id.id
vat = record.vat
if vat and country_id:
vat_with_code = record.fix_eu_vat_number(country_id, vat)
if country_id and vat != vat_with_code:
record.with_context({"ignore_vat_update": True}).write(
{"vat": vat_with_code}
)
if record.id_numbers:
country_id = record.id_numbers[0].country_id.id
vat = record.vat
if vat and country_id:
vat_with_code = record.fix_eu_vat_number(country_id, vat)
if country_id and vat != vat_with_code:
record.with_context({"ignore_vat_update": True}).write(
{"vat": vat_with_code}
)

0 comments on commit 048f33a

Please sign in to comment.