Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pms/models/pms_checkin_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ class PmsCheckinPartner(models.Model):
readonly=False,
store=True,
compute="_compute_email",
inverse=lambda r: r._inverse_partner_fields("email", "email"),
)
mobile = fields.Char(
help="Checkin Partner Mobile",
readonly=False,
store=True,
compute="_compute_mobile",
inverse=lambda r: r._inverse_partner_fields("mobile", "mobile"),
)
phone = fields.Char(
help="Checkin Partner Phone",
readonly=False,
store=True,
compute="_compute_phone",
inverse=lambda r: r._inverse_partner_fields("phone", "phone"),
)
image_128 = fields.Image(
string="Image",
Expand Down Expand Up @@ -130,6 +133,7 @@ class PmsCheckinPartner(models.Model):
store=True,
compute="_compute_gender",
selection=[("male", "Male"), ("female", "Female"), ("other", "Other")],
inverse=lambda r: r._inverse_partner_fields("gender", "gender"),
)
nationality_id = fields.Many2one(
string="Nationality",
Expand All @@ -139,6 +143,7 @@ class PmsCheckinPartner(models.Model):
index=True,
compute="_compute_nationality_id",
comodel_name="res.country",
inverse=lambda r: r._inverse_partner_fields("nationality_id", "nationality_id"),
)
residence_street = fields.Char(
string="Street",
Expand Down Expand Up @@ -194,27 +199,31 @@ class PmsCheckinPartner(models.Model):
readonly=False,
store=True,
compute="_compute_firstname",
inverse=lambda r: r._inverse_partner_fields("firstname", "firstname"),
)
lastname = fields.Char(
string="Last Name",
help="host lastname",
readonly=False,
store=True,
compute="_compute_lastname",
inverse=lambda r: r._inverse_partner_fields("lastname", "lastname"),
)
lastname2 = fields.Char(
string="Second Last Name",
help="host second lastname",
readonly=False,
store=True,
compute="_compute_lastname2",
inverse=lambda r: r._inverse_partner_fields("lastname2", "lastname2"),
)
birthdate_date = fields.Date(
string="Birthdate",
help="host birthdate",
readonly=False,
store=True,
compute="_compute_birth_date",
inverse=lambda r: r._inverse_partner_fields("birthdate_date", "birthdate_date"),
)
document_number = fields.Char(
help="Host document number",
Expand Down Expand Up @@ -285,6 +294,11 @@ class PmsCheckinPartner(models.Model):
compute="_compute_sign_on",
)

def _inverse_partner_fields(self, checkin_field_name, partner_field_name):
for record in self:
if record.partner_id:
record.partner_id[partner_field_name] = record[checkin_field_name]

@api.depends("partner_id")
def _compute_document_number(self):
for record in self:
Expand Down
8 changes: 4 additions & 4 deletions pms/models/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def _compute_reservation_line_ids(self):
reservation.reservation_line_ids = False
reservation.check_in_out_dates()

@api.depends("board_service_room_id")
@api.depends("board_service_room_id", "adults", "children")
def _compute_board_service_ids(self):
if self.env.context.get("skip_compute_board_service_ids", False):
return
Expand Down Expand Up @@ -2185,10 +2185,10 @@ def _check_clousure_reason(self, reservation_type, closure_reason_id):
)

def _check_services(self, vals):
# If we create a reservation with board service and other service at the
# same time, compute_service_ids dont run (compute with readonly to False), and
# If we create a reservation with board service, compute_service_ids dont run
# (compute with readonly to False), and
# we must force it to compute the services linked with the board service:
if "board_service_room_id" in vals and "service_ids" in vals:
if "board_service_room_id" in vals:
self._compute_board_service_ids()

def get_folios_to_update_channel(self, vals):
Expand Down
2 changes: 1 addition & 1 deletion pms/models/pms_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def _compute_address_id(self):
"type": "other",
"is_company": False,
"active": True,
"parent_id": record.pms_property_id.id,
"parent_id": record.pms_property_id.partner_id.id,
}
)
)
Expand Down
191 changes: 0 additions & 191 deletions pms/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,53 +87,7 @@ class ResPartner(models.Model):
comodel_name="pms.folio",
inverse_name="partner_id",
)
gender = fields.Selection(
readonly=False,
store=True,
compute="_compute_gender",
)
birthdate_date = fields.Date(
readonly=False,
store=True,
compute="_compute_birthdate_date",
)
nationality_id = fields.Many2one(
readonly=False,
store=True,
index=True,
compute="_compute_nationality_id",
)
email = fields.Char(
readonly=False,
store=True,
compute="_compute_email",
)
mobile = fields.Char(
readonly=False,
store=True,
compute="_compute_mobile",
)
phone = fields.Char(
readonly=False,
store=True,
compute="_compute_phone",
)
firstname = fields.Char(
readonly=False,
store=True,
compute="_compute_firstname",
)

