diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py
index a49c88d15..e985ad667 100644
--- a/pms/models/pms_folio.py
+++ b/pms/models/pms_folio.py
@@ -152,6 +152,9 @@ class PmsFolio(models.Model):
)
channel_type_id = fields.Many2one(
"pms.sale.channel",
+ compute="_compute_channel_type_id",
+ readonly=False,
+ store=True,
string="Direct Sale Channel",
ondelete="restrict",
domain=[("channel_type", "=", "direct")],
@@ -503,6 +506,12 @@ class PmsFolio(models.Model):
else:
folio.commission = 0
+ @api.depends("agency_id")
+ def _compute_channel_type_id(self):
+ for folio in self:
+ if folio.agency_id:
+ folio.channel_type_id = folio.agency_id.sale_channel_id.id
+
@api.depends("sale_line_ids.invoice_lines")
def _compute_get_invoiced(self):
# The invoice_ids are obtained thanks to the invoice lines of the SO
@@ -639,7 +648,7 @@ class PmsFolio(models.Model):
@api.depends("pending_checkin_data")
def _compute_ratio_checkin_data(self):
self.ratio_checkin_data = 0
- for folio in self:
+ for folio in self.filtered("reservation_ids"):
folio.ratio_checkin_data = (
(
sum(folio.reservation_ids.mapped("adults"))
@@ -1191,8 +1200,14 @@ class PmsFolio(models.Model):
@api.constrains("agency_id", "channel_type_id")
def _check_only_one_channel(self):
for record in self:
- if record.agency_id and record.channel_type_id:
- raise models.ValidationError(_("There must be only one sale channel"))
+ if (
+ record.agency_id
+ and record.channel_type_id.channel_type
+ != record.agency_id.sale_channel_id.channel_type
+ ):
+ raise models.ValidationError(
+ _("The Sale Channel does not correspond to the agency's")
+ )
@api.model
def _prepare_down_payment_section_line(self, **optional_values):
diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py
index d3e8dee5b..9c6dfe502 100644
--- a/pms/models/pms_reservation.py
+++ b/pms/models/pms_reservation.py
@@ -143,7 +143,6 @@ class PmsReservation(models.Model):
channel_type_id = fields.Many2one(
related="folio_id.channel_type_id",
readonly=False,
- store=True,
)
partner_invoice_id = fields.Many2one(
"res.partner",
@@ -643,6 +642,8 @@ class PmsReservation(models.Model):
@api.depends("partner_id")
def _compute_pricelist_id(self):
for reservation in self:
+ # TODO: Review logic pricelist by partner
+ # and by allowed channel pricelist_ids
if reservation.folio_id:
pricelist_id = reservation.folio_id.pricelist_id.id
else:
diff --git a/pms/models/pms_sale_channel.py b/pms/models/pms_sale_channel.py
index 1daa07a59..a33dae02b 100644
--- a/pms/models/pms_sale_channel.py
+++ b/pms/models/pms_sale_channel.py
@@ -10,3 +10,5 @@ class PmsSaleChannel(models.Model):
channel_type = fields.Selection(
[("direct", "Direct"), ("indirect", "Indirect")], string="Sale Channel Type"
)
+ on_line = fields.Boolean("On Line")
+ product_pricelist_ids = fields.Many2many("product.pricelist", string="Pricelists")
diff --git a/pms/models/product_pricelist.py b/pms/models/product_pricelist.py
index 213f77d23..d77a9b412 100644
--- a/pms/models/product_pricelist.py
+++ b/pms/models/product_pricelist.py
@@ -25,6 +25,9 @@ class ProductPricelist(models.Model):
pricelist_type = fields.Selection(
[("daily", "Daily Plan")], string="Pricelist Type", default="daily"
)
+ pms_sale_channel_ids = fields.Many2many(
+ "pms.sale.channel", string="Available Channels"
+ )
availability_plan_id = fields.Many2one(
comodel_name="pms.room.type.availability.plan",
diff --git a/pms/views/pms_folio_views.xml b/pms/views/pms_folio_views.xml
index d4e5b059a..ff75dd430 100644
--- a/pms/views/pms_folio_views.xml
+++ b/pms/views/pms_folio_views.xml
@@ -168,16 +168,11 @@
name="reservation_type"
attrs="{'readonly':[('state','not in',('draft'))]}"
/>
-
-
+
-
+
+
+
@@ -21,6 +23,8 @@
+
+
diff --git a/pms/views/product_pricelist_views.xml b/pms/views/product_pricelist_views.xml
index deac8fbc3..149540fb2 100644
--- a/pms/views/product_pricelist_views.xml
+++ b/pms/views/product_pricelist_views.xml
@@ -13,6 +13,7 @@
+