mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF]pms: Refactor computes of partner_id, partner_name, email and mobile in folio and reservation
This commit is contained in:
@@ -639,10 +639,6 @@ class PmsFolio(models.Model):
|
||||
for folio in self:
|
||||
if folio.agency_id and folio.agency_id.invoice_to_agency:
|
||||
folio.partner_id = folio.agency_id.id
|
||||
elif folio.agency_id and not folio.partner_name:
|
||||
# if the customer not is the agency but we dont know the customer's name,
|
||||
# set the name provisional
|
||||
folio.partner_name = _("Reservation from ") + folio.agency_id.name
|
||||
elif not folio.partner_id:
|
||||
folio.partner_id = False
|
||||
|
||||
@@ -768,6 +764,7 @@ class PmsFolio(models.Model):
|
||||
@api.depends("partner_id", "partner_id.name", "reservation_ids.partner_name")
|
||||
def _compute_partner_name(self):
|
||||
for record in self:
|
||||
<<<<<<< HEAD
|
||||
if record.partner_id and not record.partner_name:
|
||||
record.partner_name = record.partner_id.name
|
||||
# if there is only one customer name in the folio reservations
|
||||
@@ -780,10 +777,14 @@ class PmsFolio(models.Model):
|
||||
record.partner_name = record.reservation_ids[0].partner_name
|
||||
elif not record.partner_name:
|
||||
record.partner_name = False
|
||||
=======
|
||||
self._apply_partner_name(record)
|
||||
>>>>>>> [REF]pms: Refactor computes of partner_id, partner_name, email and mobile in folio and reservation
|
||||
|
||||
@api.depends("partner_id", "partner_id.email", "reservation_ids.partner_email")
|
||||
def _compute_email(self):
|
||||
for record in self:
|
||||
<<<<<<< HEAD
|
||||
if record.partner_id and not record.email:
|
||||
record.email = record.partner_id.email
|
||||
# if there is only one customer email in the folio reservations
|
||||
@@ -796,10 +797,14 @@ class PmsFolio(models.Model):
|
||||
record.email = record.reservation_ids[0].partner_email
|
||||
elif not record.email:
|
||||
record.email = False
|
||||
=======
|
||||
self._apply_email(record)
|
||||
>>>>>>> [REF]pms: Refactor computes of partner_id, partner_name, email and mobile in folio and reservation
|
||||
|
||||
@api.depends("partner_id", "partner_id.mobile", "reservation_ids.partner_mobile")
|
||||
def _compute_mobile(self):
|
||||
for record in self:
|
||||
<<<<<<< HEAD
|
||||
if record.partner_id and not record.mobile:
|
||||
record.mobile = record.partner_id.mobile
|
||||
# if there is only one customer mobile in the folio reservations
|
||||
@@ -812,6 +817,9 @@ class PmsFolio(models.Model):
|
||||
record.mobile = record.reservation_ids[0].partner_mobile
|
||||
elif not record.mobile:
|
||||
record.mobile = False
|
||||
=======
|
||||
self._apply_mobile(record)
|
||||
>>>>>>> [REF]pms: Refactor computes of partner_id, partner_name, email and mobile in folio and reservation
|
||||
|
||||
@api.depends(
|
||||
"partner_name",
|
||||
@@ -1706,3 +1714,32 @@ class PmsFolio(models.Model):
|
||||
discount_factor = discount_factor * ((100.0 - discount) / 100.0)
|
||||
final_discount = 100.0 - (discount_factor * 100.0)
|
||||
return final_discount
|
||||
|
||||
@api.model
|
||||
def _apply_partner_name(self, record):
|
||||
if record.partner_id and not record.partner_name:
|
||||
record.partner_name = record.partner_id.name
|
||||
elif (
|
||||
record.agency_id
|
||||
and not record.agency_id.invoice_to_agency
|
||||
and not record.partner_name
|
||||
):
|
||||
# if the customer not is the agency but we dont know the customer's name,
|
||||
# set the name provisional
|
||||
record.partner_name = _("Reservation from ") + record.agency_id.name
|
||||
elif not record.partner_name:
|
||||
record.partner_name = False
|
||||
|
||||
@api.model
|
||||
def _apply_mobile(self, record):
|
||||
if record.partner_id and not record.mobile:
|
||||
record.mobile = record.partner_id.mobile
|
||||
elif not record.mobile:
|
||||
record.mobile = False
|
||||
|
||||
@api.model
|
||||
def _apply_email(self, record):
|
||||
if record.partner_id and not record.email:
|
||||
record.email = record.partner_id.email
|
||||
elif not record.email:
|
||||
record.email = False
|
||||
|
||||
@@ -466,14 +466,14 @@ class PmsReservation(models.Model):
|
||||
readonly=False,
|
||||
compute="_compute_partner_name",
|
||||
)
|
||||
partner_email = fields.Char(
|
||||
email = fields.Char(
|
||||
string="E-mail",
|
||||
help="Customer E-mail",
|
||||
store=True,
|
||||
readonly=False,
|
||||
compute="_compute_email",
|
||||
)
|
||||
partner_mobile = fields.Char(
|
||||
mobile = fields.Char(
|
||||
string="Mobile",
|
||||
help="Customer Mobile",
|
||||
store=True,
|
||||
@@ -752,10 +752,12 @@ class PmsReservation(models.Model):
|
||||
def _compute_partner_id(self):
|
||||
for reservation in self:
|
||||
if not reservation.partner_id:
|
||||
if reservation.folio_id:
|
||||
if reservation.folio_id and reservation.folio_id.partner_id:
|
||||
reservation.partner_id = reservation.folio_id.partner_id
|
||||
elif reservation.agency_id:
|
||||
elif reservation.agency_id and reservation.agency_id.invoice_to_agency:
|
||||
reservation.partner_id = reservation.agency_id
|
||||
elif not reservation.folio_id and not reservation.agency_id:
|
||||
reservation.partner_id = False
|
||||
|
||||
@api.depends("checkin", "checkout")
|
||||
def _compute_reservation_line_ids(self):
|
||||
@@ -1213,44 +1215,56 @@ class PmsReservation(models.Model):
|
||||
@api.depends("partner_id", "partner_id.name", "folio_id.partner_name")
|
||||
def _compute_partner_name(self):
|
||||
for record in self:
|
||||
<<<<<<< HEAD
|
||||
if record.partner_id and not record.partner_name:
|
||||
record.partner_name = record.partner_id.name
|
||||
elif record.folio_id.partner_name and not record.partner_name:
|
||||
record.partner_name = record.folio_id.partner_name
|
||||
elif not record.partner_name:
|
||||
record.partner_name = False
|
||||
=======
|
||||
self.folio_id._apply_partner_name(record)
|
||||
>>>>>>> [REF]pms: Refactor computes of partner_id, partner_name, email and mobile in folio and reservation
|
||||
|
||||
@api.depends("partner_id", "partner_id.email")
|
||||
def _compute_email(self):
|
||||
for record in self:
|
||||
<<<<<<< HEAD
|
||||
if record.partner_id and not record.partner_email:
|
||||
record.partner_email = record.partner_id.email
|
||||
elif record.folio_id.email and not record.partner_email:
|
||||
record.partner_email = record.folio_id.partner_email
|
||||
elif not record.partner_email:
|
||||
record.partner_email = False
|
||||
=======
|
||||
self.folio_id._apply_email(record)
|
||||
>>>>>>> [REF]pms: Refactor computes of partner_id, partner_name, email and mobile in folio and reservation
|
||||
|
||||
@api.depends("partner_id", "partner_id.mobile")
|
||||
def _compute_mobile(self):
|
||||
for record in self:
|
||||
<<<<<<< HEAD
|
||||
if record.partner_id and not record.partner_mobile:
|
||||
record.partner_mobile = record.partner_id.mobile
|
||||
elif record.folio_id.mobile and not record.partner_mobile:
|
||||
record.partner_mobile = record.folio_id.partner_mobile
|
||||
elif not record.partner_mobile:
|
||||
record.partner_mobile = False
|
||||
=======
|
||||
self.folio_id._apply_mobile(record)
|
||||
>>>>>>> [REF]pms: Refactor computes of partner_id, partner_name, email and mobile in folio and reservation
|
||||
|
||||
@api.depends(
|
||||
"partner_name",
|
||||
"partner_email",
|
||||
"partner_mobile",
|
||||
"email",
|
||||
"mobile",
|
||||
"partner_id",
|
||||
)
|
||||
def _compute_partner_incongruences(self):
|
||||
fields_mapping = {
|
||||
"partner_name": "name",
|
||||
"partner_email": "email",
|
||||
"partner_mobile": "mobile",
|
||||
"email": "email",
|
||||
"mobile": "mobile",
|
||||
}
|
||||
for record in self:
|
||||
incongruous_fields = False
|
||||
@@ -1581,8 +1595,8 @@ class PmsReservation(models.Model):
|
||||
default_vals["partner_id"] = folio.partner_id.id
|
||||
elif folio.partner_name:
|
||||
default_vals["partner_name"] = folio.partner_name
|
||||
default_vals["partner_mobile"] = folio.mobile
|
||||
default_vals["partner_email"] = folio.email
|
||||
default_vals["mobile"] = folio.mobile
|
||||
default_vals["email"] = folio.email
|
||||
else:
|
||||
raise ValidationError(_("Partner contact name is required"))
|
||||
vals.update(default_vals)
|
||||
@@ -1598,8 +1612,8 @@ class PmsReservation(models.Model):
|
||||
folio_vals["agency_id"] = vals.get("agency_id")
|
||||
elif vals.get("partner_name"):
|
||||
folio_vals["partner_name"] = vals.get("partner_name")
|
||||
folio_vals["mobile"] = vals.get("partner_mobile")
|
||||
folio_vals["email"] = vals.get("partner_email")
|
||||
folio_vals["mobile"] = vals.get("mobile")
|
||||
folio_vals["email"] = vals.get("email")
|
||||
else:
|
||||
raise ValidationError(_("Partner contact name is required"))
|
||||
# Create the folio in case of need
|
||||
|
||||
@@ -176,7 +176,7 @@ class ResPartner(models.Model):
|
||||
"pms_checkin_partner_ids",
|
||||
"pms_checkin_partner_ids.email",
|
||||
"pms_reservation_ids",
|
||||
"pms_reservation_ids.partner_email",
|
||||
"pms_reservation_ids.email",
|
||||
"pms_folio_ids",
|
||||
"pms_folio_ids.email",
|
||||
)
|
||||
@@ -194,7 +194,7 @@ class ResPartner(models.Model):
|
||||
None,
|
||||
set(
|
||||
record.pms_checkin_partner_ids.mapped("email")
|
||||
+ record.pms_reservation_ids.mapped("partner_email")
|
||||
+ record.pms_reservation_ids.mapped("email")
|
||||
+ record.pms_folio_ids.mapped("email"),
|
||||
),
|
||||
)
|
||||
@@ -210,7 +210,7 @@ class ResPartner(models.Model):
|
||||
"pms_checkin_partner_ids",
|
||||
"pms_checkin_partner_ids.mobile",
|
||||
"pms_reservation_ids",
|
||||
"pms_reservation_ids.partner_mobile",
|
||||
"pms_reservation_ids.mobile",
|
||||
"pms_folio_ids",
|
||||
"pms_folio_ids.mobile",
|
||||
)
|
||||
@@ -228,7 +228,7 @@ class ResPartner(models.Model):
|
||||
None,
|
||||
set(
|
||||
record.pms_checkin_partner_ids.mapped("mobile")
|
||||
+ record.pms_reservation_ids.mapped("partner_mobile")
|
||||
+ record.pms_reservation_ids.mapped("mobile")
|
||||
+ record.pms_folio_ids.mapped("mobile"),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -304,13 +304,13 @@
|
||||
attrs="{'invisible':[('reservation_type','in',('out'))]}"
|
||||
/>
|
||||
<field
|
||||
name="partner_email"
|
||||
name="email"
|
||||
placeholder="email"
|
||||
widget="email"
|
||||
attrs="{'invisible':[('reservation_type','in',('out'))]}"
|
||||
/>
|
||||
<field
|
||||
name="partner_mobile"
|
||||
name="mobile"
|
||||
placeholder="mobile"
|
||||
widget="phone"
|
||||
attrs="{'invisible':[('reservation_type','in',('out'))]}"
|
||||
|
||||
@@ -259,7 +259,7 @@
|
||||
<div class="col pl-md-0">
|
||||
<div
|
||||
t-field="reservation.partner_id"
|
||||
t-options='{"widget": "contact", "fields": ["name", "partner_email", "partner_mobile"]}'
|
||||
t-options='{"widget": "contact", "fields": ["name", "email", "mobile"]}'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user