mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF]Refactor pms_reservation possible_existing_customers
This commit is contained in:
@@ -635,11 +635,13 @@ class PmsReservation(models.Model):
|
||||
ondelete="restrict",
|
||||
)
|
||||
|
||||
is_possible_existing_customer_id = fields.Many2one(
|
||||
possible_existing_customer_ids = fields.One2many(
|
||||
string="Possible existing customer",
|
||||
readonly=False,
|
||||
store=True,
|
||||
compute="_compute_is_possible_existing_customer_id",
|
||||
compute="_compute_possible_existing_customer_ids",
|
||||
comodel_name="res.partner",
|
||||
inverse_name="reservation_possible_customer_id",
|
||||
)
|
||||
|
||||
add_possible_customer = fields.Boolean(string="Add possible Customer")
|
||||
@@ -838,7 +840,6 @@ class PmsReservation(models.Model):
|
||||
"partner_name",
|
||||
"email",
|
||||
"mobile",
|
||||
"add_possible_customer",
|
||||
)
|
||||
def _compute_partner_id(self):
|
||||
for reservation in self:
|
||||
@@ -851,8 +852,6 @@ class PmsReservation(models.Model):
|
||||
reservation.partner_id = reservation.agency_id
|
||||
elif reservation.document_number and reservation.document_type:
|
||||
self.env["pms.folio"]._create_partner(reservation)
|
||||
elif reservation.add_possible_customer:
|
||||
self.env["pms.folio"]._add_customer(reservation)
|
||||
elif not reservation.partner_id:
|
||||
reservation.partner_id = False
|
||||
|
||||
@@ -1340,7 +1339,7 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
record.partner_name = record.out_service_description
|
||||
|
||||
@api.depends("partner_id", "partner_id.email", "agency_id", "add_possible_customer")
|
||||
@api.depends("partner_id", "partner_id.email", "agency_id")
|
||||
def _compute_email(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_email(record)
|
||||
@@ -1436,10 +1435,21 @@ class PmsReservation(models.Model):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_document_id(record)
|
||||
|
||||
@api.depends("email", "mobile")
|
||||
def _compute_is_possible_existing_customer_id(self):
|
||||
@api.depends("email", "mobile", "partner_name")
|
||||
def _compute_possible_existing_customer_ids(self):
|
||||
for record in self:
|
||||
self.env["pms.folio"]._apply_is_possible_existing_customer_id(record)
|
||||
if record.partner_name:
|
||||
possible_customer = self.env[
|
||||
"pms.folio"
|
||||
]._apply_possible_existing_customer_ids(
|
||||
record.email, record.mobile, record.partner_id
|
||||
)
|
||||
if possible_customer:
|
||||
record.possible_existing_customer_ids = possible_customer
|
||||
else:
|
||||
record.possible_existing_customer_ids = False
|
||||
else:
|
||||
record.possible_existing_customer_ids = False
|
||||
|
||||
@api.depends("checkin", "checkout")
|
||||
def _compute_is_modified_reservation(self):
|
||||
@@ -1746,6 +1756,21 @@ class PmsReservation(models.Model):
|
||||
"context": ctx,
|
||||
}
|
||||
|
||||
def open_wizard_several_partners(self):
|
||||
ctx = dict(
|
||||
reservation_id=self.id,
|
||||
possible_existing_customer_ids=self.possible_existing_customer_ids.ids,
|
||||
)
|
||||
return {
|
||||
"view_type": "form",
|
||||
"view_mode": "form",
|
||||
"name": "Several Customers",
|
||||
"res_model": "pms.several.partners.wizard",
|
||||
"target": "new",
|
||||
"type": "ir.actions.act_window",
|
||||
"context": ctx,
|
||||
}
|
||||
|
||||
@api.model
|
||||
def name_search(self, name="", args=None, operator="ilike", limit=100):
|
||||
if args is None:
|
||||
|
||||
@@ -140,13 +140,14 @@
|
||||
class="alert alert-warning"
|
||||
role="alert"
|
||||
style="margin-bottom:0px;"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',[])]}"
|
||||
attrs="{'invisible': [('possible_existing_customer_ids','=',[])]}"
|
||||
>
|
||||
There is a customer with this email or mobile, do you want to add it to the reservation?
|
||||
<field name="is_possible_existing_customer_id" invisible="1" />
|
||||
<field
|
||||
name="add_possible_customer"
|
||||
attrs="{'invisible': [('is_possible_existing_customer_id','=',False)]}"
|
||||
A customer/s has this email or mobile, do you want to add it?
|
||||
<field name="possible_existing_customer_ids" invisible="1" />
|
||||
<button
|
||||
name="open_wizard_several_partners"
|
||||
string="Add customer"
|
||||
type="object"
|
||||
/>
|
||||
</div>
|
||||
<sheet>
|
||||
|
||||
Reference in New Issue
Block a user