mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
@@ -172,7 +172,7 @@ class PmsAvailability(models.Model):
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
record.parent_avail_id = False
|
record.child_avail_ids = False
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_rooms_not_avail(
|
def get_rooms_not_avail(
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ class PmsAvailabilityPlan(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def update_quota(self, pricelist_id, room_type_id, date, line):
|
def update_quota(self, pricelist_id, room_type_id, date, impacts_quota_id=False):
|
||||||
if pricelist_id and room_type_id and date:
|
if pricelist_id and room_type_id and date:
|
||||||
rule = self.env["pms.availability.plan.rule"].search(
|
rule = self.env["pms.availability.plan.rule"].search(
|
||||||
[
|
[
|
||||||
@@ -96,19 +96,19 @@ class PmsAvailabilityPlan(models.Model):
|
|||||||
if rule and rule.quota != -1 and rule.quota > 0:
|
if rule and rule.quota != -1 and rule.quota > 0:
|
||||||
|
|
||||||
# the line has no rule item applied before
|
# the line has no rule item applied before
|
||||||
if not line.impacts_quota:
|
if not impacts_quota_id:
|
||||||
rule.quota -= 1
|
rule.quota -= 1
|
||||||
return rule.id
|
return rule.id
|
||||||
|
|
||||||
# the line has a rule item applied before
|
# the line has a rule item applied before
|
||||||
elif line.impacts_quota != rule.id:
|
elif impacts_quota_id != rule.id:
|
||||||
|
|
||||||
# decrement quota on current rule item
|
# decrement quota on current rule item
|
||||||
rule.quota -= 1
|
rule.quota -= 1
|
||||||
|
|
||||||
# check old rule item
|
# check old rule item
|
||||||
old_rule = self.env["pms.availability.plan.rule"].search(
|
old_rule = self.env["pms.availability.plan.rule"].search(
|
||||||
[("id", "=", line.impacts_quota)]
|
[("id", "=", impacts_quota_id)]
|
||||||
)
|
)
|
||||||
|
|
||||||
# restore quota in old rule item
|
# restore quota in old rule item
|
||||||
@@ -118,9 +118,9 @@ class PmsAvailabilityPlan(models.Model):
|
|||||||
return rule.id
|
return rule.id
|
||||||
|
|
||||||
# in any case, check old rule item
|
# in any case, check old rule item
|
||||||
if line.impacts_quota:
|
if impacts_quota_id:
|
||||||
old_rule = self.env["pms.availability.plan.rule"].search(
|
old_rule = self.env["pms.availability.plan.rule"].search(
|
||||||
[("id", "=", line.impacts_quota)]
|
[("id", "=", impacts_quota_id)]
|
||||||
)
|
)
|
||||||
# and restore quota in old rule item
|
# and restore quota in old rule item
|
||||||
if old_rule:
|
if old_rule:
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ class PmsReservationLine(models.Model):
|
|||||||
impacts_quota = fields.Integer(
|
impacts_quota = fields.Integer(
|
||||||
string="Impacts quota",
|
string="Impacts quota",
|
||||||
help="This line has been taken into account in the avail quota",
|
help="This line has been taken into account in the avail quota",
|
||||||
readonly=False,
|
readonly=True,
|
||||||
store=True,
|
store=True,
|
||||||
compute="_compute_impact_quota",
|
compute="_compute_impacts_quota",
|
||||||
)
|
)
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
@@ -330,14 +330,18 @@ class PmsReservationLine(models.Model):
|
|||||||
line.room_id = list(bests.keys())[0]
|
line.room_id = list(bests.keys())[0]
|
||||||
|
|
||||||
@api.depends("reservation_id.room_type_id", "reservation_id.pricelist_id")
|
@api.depends("reservation_id.room_type_id", "reservation_id.pricelist_id")
|
||||||
def _compute_impact_quota(self):
|
def _compute_impacts_quota(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
reservation = line.reservation_id
|
reservation = line.reservation_id
|
||||||
|
if isinstance(line.id, int):
|
||||||
|
impacts_quota = False
|
||||||
|
else:
|
||||||
|
impacts_quota = line.impacts_quota
|
||||||
line.impacts_quota = self.env["pms.availability.plan"].update_quota(
|
line.impacts_quota = self.env["pms.availability.plan"].update_quota(
|
||||||
pricelist_id=reservation.pricelist_id,
|
pricelist_id=reservation.pricelist_id,
|
||||||
room_type_id=reservation.room_type_id,
|
room_type_id=reservation.room_type_id,
|
||||||
date=line.date,
|
date=line.date,
|
||||||
line=line,
|
impacts_quota_id=impacts_quota,
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends(
|
@api.depends(
|
||||||
|
|||||||
Reference in New Issue
Block a user