mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[WIP]pms:added ir.pms.property model
This commit is contained in:
@@ -48,3 +48,4 @@ from . import pms_automated_mails
|
||||
from . import payment_transaction
|
||||
from . import res_partner_id_category
|
||||
from . import pms_team_member
|
||||
from . import ir_pms_property
|
||||
|
||||
13
pms/models/ir_pms_property.py
Normal file
13
pms/models/ir_pms_property.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class IrPmsProperty(models.Model):
|
||||
_name = "ir.pms.property"
|
||||
|
||||
pms_property_id = fields.Many2one(string="Properties", comodel_name="pms.property")
|
||||
|
||||
model_id = fields.Many2one(string="Model", comodel_name="ir.model")
|
||||
|
||||
field_id = fields.Many2one(string="Field", comodel_name="ir.model.fields")
|
||||
|
||||
value = fields.Integer(string="Field Value")
|
||||
@@ -1,7 +1,7 @@
|
||||
# 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
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
@@ -35,7 +35,12 @@ class ProductTemplate(models.Model):
|
||||
default="before",
|
||||
)
|
||||
daily_limit = fields.Integer(
|
||||
string="Daily limit", help="Indicates how much products can consumed in one day"
|
||||
string="Daily limit",
|
||||
help="Indicates how much products can consumed in one day",
|
||||
compute="_compute_daily_limit",
|
||||
inverse="_inverse_ir_pms_property",
|
||||
readonly=False,
|
||||
store=True,
|
||||
)
|
||||
is_extra_bed = fields.Boolean(
|
||||
string="Is extra bed",
|
||||
@@ -47,3 +52,48 @@ class ProductTemplate(models.Model):
|
||||
help="Indicates if that product is a crib",
|
||||
default=False,
|
||||
)
|
||||
|
||||
# @api.depends_context("allowed_pms_property_ids")
|
||||
@api.depends("pms_property_ids")
|
||||
def _compute_daily_limit(self):
|
||||
for record in self:
|
||||
pms_property_id = False
|
||||
if record.pms_property_ids:
|
||||
pms_property_id = self.env.user.get_active_property_ids()[0]
|
||||
if pms_property_id:
|
||||
property = self.env["pms.property"].browse(pms_property_id)
|
||||
else:
|
||||
property = False
|
||||
if property:
|
||||
model_id = self.env["ir.model"].browse(self._name)
|
||||
model = self.env["ir.model"].search([("id", "=", model_id)])
|
||||
field_id = self.env["ir.model.fields"].search(
|
||||
[("name", "=", "daily_limit"), ("model_id", "=", model)]
|
||||
)
|
||||
ir_pms_property = self.env["ir.pms.property"].search(
|
||||
[
|
||||
("pms_property_id", "=", property.id),
|
||||
("field_id", "=", field_id.id),
|
||||
("res_id", "=", record),
|
||||
]
|
||||
)
|
||||
record.daily_limit = ir_pms_property.value
|
||||
|
||||
def _inverse_ir_pms_property(self):
|
||||
for record in self:
|
||||
pms_property_id = self.env.user.get_active_property_ids()[0]
|
||||
field_id = self.env["ir.model.fields"].search(
|
||||
[("name", "=", "daily_limit")]
|
||||
)
|
||||
model_id = self.env["ir.model"].search([("field_id", "=", field_id[1].id)])
|
||||
ir_pms_property = self.env["ir.pms.property"].search(
|
||||
[
|
||||
("pms_property_id", "=", pms_property_id),
|
||||
("model_id", "=", model_id.id),
|
||||
("field_id", "=", field_id[1].id),
|
||||
]
|
||||
)
|
||||
if ir_pms_property:
|
||||
ir_pms_property.value = record.daily_limit
|
||||
# else:
|
||||
# crear
|
||||
|
||||
@@ -68,3 +68,4 @@ user_access_res_partner_portal,user_access_res_partner_portal,model_res_partner,
|
||||
user_access_pms_precheckin_portal,user_access_pms_precheckin_portal,model_pms_checkin_partner,base.group_portal,1,1,1,1
|
||||
user_access_pms_booking_duplicate,user_access_pms_booking_duplicate,model_pms_booking_duplicate,pms.group_pms_user,1,1,1,1
|
||||
user_access_pms_reservation_duplicate,user_access_pms_reservation_duplicate,model_pms_reservation_duplicate,pms.group_pms_user,1,1,1,1
|
||||
user_access_ir_pms_property,user_access_ir_pms_property,model_ir_pms_property,pms.group_pms_user,1,1,1,1
|
||||
|
||||
|
Reference in New Issue
Block a user