[FIX] pms: fix error when existing rules with same values @ av. rules

This commit is contained in:
miguelpadin
2021-12-15 15:21:05 +01:00
parent a0dce600a4
commit 25a0bcca0d
2 changed files with 49 additions and 40 deletions

View File

@@ -424,6 +424,55 @@ class TestPmsWizardMassiveChanges(TestPms):
"The wizard should create as many rules as properties given.",
)
def test_create_rule_existing_previous(self):
"""
If there's a previous rule with some value and new values are set
that contains date of previuos value should overwrite the value.
"""
# ARRANGE
room_type_double = self.env["pms.room.type"].create(
{
"pms_property_ids": [self.pms_property1.id],
"name": "Double Test",
"default_code": "DBL_Test",
"class_id": self.room_type_class1.id,
}
)
date = fields.date.today()
initial_quota = 20
self.env["pms.availability.plan.rule"].create(
{
"availability_plan_id": self.availability_plan1.id,
"room_type_id": room_type_double.id,
"date": date,
"quota": initial_quota,
"pms_property_id": self.pms_property1.id,
}
)
vals_wizard = {
"massive_changes_on": "availability_plan",
"availability_plan_ids": [(6, 0, [self.availability_plan1.id])],
"start_date": date,
"end_date": fields.date.today() + datetime.timedelta(days=1),
"room_type_ids": [(6, 0, [room_type_double.id])],
"apply_quota": True,
"quota": 20,
"pms_property_ids": [self.pms_property1.id],
}
# ACT
self.env["pms.massive.changes.wizard"].create(
vals_wizard
).apply_massive_changes()
# ASSERT
self.assertEqual(
self.availability_plan1.rule_ids[0].quota,
initial_quota,
"A rule value shouldnt overwrite with the default values "
"another rules for the same day and room type",
)
# MASSIVE CHANGE WIZARD TESTS ON PRICELIST ITEMS
def test_pricelist_items_create(self):

View File

@@ -1,7 +1,6 @@
import datetime
from odoo import _, api, fields, models
from odoo.osv import expression
class AvailabilityWizard(models.TransientModel):
@@ -391,14 +390,6 @@ class AvailabilityWizard(models.TransientModel):
if self.end_date:
domain.append(("date", "<=", self.end_date))
domain_overwrite = self.build_domain_rules()
if len(domain_overwrite):
if len(domain_overwrite) == 1:
domain.append(domain_overwrite[0][0])
else:
domain_overwrite = expression.OR(domain_overwrite)
domain.extend(domain_overwrite)
rules = self.env["pms.availability.plan.rule"]
if self.start_date and self.end_date:
rules = rules.search(domain)
@@ -603,37 +594,6 @@ class AvailabilityWizard(models.TransientModel):
record.pricelist_items_to_overwrite
)
def build_domain_rules(self):
for record in self:
domain_overwrite = []
if record.apply_min_stay:
domain_overwrite.append([("min_stay", "!=", record.min_stay)])
if record.apply_max_stay:
domain_overwrite.append([("max_stay", "!=", record.max_stay)])
if record.apply_min_stay_arrival:
domain_overwrite.append(
[("min_stay_arrival", "!=", record.min_stay_arrival)]
)
if record.apply_max_stay_arrival:
domain_overwrite.append(
[("max_stay_arrival", "!=", record.max_stay_arrival)]
)
if record.apply_quota:
domain_overwrite.append([("quota", "!=", record.quota)])
if record.apply_max_avail:
domain_overwrite.append([("max_avail", "!=", record.max_avail)])
if record.apply_closed:
domain_overwrite.append([("closed", "!=", record.closed)])
if record.apply_closed_arrival:
domain_overwrite.append(
[("closed_arrival", "!=", record.closed_arrival)]
)
if record.apply_closed_departure:
domain_overwrite.append(
[("closed_departure", "!=", record.closed_departure)]
)
return domain_overwrite
@api.model
def generate_product_ids_to_filter(
self,