mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX]:pms compute impacts quota reservation line
This commit is contained in:
@@ -81,7 +81,7 @@ class PmsAvailabilityPlan(models.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:
|
||||
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:
|
||||
|
||||
# the line has no rule item applied before
|
||||
if not line.impacts_quota:
|
||||
if not impacts_quota_id:
|
||||
rule.quota -= 1
|
||||
return rule.id
|
||||
|
||||
# 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
|
||||
rule.quota -= 1
|
||||
|
||||
# check old rule item
|
||||
old_rule = self.env["pms.availability.plan.rule"].search(
|
||||
[("id", "=", line.impacts_quota)]
|
||||
[("id", "=", impacts_quota_id)]
|
||||
)
|
||||
|
||||
# restore quota in old rule item
|
||||
@@ -118,9 +118,9 @@ class PmsAvailabilityPlan(models.Model):
|
||||
return rule.id
|
||||
|
||||
# in any case, check old rule item
|
||||
if line.impacts_quota:
|
||||
if impacts_quota_id:
|
||||
old_rule = self.env["pms.availability.plan.rule"].search(
|
||||
[("id", "=", line.impacts_quota)]
|
||||
[("id", "=", impacts_quota_id)]
|
||||
)
|
||||
# and restore quota in old rule item
|
||||
if old_rule:
|
||||
|
||||
@@ -108,9 +108,9 @@ class PmsReservationLine(models.Model):
|
||||
impacts_quota = fields.Integer(
|
||||
string="Impacts quota",
|
||||
help="This line has been taken into account in the avail quota",
|
||||
readonly=False,
|
||||
readonly=True,
|
||||
store=True,
|
||||
compute="_compute_impact_quota",
|
||||
compute="_compute_impacts_quota",
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
@@ -330,14 +330,18 @@ class PmsReservationLine(models.Model):
|
||||
line.room_id = list(bests.keys())[0]
|
||||
|
||||
@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:
|
||||
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(
|
||||
pricelist_id=reservation.pricelist_id,
|
||||
room_type_id=reservation.room_type_id,
|
||||
date=line.date,
|
||||
line=line,
|
||||
impacts_quota_id=impacts_quota,
|
||||
)
|
||||
|
||||
@api.depends(
|
||||
|
||||
Reference in New Issue
Block a user