[ADD] pms: add ine code to res.partner

This commit is contained in:
miguelpadin
2021-10-01 09:29:19 +02:00
committed by Eric Antones
parent 80b5722c1b
commit f8958030ba
4 changed files with 80 additions and 0 deletions

View File

@@ -5,3 +5,4 @@ from . import pms_log_institution_traveller_report
from . import res_country_state
from . import pms_ine_tourism_type_category
from . import pms_room
from . import res_partner

View File

@@ -0,0 +1,28 @@
import logging
from odoo import api, fields, models
CODE_SPAIN = "ES"
_logger = logging.getLogger(__name__)
class ResPartner(models.Model):
_inherit = "res.partner"
ine_code = fields.Char(
string="INE State Code",
required=True,
compute="_compute_ine_code",
store=True,
)
@api.depends("nationality_id")
def _compute_ine_code(self):
for record in self:
if not record.nationality_id:
record.ine_code = False
elif record.nationality_id.code != CODE_SPAIN:
record.ine_code = record.country_id.code_alpha3
else:
record.ine_code = record.state_id.ine_code

View File

@@ -1 +1,2 @@
from . import test_wizard_ine
from . import test_res_partner

View File

@@ -0,0 +1,50 @@
from .common import TestPms
class TestResPartner(TestPms):
def setUp(self):
super().setUp()
def test_ine_code_foreign_partner(self):
# ARRANGE & ACT
# get record of russia
self.country_russia = self.env["res.country"].search([("code", "=", "RU")])
# Create partner 1 (russia)
self.partner_1 = self.env["res.partner"].create(
{
"name": "partner1",
"country_id": self.country_russia.id,
"nationality_id": self.country_russia.id,
"birthdate_date": "2000-06-25",
"gender": "male",
}
)
# ASSERT
self.assertEqual(
self.partner_1.ine_code,
self.partner_1.country_id.code_alpha3
)
def test_ine_code_spanish_partner(self):
# ARRANGE & ACT
# get record of russia
country_spain = self.env["res.country"].search([("code", "=", "ES")])
state_madrid = self.env["res.country.state"].search([("name", "=", "Madrid")])
# Create partner 1 (russia)
self.partner_1 = self.env["res.partner"].create(
{
"name": "partner1",
"country_id": country_spain.id,
"nationality_id": country_spain.id,
"state_id": state_madrid.id,
"birthdate_date": "2000-06-25",
"gender": "male",
}
)
# ASSERT
self.assertEqual(
self.partner_1.ine_code,
self.partner_1.state_id.ine_code
)