lastname = fields.Char(
readonly=False,
store=True,
compute="_compute_lastname",
)
lastname2 = fields.Char(
readonly=False,
store=True,
compute="_compute_lastname2",
)
country_id = fields.Many2one(
readonly=False,
store=True,
Expand Down Expand Up @@ -245,67 +199,6 @@ class ResPartner(models.Model):
comodel_name="res.country.state",
)

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.gender")
def _compute_gender(self):
if hasattr(super(), "_compute_gender"):
super()._compute_gender()
for record in self:
if record.pms_checkin_partner_ids:
last_update_gender = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_gender and last_update_gender[0].gender:
record.gender = last_update_gender[0].gender

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.birthdate_date")
def _compute_birthdate_date(self):
if hasattr(super(), "_compute_birthdate_date"):
super()._compute_birthdate_date()
for record in self:
if record.pms_checkin_partner_ids:
last_update_birthdate = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_birthdate and last_update_birthdate[0].birthdate_date:
record.birthdate_date = last_update_birthdate[0].birthdate_date

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.nationality_id")
def _compute_nationality_id(self):
if hasattr(super(), "_compute_nationality_id"):
super()._compute_nationality_id()
for record in self:
if record.pms_checkin_partner_ids:
last_update_nationality = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if (
last_update_nationality
and last_update_nationality[0].nationality_id
):
record.nationality_id = last_update_nationality[0].nationality_id
if not record.nationality_id and record.country_id:
record.nationality_id = record.country_id

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.phone")
def _compute_phone(self):
if hasattr(super(), "_compute_phone"):
super()._compute_phone()
for record in self:
if record.pms_checkin_partner_ids:
last_update_phone = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_phone and last_update_phone[0].phone:
record.phone = last_update_phone[0].phone

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.residence_street")
def _compute_residence_street(self):
Expand Down Expand Up @@ -398,90 +291,6 @@ def _compute_residence_state_id(self):
if last_update_state and last_update_state[0].residence_state_id:
record.residence_state_id = last_update_state[0].residence_state_id

# pylint: disable=W8110
@api.depends(
"pms_checkin_partner_ids",
"pms_checkin_partner_ids.email",
"pms_reservation_ids",
"pms_reservation_ids.email",
"pms_folio_ids",
"pms_folio_ids.email",
)
def _compute_email(self):
if hasattr(super(), "_compute_email"):
super()._compute_email()
for record in self:
if record.pms_checkin_partner_ids:
last_update_checkin_mail = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_checkin_mail and last_update_checkin_mail[0].email:
record.email = last_update_checkin_mail[0].email

# pylint: disable=W8110
@api.depends(
"pms_checkin_partner_ids",
"pms_checkin_partner_ids.mobile",
"pms_reservation_ids",
"pms_reservation_ids.mobile",
"pms_folio_ids",
"pms_folio_ids.mobile",
)
def _compute_mobile(self):
if hasattr(super(), "_compute_mobile"):
super()._compute_mobile()
for record in self:
if record.pms_checkin_partner_ids:
last_update_mobile = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_mobile and last_update_mobile[0].mobile:
record.mobile = last_update_mobile[0].mobile

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.firstname")
def _compute_firstname(self):
if hasattr(super(), "_compute_firstname"):
super()._compute_firstname()
for record in self:
if record.pms_checkin_partner_ids:
last_update_firstname = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_firstname and last_update_firstname[0].firstname:
record.firstname = last_update_firstname[0].firstname

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.lastname")
def _compute_lastname(self):
if hasattr(super(), "_compute_lastname"):
super()._compute_lastname()
for record in self:
if record.pms_checkin_partner_ids:
last_update_lastname = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_lastname and last_update_lastname[0].lastname:
record.lastname = last_update_lastname[0].lastname

# pylint: disable=W8110
@api.depends("pms_checkin_partner_ids", "pms_checkin_partner_ids.lastname2")
def _compute_lastname2(self):
if hasattr(super(), "_compute_lastname2"):
super()._compute_lastname2()
for record in self:
if record.pms_checkin_partner_ids:
last_update_lastname2 = record.pms_checkin_partner_ids.filtered(
lambda x, r=record: x.write_date
== max(r.pms_checkin_partner_ids.mapped("write_date"))
)
if last_update_lastname2 and last_update_lastname2[0].lastname2:
record.lastname2 = last_update_lastname2[0].lastname2

# pylint: disable=W8110
@api.depends("id_numbers")
def _compute_country_id(self):
Expand Down
23 changes: 22 additions & 1 deletion pms/tests/test_pms_checkin_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -1556,10 +1556,12 @@ def test_save_checkin_from_portal(self):
"The value of " + key + " is not correctly established",
)

def test_compute_partner_fields(self):
def test_compute_inverse_partner_fields(self):
"""
Check that the computes of the checkin_partner fields related to your partner
correctly add these fields to the checkin_partner.
Also check if a change in checkin_partner fields correctly
executes the inverse way.
---------------------------------------
A reservation is created with an adult (checkin_partner) ql which is
saved in the checkin_partner_id variable, a partner is also created with all
Expand Down Expand Up @@ -1624,3 +1626,22 @@ def test_compute_partner_fields(self):
self.partner_id[key],
"The value of " + key + " is not correctly established",
)

checkin_partner_vals = {
"firstname": "Carlos",
"lastname": "balenzuela",
"lastname2": "Sota",
"email": "paz2@example.com",
"birthdate_date": datetime.date(1980, 10, 3),
"gender": "male",
"mobile": "626555444",
"phone": "124456789",
}
checkin_partner.write(checkin_partner_vals)
for key in checkin_partner_vals:
with self.subTest(k=key):
self.assertEqual(
self.reservation.checkin_partner_ids[0][key],
self.partner_id[key],
"The value of " + key + " is not correctly established",
)