[IMP]pms-api-rest: added configurable avail rules in pms_property

This commit is contained in:
braisab
2022-07-14 20:32:04 +02:00
committed by Darío Lodeiros
parent 40ae079934
commit 3518789332
5 changed files with 42 additions and 8 deletions

View File

@@ -27,3 +27,4 @@ class PmsPropertyInfo(Datamodel):
simpleOutColor = fields.String(required=False, allow_none=True) simpleOutColor = fields.String(required=False, allow_none=True)
simpleInColor = fields.String(required=False, allow_none=True) simpleInColor = fields.String(required=False, allow_none=True)
simpleFutureColor = fields.String(required=False, allow_none=True) simpleFutureColor = fields.String(required=False, allow_none=True)
availabilityRuleFields = fields.List(fields.String(), required=False, allow_none=True)

View File

@@ -82,3 +82,21 @@ class PmsProperty(models.Model):
help="Color for pending payment reservations in the planning.", help="Color for pending payment reservations in the planning.",
default="rgba(162,70,137)", default="rgba(162,70,137)",
) )
availability_rule_field_ids = fields.Many2many(
string="Availability Rules",
help="Configurable availability rules",
default=lambda x: x._get_default_avail_rule_fields(),
comodel_name="ir.model.fields",
relation="ir_model_fields_pms_property_rel",
column1="ir_model_fields",
column2="pms_property",
)
def _get_default_avail_rule_fields(self):
avail_rule_fields = self.env['ir.model.fields'].search([('model_id', '=', 'pms.availability.plan.rule'), ('name', 'in', ('min_stay', 'quota'))])
if avail_rule_fields:
return avail_rule_fields.ids
else:
return []

View File

@@ -220,14 +220,13 @@ class PmsAvailabilityPlanService(Component):
vals.update( vals.update(
{"max_stay_arrival": pms_avail_plan_rule_info.maxStayArrival} {"max_stay_arrival": pms_avail_plan_rule_info.maxStayArrival}
) )
if pms_avail_plan_rule_info.closed:
vals.update({"closed": pms_avail_plan_rule_info.closed})
if pms_avail_plan_rule_info.closedDeparture:
vals.update(
{"closed_departure": pms_avail_plan_rule_info.closedDeparture}
)
if pms_avail_plan_rule_info.closedArrival:
vals.update({"closed_arrival": pms_avail_plan_rule_info.closedArrival})
if pms_avail_plan_rule_info.quota: if pms_avail_plan_rule_info.quota:
vals.update({"quota": pms_avail_plan_rule_info.quota}) vals.update({"quota": pms_avail_plan_rule_info.quota})
vals.update(
{
"closed": pms_avail_plan_rule_info.closed,
"closed_departure": pms_avail_plan_rule_info.closedDeparture,
"closed_arrival": pms_avail_plan_rule_info.closedArrival
}
)
avail_rule.write(vals) avail_rule.write(vals)

View File

@@ -28,6 +28,9 @@ class PmsPropertyService(Component):
for prop in self.env["pms.property"].search( for prop in self.env["pms.property"].search(
domain, domain,
): ):
avail_rule_names = []
for avail_field in prop.availability_rule_field_ids:
avail_rule_names.append(avail_field.name)
result_properties.append( result_properties.append(
PmsPropertyInfo( PmsPropertyInfo(
id=prop.id, id=prop.id,
@@ -46,6 +49,7 @@ class PmsPropertyService(Component):
simpleOutColor=prop.simple_out_color, simpleOutColor=prop.simple_out_color,
simpleInColor=prop.simple_in_color, simpleInColor=prop.simple_in_color,
simpleFutureColor=prop.simple_future_color, simpleFutureColor=prop.simple_future_color,
availabilityRuleFields=avail_rule_names,
) )
) )
return result_properties return result_properties
@@ -65,10 +69,13 @@ class PmsPropertyService(Component):
def get_property(self, property_id): def get_property(self, property_id):
pms_property = self.env["pms.property"].search([("id", "=", property_id)]) pms_property = self.env["pms.property"].search([("id", "=", property_id)])
res = [] res = []
avail_rule_names = []
PmsPropertyInfo = self.env.datamodels["pms.property.info"] PmsPropertyInfo = self.env.datamodels["pms.property.info"]
if not pms_property: if not pms_property:
pass pass
else: else:
for avail_field in pms_property.availability_rule_field_ids:
avail_rule_names.append(avail_field.name)
res = PmsPropertyInfo( res = PmsPropertyInfo(
id=pms_property.id, id=pms_property.id,
name=pms_property.name, name=pms_property.name,
@@ -84,6 +91,7 @@ class PmsPropertyService(Component):
staffReservationColor=pms_property.staff_reservation_color, staffReservationColor=pms_property.staff_reservation_color,
toAssignReservationColor=pms_property.to_assign_reservation_color, toAssignReservationColor=pms_property.to_assign_reservation_color,
pendingPaymentReservationColor=pms_property.pending_payment_reservation_color, pendingPaymentReservationColor=pms_property.pending_payment_reservation_color,
availabilityRuleFields=avail_rule_names
) )
return res return res

View File

@@ -71,6 +71,14 @@
attrs="{'invisible': [('color_option_config', '!=', 'advanced')]}" attrs="{'invisible': [('color_option_config', '!=', 'advanced')]}"
/> />
</group> </group>
<group string="Configurable Availability Rules">
<field
name="availability_rule_field_ids"
widget="many2many_tags"
options="{'no_create': True}"
domain="['&amp;',('model_id', '=', 'pms.availability.plan.rule'), ('name', 'in', ('min_stay', 'max_stay', 'quota', 'max_stay_arrival', 'closed_arrival', 'closed', 'closed_departure'))]"
/>
</group>
</group> </group>
</xpath> </xpath>
</field> </field>