diff --git a/pms/models/pms_service.py b/pms/models/pms_service.py
index cc11196b2..655024fea 100644
--- a/pms/models/pms_service.py
+++ b/pms/models/pms_service.py
@@ -271,7 +271,12 @@ class PmsService(models.Model):
name += "\n" + product.description_sale
service.name = name
- @api.depends("reservation_id.checkin", "reservation_id.checkout", "product_id")
+ @api.depends(
+ "reservation_id.checkin",
+ "reservation_id.checkout",
+ "product_id",
+ "reservation_id.adults",
+ )
def _compute_service_line_ids(self):
for service in self:
if service.product_id:
@@ -288,15 +293,22 @@ class PmsService(models.Model):
if consumed_on == "after":
i += 1
idate = reservation.checkin + timedelta(days=i)
- old_line = service._search_old_lines(idate)
- if idate in [
- line.date for line in service.service_line_ids
- ]:
- # REVIEW: If the date is already
- # cached (otherwise double the date)
- pass
+ old_line = service.service_line_ids.filtered(
+ lambda r: r.date == idate
+ )
+ price_unit = service._get_price_unit_line(idate)
+ if old_line and old_line.auto_qty:
+ lines.append(
+ (
+ 1,
+ old_line.id,
+ {
+ "day_qty": day_qty,
+ "auto_qty": True,
+ },
+ )
+ )
elif not old_line:
- price_unit = service._get_price_unit_line(idate)
lines.append(
(
0,
@@ -304,12 +316,11 @@ class PmsService(models.Model):
{
"date": idate,
"day_qty": day_qty,
+ "auto_qty": True,
"price_unit": price_unit,
},
)
)
- else:
- lines.append((4, old_line.id))
move_day = 0
if consumed_on == "after":
move_day = 1
@@ -332,7 +343,6 @@ class PmsService(models.Model):
)
service.service_line_ids = lines
else:
- # TODO: Review (business logic refact) no per_day logic service
if not service.service_line_ids:
price_unit = service._get_price_unit_line()
service.service_line_ids = [
@@ -347,8 +357,6 @@ class PmsService(models.Model):
)
]
else:
- # TODO: Service without reservation(room) but with folio¿?
- # example: tourist tour in group
if not service.service_line_ids:
price_unit = service._get_price_unit_line()
service.service_line_ids = [
@@ -365,13 +373,6 @@ class PmsService(models.Model):
else:
service.service_line_ids = False
- def _search_old_lines(self, date):
- self.ensure_one()
- if isinstance(self._origin.id, int):
- old_line = self._origin.service_line_ids.filtered(lambda r: r.date == date)
- return old_line
- return False
-
# Default methods
def name_get(self):
diff --git a/pms/models/pms_service_line.py b/pms/models/pms_service_line.py
index 61cacc7e2..078ace4ff 100644
--- a/pms/models/pms_service_line.py
+++ b/pms/models/pms_service_line.py
@@ -110,6 +110,13 @@ class PmsServiceLine(models.Model):
readonly=True,
store=True,
)
+ auto_qty = fields.Boolean(
+ string="Qty automated setted",
+ help="Show if the day qty was calculated automatically",
+ compute="_compute_auto_qty",
+ readonly=False,
+ store=True,
+ )
@api.depends("day_qty", "discount", "price_unit", "tax_ids")
def _compute_day_amount_service(self):
@@ -213,6 +220,16 @@ class PmsServiceLine(models.Model):
# else:
# reservation.reservation_line_ids.update({"cancel_discount": 0})
+ @api.depends("day_qty")
+ def _compute_auto_qty(self):
+ """
+ Set auto_qty = False if the service is no linked to room or
+ if the day_qty was set manually
+ (See autogeneration of service lines in
+ _compute_service_line_ids -pms.service-)
+ """
+ self.auto_qty = False
+
# Constraints and onchanges
@api.constrains("day_qty")
def no_free_resources(self):
diff --git a/pms/wizards/wizard_folio.py b/pms/wizards/wizard_folio.py
index f38093031..bbc1b53e8 100644
--- a/pms/wizards/wizard_folio.py
+++ b/pms/wizards/wizard_folio.py
@@ -30,6 +30,9 @@ class FolioWizard(models.TransientModel):
string="Property",
default=lambda self: self._default_pms_property_id(),
)
+ segmentation_ids = fields.Many2many(
+ "res.partner.category", string="Segmentation", ondelete="restrict"
+ )
partner_id = fields.Many2one(
"res.partner",
)
@@ -43,6 +46,21 @@ class FolioWizard(models.TransientModel):
store=True,
readonly=False,
)
+ agency_id = fields.Many2one(
+ string="Agency",
+ comodel_name="res.partner",
+ ondelete="restrict",
+ domain=[("is_agency", "=", True)],
+ )
+ channel_type_id = fields.Many2one(
+ string="Direct Sale Channel",
+ readonly=False,
+ store=True,
+ comodel_name="pms.sale.channel",
+ domain=[("channel_type", "=", "direct")],
+ compute="_compute_channel_type_id",
+ ondelete="restrict",
+ )
total_price_folio = fields.Float(
string="Total Price", compute="_compute_total_price_folio"
)
@@ -71,6 +89,12 @@ class FolioWizard(models.TransientModel):
for record in self:
record.pricelist_id = record.partner_id.property_product_pricelist.id
+ @api.depends("agency_id")
+ def _compute_channel_type_id(self):
+ for record in self:
+ if record.agency_id:
+ record.channel_type_id = record.agency_id.sale_channel_id.id
+
@api.depends("availability_results.price_total", "discount")
def _compute_total_price_folio(self):
for record in self:
@@ -144,6 +168,9 @@ class FolioWizard(models.TransientModel):
"pricelist_id": record.pricelist_id.id,
"partner_id": record.partner_id.id,
"pms_property_id": record.pms_property_id.id,
+ "agency_id": record.agency_id.id,
+ "channel_type_id": record.channel_type_id.id,
+ "segmentation_ids": [(6, 0, record.segmentation_ids.ids)],
}
)
else:
@@ -159,6 +186,7 @@ class FolioWizard(models.TransientModel):
"partner_id": record.partner_id.id,
"pricelist_id": record.pricelist_id.id,
"pms_property_id": folio.pms_property_id.id,
+ "board_service_room_id": line.board_service_room_id.id,
}
)
res.reservation_line_ids.discount = record.discount * 100
diff --git a/pms/wizards/wizard_folio.xml b/pms/wizards/wizard_folio.xml
index e8e38d196..734af8fd0 100644
--- a/pms/wizards/wizard_folio.xml
+++ b/pms/wizards/wizard_folio.xml
@@ -19,11 +19,18 @@
options="{'related_start_date': 'start_date'}"
/>