mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]multi_pms_properties (#66)
* [WIP]pms: models check_pms_property * [WIP][IMP+REF] multi_pms_properties: refactor and added test skeleton * [FIX] inherit create models * [ADD] room multiproperty check * [ADD] room multiproperty check * [IMP] Multiproperty checks in pms models * [IMP] Fix Multiproperty checks in pms models * [IMP] Add multiproperty domain in multi_pms_properties module * [IMP] Fix multiproperty checks in pms tests * [IMP] Fix multiproperty checks logic * [IMP] Auto Domains * [IMP] availability property results, domain preferred_room_id * [IMP] model domain properties * [ADD] pms multiproperty depends * [IMP] models and views multiproperty checks * [FIX] Multiple rebase multiproperty fixes * [ADD] Readme * [ADD] Company - multiproperty checks * [ADD] travis server wide modules multiproperty * [FIX] travis conf load * [FIX] travis conf load2 * [FIX] travis conf load2 Co-authored-by: Eric Antones <eantones@nuobit.com> Co-authored-by: Sara Lago <saralago126@gmail.com>
This commit is contained in:
64
multi_pms_properties/__init__.py
Normal file
64
multi_pms_properties/__init__.py
Normal file
@@ -0,0 +1,64 @@
|
||||
# Copyright 2021 Dario Lodeiros
|
||||
# Copyright 2021 Eric Antones
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import logging
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tools import config
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
def _description_domain(self, env):
|
||||
if self.check_company and not self.domain:
|
||||
if self.company_dependent:
|
||||
if self.comodel_name == "res.users":
|
||||
# user needs access to current company (self.env.company)
|
||||
return "[('company_ids', 'in', allowed_company_ids[0])]"
|
||||
else:
|
||||
return "[('company_id', 'in', [allowed_company_ids[0], False])]"
|
||||
else:
|
||||
# when using check_company=True on a field on 'res.company', the
|
||||
# company_id comes from the id of the current record
|
||||
cid = "id" if self.model_name == "res.company" else "company_id"
|
||||
if self.comodel_name == "res.users":
|
||||
# User allowed company ids = user.company_ids
|
||||
return f"['|', (not {cid}, '=', True), ('company_ids', 'in', [{cid}])]"
|
||||
else:
|
||||
return f"[('company_id', 'in', [{cid}, False])]"
|
||||
|
||||
if self.check_pms_properties and not self.domain:
|
||||
record = env[self.model_name]
|
||||
# Skip company_id domain to avoid domain multiproperty error in inherited views
|
||||
if (
|
||||
self.check_pms_properties
|
||||
and not self.domain
|
||||
and self.name not in ["company_id"]
|
||||
):
|
||||
if self.model_name == "pms.property":
|
||||
prop1 = "id"
|
||||
prop2 = f"[{prop1}]"
|
||||
elif "pms_property_id" in record._fields:
|
||||
prop1 = "pms_property_id"
|
||||
prop2 = f"[{prop1}]"
|
||||
else:
|
||||
prop1 = prop2 = "pms_property_ids"
|
||||
coprop = (
|
||||
"pms_property_id"
|
||||
if "pms_property_id" in env[self.comodel_name]._fields
|
||||
else "pms_property_ids"
|
||||
)
|
||||
return f"['|', '|', \
|
||||
(not {prop1}, '=', True), \
|
||||
('{coprop}', 'in', {prop2}), \
|
||||
('{coprop}', '=', False)]"
|
||||
|
||||
return self.domain(env[self.model_name]) if callable(self.domain) else self.domain
|
||||
|
||||
|
||||
if "multi_pms_properties" in config.get("server_wide_modules"):
|
||||
_logger = logging.getLogger(__name__)
|
||||
_logger.info("monkey patching fields._Relational")
|
||||
|
||||
fields._Relational.check_pms_properties = False
|
||||
fields._Relational._description_domain = _description_domain
|
||||
Reference in New Issue
Block a user