mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: change many2one fields to many2many
This commit is contained in:
@@ -99,10 +99,12 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
self.env["pms.massive.changes.wizard"].create(
|
self.env["pms.massive.changes.wizard"].create(
|
||||||
{
|
{
|
||||||
"massive_changes_on": "availability_plan",
|
"massive_changes_on": "availability_plan",
|
||||||
"availability_plan_id": self.test_availability_plan.id,
|
"availability_plan_ids": [
|
||||||
|
(6, 0, [self.test_availability_plan.id])
|
||||||
|
],
|
||||||
"start_date": fields.date.today(),
|
"start_date": fields.date.today(),
|
||||||
"end_date": fields.date.today() + datetime.timedelta(days=days),
|
"end_date": fields.date.today() + datetime.timedelta(days=days),
|
||||||
"room_type_id": self.test_room_type_double.id,
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
}
|
}
|
||||||
).apply_massive_changes()
|
).apply_massive_changes()
|
||||||
@@ -137,7 +139,7 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
self.env["pms.massive.changes.wizard"].create(
|
self.env["pms.massive.changes.wizard"].create(
|
||||||
{
|
{
|
||||||
"massive_changes_on": "availability_plan",
|
"massive_changes_on": "availability_plan",
|
||||||
"availability_plan_id": self.test_availability_plan.id,
|
"availability_plan_ids": [(6, 0, [self.test_availability_plan.id])],
|
||||||
"start_date": date_from,
|
"start_date": date_from,
|
||||||
"end_date": date_to,
|
"end_date": date_to,
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
@@ -164,10 +166,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
|
|
||||||
vals = {
|
vals = {
|
||||||
"massive_changes_on": "availability_plan",
|
"massive_changes_on": "availability_plan",
|
||||||
"availability_plan_id": self.test_availability_plan.id,
|
"availability_plan_ids": [(6, 0, [self.test_availability_plan.id])],
|
||||||
"start_date": date_from,
|
"start_date": date_from,
|
||||||
"end_date": date_to,
|
"end_date": date_to,
|
||||||
"room_type_id": self.test_room_type_double.id,
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
"quota": 50,
|
"quota": 50,
|
||||||
"max_avail": 5,
|
"max_avail": 5,
|
||||||
"min_stay": 10,
|
"min_stay": 10,
|
||||||
@@ -185,10 +187,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
|
|
||||||
# ASSERT
|
# ASSERT
|
||||||
del vals["massive_changes_on"]
|
del vals["massive_changes_on"]
|
||||||
del vals["availability_plan_id"]
|
del vals["availability_plan_ids"]
|
||||||
del vals["start_date"]
|
del vals["start_date"]
|
||||||
del vals["end_date"]
|
del vals["end_date"]
|
||||||
del vals["room_type_id"]
|
del vals["room_type_ids"]
|
||||||
del vals["pms_property_ids"]
|
del vals["pms_property_ids"]
|
||||||
for key in vals:
|
for key in vals:
|
||||||
with self.subTest(k=key):
|
with self.subTest(k=key):
|
||||||
@@ -221,8 +223,8 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
wizard = self.env["pms.massive.changes.wizard"].create(
|
wizard = self.env["pms.massive.changes.wizard"].create(
|
||||||
{
|
{
|
||||||
"massive_changes_on": "availability_plan",
|
"massive_changes_on": "availability_plan",
|
||||||
"availability_plan_id": self.test_availability_plan.id,
|
"availability_plan_ids": [(6, 0, [self.test_availability_plan.id])],
|
||||||
"room_type_id": self.test_room_type_double.id,
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
"start_date": date_from,
|
"start_date": date_from,
|
||||||
"end_date": date_to,
|
"end_date": date_to,
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
@@ -276,10 +278,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
)
|
)
|
||||||
vals_wizard = {
|
vals_wizard = {
|
||||||
"massive_changes_on": "availability_plan",
|
"massive_changes_on": "availability_plan",
|
||||||
"availability_plan_id": self.test_availability_plan.id,
|
"availability_plan_ids": [(6, 0, [self.test_availability_plan.id])],
|
||||||
"start_date": date,
|
"start_date": date,
|
||||||
"end_date": date,
|
"end_date": date,
|
||||||
"room_type_id": self.test_room_type_double.id,
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
"apply_max_avail": True,
|
"apply_max_avail": True,
|
||||||
"max_avail": 2,
|
"max_avail": 2,
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
@@ -318,10 +320,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
self.env["pms.massive.changes.wizard"].create(
|
self.env["pms.massive.changes.wizard"].create(
|
||||||
{
|
{
|
||||||
"massive_changes_on": "pricelist",
|
"massive_changes_on": "pricelist",
|
||||||
"pricelist_id": self.test_pricelist.id,
|
"pricelist_ids": [(6, 0, [self.test_pricelist.id])],
|
||||||
"start_date": fields.date.today(),
|
"start_date": fields.date.today(),
|
||||||
"end_date": fields.date.today() + datetime.timedelta(days=days),
|
"end_date": fields.date.today() + datetime.timedelta(days=days),
|
||||||
"room_type_id": self.test_room_type_double.id,
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
}
|
}
|
||||||
).apply_massive_changes()
|
).apply_massive_changes()
|
||||||
@@ -359,7 +361,7 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
self.env["pms.massive.changes.wizard"].create(
|
self.env["pms.massive.changes.wizard"].create(
|
||||||
{
|
{
|
||||||
"massive_changes_on": "pricelist",
|
"massive_changes_on": "pricelist",
|
||||||
"pricelist_id": self.test_pricelist.id,
|
"pricelist_ids": [(6, 0, [self.test_pricelist.id])],
|
||||||
"start_date": date_from,
|
"start_date": date_from,
|
||||||
"end_date": date_to,
|
"end_date": date_to,
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
@@ -402,10 +404,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
self.env["pms.massive.changes.wizard"].create(
|
self.env["pms.massive.changes.wizard"].create(
|
||||||
{
|
{
|
||||||
"massive_changes_on": "pricelist",
|
"massive_changes_on": "pricelist",
|
||||||
"pricelist_id": self.test_pricelist.id,
|
"pricelist_ids": [(6, 0, [self.test_pricelist.id])],
|
||||||
"start_date": date_from,
|
"start_date": date_from,
|
||||||
"end_date": date_to,
|
"end_date": date_to,
|
||||||
"room_type_id": self.test_room_type_double.id,
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
"price": price,
|
"price": price,
|
||||||
"min_quantity": min_quantity,
|
"min_quantity": min_quantity,
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
@@ -446,8 +448,8 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
wizard = self.env["pms.massive.changes.wizard"].create(
|
wizard = self.env["pms.massive.changes.wizard"].create(
|
||||||
{
|
{
|
||||||
"massive_changes_on": "pricelist",
|
"massive_changes_on": "pricelist",
|
||||||
"pricelist_id": self.test_pricelist.id,
|
"pricelist_ids": [(6, 0, [self.test_pricelist.id])],
|
||||||
"room_type_id": self.test_room_type_double.id,
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
"start_date": date_from,
|
"start_date": date_from,
|
||||||
"end_date": date_to,
|
"end_date": date_to,
|
||||||
"pms_property_ids": [self.test_property.id],
|
"pms_property_ids": [self.test_property.id],
|
||||||
@@ -483,3 +485,107 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
|
|||||||
and test_case[index],
|
and test_case[index],
|
||||||
"Rule not created on correct day of week",
|
"Rule not created on correct day of week",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@freeze_time("2025-12-01")
|
||||||
|
def test_several_availability_plan(self):
|
||||||
|
self.create_common_scenario()
|
||||||
|
date_from = fields.date.today()
|
||||||
|
date_to = date_from + datetime.timedelta(days=6)
|
||||||
|
self.test_availability_plan_2 = self.env["pms.availability.plan"].create(
|
||||||
|
{
|
||||||
|
"name": "Second availability plan for TEST",
|
||||||
|
"pms_pricelist_ids": [(6, 0, [self.test_pricelist.id])],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
wizard = self.env["pms.massive.changes.wizard"].create(
|
||||||
|
{
|
||||||
|
"massive_changes_on": "pricelist",
|
||||||
|
"availability_plan_ids": [
|
||||||
|
(
|
||||||
|
6,
|
||||||
|
0,
|
||||||
|
[
|
||||||
|
self.test_availability_plan.id,
|
||||||
|
self.test_availability_plan_2.id,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
|
"pms_property_ids": [self.test_property.id],
|
||||||
|
"start_date": date_from,
|
||||||
|
"end_date": date_to,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
availability_plan_ids = [
|
||||||
|
self.test_availability_plan.id,
|
||||||
|
self.test_availability_plan_2.id,
|
||||||
|
]
|
||||||
|
for avail_plan_id in wizard["availability_plan_ids"].ids:
|
||||||
|
with self.subTest(k=avail_plan_id):
|
||||||
|
self.assertIn(
|
||||||
|
avail_plan_id,
|
||||||
|
availability_plan_ids,
|
||||||
|
"Availability plan has not been write ",
|
||||||
|
)
|
||||||
|
|
||||||
|
@freeze_time("2025-01-01")
|
||||||
|
def test_several_pricelists(self):
|
||||||
|
self.create_common_scenario()
|
||||||
|
date_from = fields.date.today()
|
||||||
|
date_to = date_from + datetime.timedelta(days=6)
|
||||||
|
self.test_pricelist_2 = self.env["product.pricelist"].create(
|
||||||
|
{
|
||||||
|
"name": "test pricelist 2",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
wizard = self.env["pms.massive.changes.wizard"].create(
|
||||||
|
{
|
||||||
|
"massive_changes_on": "pricelist",
|
||||||
|
"pricelist_ids": [
|
||||||
|
(6, 0, [self.test_pricelist.id, self.test_pricelist_2.id])
|
||||||
|
],
|
||||||
|
"room_type_ids": [(6, 0, [self.test_room_type_double.id])],
|
||||||
|
"pms_property_ids": [self.test_property.id],
|
||||||
|
"start_date": date_from,
|
||||||
|
"end_date": date_to,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
pricelist_ids = [self.test_pricelist.id, self.test_pricelist_2.id]
|
||||||
|
for pricelist_id in wizard["pricelist_ids"].ids:
|
||||||
|
with self.subTest(k=pricelist_id):
|
||||||
|
self.assertIn(
|
||||||
|
pricelist_id, pricelist_ids, "Pricelist has not been write "
|
||||||
|
)
|
||||||
|
|
||||||
|
@freeze_time("2025-02-01")
|
||||||
|
def test_several_room_types(self):
|
||||||
|
self.create_common_scenario()
|
||||||
|
date_from = fields.date.today()
|
||||||
|
date_to = date_from + datetime.timedelta(days=6)
|
||||||
|
wizard = self.env["pms.massive.changes.wizard"].create(
|
||||||
|
{
|
||||||
|
"massive_changes_on": "pricelist",
|
||||||
|
"pricelist_ids": [(6, 0, [self.test_pricelist.id])],
|
||||||
|
"room_type_ids": [
|
||||||
|
(
|
||||||
|
6,
|
||||||
|
0,
|
||||||
|
[self.test_room_type_double.id, self.test_room_type_double.id],
|
||||||
|
)
|
||||||
|
],
|
||||||
|
"pms_property_ids": [self.test_property.id],
|
||||||
|
"start_date": date_from,
|
||||||
|
"end_date": date_to,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
room_type_ids = [self.test_room_type_double.id, self.test_room_type_double.id]
|
||||||
|
for room_type_id in wizard["room_type_ids"].ids:
|
||||||
|
with self.subTest(k=room_type_id):
|
||||||
|
self.assertIn(
|
||||||
|
room_type_id, room_type_ids, "Room type has not been write "
|
||||||
|
)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
<field name="model">pms.availability.plan.rule</field>
|
<field name="model">pms.availability.plan.rule</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="Availability rules">
|
<tree string="Availability rules">
|
||||||
|
<field name="availability_plan_id" />
|
||||||
<field name="date" />
|
<field name="date" />
|
||||||
<field name="room_type_id" />
|
<field name="room_type_id" />
|
||||||
<field name="quota" />
|
<field name="quota" />
|
||||||
@@ -57,4 +58,12 @@
|
|||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record id="availability_plan_rule_view_tree_action" model="ir.actions.act_window">
|
||||||
|
<field name="name">Availability Plan Rules</field>
|
||||||
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
<field name="res_model">pms.availability.plan.rule</field>
|
||||||
|
<field name="context">{'group_by':'availability_plan_id'}</field>
|
||||||
|
<field name="view_id" ref="availability_plan_rule_view_tree" />
|
||||||
|
<field name="view_mode">tree</field>
|
||||||
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -26,4 +26,25 @@
|
|||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record id="product_pricelist_item_view_tree" model="ir.ui.view">
|
||||||
|
<field name="model">product.pricelist.item</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<tree>
|
||||||
|
<field name="pricelist_id" />
|
||||||
|
<field string="Applicable on" name="name" />
|
||||||
|
<field name="date_start_overnight" />
|
||||||
|
<field name="date_end_overnight" />
|
||||||
|
<field name="price" />
|
||||||
|
</tree>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="product_pricelist_item_action2" model="ir.actions.act_window">
|
||||||
|
<field name="name">Pricelists Items</field>
|
||||||
|
<field name="type">ir.actions.act_window</field>
|
||||||
|
<field name="res_model">product.pricelist.item</field>
|
||||||
|
<field name="context">{'group_by':'pricelist_id'}</field>
|
||||||
|
<field name="view_id" ref="product_pricelist_item_view_tree" />
|
||||||
|
<field name="view_mode">tree</field>
|
||||||
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|||||||
@@ -24,18 +24,23 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
("pricelist", "Pricelist"),
|
("pricelist", "Pricelist"),
|
||||||
("availability_plan", "Availability Plan"),
|
("availability_plan", "Availability Plan"),
|
||||||
],
|
],
|
||||||
required=True,
|
default=lambda self: "availability_plan"
|
||||||
default="availability_plan",
|
if self._context.get("availability_plan_ids")
|
||||||
|
else "pricelist"
|
||||||
|
if self._context.get("pricelist_ids")
|
||||||
|
else "availability_plan",
|
||||||
)
|
)
|
||||||
availability_plan_id = fields.Many2one(
|
|
||||||
string="Availability Plan to apply massive changes",
|
availability_plan_ids = fields.Many2many(
|
||||||
comodel_name="pms.availability.plan",
|
comodel_name="pms.availability.plan",
|
||||||
|
string="Availability Plan to apply massive changes",
|
||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
# can be setted by context from availability plan detail
|
# can be setted by context from availability plan detail
|
||||||
)
|
)
|
||||||
pricelist_id = fields.Many2one(
|
|
||||||
string="Pricelist to apply massive changes",
|
pricelist_ids = fields.Many2many(
|
||||||
comodel_name="product.pricelist",
|
comodel_name="product.pricelist",
|
||||||
|
string="Pricelist to apply massive changes",
|
||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
)
|
)
|
||||||
allowed_pricelist_ids = fields.One2many(
|
allowed_pricelist_ids = fields.One2many(
|
||||||
@@ -51,9 +56,10 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
string="To",
|
string="To",
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
room_type_id = fields.Many2one(
|
|
||||||
string="Room Type",
|
room_type_ids = fields.Many2many(
|
||||||
comodel_name="pms.room.type",
|
comodel_name="pms.room.type",
|
||||||
|
string="Room Type",
|
||||||
check_pms_properties=True,
|
check_pms_properties=True,
|
||||||
)
|
)
|
||||||
price = fields.Float(string="Price")
|
price = fields.Float(string="Price")
|
||||||
@@ -210,10 +216,10 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _default_avail_readonly(self):
|
def _default_avail_readonly(self):
|
||||||
return True if self._context.get("availability_plan_id") else False
|
return True if self._context.get("availability_plan_ids") else False
|
||||||
|
|
||||||
def _default_pricelist_readonly(self):
|
def _default_pricelist_readonly(self):
|
||||||
return True if self._context.get("pricelist_id") else False
|
return True if self._context.get("pricelist_ids") else False
|
||||||
|
|
||||||
@api.depends("massive_changes_on")
|
@api.depends("massive_changes_on")
|
||||||
def _compute_allowed_pricelist_ids(self):
|
def _compute_allowed_pricelist_ids(self):
|
||||||
@@ -227,7 +233,7 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
@api.depends(
|
@api.depends(
|
||||||
"start_date",
|
"start_date",
|
||||||
"end_date",
|
"end_date",
|
||||||
"room_type_id",
|
"room_type_ids",
|
||||||
"apply_on_monday",
|
"apply_on_monday",
|
||||||
"apply_on_tuesday",
|
"apply_on_tuesday",
|
||||||
"apply_on_wednesday",
|
"apply_on_wednesday",
|
||||||
@@ -236,7 +242,7 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
"apply_on_saturday",
|
"apply_on_saturday",
|
||||||
"apply_on_sunday",
|
"apply_on_sunday",
|
||||||
"apply_on_all_week",
|
"apply_on_all_week",
|
||||||
"availability_plan_id",
|
"availability_plan_ids",
|
||||||
"apply_quota",
|
"apply_quota",
|
||||||
"apply_max_avail",
|
"apply_max_avail",
|
||||||
"apply_min_stay",
|
"apply_min_stay",
|
||||||
@@ -258,20 +264,21 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
)
|
)
|
||||||
def _compute_rules_to_overwrite(self):
|
def _compute_rules_to_overwrite(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
|
if not record.availability_plan_ids and self._context.get(
|
||||||
if not record.availability_plan_id and self._context.get(
|
"availability_plan_ids"
|
||||||
"availability_plan_id"
|
|
||||||
):
|
):
|
||||||
record.availability_plan_id = self._context.get("availability_plan_id")
|
record.availability_plan_ids = [
|
||||||
|
(4, self._context.get("availability_plan_ids"))
|
||||||
|
]
|
||||||
record.massive_changes_on = "availability_plan"
|
record.massive_changes_on = "availability_plan"
|
||||||
|
|
||||||
if record.availability_plan_id:
|
if record.availability_plan_ids:
|
||||||
domain = [
|
domain = [
|
||||||
("availability_plan_id", "=", record.availability_plan_id.id),
|
("availability_plan_id", "in", record.availability_plan_ids.ids),
|
||||||
]
|
]
|
||||||
|
|
||||||
if record.room_type_id:
|
if record.room_type_ids:
|
||||||
domain.append(("room_type_id", "=", record.room_type_id.id))
|
domain.append(("room_type_id", "in", record.room_type_ids.ids))
|
||||||
if record.start_date:
|
if record.start_date:
|
||||||
domain.append(("date", ">=", record.start_date))
|
domain.append(("date", ">=", record.start_date))
|
||||||
if record.end_date:
|
if record.end_date:
|
||||||
@@ -284,7 +291,6 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
else:
|
else:
|
||||||
domain_overwrite = expression.OR(domain_overwrite)
|
domain_overwrite = expression.OR(domain_overwrite)
|
||||||
domain.extend(domain_overwrite)
|
domain.extend(domain_overwrite)
|
||||||
|
|
||||||
week_days_to_apply = (
|
week_days_to_apply = (
|
||||||
record.apply_on_monday,
|
record.apply_on_monday,
|
||||||
record.apply_on_tuesday,
|
record.apply_on_tuesday,
|
||||||
@@ -314,7 +320,7 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
@api.depends(
|
@api.depends(
|
||||||
"start_date",
|
"start_date",
|
||||||
"end_date",
|
"end_date",
|
||||||
"room_type_id",
|
"room_type_ids",
|
||||||
"apply_on_monday",
|
"apply_on_monday",
|
||||||
"apply_on_tuesday",
|
"apply_on_tuesday",
|
||||||
"apply_on_wednesday",
|
"apply_on_wednesday",
|
||||||
@@ -323,18 +329,17 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
"apply_on_saturday",
|
"apply_on_saturday",
|
||||||
"apply_on_sunday",
|
"apply_on_sunday",
|
||||||
"apply_on_all_week",
|
"apply_on_all_week",
|
||||||
"pricelist_id",
|
"pricelist_ids",
|
||||||
)
|
)
|
||||||
def _compute_pricelist_items_to_overwrite(self):
|
def _compute_pricelist_items_to_overwrite(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
|
if not record.pricelist_ids and self._context.get("pricelist_ids"):
|
||||||
if not record.pricelist_id and self._context.get("pricelist_id"):
|
record.pricelist_ids = [(4, self._context.get("pricelist_ids"))]
|
||||||
record.pricelist_id = self._context.get("pricelist_id")
|
|
||||||
record.massive_changes_on = "pricelist"
|
record.massive_changes_on = "pricelist"
|
||||||
|
|
||||||
if record.pricelist_id:
|
if record.pricelist_ids:
|
||||||
domain = [
|
domain = [
|
||||||
("pricelist_id", "=", record.pricelist_id.id),
|
("pricelist_id", "in", record.pricelist_ids.ids),
|
||||||
"|",
|
"|",
|
||||||
("pms_property_ids", "=", False),
|
("pms_property_ids", "=", False),
|
||||||
("pms_property_ids", "in", record.pms_property_ids.ids),
|
("pms_property_ids", "in", record.pms_property_ids.ids),
|
||||||
@@ -344,16 +349,21 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
domain.append(("date_start_overnight", ">=", record.start_date))
|
domain.append(("date_start_overnight", ">=", record.start_date))
|
||||||
if record.end_date:
|
if record.end_date:
|
||||||
domain.append(("date_end_overnight", "<=", record.end_date))
|
domain.append(("date_end_overnight", "<=", record.end_date))
|
||||||
|
if record.room_type_ids:
|
||||||
if record.room_type_id:
|
room_type_ids = record.room_type_ids.ids
|
||||||
|
product_ids = (
|
||||||
|
self.env["pms.room.type"]
|
||||||
|
.search([("id", "in", room_type_ids)])
|
||||||
|
.mapped("product_id")
|
||||||
|
.ids
|
||||||
|
)
|
||||||
domain.append(
|
domain.append(
|
||||||
(
|
(
|
||||||
"product_tmpl_id",
|
"product_id",
|
||||||
"=",
|
"in",
|
||||||
record.room_type_id.product_id.product_tmpl_id.id,
|
product_ids,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
week_days_to_apply = (
|
week_days_to_apply = (
|
||||||
record.apply_on_monday,
|
record.apply_on_monday,
|
||||||
record.apply_on_tuesday,
|
record.apply_on_tuesday,
|
||||||
@@ -445,6 +455,7 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# dates between start and end (both included)
|
# dates between start and end (both included)
|
||||||
|
items = []
|
||||||
for date in [
|
for date in [
|
||||||
record.start_date + datetime.timedelta(days=x)
|
record.start_date + datetime.timedelta(days=x)
|
||||||
for x in range(0, (record.end_date - record.start_date).days + 1)
|
for x in range(0, (record.end_date - record.start_date).days + 1)
|
||||||
@@ -456,7 +467,7 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not record.room_type_id:
|
if not record.room_type_ids:
|
||||||
room_types = self.env["pms.room.type"].search(
|
room_types = self.env["pms.room.type"].search(
|
||||||
[
|
[
|
||||||
"|",
|
"|",
|
||||||
@@ -465,119 +476,129 @@ class AvailabilityWizard(models.TransientModel):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
room_types = [record.room_type_id]
|
room_types = record.room_type_ids
|
||||||
for room_type in room_types:
|
for pms_property in record.pms_property_ids:
|
||||||
for pms_property in record.pms_property_ids:
|
for room_type in room_types:
|
||||||
if record.massive_changes_on == "pricelist":
|
if record.massive_changes_on == "pricelist":
|
||||||
|
for pricelist in record.pricelist_ids:
|
||||||
self.env["product.pricelist.item"].create(
|
pricelist_item = self.env[
|
||||||
{
|
"product.pricelist.item"
|
||||||
"pricelist_id": record.pricelist_id.id,
|
].create(
|
||||||
"date_start_overnight": date,
|
|
||||||
"date_end_overnight": date,
|
|
||||||
"compute_price": "fixed",
|
|
||||||
"applied_on": "0_product_variant",
|
|
||||||
"product_id": room_type.product_id.id,
|
|
||||||
"fixed_price": record.price,
|
|
||||||
"min_quantity": record.min_quantity,
|
|
||||||
"pms_property_ids": [pms_property.id],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
avail_plan_id = record.availability_plan_id.id
|
|
||||||
vals = {}
|
|
||||||
vals.update(
|
|
||||||
{"min_stay": record.min_stay}
|
|
||||||
if record.apply_min_stay
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
vals.update(
|
|
||||||
{"min_stay_arrival": record.min_stay_arrival}
|
|
||||||
if record.apply_min_stay_arrival
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
vals.update(
|
|
||||||
{"max_stay": record.max_stay}
|
|
||||||
if record.apply_max_stay
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
|
|
||||||
vals.update(
|
|
||||||
{"max_stay_arrival": record.max_stay_arrival}
|
|
||||||
if record.apply_max_stay_arrival
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
vals.update(
|
|
||||||
{"quota": record.quota} if record.apply_quota else {}
|
|
||||||
)
|
|
||||||
vals.update(
|
|
||||||
{"max_avail": record.max_avail}
|
|
||||||
if record.apply_max_avail
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
|
|
||||||
vals.update(
|
|
||||||
{"closed": record.closed} if record.apply_closed else {}
|
|
||||||
)
|
|
||||||
vals.update(
|
|
||||||
{"closed_arrival": record.closed_arrival}
|
|
||||||
if record.apply_closed_arrival
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
vals.update(
|
|
||||||
{"closed_departure": record.closed_departure}
|
|
||||||
if record.apply_closed_departure
|
|
||||||
else {}
|
|
||||||
)
|
|
||||||
|
|
||||||
if date in record.rules_to_overwrite.mapped(
|
|
||||||
"date"
|
|
||||||
) and room_type in record.rules_to_overwrite.mapped(
|
|
||||||
"room_type_id"
|
|
||||||
):
|
|
||||||
|
|
||||||
overwrite = record.rules_to_overwrite.search(
|
|
||||||
[
|
|
||||||
("room_type_id", "=", room_type.id),
|
|
||||||
("date", "=", date),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
overwrite.write(vals)
|
|
||||||
else:
|
|
||||||
self.env["pms.availability.plan.rule"].create(
|
|
||||||
{
|
{
|
||||||
"availability_plan_id": avail_plan_id,
|
"pricelist_id": pricelist.id,
|
||||||
"date": date,
|
"date_start_overnight": date,
|
||||||
"room_type_id": room_type.id,
|
"date_end_overnight": date,
|
||||||
"quota": record.quota,
|
"compute_price": "fixed",
|
||||||
"max_avail": record.max_avail,
|
"applied_on": "0_product_variant",
|
||||||
"min_stay": record.min_stay,
|
"product_id": room_type.product_id.id,
|
||||||
"min_stay_arrival": record.min_stay_arrival,
|
"fixed_price": record.price,
|
||||||
"max_stay": record.max_stay,
|
"min_quantity": record.min_quantity,
|
||||||
"max_stay_arrival": record.max_stay_arrival,
|
"pms_property_ids": [pms_property.id],
|
||||||
"closed": record.closed,
|
|
||||||
"closed_arrival": record.closed_arrival,
|
|
||||||
"closed_departure": record.closed_departure,
|
|
||||||
"pms_property_id": pms_property.id,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
items.append(pricelist_item.id)
|
||||||
|
else:
|
||||||
|
for avail_plan_id in record.availability_plan_ids:
|
||||||
|
vals = {}
|
||||||
|
vals.update(
|
||||||
|
{"min_stay": record.min_stay}
|
||||||
|
if record.apply_min_stay
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
vals.update(
|
||||||
|
{"min_stay_arrival": record.min_stay_arrival}
|
||||||
|
if record.apply_min_stay_arrival
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
vals.update(
|
||||||
|
{"max_stay": record.max_stay}
|
||||||
|
if record.apply_max_stay
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
|
||||||
|
vals.update(
|
||||||
|
{"max_stay_arrival": record.max_stay_arrival}
|
||||||
|
if record.apply_max_stay_arrival
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
vals.update(
|
||||||
|
{"quota": record.quota}
|
||||||
|
if record.apply_quota
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
vals.update(
|
||||||
|
{"max_avail": record.max_avail}
|
||||||
|
if record.apply_max_avail
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
|
||||||
|
vals.update(
|
||||||
|
{"closed": record.closed}
|
||||||
|
if record.apply_closed
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
vals.update(
|
||||||
|
{"closed_arrival": record.closed_arrival}
|
||||||
|
if record.apply_closed_arrival
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
vals.update(
|
||||||
|
{"closed_departure": record.closed_departure}
|
||||||
|
if record.apply_closed_departure
|
||||||
|
else {}
|
||||||
|
)
|
||||||
|
|
||||||
|
if date in record.rules_to_overwrite.mapped(
|
||||||
|
"date"
|
||||||
|
) and room_type in record.rules_to_overwrite.mapped(
|
||||||
|
"room_type_id"
|
||||||
|
):
|
||||||
|
overwrite = record.rules_to_overwrite.search(
|
||||||
|
[
|
||||||
|
("room_type_id", "=", room_type.id),
|
||||||
|
("date", "=", date),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
overwrite.write(vals)
|
||||||
|
items.append(overwrite.id)
|
||||||
|
else:
|
||||||
|
plan_rule = self.env[
|
||||||
|
"pms.availability.plan.rule"
|
||||||
|
].create(
|
||||||
|
{
|
||||||
|
"availability_plan_id": avail_plan_id.id,
|
||||||
|
"date": date,
|
||||||
|
"room_type_id": room_type.id,
|
||||||
|
"quota": record.quota,
|
||||||
|
"max_avail": record.max_avail,
|
||||||
|
"min_stay": record.min_stay,
|
||||||
|
"min_stay_arrival": record.min_stay_arrival,
|
||||||
|
"max_stay": record.max_stay,
|
||||||
|
"max_stay_arrival": record.max_stay_arrival,
|
||||||
|
"closed": record.closed,
|
||||||
|
"closed_arrival": record.closed_arrival,
|
||||||
|
"closed_departure": record.closed_departure,
|
||||||
|
"pms_property_id": pms_property.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
items.append(plan_rule.id)
|
||||||
|
action = {}
|
||||||
if (
|
if (
|
||||||
record.massive_changes_on == "pricelist"
|
record.massive_changes_on == "pricelist"
|
||||||
and not record.pricelist_readonly
|
and not record.pricelist_readonly
|
||||||
):
|
):
|
||||||
action = self.env.ref("product.product_pricelist_action2").read()[0]
|
action = {
|
||||||
action["views"] = [
|
"view": self.env.ref("pms.product_pricelist_item_action2").read()[0]
|
||||||
(self.env.ref("pms.product_pricelist_view_form").id, "form")
|
}
|
||||||
]
|
|
||||||
action["res_id"] = record.pricelist_id.id
|
|
||||||
return action
|
|
||||||
if (
|
if (
|
||||||
record.massive_changes_on == "availability_plan"
|
record.massive_changes_on == "availability_plan"
|
||||||
and not record.avail_readonly
|
and not record.avail_readonly
|
||||||
):
|
):
|
||||||
action = self.env.ref("pms.availability_action").read()[0]
|
action = {
|
||||||
action["views"] = [
|
"view": self.env.ref(
|
||||||
(self.env.ref("pms.availability_view_form").id, "form")
|
"pms.availability_plan_rule_view_tree_action"
|
||||||
]
|
).read()[0]
|
||||||
action["res_id"] = record.availability_plan_id.id
|
}
|
||||||
return action
|
action["view"]["domain"] = [("id", "in", items)]
|
||||||
|
return action["view"]
|
||||||
|
|||||||
@@ -33,9 +33,11 @@
|
|||||||
<group class="">
|
<group class="">
|
||||||
<field name="pms_property_ids" widget="many2many_tags" />
|
<field name="pms_property_ids" widget="many2many_tags" />
|
||||||
<field
|
<field
|
||||||
name="availability_plan_id"
|
name="availability_plan_ids"
|
||||||
class="mr-5"
|
class="mr-5"
|
||||||
string="Availability Plan"
|
string="Availability Plan"
|
||||||
|
widget="many2many_tags"
|
||||||
|
options="{'no_create': True,'no_open': True}"
|
||||||
attrs="{'invisible':['|','|',('massive_changes_on','=','pricelist'), ('avail_readonly','=',True),
|
attrs="{'invisible':['|','|',('massive_changes_on','=','pricelist'), ('avail_readonly','=',True),
|
||||||
('pricelist_readonly', '=', True)],
|
('pricelist_readonly', '=', True)],
|
||||||
'required': [('massive_changes_on','=','availability_plan')]}"
|
'required': [('massive_changes_on','=','availability_plan')]}"
|
||||||
@@ -43,14 +45,21 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<field
|
<field
|
||||||
name="pricelist_id"
|
name="pricelist_ids"
|
||||||
string="Pricelist"
|
string="Pricelist"
|
||||||
|
widget="many2many_tags"
|
||||||
|
options="{'no_create': True,'no_open': True}"
|
||||||
attrs="{'invisible':['|','|',('massive_changes_on','=','availability_plan'),
|
attrs="{'invisible':['|','|',('massive_changes_on','=','availability_plan'),
|
||||||
('pricelist_readonly','=',True), ('pricelist_readonly', '=', True)],
|
('pricelist_readonly','=',True), ('pricelist_readonly', '=', True)],
|
||||||
'required': [('massive_changes_on','=','pricelist')]}"
|
'required': [('massive_changes_on','=','pricelist')]}"
|
||||||
domain="[('id', 'in', allowed_pricelist_ids), '|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_ids)]"
|
domain="[('id', 'in', allowed_pricelist_ids), '|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_ids)]"
|
||||||
/>
|
/>
|
||||||
<field name="room_type_id" default_focus="1" />
|
<field
|
||||||
|
name="room_type_ids"
|
||||||
|
default_focus="1"
|
||||||
|
widget="many2many_tags"
|
||||||
|
options="{'no_create': True,'no_open': True}"
|
||||||
|
/>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user