[ADD] Pricelist item rules by property

This commit is contained in:
Darío Lodeiros
2020-10-23 17:20:06 +02:00
parent 736f20ff61
commit 9ddfac3641
9 changed files with 96 additions and 4 deletions

View File

@@ -59,6 +59,7 @@
"views/pms_shared_room_views.xml",
"views/res_partner_views.xml",
"views/product_pricelist_views.xml",
"views/product_pricelist_item_views.xml",
"views/product_template_views.xml",
"views/webclient_templates.xml",
"views/ir_sequence_views.xml",

View File

@@ -28,6 +28,7 @@ from . import pms_room_type_restriction_item
from . import pms_reservation_line
from . import pms_checkin_partner
from . import product_pricelist
from . import product_pricelist_item
from . import res_partner
# from . import mail_compose_message

View File

@@ -128,11 +128,16 @@ class PmsReservationLine(models.Model):
"reservation_id.pricelist_id",
"reservation_id.room_type_id",
"reservation_id.reservation_type",
"reservation_id.pms_property_id",
)
def _compute_price(self):
for line in self:
reservation = line.reservation_id
if not reservation.room_type_id or not reservation.pricelist_id:
if (
not reservation.room_type_id
or not reservation.pricelist_id
or not reservation.pms_property_id
):
line.price = 0
elif line._recompute_price():
room_type_id = reservation.room_type_id.id
@@ -145,6 +150,7 @@ class PmsReservationLine(models.Model):
date=line.date,
pricelist=reservation.pricelist_id.id,
uom=product.uom_id.id,
property=reservation.pms_property_id.id,
)
line.price = self.env["account.tax"]._fix_tax_included_price_company(
line._get_display_price(product),
@@ -174,7 +180,12 @@ class PmsReservationLine(models.Model):
self.ensure_one()
origin = self._origin.reservation_id
new = self.reservation_id
price_fields = ["pricelist_id", "room_type_id", "reservation_type"]
price_fields = [
"pricelist_id",
"room_type_id",
"reservation_type",
"pms_property_id",
]
if (
any(origin[field] != new[field] for field in price_fields)
or self._origin.price == 0
@@ -274,7 +285,6 @@ class PmsReservationLine(models.Model):
date=self.date,
uom=product.uom_id.id,
)
final_price, rule_id = self.reservation_id.pricelist_id.with_context(
product_context
).get_product_price_rule(product, 1.0, self.reservation_id.partner_id)

View File

@@ -32,7 +32,6 @@ class PmsRoom(models.Model):
"pms.property",
store=True,
readonly=True,
domain="[('id', 'in', room_type_id.pms_property_ids)]",
)
room_type_id = fields.Many2one(
"pms.room.type", "Property Room Type", required=True, ondelete="restrict"

View File

@@ -51,3 +51,21 @@ class ProductPricelist(models.Model):
# "different property."
# )
# )
def _compute_price_rule_get_items(
self, products_qty_partner, date, uom_id, prod_tmpl_ids, prod_ids, categ_ids
):
items = super(ProductPricelist, self)._compute_price_rule_get_items(
products_qty_partner, date, uom_id, prod_tmpl_ids, prod_ids, categ_ids
)
# Discard the rules with defined properties other than the context,
# and we reorder the rules to return the most concrete property rule first
if "property" in self._context:
return items.filtered(
lambda i: not i.pms_property_ids
or self._context["property"] in i.pms_property_ids.ids
).sorted(
key=lambda s: ((not s.pms_property_ids, s), len(s.pms_property_ids))
)
else:
return items

View File

@@ -0,0 +1,11 @@
# Copyright 2017 Alexandre Díaz, Pablo Quesada, Darío Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductPricelistItem(models.Model):
_inherit = "product.pricelist.item"
pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict"
)

View File

@@ -0,0 +1,26 @@
# Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict"
)
per_day = fields.Boolean("Unit increment per day")
per_person = fields.Boolean("Unit increment per person")
consumed_on = fields.Selection(
[("before", "Before night"), ("after", "After night")],
"Consumed",
default="before",
)
daily_limit = fields.Integer("Daily limit")
is_extra_bed = fields.Boolean("Is extra bed", default=False)
show_in_calendar = fields.Boolean(
"Show in Calendar",
default=False,
help="Specifies if the product is shown in the calendar information.",
)

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" ?>
<odoo>
<record id="product_pricelist_item_view_form" model="ir.ui.view">
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='min_quantity']" position="before">
<field
name="pms_property_ids"
widget="many2many_tags"
options="{'no_create': True,'no_open': True}"
/>
</xpath>
</field>
</record>
</odoo>

View File

@@ -13,6 +13,16 @@
<field name="pricelist_type" />
<field name="cancelation_rule_id" />
</xpath>
<xpath
expr="//field[@name='item_ids']/tree/field[@name='base']"
position="after"
>
<field
name="pms_property_ids"
widget="many2many_tags"
options="{'no_create': True,'no_open': True}"
/>
</xpath>
</field>
</record>
<menuitem