mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms: flow when sale channels of a service change in reservation and folio
This commit is contained in:
committed by
Darío Lodeiros
parent
a892096aca
commit
95b992cc2c
@@ -204,17 +204,6 @@ class PmsFolio(models.Model):
|
||||
ondelete="restrict",
|
||||
check_pms_properties=True,
|
||||
)
|
||||
# channel_type_id = fields.Many2one(
|
||||
# string="Direct Sale Channel",
|
||||
# help="Only allowed if the field of sale channel channel_type is 'direct'",
|
||||
# readonly=False,
|
||||
# store=True,
|
||||
# comodel_name="pms.sale.channel",
|
||||
# domain=[("channel_type", "=", "direct")],
|
||||
# ondelete="restrict",
|
||||
# compute="_compute_channel_type_id",
|
||||
# check_pms_properties=True,
|
||||
# )
|
||||
sale_channel_ids = fields.Many2many(
|
||||
string="Sale Channels",
|
||||
help="Sale Channels through which reservations were managed",
|
||||
@@ -1061,12 +1050,25 @@ class PmsFolio(models.Model):
|
||||
if reservation.commission_amount != 0:
|
||||
folio.commission = folio.commission + reservation.commission_amount
|
||||
|
||||
@api.depends("reservation_ids", "reservation_ids.sale_channel_ids")
|
||||
@api.depends(
|
||||
"reservation_ids",
|
||||
"reservation_ids.sale_channel_ids",
|
||||
"service_ids",
|
||||
"service_ids.sale_channel_ids",
|
||||
)
|
||||
def _compute_sale_channel_ids(self):
|
||||
for record in self:
|
||||
record.sale_channel_ids = [
|
||||
(6, 0, record.mapped("reservation_ids.sale_channel_origin_id.id"))
|
||||
]
|
||||
sale_channel_ids = []
|
||||
if record.reservation_ids:
|
||||
for sale in record.reservation_ids.mapped("sale_channel_ids.id"):
|
||||
sale_channel_ids.append(sale)
|
||||
if record.service_ids:
|
||||
# si es un board service que mire sale_channel_ids
|
||||
# y si es un servicio a secas entonces que coja el origen
|
||||
for sale in record.service_ids.mapped("sale_channel_origin_id.id"):
|
||||
sale_channel_ids.append(sale)
|
||||
sale_channel_ids = list(set(sale_channel_ids))
|
||||
record.sale_channel_ids = [(6, 0, sale_channel_ids)]
|
||||
|
||||
@api.depends("sale_line_ids.invoice_lines")
|
||||
def _compute_get_invoiced(self):
|
||||
@@ -1539,21 +1541,50 @@ class PmsFolio(models.Model):
|
||||
|
||||
def write(self, vals):
|
||||
reservations_to_update = self.env["pms.reservation"]
|
||||
services_to_update = self.env["pms.service"]
|
||||
if "sale_channel_origin_id" in vals:
|
||||
for record in self:
|
||||
for reservation in record.reservation_ids:
|
||||
if (
|
||||
reservation.sale_channel_origin_id
|
||||
== self.sale_channel_origin_id
|
||||
):
|
||||
reservations_to_update += reservation
|
||||
reservations_to_update = self.get_reservations_to_update_channel(vals)
|
||||
services_to_update = self.get_services_to_update_channel(vals)
|
||||
|
||||
res = super(PmsFolio, self).write(vals)
|
||||
if reservations_to_update:
|
||||
reservations_to_update.sale_channel_origin_id = vals[
|
||||
"sale_channel_origin_id"
|
||||
]
|
||||
|
||||
if services_to_update:
|
||||
services_to_update.sale_channel_origin_id = vals["sale_channel_origin_id"]
|
||||
|
||||
return res
|
||||
|
||||
def get_reservations_to_update_channel(self, vals):
|
||||
reservations_to_update = self.env["pms.reservation"]
|
||||
for record in self:
|
||||
for reservation in record.reservation_ids:
|
||||
if (
|
||||
reservation.sale_channel_origin_id == self.sale_channel_origin_id
|
||||
) and (
|
||||
vals["sale_channel_origin_id"]
|
||||
!= reservation.sale_channel_origin_id.id
|
||||
):
|
||||
reservations_to_update += reservation
|
||||
return reservations_to_update
|
||||
|
||||
def get_services_to_update_channel(self, vals):
|
||||
services_to_update = self.env["pms.service"]
|
||||
for record in self:
|
||||
for service in record.service_ids:
|
||||
if (
|
||||
not service.reservation_id
|
||||
and (service.sale_channel_origin_id == self.sale_channel_origin_id)
|
||||
and (
|
||||
vals["sale_channel_origin_id"]
|
||||
!= service.sale_channel_origin_id.id
|
||||
)
|
||||
):
|
||||
services_to_update += service
|
||||
return services_to_update
|
||||
|
||||
def action_pay(self):
|
||||
self.ensure_one()
|
||||
self.ensure_one()
|
||||
|
||||
@@ -134,9 +134,6 @@ class PmsReservation(models.Model):
|
||||
sale_channel_origin_id = fields.Many2one(
|
||||
string="Sale Channel Origin",
|
||||
help="Sale Channel through which reservation was created, the original",
|
||||
store=True,
|
||||
readonly=False,
|
||||
compute="_compute_sale_channel_origin_id",
|
||||
default=lambda self: self._get_default_sale_channel_origin(),
|
||||
comodel_name="pms.sale.channel",
|
||||
)
|
||||
@@ -1633,12 +1630,24 @@ class PmsReservation(models.Model):
|
||||
record.lang = self.env["res.lang"].get_installed()
|
||||
|
||||
|
||||
@api.depends("reservation_line_ids", "reservation_line_ids.sale_channel_id")
|
||||
@api.depends(
|
||||
"reservation_line_ids",
|
||||
"reservation_line_ids.sale_channel_id",
|
||||
"service_ids",
|
||||
"service_ids.sale_channel_ids",
|
||||
"service_ids.sale_channel_origin_id",
|
||||
)
|
||||
def _compute_sale_channel_ids(self):
|
||||
for record in self:
|
||||
record.sale_channel_ids = [
|
||||
(6, 0, record.mapped("reservation_line_ids.sale_channel_id.id"))
|
||||
]
|
||||
sale_channel_ids = []
|
||||
if record.reservation_line_ids:
|
||||
for sale in record.reservation_line_ids.mapped("sale_channel_id.id"):
|
||||
sale_channel_ids.append(sale)
|
||||
if record.service_ids:
|
||||
for sale in record.service_ids.mapped("sale_channel_ids.id"):
|
||||
sale_channel_ids.append(sale)
|
||||
sale_channel_ids = list(set(sale_channel_ids))
|
||||
record.sale_channel_ids = [(6, 0, sale_channel_ids)]
|
||||
|
||||
@api.depends("agency_id")
|
||||
def _compute_sale_channel_origin_id(self):
|
||||
@@ -1654,7 +1663,8 @@ class PmsReservation(models.Model):
|
||||
if (
|
||||
record.sale_channel_origin_id != record.folio_id.sale_channel_origin_id
|
||||
and record.folio_id
|
||||
and isinstance(self.id, int)
|
||||
# and isinstance(self.id, int)
|
||||
and record._origin.sale_channel_origin_id.id
|
||||
):
|
||||
record.is_origin_channel_check_visible = True
|
||||
else:
|
||||
@@ -2099,9 +2109,11 @@ class PmsReservation(models.Model):
|
||||
def write(self, vals):
|
||||
folios_to_update_channel = self.env["pms.folio"]
|
||||
lines_to_update_channel = self.env["pms.reservation.line"]
|
||||
services_to_update_channel = self.env["pms.service"]
|
||||
if "sale_channel_origin_id" in vals:
|
||||
folios_to_update_channel = self.get_folios_to_update_channel(vals)
|
||||
lines_to_update_channel = self.get_lines_to_update_channel(vals)
|
||||
services_to_update_channel = self.get_services_to_update_channel(vals)
|
||||
res = super(PmsReservation, self).write(vals)
|
||||
if folios_to_update_channel:
|
||||
folios_to_update_channel.sale_channel_origin_id = vals[
|
||||
@@ -2109,6 +2121,11 @@ class PmsReservation(models.Model):
|
||||
]
|
||||
if lines_to_update_channel:
|
||||
lines_to_update_channel.sale_channel_id = vals["sale_channel_origin_id"]
|
||||
if services_to_update_channel:
|
||||
services_to_update_channel.sale_channel_origin_id = vals[
|
||||
"sale_channel_origin_id"
|
||||
]
|
||||
|
||||
self._check_services(vals)
|
||||
# Only check if adult to avoid to check capacity in intermediate states (p.e. flush)
|
||||
# that not take access to possible extra beds service in vals
|
||||
@@ -2150,6 +2167,20 @@ class PmsReservation(models.Model):
|
||||
lines_to_update_channel += line
|
||||
return lines_to_update_channel
|
||||
|
||||
def get_services_to_update_channel(self, vals):
|
||||
services_to_update_channel = self.env["pms.service"]
|
||||
for record in self:
|
||||
for service in record.service_ids:
|
||||
if (
|
||||
service.sale_channel_origin_id == record.sale_channel_origin_id
|
||||
and (
|
||||
vals["sale_channel_origin_id"]
|
||||
!= service.sale_channel_origin_id.id
|
||||
)
|
||||
):
|
||||
services_to_update_channel += service
|
||||
return services_to_update_channel
|
||||
|
||||
def update_prices(self):
|
||||
self.ensure_one()
|
||||
for line in self.reservation_line_ids:
|
||||
|
||||
Reference in New Issue
Block a user