[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:
Darío Lodeiros
2021-04-27 20:01:42 +02:00
committed by GitHub
parent de786a375b
commit e7c0c3e5bd
76 changed files with 1471 additions and 759 deletions

View File

@@ -27,10 +27,11 @@ jobs:
before_install: before_install:
- stage: test - stage: test
env: env:
- TESTS=1 ODOO_REPO="odoo/odoo" MAKEPOT="1" - TESTS=1 ODOO_REPO="odoo/odoo" MAKEPOT="1" OPTIONS="--load
web,multi_pms_properties"
- stage: test - stage: test
env: env:
- TESTS=1 ODOO_REPO="OCA/OCB" - TESTS=1 ODOO_REPO="OCA/OCB" OPTIONS="--load web,multi_pms_properties"
env: env:
global: global:
- VERSION="14.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0" - VERSION="14.0" TESTS="0" LINT_CHECK="0" MAKEPOT="0"

View File

@@ -0,0 +1,101 @@
====================
multi_pms_properties
====================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpms-lightgray.png?logo=github
:target: https://github.com/OCA/pms/tree/14.0/multi_pms_properties
:alt: OCA/pms
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-multi_pms_properties
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/293/14.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
Technical addon to support multipropety in pms
**Table of contents**
.. contents::
:local:
Installation
============
To install this module, you only need to add it to your addons, and load it as
a server-wide module.
This can be done with the ``server_wide_modules`` parameter in ``/etc/odoo.conf``
or with the ``--load`` command-line parameter
``server_wide_modules = "multi_pms_properties"``
Configuration
=============
Technical Module to Multi Property Manage System proposit.
* Use the standar multicompany guidelines applied to pms.property:
``_check_pms_properties_auto like model attribute to autocheck on create/write``
``check_pms_properties like field attribute to check relational record properties consistence``
``This module not implement propety dependent fields``
Usage
=====
To use this module, you need implement pms.property functionality
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/pms/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/pms/issues/new?body=module:%20multi_pms_properties%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Therp BV
Contributors
~~~~~~~~~~~~
* Dario Lodeiros <dario@commitsun.com>
* Eric Antones <eric@commitsun.com>
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
This module is part of the `OCA/pms <https://github.com/OCA/pms/tree/14.0/multi_pms_properties>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View 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

View File

@@ -0,0 +1,17 @@
# © 2013 Therp BV
# © 2014 ACSONE SA/NV
# Copyright 2018 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "multi_pms_properties",
"summary": "Multi Properties Manager",
"version": "14.0.1.0.0",
"website": "https://github.com/OCA/pms",
"author": "Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Pms",
"depends": ["base"],
"auto_install": False,
"installable": True,
}

View File

@@ -0,0 +1,186 @@
# Copyright 2021 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, models
from odoo.exceptions import UserError
class BaseModel(models.AbstractModel):
_inherit = "base"
_check_pms_properties_auto = False
"""On write and create, call ``_check_pms_properties_auto`` to ensure properties
consistency on the relational fields having ``check_pms_properties=True``
as attribute.
"""
@api.model_create_multi
def create(self, vals_list):
records = super(BaseModel, self).create(vals_list)
if self._check_pms_properties_auto:
records._check_pms_properties()
return records
def write(self, vals):
res = super(BaseModel, self).write(vals)
check_pms_properties = False
for fname in vals:
field = self._fields.get(fname)
if (
fname == "pms_property_id"
or fname == "pms_property_ids"
or fname == "company_id"
or (field.relational and field.check_pms_properties)
):
check_pms_properties = True
if res and check_pms_properties and self._check_pms_properties_auto:
self._check_pms_properties()
return res
def _check_pms_properties(self, fnames=None):
"""Check the properties of the values of the given field names.
:param list fnames: names of relational fields to check
:raises UserError: if the `pms_properties` of the value of any field is not
in `[False, self.pms_property_id]` (or `self` if
:class:`~odoo.addons.base.models.pms_property`).
For :class:`~odoo.addons.base.models.res_users` relational fields,
verifies record company is in `company_ids` fields.
User with main pms property A, having access to pms property A and B, could be
assigned or linked to records in property B.
"""
if fnames is None:
fnames = self._fields
regular_fields = self._get_regular_fields(fnames)
if not regular_fields:
return
inconsistencies = self._check_inconsistencies(regular_fields)
if inconsistencies:
lines = [_("Incompatible properties on records:")]
property_msg = _(
"""- Record is properties %(pms_properties)r and %(field)r
(%(fname)s: %(values)s) belongs to another properties."""
)
record_msg = _(
"""- %(record)r belongs to properties %(pms_properties)r and
%(field)r (%(fname)s: %(values)s) belongs to another properties."""
)
for record, name, corecords in inconsistencies[:5]:
if record._name == "pms.property":
msg, pms_properties = property_msg, record
else:
msg, pms_properties = (
record_msg,
record.pms_property_id.name
if "pms_property_id" in record
else ", ".join(repr(p.name) for p in record.pms_property_ids),
)
field = self.env["ir.model.fields"]._get(self._name, name)
lines.append(
msg
% {
"record": record.display_name,
"pms_properties": pms_properties,
"field": field.field_description,
"fname": field.name,
"values": ", ".join(
repr(rec.display_name) for rec in corecords
),
}
)
raise UserError("\n".join(lines))
def _get_regular_fields(self, fnames):
regular_fields = []
for name in fnames:
field = self._fields[name]
if (
field.relational
and field.check_pms_properties
and (
"pms_property_id" in self.env[field.comodel_name]
or "pms_property_ids" in self.env[field.comodel_name]
)
):
regular_fields.append(name)
return regular_fields
def _check_inconsistencies(self, regular_fields):
inconsistencies = []
for record in self:
pms_properties = False
if record._name == "pms.property":
pms_properties = record
if "pms_property_id" in record:
pms_properties = record.pms_property_id
if "pms_property_ids" in record:
pms_properties = record.pms_property_ids
# Check the property & company consistence
if "company_id" in self._fields:
if record.company_id and pms_properties:
property_companies = pms_properties.mapped("company_id.id")
if (
len(property_companies) > 1
or record.company_id.id != property_companies[0]
):
raise UserError(
_(
"You cannot establish a company other than "
"the one with the established properties"
)
)
# Check verifies that all
# records linked via relation fields are compatible
# with the properties of the origin document,
for name in regular_fields:
field = self._fields[name]
co_pms_properties = False
corecord = record.sudo()[name]
# TODO:res.users management properties
if "pms_property_id" in corecord:
co_pms_properties = corecord.pms_property_id
if "pms_property_ids" in corecord:
co_pms_properties = corecord.pms_property_ids
if (
# There is an inconsistency if:
#
# - Record has properties and corecord too and
# there's no match between them:
# X Pms_room_class with Property1 cannot contain
# Pms_room with property2 X
#
# - Record has a relation one2many with corecord and
# corecord properties aren't included in record properties
# or what is the same, subtraction between corecord properties
# and record properties must be False:
# X Pricelist with Prop1 and Prop2 cannot contain
# Pricelist_item with Prop1 and Prop3 X
# X Pricelist with Prop1 and Prop2 cannot contain
# Pricelist_item with Prop1, Prop2 and Prop3 X
# -In case that record has a relation many2one
# with corecord the condition is the same as avobe
(
pms_properties
and co_pms_properties
and (not pms_properties & co_pms_properties)
)
or (
corecord
and field.type == "one2many"
and pms_properties
and (co_pms_properties - pms_properties)
)
or (
field.type == "many2one"
and co_pms_properties
and ((pms_properties - co_pms_properties) or not pms_properties)
)
):
inconsistencies.append((record, name, corecord))
return inconsistencies

View File

@@ -0,0 +1,7 @@
Technical Module to Multi Property Manage System proposit.
* Use the standar multicompany guidelines applied to pms.property:
``_check_pms_properties_auto like model attribute to autocheck on create/write``
``check_pms_properties like field attribute to check relational record properties consistence``
``This module not implement propety dependent fields``

View File

@@ -0,0 +1,2 @@
* Dario Lodeiros <dario@commitsun.com>
* Eric Antones <eric@commitsun.com>

View File

@@ -0,0 +1 @@
Technical addon to support multipropety in pms

View File

@@ -0,0 +1,7 @@
To install this module, you only need to add it to your addons, and load it as
a server-wide module.
This can be done with the ``server_wide_modules`` parameter in ``/etc/odoo.conf``
or with the ``--load`` command-line parameter
``server_wide_modules = "multi_pms_properties"``

View File

@@ -0,0 +1 @@
To use this module, you need implement pms.property functionality

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,446 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>multi_pms_properties</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="multi-pms-properties">
<h1 class="title">multi_pms_properties</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/pms/tree/14.0/multi_pms_properties"><img alt="OCA/pms" src="https://img.shields.io/badge/github-OCA%2Fpms-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-multi_pms_properties"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/293/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Technical addon to support multipropety in pms</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#installation" id="id1">Installation</a></li>
<li><a class="reference internal" href="#configuration" id="id2">Configuration</a></li>
<li><a class="reference internal" href="#usage" id="id3">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id5">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id6">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id7">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id8">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="installation">
<h1><a class="toc-backref" href="#id1">Installation</a></h1>
<p>To install this module, you only need to add it to your addons, and load it as
a server-wide module.</p>
<p>This can be done with the <tt class="docutils literal">server_wide_modules</tt> parameter in <tt class="docutils literal">/etc/odoo.conf</tt>
or with the <tt class="docutils literal"><span class="pre">--load</span></tt> command-line parameter</p>
<p><tt class="docutils literal">server_wide_modules = &quot;multi_pms_properties&quot;</tt></p>
</div>
<div class="section" id="configuration">
<h1><a class="toc-backref" href="#id2">Configuration</a></h1>
<p>Technical Module to Multi Property Manage System proposit.</p>
<ul>
<li><p class="first">Use the standar multicompany guidelines applied to pms.property:</p>
<p><tt class="docutils literal">_check_pms_properties_auto like model attribute to autocheck&nbsp; on create/write</tt>
<tt class="docutils literal">check_pms_properties like field attribute to check relational record properties consistence</tt>
<tt class="docutils literal">This module not implement propety dependent fields</tt></p>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id3">Usage</a></h1>
<p>To use this module, you need implement pms.property functionality</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/pms/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/pms/issues/new?body=module:%20multi_pms_properties%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id5">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id6">Authors</a></h2>
<ul class="simple">
<li>Therp BV</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id7">Contributors</a></h2>
<ul class="simple">
<li>Dario Lodeiros &lt;<a class="reference external" href="mailto:dario&#64;commitsun.com">dario&#64;commitsun.com</a>&gt;</li>
<li>Eric Antones &lt;<a class="reference external" href="mailto:eric&#64;commitsun.com">eric&#64;commitsun.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/pms/tree/14.0/multi_pms_properties">OCA/pms</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,4 @@
# Copyright 2021 Eric Antones
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import common
from . import test_multi_pms_properties

View File

@@ -0,0 +1,20 @@
# Copyright 2021 Eric Antones
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
def setup_test_model(env, model_clses):
for model_cls in model_clses:
model_cls._build_model(env.registry, env.cr)
env.registry.setup_models(env.cr)
env.registry.init_models(
env.cr,
[model_cls._name for model_cls in model_clses],
dict(env.context, update_custom_fields=True),
)
def teardown_test_model(env, model_clses):
for model_cls in model_clses:
del env.registry.models[model_cls._name]
env.registry.setup_models(env.cr)

View File

@@ -0,0 +1,17 @@
# Copyright 2021 Eric Antones
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ParentTester(models.Model):
_name = "pms.parent.tester"
name = fields.Char(required=True)
class ChildTester(models.Model):
_name = "pms.child.tester"
name = fields.Char(required=True)
parent_id = fields.Many2one("pms.parent.tester", check_pms_properties=True)

View File

@@ -0,0 +1,41 @@
# Copyright 2021 Eric Antones
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo.tests import common
from .common import setup_test_model # , teardown_test_model
from .multi_pms_properties_tester import ChildTester, ParentTester
_logger = logging.getLogger(__name__)
@common.tagged("-at_install", "post_install")
class TestMultiPMSProperties(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestMultiPMSProperties, cls).setUpClass()
model_classes = [ParentTester, ChildTester]
setup_test_model(cls.env, model_classes)
for mdl_cls in model_classes:
tester_model = cls.env["ir.model"].search([("model", "=", mdl_cls._name)])
# Access record
cls.env["ir.model.access"].create(
{
"name": "access.%s" % mdl_cls._name,
"model_id": tester_model.id,
"perm_read": 1,
"perm_write": 1,
"perm_create": 1,
"perm_unlink": 1,
}
)
# @classmethod
# def tearDownClass(cls):
# teardown_test_model(cls.env, [ParentTester])
# super(TestMultiPMSProperties, cls).tearDownClass()
# def test_exist_attribute(self):
# parent = self.env["pms.parent.tester"].create({"name": "parent test"})

View File

@@ -23,6 +23,7 @@
# "partner_firstname", # "partner_firstname",
# "email_template_qweb", # "email_template_qweb",
"sale", "sale",
"multi_pms_properties",
], ],
"data": [ "data": [
"security/pms_security.xml", "security/pms_security.xml",

View File

@@ -5,3 +5,6 @@ class AccountBankStatement(models.Model):
_inherit = "account.bank.statement" _inherit = "account.bank.statement"
property_id = fields.Many2one("pms.property", string="Property", copy=False) property_id = fields.Many2one("pms.property", string="Property", copy=False)
company_id = fields.Many2one(
check_pms_properties=True,
)

View File

@@ -1,21 +1,20 @@
from odoo import _, api, fields, models from odoo import fields, models
from odoo.exceptions import UserError
class AccountJournal(models.Model): class AccountJournal(models.Model):
_inherit = "account.journal" _inherit = "account.journal"
pms_property_ids = fields.Many2many("pms.property", string="Property", copy=False) pms_property_ids = fields.Many2many(
string="Properties",
@api.constrains("pms_property_ids", "company_id") help="Properties with access to the element;"
def _check_property_company_integrity(self): " if not set, all properties can access",
for rec in self: comodel_name="pms.property",
if rec.company_id and rec.pms_property_ids: ondelete="restrict",
property_companies = rec.pms_property_ids.mapped("company_id") relation="account_journal_pms_property_rel",
if len(property_companies) > 1 or rec.company_id != property_companies: column1="account_journal_id",
raise UserError( column2="pms_property_id",
_( check_pms_properties=True,
"The company of the properties must match "
"the company on account journal"
) )
company_id = fields.Many2one(
check_pms_properties=True,
) )

View File

@@ -557,6 +557,7 @@ class FolioSaleLine(models.Model):
store=True, store=True,
readonly=True, readonly=True,
index=True, index=True,
check_pms_properties=True,
) )
folio_partner_id = fields.Many2one( folio_partner_id = fields.Many2one(
related="folio_id.partner_id", store=True, string="Customer", readonly=False related="folio_id.partner_id", store=True, string="Customer", readonly=False

View File

@@ -11,6 +11,9 @@ class PaymentReturn(models.Model):
pms_property_id = fields.Many2one( pms_property_id = fields.Many2one(
"pms.property", store=True, readonly=True, related="folio_id.pms_property_id" "pms.property", store=True, readonly=True, related="folio_id.pms_property_id"
) )
company_id = fields.Many2one(
check_pms_properties=True,
)
# Business methods # Business methods

View File

@@ -1,13 +1,13 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models from odoo import fields, models
from odoo.exceptions import ValidationError
class PmsRoomAmenity(models.Model): class PmsRoomAmenity(models.Model):
_name = "pms.amenity" _name = "pms.amenity"
_description = "Room amenity" _description = "Room amenity"
_check_pms_properties_auto = True
active = fields.Boolean( active = fields.Boolean(
string="Active", string="Active",
@@ -25,28 +25,18 @@ class PmsRoomAmenity(models.Model):
help="Properties with access to the element;" help="Properties with access to the element;"
" if not set, all properties can access", " if not set, all properties can access",
comodel_name="pms.property", comodel_name="pms.property",
ondelete="restrict",
relation="pms_amenity_pms_property_rel", relation="pms_amenity_pms_property_rel",
column1="amenity_type_id", column1="amenity_type_id",
column2="pms_property_id", column2="pms_property_id",
check_pms_properties=True,
) )
pms_amenity_type_id = fields.Many2one( pms_amenity_type_id = fields.Many2one(
string="Amenity Category", string="Amenity Category",
help="Segment the amenities by categories (multimedia, comfort, etc ...)", help="Segment the amenities by categories (multimedia, comfort, etc ...)",
comodel_name="pms.amenity.type", comodel_name="pms.amenity.type",
domain="['|', ('pms_property_ids', '=', False),('pms_property_ids', 'in', " check_pms_properties=True,
"pms_property_ids)]",
) )
default_code = fields.Char( default_code = fields.Char(
string="Internal Reference", help="Internal unique identifier of the amenity" string="Internal Reference", help="Internal unique identifier of the amenity"
) )
@api.constrains(
"pms_amenity_type_id",
"pms_property_ids",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_amenity_type_id and rec.pms_amenity_type_id.pms_property_ids:
res = rec.pms_property_ids - rec.pms_amenity_type_id.pms_property_ids
if res:
raise ValidationError(_("Property not allowed"))

View File

@@ -1,13 +1,13 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models from odoo import fields, models
from odoo.exceptions import ValidationError
class PmsRoomAmenityType(models.Model): class PmsRoomAmenityType(models.Model):
_name = "pms.amenity.type" _name = "pms.amenity.type"
_description = "Amenity Type" _description = "Amenity Type"
_check_pms_properties_auto = True
active = fields.Boolean( active = fields.Boolean(
string="Active", string="Active",
@@ -25,24 +25,16 @@ class PmsRoomAmenityType(models.Model):
help="Properties with access to the element;" help="Properties with access to the element;"
" if not set, all properties can access", " if not set, all properties can access",
comodel_name="pms.property", comodel_name="pms.property",
ondelete="restrict",
relation="pms_amenity_type_pms_property_rel", relation="pms_amenity_type_pms_property_rel",
column1="amenity_type_id", column1="amenity_type_id",
column2="pms_property_id", column2="pms_property_id",
check_pms_properties=True,
) )
pms_amenity_ids = fields.One2many( pms_amenity_ids = fields.One2many(
string="Amenities In This Category", string="Amenities In This Category",
help="Amenities included in this type", help="Amenities included in this type",
comodel_name="pms.amenity", comodel_name="pms.amenity",
inverse_name="pms_amenity_type_id", inverse_name="pms_amenity_type_id",
check_pms_properties=True,
) )
@api.constrains(
"pms_property_ids",
"pms_amenity_ids",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_ids:
res = rec.pms_amenity_ids.pms_property_ids - rec.pms_property_ids
if res:
raise ValidationError(_("Property not allowed"))

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsAvailability(models.Model): class PmsAvailability(models.Model):
_name = "pms.availability" _name = "pms.availability"
_description = "Room type availability per day" _description = "Room type availability per day"
_check_pms_properties_auto = True
room_type_id = fields.Many2one( room_type_id = fields.Many2one(
string="Room Type", string="Room Type",
@@ -15,6 +16,7 @@ class PmsAvailability(models.Model):
required=True, required=True,
comodel_name="pms.room.type", comodel_name="pms.room.type",
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
date = fields.Date( date = fields.Date(
string="Date", string="Date",
@@ -37,6 +39,7 @@ class PmsAvailability(models.Model):
readonly=True, readonly=True,
comodel_name="pms.reservation.line", comodel_name="pms.reservation.line",
inverse_name="avail_id", inverse_name="avail_id",
check_pms_properties=True,
) )
real_avail = fields.Integer( real_avail = fields.Integer(
string="Real Avail", string="Real Avail",

View File

@@ -13,6 +13,7 @@ class PmsAvailabilityPlan(models.Model):
_name = "pms.availability.plan" _name = "pms.availability.plan"
_description = "Reservation availability plan" _description = "Reservation availability plan"
_check_pms_properties_auto = True
@api.model @api.model
def _get_default_pms_property(self): def _get_default_pms_property(self):
@@ -26,15 +27,18 @@ class PmsAvailabilityPlan(models.Model):
help="Properties with access to the element;" help="Properties with access to the element;"
" if not set, all properties can access", " if not set, all properties can access",
comodel_name="pms.property", comodel_name="pms.property",
ondelete="restrict",
relation="pms_availability_plan_pms_property_rel", relation="pms_availability_plan_pms_property_rel",
column1="availability_plan_id", column1="availability_plan_id",
column2="pms_property_id", column2="pms_property_id",
check_pms_properties=True,
) )
pms_pricelist_ids = fields.One2many( pms_pricelist_ids = fields.One2many(
string="Pricelists", string="Pricelists",
help="Pricelists of the availability plan ", help="Pricelists of the availability plan ",
comodel_name="product.pricelist", comodel_name="product.pricelist",
inverse_name="availability_plan_id", inverse_name="availability_plan_id",
check_pms_properties=True,
) )
rule_ids = fields.One2many( rule_ids = fields.One2many(
@@ -42,6 +46,7 @@ class PmsAvailabilityPlan(models.Model):
help="Rules in a availability plan", help="Rules in a availability plan",
comodel_name="pms.availability.plan.rule", comodel_name="pms.availability.plan.rule",
inverse_name="availability_plan_id", inverse_name="availability_plan_id",
check_pms_properties=True,
) )
active = fields.Boolean( active = fields.Boolean(
@@ -51,76 +56,6 @@ class PmsAvailabilityPlan(models.Model):
default=True, default=True,
) )
@api.model
def get_count_rooms_available(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
pricelist_id=False,
):
if current_lines and not isinstance(current_lines, list):
current_lines = [current_lines]
avail = self.get_count_real_free_rooms(
checkin, checkout, room_type_id, pms_property_id, current_lines
)
domain_rules = [
("date", ">=", checkin),
(
"date",
"<=",
checkout,
), # TODO: only closed_departure take account checkout date!
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
if pricelist_id:
pricelist = self.env["product.pricelist"].browse(pricelist_id)
if pricelist and pricelist.availability_plan_id:
domain_rules.append(
("availability_plan_id", "=", pricelist.availability_plan_id.id)
)
rule_items = self.env["pms.availability.plan.rule"].search(domain_rules)
if len(rule_items) > 0:
for item in rule_items:
if self.any_rule_applies(checkin, checkout, item):
return 0
avail = min(rule_items.mapped("plan_avail"))
return avail
def get_count_real_free_rooms(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
):
Avail = self.env["pms.availability"]
count_free_rooms = len(self.env["pms.room.type"].browse(room_type_id).room_ids)
if isinstance(checkin, str):
checkin = datetime.datetime.strptime(
checkin, DEFAULT_SERVER_DATE_FORMAT
).date()
if isinstance(checkout, str):
checkout = datetime.datetime.strptime(
checkout, DEFAULT_SERVER_DATE_FORMAT
).date()
for avail in Avail.search(
[
("date", ">=", checkin),
("date", "<=", checkout - datetime.timedelta(1)),
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
):
if avail.real_avail < count_free_rooms:
count_free_rooms = avail.real_avail
return count_free_rooms
@classmethod @classmethod
def any_rule_applies(cls, checkin, checkout, item): def any_rule_applies(cls, checkin, checkout, item):
reservation_len = (checkout - checkin).days reservation_len = (checkout - checkin).days
@@ -224,6 +159,80 @@ class PmsAvailabilityPlan(models.Model):
domain_rooms.append(("room_type_id", "=", room_type_id)) domain_rooms.append(("room_type_id", "=", room_type_id))
return self.env["pms.room"].search(domain_rooms) return self.env["pms.room"].search(domain_rooms)
@api.model
def get_count_rooms_available(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
pricelist_id=False,
):
if current_lines and not isinstance(current_lines, list):
current_lines = [current_lines]
avail = self.get_count_real_free_rooms(
checkin, checkout, room_type_id, pms_property_id, current_lines
)
domain_rules = [
("date", ">=", checkin),
(
"date",
"<=",
checkout,
), # TODO: only closed_departure take account checkout date!
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
if pricelist_id:
pricelist = self.env["product.pricelist"].browse(pricelist_id)
if pricelist and pricelist.availability_plan_id:
domain_rules.append(
("availability_plan_id", "=", pricelist.availability_plan_id.id)
)
rule_items = self.env["pms.availability.plan.rule"].search(domain_rules)
if len(rule_items) > 0:
for item in rule_items:
if self.any_rule_applies(checkin, checkout, item):
return 0
avail = min(rule_items.mapped("plan_avail"))
return avail
def get_count_real_free_rooms(
self,
checkin,
checkout,
room_type_id,
pms_property_id,
current_lines=False,
):
Avail = self.env["pms.availability"]
count_free_rooms = len(
self.env["pms.room.type"]
.browse(room_type_id)
.room_ids.filtered(lambda r: r.pms_property_id.id == pms_property_id)
)
if isinstance(checkin, str):
checkin = datetime.datetime.strptime(
checkin, DEFAULT_SERVER_DATE_FORMAT
).date()
if isinstance(checkout, str):
checkout = datetime.datetime.strptime(
checkout, DEFAULT_SERVER_DATE_FORMAT
).date()
for avail in Avail.search(
[
("date", ">=", checkin),
("date", "<=", checkout - datetime.timedelta(1)),
("room_type_id", "=", room_type_id),
("pms_property_id", "=", pms_property_id),
]
):
if avail.real_avail < count_free_rooms:
count_free_rooms = avail.real_avail
return count_free_rooms
@api.model @api.model
def splitted_availability( def splitted_availability(
self, self,

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsAvailabilityPlanRule(models.Model): class PmsAvailabilityPlanRule(models.Model):
_name = "pms.availability.plan.rule" _name = "pms.availability.plan.rule"
_description = "Reservation rule by day" _description = "Reservation rule by day"
_check_pms_properties_auto = True
availability_plan_id = fields.Many2one( availability_plan_id = fields.Many2one(
string="Availability Plan", string="Availability Plan",
@@ -14,6 +15,7 @@ class PmsAvailabilityPlanRule(models.Model):
index=True, index=True,
comodel_name="pms.availability.plan", comodel_name="pms.availability.plan",
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
room_type_id = fields.Many2one( room_type_id = fields.Many2one(
string="Room Type", string="Room Type",
@@ -21,6 +23,7 @@ class PmsAvailabilityPlanRule(models.Model):
required=True, required=True,
comodel_name="pms.room.type", comodel_name="pms.room.type",
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
date = fields.Date( date = fields.Date(
string="Date", string="Date",
@@ -83,17 +86,6 @@ class PmsAvailabilityPlanRule(models.Model):
required=True, required=True,
comodel_name="pms.property", comodel_name="pms.property",
) )
allowed_property_ids = fields.Many2many(
string="Allowed Properties",
help="Allowed properties for user",
store=True,
readonly=True,
compute="_compute_allowed_property_ids",
comodel_name="pms.property",
relation="allowed_availability_move_rel",
column1="availability_plan_rule_id",
column2="property_id",
)
avail_id = fields.Many2one( avail_id = fields.Many2one(
string="Avail record", string="Avail record",
comodel_name="pms.availability", comodel_name="pms.availability",
@@ -101,6 +93,7 @@ class PmsAvailabilityPlanRule(models.Model):
store=True, store=True,
readonly=False, readonly=False,
ondelete="restrict", ondelete="restrict",
check_pms_properties=True,
) )
real_avail = fields.Integer( real_avail = fields.Integer(
string="Real availability", string="Real availability",
@@ -171,59 +164,6 @@ class PmsAvailabilityPlanRule(models.Model):
if not record.max_avail: if not record.max_avail:
record.max_avail = record.room_type_id.default_max_avail record.max_avail = record.room_type_id.default_max_avail
@api.depends(
"availability_plan_id.pms_property_ids", "room_type_id.pms_property_ids"
)
def _compute_allowed_property_ids(self):
for rule in self:
properties = []
if not (
rule.availability_plan_id.pms_property_ids
or rule.room_type_id.pms_property_ids
):
rule.allowed_property_ids = False
else:
if rule.availability_plan_id.pms_property_ids:
if rule.room_type_id.pms_property_ids:
for prp in rule.availability_plan_id.pms_property_ids:
if prp in rule.room_type_id.pms_property_ids:
properties.append(prp)
rule.allowed_property_ids = [
(4, prop.id) for prop in properties
]
else:
rule.allowed_property_ids = (
rule.availability_plan_id.pms_property_ids
)
else:
rule.allowed_property_ids = rule.room_type_id.pms_property_ids
@api.constrains(
"allowed_property_ids",
"pms_property_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_id and rec.allowed_property_ids:
if rec.pms_property_id.id not in rec.allowed_property_ids.ids:
raise ValidationError(_("Property not allowed"))
# @api.constrains(
# "allowed_property_ids",
# "pms_property_ids",
# )
# def _check_property_integrity(self):
# for rule in self:
# for p in rule.pms_property_ids:
# allowed = list(
# set(rule.room_type_id.pms_property_ids.ids)
# &
# set(rule.availability_plan_id.pms_property_ids.ids))
# if p.id not in allowed:
# raise ValidationError(_("Property not allowed"))
@api.constrains("min_stay", "min_stay_arrival", "max_stay", "max_stay_arrival") @api.constrains("min_stay", "min_stay_arrival", "max_stay", "max_stay_arrival")
def _check_min_max_stay(self): def _check_min_max_stay(self):
for record in self: for record in self:

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsBoardService(models.Model): class PmsBoardService(models.Model):
_name = "pms.board.service" _name = "pms.board.service"
_description = "Board Services" _description = "Board Services"
_check_pms_properties_auto = True
name = fields.Char( name = fields.Char(
string="Board Service Name", string="Board Service Name",
@@ -32,10 +33,12 @@ class PmsBoardService(models.Model):
help="Properties with access to the element;" help="Properties with access to the element;"
" if not set, all properties can access", " if not set, all properties can access",
required=False, required=False,
ondelete="restrict",
comodel_name="pms.property", comodel_name="pms.property",
relation="pms_board_service_pms_property_rel", relation="pms_board_service_pms_property_rel",
column1="board_service_id", column1="board_service_id",
column2="pms_property_id", column2="pms_property_id",
check_pms_properties=True,
) )
pms_board_service_room_type_ids = fields.One2many( pms_board_service_room_type_ids = fields.One2many(
string="Board Services Room Type", string="Board Services Room Type",

View File

@@ -1,12 +1,12 @@
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models from odoo import api, fields, models
from odoo.exceptions import ValidationError
class PmsBoardServiceLine(models.Model): class PmsBoardServiceLine(models.Model):
_name = "pms.board.service.line" _name = "pms.board.service.line"
_description = "Services on Board Service included" _description = "Services on Board Service included"
_check_pms_properties_auto = True
pms_board_service_id = fields.Many2one( pms_board_service_id = fields.Many2one(
string="Board Service", string="Board Service",
@@ -14,19 +14,25 @@ class PmsBoardServiceLine(models.Model):
required=True, required=True,
comodel_name="pms.board.service", comodel_name="pms.board.service",
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
product_id = fields.Many2one( product_id = fields.Many2one(
string="Product", string="Product",
help="Product associated with this board service line", help="Product associated with this board service line",
required=True, required=True,
comodel_name="product.product", comodel_name="product.product",
check_pms_properties=True,
) )
pms_property_ids = fields.Many2many( pms_property_ids = fields.Many2many(
string="Properties", string="Properties",
help="Properties with access to the element;" help="Properties with access to the element;"
" if not set, all properties can access", " if not set, all properties can access",
comodel_name="pms.property", comodel_name="pms.property",
related="pms_board_service_id.pms_property_ids", relation="pms_board_service_line_pms_property_rel",
column1="pms_board_service_line_id",
column2="pms_property_id",
store=True,
check_pms_properties=True,
) )
amount = fields.Float( amount = fields.Float(
string="Amount", string="Amount",
@@ -44,10 +50,33 @@ class PmsBoardServiceLine(models.Model):
if self.product_id: if self.product_id:
self.update({"amount": self.product_id.list_price}) self.update({"amount": self.product_id.list_price})
@api.constrains("pms_property_ids", "product_id") @api.model
def _check_property_integrity(self): def create(self, vals):
for record in self: properties = False
if record.pms_property_ids and record.product_id.pms_property_ids: if "pms_board_service_id" in vals:
for pms_property in record.pms_property_ids: board_service = self.env["pms.board.service"].browse(
if pms_property not in record.product_id.pms_property_ids: vals["pms_board_service_id"]
raise ValidationError(_("Property not allowed in product")) )
properties = board_service.pms_property_ids
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceLine, self).create(vals)
def write(self, vals):
properties = False
if "pms_board_service_id" in vals:
board_service = self.env["pms.board.service"].browse(
vals["pms_board_service_id"]
)
properties = board_service.pms_property_ids
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceLine, self).write(vals)

View File

@@ -10,6 +10,7 @@ class PmsBoardServiceRoomType(models.Model):
_rec_name = "pms_board_service_id" _rec_name = "pms_board_service_id"
_log_access = False _log_access = False
_description = "Board Service included in Room" _description = "Board Service included in Room"
_check_pms_properties_auto = True
pms_board_service_id = fields.Many2one( pms_board_service_id = fields.Many2one(
string="Board Service", string="Board Service",
@@ -18,14 +19,19 @@ class PmsBoardServiceRoomType(models.Model):
index=True, index=True,
comodel_name="pms.board.service", comodel_name="pms.board.service",
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
pms_property_ids = fields.Many2many( pms_property_ids = fields.Many2many(
string="Properties", string="Properties",
help="Properties with access to the element; " help="Properties with access to the element;"
"if not set, all properties can access", " if not set, all properties can access",
required=False, required=False,
comodel_name="pms.property",
ondelete="restrict", ondelete="restrict",
comodel_name="pms.property",
relation="pms_board_service_room_type_pms_property_rel",
column1="pms_board_service_room_type_id",
column2="pms_property_id",
check_pms_properties=True,
) )
pms_room_type_id = fields.Many2one( pms_room_type_id = fields.Many2one(
string="Room Type", string="Room Type",
@@ -33,18 +39,15 @@ class PmsBoardServiceRoomType(models.Model):
required=True, required=True,
index=True, index=True,
comodel_name="pms.room.type", comodel_name="pms.room.type",
domain=[
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", pms_property_ids),
],
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
board_service_line_ids = fields.One2many( board_service_line_ids = fields.One2many(
string="Board Service Lines", string="Board Service Lines",
help="Services included in this Board Service", help="Services included in this Board Service",
comodel_name="pms.board.service.room.type.line", comodel_name="pms.board.service.room.type.line",
inverse_name="pms_board_service_room_type_id", inverse_name="pms_board_service_room_type_id",
required=True,
) )
amount = fields.Float( amount = fields.Float(
string="Amount", string="Amount",
@@ -104,10 +107,28 @@ class PmsBoardServiceRoomType(models.Model):
@api.model @api.model
def create(self, vals): def create(self, vals):
properties = False
if "pms_board_service_id" in vals: if "pms_board_service_id" in vals:
vals.update( vals.update(
self.prepare_board_service_reservation_ids(vals["pms_board_service_id"]) self.prepare_board_service_reservation_ids(vals["pms_board_service_id"])
) )
board_service = self.env["pms.board.service"].browse(
vals["pms_board_service_id"]
)
properties = board_service.pms_property_ids
if "pms_room_type_id" in vals:
room_type = self.env["pms.room.type"].browse(vals["pms_room_type_id"])
properties = (
properties + room_type.pms_property_ids
if properties
else room_type.pms_property_ids
)
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceRoomType, self).create(vals) return super(PmsBoardServiceRoomType, self).create(vals)
def write(self, vals): def write(self, vals):

View File

@@ -1,12 +1,12 @@
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models from odoo import api, fields, models
from odoo.exceptions import ValidationError
class PmsBoardServiceRoomTypeLine(models.Model): class PmsBoardServiceRoomTypeLine(models.Model):
_name = "pms.board.service.room.type.line" _name = "pms.board.service.room.type.line"
_description = "Services on Board Service included in Room" _description = "Services on Board Service included in Room"
_check_pms_properties_auto = True
# Fields declaration # Fields declaration
pms_board_service_room_type_id = fields.Many2one( pms_board_service_room_type_id = fields.Many2one(
@@ -16,12 +16,22 @@ class PmsBoardServiceRoomTypeLine(models.Model):
comodel_name="pms.board.service.room.type", comodel_name="pms.board.service.room.type",
ondelete="cascade", ondelete="cascade",
) )
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
relation="pms_board_service_room_type_line_pms_property_rel",
column1="pms_board_service_room_type_id",
column2="pms_property_id",
check_pms_properties=True,
)
product_id = fields.Many2one( product_id = fields.Many2one(
string="Product", string="Product",
help="Product associated with this board service room type line", help="Product associated with this board service room type line",
readonly=True,
required=True,
comodel_name="product.product", comodel_name="product.product",
readonly=True,
check_pms_properties=True,
) )
# TODO def default_amount "amount of service" # TODO def default_amount "amount of service"
amount = fields.Float( amount = fields.Float(
@@ -31,15 +41,33 @@ class PmsBoardServiceRoomTypeLine(models.Model):
digits=("Product Price"), digits=("Product Price"),
) )
@api.constrains("pms_board_service_room_type_id", "product_id") @api.model
def _check_property_integrity(self): def create(self, vals):
for record in self: properties = False
if ( if "pms_board_service_room_type_id" in vals:
record.pms_board_service_room_type_id.pms_property_ids board_service = self.env["pms.board.service.room.type"].browse(
and record.product_id.pms_property_ids vals["pms_board_service_room_type_id"]
): )
for ( properties = board_service.pms_property_ids
pms_property if properties:
) in record.pms_board_service_room_type_id.pms_property_ids: vals.update(
if pms_property not in record.product_id.pms_property_ids: {
raise ValidationError(_("Property not allowed")) "pms_property_ids": properties,
}
)
return super(PmsBoardServiceRoomTypeLine, self).create(vals)
def write(self, vals):
properties = False
if "pms_board_service_room_type_id" in vals:
board_service = self.env["pms.board.service.room.type"].browse(
vals["pms_board_service_room_type_id"]
)
properties = board_service.pms_property_ids
if properties:
vals.update(
{
"pms_property_ids": properties,
}
)
return super(PmsBoardServiceRoomTypeLine, self).write(vals)

View File

@@ -8,14 +8,27 @@ from odoo import fields, models
class PmsCancelationRule(models.Model): class PmsCancelationRule(models.Model):
_name = "pms.cancelation.rule" _name = "pms.cancelation.rule"
_description = "Cancelation Rules" _description = "Cancelation Rules"
_check_pms_properties_auto = True
# Fields declaration # Fields declaration
name = fields.Char(string="Cancelation Rule", translate=True, required=True) name = fields.Char(string="Cancelation Rule", translate=True, required=True)
pricelist_ids = fields.One2many( pricelist_ids = fields.One2many(
"product.pricelist", "cancelation_rule_id", "Pricelist that use this rule" "product.pricelist",
"cancelation_rule_id",
"Pricelist that use this rule",
check_pms_properties=True,
) )
pms_property_ids = fields.Many2many( pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict" string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
ondelete="restrict",
comodel_name="pms.property",
relation="pms_cancelation_rule_pms_property_rel",
column1="pms_cancelation_rule_id",
column2="pms_property_id",
check_pms_properties=True,
) )
active = fields.Boolean("Active", default=True) active = fields.Boolean("Active", default=True)
days_intime = fields.Integer( days_intime = fields.Integer(
@@ -35,5 +48,3 @@ class PmsCancelationRule(models.Model):
default="all", default="all",
) )
days_noshow = fields.Integer("NoShow first days", default="2") days_noshow = fields.Integer("NoShow first days", default="2")
# TODO: Constrain coherence pms_property_ids pricelist and cancelation_rules

View File

@@ -13,6 +13,7 @@ class PmsCheckinPartner(models.Model):
_name = "pms.checkin.partner" _name = "pms.checkin.partner"
_description = "Partner Checkins" _description = "Partner Checkins"
_rec_name = "identifier" _rec_name = "identifier"
_check_pms_properties_auto = True
# Fields declaration # Fields declaration
identifier = fields.Char( identifier = fields.Char(
@@ -22,11 +23,15 @@ class PmsCheckinPartner(models.Model):
"res.partner", "res.partner",
domain="[('is_company', '=', False)]", domain="[('is_company', '=', False)]",
) )
reservation_id = fields.Many2one("pms.reservation") reservation_id = fields.Many2one(
"pms.reservation",
check_pms_properties=True,
)
folio_id = fields.Many2one( folio_id = fields.Many2one(
"pms.folio", "pms.folio",
compute="_compute_folio_id", compute="_compute_folio_id",
store=True, store=True,
check_pms_properties=True,
) )
pms_property_id = fields.Many2one( pms_property_id = fields.Many2one(
"pms.property", store=True, readonly=True, related="folio_id.pms_property_id" "pms.property", store=True, readonly=True, related="folio_id.pms_property_id"

View File

@@ -18,6 +18,7 @@ class PmsFolio(models.Model):
_inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"] _inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"]
_order = "date_order" _order = "date_order"
_check_company_auto = True _check_company_auto = True
_check_pms_properties_auto = True
# Default Methods ang Gets # Default Methods ang Gets
def name_get(self): def name_get(self):
@@ -54,6 +55,7 @@ class PmsFolio(models.Model):
ondelete="restrict", ondelete="restrict",
store=True, store=True,
readonly=False, readonly=False,
check_pms_properties=True,
) )
reservation_ids = fields.One2many( reservation_ids = fields.One2many(
"pms.reservation", "pms.reservation",
@@ -62,6 +64,7 @@ class PmsFolio(models.Model):
states={"done": [("readonly", True)]}, states={"done": [("readonly", True)]},
help="Room reservation detail.", help="Room reservation detail.",
check_company=True, check_company=True,
check_pms_properties=True,
) )
number_of_rooms = fields.Integer( number_of_rooms = fields.Integer(
"Number of Rooms", "Number of Rooms",
@@ -69,7 +72,7 @@ class PmsFolio(models.Model):
store="True", store="True",
) )
number_of_services = fields.Integer( number_of_services = fields.Integer(
"Number of Rooms", "Number of Services",
compute="_compute_number_of_services", compute="_compute_number_of_services",
store="True", store="True",
) )
@@ -81,9 +84,7 @@ class PmsFolio(models.Model):
help="Services detail provide to customer and it will " help="Services detail provide to customer and it will "
"include in main Invoice.", "include in main Invoice.",
check_company=True, check_company=True,
domain="['|'," check_pms_properties=True,
"('pms_property_id','=',pms_property_id),"
"('pms_property_id','=',False)]",
) )
sale_line_ids = fields.One2many( sale_line_ids = fields.One2many(
"folio.sale.line", "folio.sale.line",
@@ -98,8 +99,8 @@ class PmsFolio(models.Model):
company_id = fields.Many2one( company_id = fields.Many2one(
"res.company", "res.company",
"Company", "Company",
required=True, compute="_compute_company_id",
default=lambda self: self.env.company, store=True,
) )
move_line_ids = fields.Many2many( move_line_ids = fields.Many2many(
"account.move.line", "account.move.line",
@@ -132,9 +133,7 @@ class PmsFolio(models.Model):
store=True, store=True,
readonly=False, readonly=False,
help="Pricelist for current folio.", help="Pricelist for current folio.",
domain="['|'," check_pms_properties=True,
"(pms_property_id, 'in', 'pms_property_ids'),"
"('pms_property_ids','=',False)]",
) )
commission = fields.Float( commission = fields.Float(
string="Commission", string="Commission",
@@ -158,6 +157,7 @@ class PmsFolio(models.Model):
string="Agency", string="Agency",
ondelete="restrict", ondelete="restrict",
domain=[("is_agency", "=", True)], domain=[("is_agency", "=", True)],
check_pms_properties=True,
) )
channel_type_id = fields.Many2one( channel_type_id = fields.Many2one(
"pms.sale.channel", "pms.sale.channel",
@@ -167,6 +167,7 @@ class PmsFolio(models.Model):
string="Direct Sale Channel", string="Direct Sale Channel",
ondelete="restrict", ondelete="restrict",
domain=[("channel_type", "=", "direct")], domain=[("channel_type", "=", "direct")],
check_pms_properties=True,
) )
transaction_ids = fields.Many2many( transaction_ids = fields.Many2many(
"payment.transaction", "payment.transaction",
@@ -236,6 +237,7 @@ class PmsFolio(models.Model):
store=True, store=True,
readonly=False, readonly=False,
help="Invoice address for current group.", help="Invoice address for current group.",
check_pms_properties=True,
) )
# REVIEW THIS # REVIEW THIS
# partner_invoice_state_id = fields.Many2one(related="partner_invoice_id.state_id") # partner_invoice_state_id = fields.Many2one(related="partner_invoice_id.state_id")
@@ -247,9 +249,7 @@ class PmsFolio(models.Model):
) )
closure_reason_id = fields.Many2one( closure_reason_id = fields.Many2one(
"room.closure.reason", "room.closure.reason",
domain="['|'," check_pms_properties=True,
"(pms_property_id, 'in', 'pms_property_ids'),"
"('pms_property_ids', '=', False)]",
) )
segmentation_ids = fields.Many2many( segmentation_ids = fields.Many2many(
"res.partner.category", string="Segmentation", ondelete="restrict" "res.partner.category", string="Segmentation", ondelete="restrict"
@@ -472,6 +472,11 @@ class PmsFolio(models.Model):
for fsl in folio_sale_lines_to_remove: for fsl in folio_sale_lines_to_remove:
self.env["folio.sale.line"].browse(fsl).unlink() self.env["folio.sale.line"].browse(fsl).unlink()
@api.depends("pms_property_id")
def _compute_company_id(self):
for record in self:
record.company_id = record.pms_property_id.company_id
@api.model @api.model
def generate_reservation_services_sale_lines(self, folio, reservation): def generate_reservation_services_sale_lines(self, folio, reservation):
for service in reservation.service_ids: for service in reservation.service_ids:
@@ -1396,18 +1401,6 @@ class PmsFolio(models.Model):
_("The Sale Channel does not correspond to the agency's") _("The Sale Channel does not correspond to the agency's")
) )
@api.constrains(
"closure_reason_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_id:
if (
rec.pms_property_id.id
not in rec.closure_reason_id.pms_property_ids.ids
):
raise ValidationError(_("Property not allowed"))
@api.model @api.model
def _prepare_down_payment_section_line(self, **optional_values): def _prepare_down_payment_section_line(self, **optional_values):
""" """

View File

@@ -30,6 +30,7 @@ class PmsProperty(models.Model):
help="The company that owns or operates this property.", help="The company that owns or operates this property.",
comodel_name="res.company", comodel_name="res.company",
required=True, required=True,
check_pms_properties=True,
) )
user_ids = fields.Many2many( user_ids = fields.Many2many(
string="Accepted Users", string="Accepted Users",
@@ -45,7 +46,6 @@ class PmsProperty(models.Model):
comodel_name="pms.room", comodel_name="pms.room",
inverse_name="pms_property_id", inverse_name="pms_property_id",
) )
# TODO: establecer tarifa publica por defecto
default_pricelist_id = fields.Many2one( default_pricelist_id = fields.Many2one(
string="Product Pricelist", string="Product Pricelist",
help="The default pricelist used in this property.", help="The default pricelist used in this property.",

View File

@@ -16,7 +16,9 @@ class PmsReservation(models.Model):
_description = "Reservation" _description = "Reservation"
_inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"] _inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"]
_order = "priority desc, create_date desc, write_date desc" _order = "priority desc, create_date desc, write_date desc"
# TODO:
# consider near_to_checkin & pending_notifications to order
_check_pms_properties_auto = True
_check_company_auto = True _check_company_auto = True
name = fields.Text( name = fields.Text(
@@ -37,9 +39,13 @@ class PmsReservation(models.Model):
"empty if reservation is splitted", "empty if reservation is splitted",
copy=False, copy=False,
comodel_name="pms.room", comodel_name="pms.room",
domain="[('id', 'in', allowed_room_ids)]",
ondelete="restrict", ondelete="restrict",
domain="["
"('id', 'in', allowed_room_ids),"
"('pms_property_id', '=', pms_property_id),"
"]",
tracking=True, tracking=True,
check_pms_properties=True,
) )
allowed_room_ids = fields.Many2many( allowed_room_ids = fields.Many2many(
string="Allowed Rooms", string="Allowed Rooms",
@@ -68,12 +74,9 @@ class PmsReservation(models.Model):
readonly=False, readonly=False,
store=True, store=True,
comodel_name="pms.board.service.room.type", comodel_name="pms.board.service.room.type",
domain="["
"'|',"
"('pms_property_ids', 'in', pms_property_id),"
"('pms_property_ids', '=', False)]",
compute="_compute_board_service_room_id", compute="_compute_board_service_room_id",
tracking=True, tracking=True,
check_pms_properties=True,
) )
room_type_id = fields.Many2one( room_type_id = fields.Many2one(
string="Room Type", string="Room Type",
@@ -84,11 +87,9 @@ class PmsReservation(models.Model):
copy=False, copy=False,
store=True, store=True,
comodel_name="pms.room.type", comodel_name="pms.room.type",
domain="['|',"
"('pms_property_ids', 'in', pms_property_id),"
"('pms_property_ids', '=', False)]",
compute="_compute_room_type_id", compute="_compute_room_type_id",
tracking=True, tracking=True,
check_pms_properties=True,
) )
partner_id = fields.Many2one( partner_id = fields.Many2one(
string="Customer", string="Customer",
@@ -99,6 +100,7 @@ class PmsReservation(models.Model):
ondelete="restrict", ondelete="restrict",
compute="_compute_partner_id", compute="_compute_partner_id",
tracking=True, tracking=True,
check_pms_properties=True,
) )
agency_id = fields.Many2one( agency_id = fields.Many2one(
string="Agency", string="Agency",
@@ -120,9 +122,7 @@ class PmsReservation(models.Model):
string="Closure Reason", string="Closure Reason",
help="Reason why the reservation cannot be made", help="Reason why the reservation cannot be made",
related="folio_id.closure_reason_id", related="folio_id.closure_reason_id",
domain="['|'," check_pms_properties=True,
"(pms_property_id, 'in', 'pms_property_ids'),"
"('pms_property_ids', '=', False)]",
) )
company_id = fields.Many2one( company_id = fields.Many2one(
string="Company", string="Company",
@@ -150,6 +150,7 @@ class PmsReservation(models.Model):
compute="_compute_reservation_line_ids", compute="_compute_reservation_line_ids",
comodel_name="pms.reservation.line", comodel_name="pms.reservation.line",
inverse_name="reservation_id", inverse_name="reservation_id",
check_pms_properties=True,
) )
service_ids = fields.One2many( service_ids = fields.One2many(
string="Services", string="Services",
@@ -158,11 +159,9 @@ class PmsReservation(models.Model):
store=True, store=True,
comodel_name="pms.service", comodel_name="pms.service",
inverse_name="reservation_id", inverse_name="reservation_id",
domain="['|',"
"('pms_property_id', '=', pms_property_id),"
"('pms_property_id', '=', False)]",
compute="_compute_service_ids", compute="_compute_service_ids",
check_company=True, check_company=True,
check_pms_properties=True,
) )
pricelist_id = fields.Many2one( pricelist_id = fields.Many2one(
string="Pricelist", string="Pricelist",
@@ -170,12 +169,10 @@ class PmsReservation(models.Model):
readonly=False, readonly=False,
store=True, store=True,
comodel_name="product.pricelist", comodel_name="product.pricelist",
domain="['|',"
"('pms_property_ids', 'in', pms_property_id),"
"('pms_property_ids', '=', False)]",
ondelete="restrict", ondelete="restrict",
compute="_compute_pricelist_id", compute="_compute_pricelist_id",
tracking=True, tracking=True,
check_pms_properties=True,
) )
user_id = fields.Many2one( user_id = fields.Many2one(
string="Salesperson", string="Salesperson",
@@ -216,6 +213,7 @@ class PmsReservation(models.Model):
compute="_compute_checkin_partner_ids", compute="_compute_checkin_partner_ids",
comodel_name="pms.checkin.partner", comodel_name="pms.checkin.partner",
inverse_name="reservation_id", inverse_name="reservation_id",
check_pms_properties=True,
) )
count_pending_arrival = fields.Integer( count_pending_arrival = fields.Integer(
string="Pending Arrival", string="Pending Arrival",
@@ -278,7 +276,7 @@ class PmsReservation(models.Model):
) )
currency_id = fields.Many2one( currency_id = fields.Many2one(
string="Currency", string="Currency",
hepl="The currency used in relation to the pricelist", help="The currency used in relation to the pricelist",
readonly=True, readonly=True,
store=True, store=True,
related="pricelist_id.currency_id", related="pricelist_id.currency_id",
@@ -1292,44 +1290,7 @@ class PmsReservation(models.Model):
if record.agency_id and not record.agency_id.is_agency: if record.agency_id and not record.agency_id.is_agency:
raise ValidationError(_("booking agency with wrong configuration: ")) raise ValidationError(_("booking agency with wrong configuration: "))
@api.constrains("pms_property_id", "preferred_room_id") # Action methods
def _check_room_property_integrity(self):
for record in self:
if record.pms_property_id and record.preferred_room_id.pms_property_id:
if record.pms_property_id != record.preferred_room_id.pms_property_id:
raise ValidationError(
_("Property doesn't match with room property")
)
@api.constrains("pms_property_id", "room_type_id")
def _check_room_type_property_integrity(self):
for record in self:
if record.pms_property_id and record.room_type_id.pms_property_ids:
if (
record.pms_property_id.id
not in record.room_type_id.pms_property_ids.ids
):
raise ValidationError(_("Property isn't allowed in Room Type"))
@api.constrains("pms_property_id", "pricelist_id")
def _check_pricelist_property_integrity(self):
for record in self:
if record.pms_property_id and record.pricelist_id.pms_property_ids:
if (
record.pms_property_id.id
not in record.pricelist_id.pms_property_ids.ids
):
raise ValidationError(_("Property isn't allowed in Pricelist"))
@api.constrains("pms_property_id", "board_service_room_id")
def _check_board_service_property_integrity(self):
for record in self:
if record.pms_property_id and record.board_service_room_id.pms_property_ids:
if (
record.pms_property_id.id
not in record.board_service_room_id.pms_property_ids.ids
):
raise ValidationError(_("Property isn't allowed in Board Service"))
def open_folio(self): def open_folio(self):
action = self.env.ref("pms.open_pms_folio1_form_tree_all").sudo().read()[0] action = self.env.ref("pms.open_pms_folio1_form_tree_all").sudo().read()[0]

View File

@@ -14,6 +14,7 @@ class PmsReservationLine(models.Model):
_name = "pms.reservation.line" _name = "pms.reservation.line"
_description = "Reservations by day" _description = "Reservations by day"
_order = "date" _order = "date"
_check_company_auto = True
reservation_id = fields.Many2one( reservation_id = fields.Many2one(
string="Reservation", string="Reservation",
@@ -22,6 +23,7 @@ class PmsReservationLine(models.Model):
copy=False, copy=False,
comodel_name="pms.reservation", comodel_name="pms.reservation",
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
room_id = fields.Many2one( room_id = fields.Many2one(
string="Room", string="Room",
@@ -31,6 +33,7 @@ class PmsReservationLine(models.Model):
compute="_compute_room_id", compute="_compute_room_id",
comodel_name="pms.room", comodel_name="pms.room",
ondelete="restrict", ondelete="restrict",
check_pms_properties=True,
) )
sale_line_ids = fields.Many2many( sale_line_ids = fields.Many2many(
@@ -41,6 +44,7 @@ class PmsReservationLine(models.Model):
relation="reservation_line_sale_line_rel", relation="reservation_line_sale_line_rel",
column1="reservation_line_id", column1="reservation_line_id",
column2="sale_line_id", column2="sale_line_id",
check_pms_properties=True,
) )
pms_property_id = fields.Many2one( pms_property_id = fields.Many2one(
string="Property", string="Property",
@@ -84,6 +88,7 @@ class PmsReservationLine(models.Model):
comodel_name="pms.availability", comodel_name="pms.availability",
ondelete="restrict", ondelete="restrict",
compute="_compute_avail_id", compute="_compute_avail_id",
check_pms_properties=True,
) )
discount = fields.Float( discount = fields.Float(

View File

@@ -15,6 +15,7 @@ class PmsRoom(models.Model):
_name = "pms.room" _name = "pms.room"
_description = "Property Room" _description = "Property Room"
_order = "sequence, room_type_id, name" _order = "sequence, room_type_id, name"
_check_pms_properties_auto = True
name = fields.Char( name = fields.Char(
string="Room Name", string="Room Name",
@@ -44,14 +45,10 @@ class PmsRoom(models.Model):
help="Unique room type for the rooms", help="Unique room type for the rooms",
required=True, required=True,
comodel_name="pms.room.type", comodel_name="pms.room.type",
domain=[
"|",
("pms_property_ids", "=", False),
(pms_property_id, "in", "pms_property_ids"),
],
ondelete="restrict", ondelete="restrict",
check_pms_properties=True,
) )
# TODO: Dario, design shared rooms # TODO: design shared rooms
shared_room_id = fields.Many2one( shared_room_id = fields.Many2one(
string="Shared Room", string="Shared Room",
help="The room can be sold by beds", help="The room can be sold by beds",
@@ -62,11 +59,7 @@ class PmsRoom(models.Model):
string="Ubication", string="Ubication",
help="At which ubication the room is located.", help="At which ubication the room is located.",
comodel_name="pms.ubication", comodel_name="pms.ubication",
domain=[ check_pms_properties=True,
"|",
("pms_property_ids", "=", False),
(pms_property_id, "in", "pms_property_ids"),
],
) )
capacity = fields.Integer( capacity = fields.Integer(
string="Capacity", help="The maximum number of people that can occupy a room" string="Capacity", help="The maximum number of people that can occupy a room"
@@ -85,18 +78,6 @@ class PmsRoom(models.Model):
translate=True, translate=True,
) )
allowed_property_ids = fields.Many2many(
string="Allowed Properties",
help="Allowed properties for rooms",
store=True,
readonly=True,
compute="_compute_allowed_property_ids",
comodel_name="pms.property",
relation="room_property_rel",
column1="room_id",
column2="property_id",
)
_sql_constraints = [ _sql_constraints = [
( (
"room_property_unique", "room_property_unique",
@@ -115,30 +96,7 @@ class PmsRoom(models.Model):
result.append((room.id, name)) result.append((room.id, name))
return result return result
@api.depends( # Constraints and onchanges
"room_type_id",
"room_type_id.pms_property_ids",
"ubication_id",
"ubication_id.pms_property_ids",
)
# TODO: Dario, revisar flujo de allowed properties
def _compute_allowed_property_ids(self):
for record in self:
if not (
record.room_type_id.pms_property_ids
or record.ubication_id.pms_property_ids
):
record.allowed_property_ids = self.env["pms.property"].search([])
elif not record.room_type_id.pms_property_ids:
record.allowed_property_ids = record.ubication_id.pms_property_ids
elif not record.ubication_id.pms_property_ids:
record.allowed_property_ids = record.room_type_id.pms_property_ids
else:
record.allowed_property_ids = (
record.room_type_id.pms_property_ids
& record.ubication_id.pms_property_ids
)
@api.constrains("capacity") @api.constrains("capacity")
def _check_capacity(self): def _check_capacity(self):
for record in self: for record in self:
@@ -150,17 +108,7 @@ class PmsRoom(models.Model):
) )
) )
@api.constrains( # Business methods
"allowed_property_ids",
"pms_property_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_id:
if rec.pms_property_id.id not in rec.allowed_property_ids.ids:
raise ValidationError(
_("Property not allowed in room type or in ubication")
)
def get_capacity(self, extra_bed=0): def get_capacity(self, extra_bed=0):
for record in self: for record in self:

View File

@@ -6,6 +6,7 @@ from odoo import fields, models
class RoomClosureReason(models.Model): class RoomClosureReason(models.Model):
_name = "room.closure.reason" _name = "room.closure.reason"
_description = "Cause of out of service" _description = "Cause of out of service"
_check_pms_properties_auto = True
name = fields.Char( name = fields.Char(
string="Name", string="Name",
@@ -22,6 +23,7 @@ class RoomClosureReason(models.Model):
column1="room_closure_reason_type_id", column1="room_closure_reason_type_id",
column2="pms_property_id", column2="pms_property_id",
ondelete="restrict", ondelete="restrict",
check_pms_properties=True,
) )
description = fields.Text( description = fields.Text(
string="Description", string="Description",

View File

@@ -17,6 +17,7 @@ class PmsRoomType(models.Model):
_description = "Room Type" _description = "Room Type"
_inherits = {"product.product": "product_id"} _inherits = {"product.product": "product_id"}
_order = "sequence,default_code,name" _order = "sequence,default_code,name"
_check_pms_properties_auto = True
sequence = fields.Integer( sequence = fields.Integer(
string="Sequence", string="Sequence",
@@ -30,36 +31,28 @@ class PmsRoomType(models.Model):
required=True, required=True,
delegate=True, delegate=True,
ondelete="cascade", ondelete="cascade",
# check_pms_properties=True,
) )
room_ids = fields.One2many( room_ids = fields.One2many(
string="Rooms", string="Rooms",
help="Rooms that belong to room type.", help="Rooms that belong to room type.",
comodel_name="pms.room", comodel_name="pms.room",
inverse_name="room_type_id", inverse_name="room_type_id",
domain="[" check_pms_properties=True,
"'|', "
"('pms_property_id', '=', False), "
"('pms_property_id','in', pms_property_ids)"
"]",
) )
class_id = fields.Many2one( class_id = fields.Many2one(
string="Property Type Class", string="Property Type Class",
help="Class to which the room type belongs", help="Class to which the room type belongs",
comodel_name="pms.room.type.class", comodel_name="pms.room.type.class",
required=True, required=True,
domain="[" check_pms_properties=True,
"'|', "
"('pms_property_ids', '=', False), "
"('pms_property_ids', 'in', pms_property_ids)"
"]",
) )
board_service_room_type_ids = fields.One2many( board_service_room_type_ids = fields.One2many(
string="Board Services", string="Board Services",
help="Board Service included in room type", help="Board Service included in room type",
comodel_name="pms.board.service.room.type", comodel_name="pms.board.service.room.type",
inverse_name="pms_room_type_id", inverse_name="pms_room_type_id",
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', " check_pms_properties=True,
"pms_property_ids)]",
) )
room_amenity_ids = fields.Many2many( room_amenity_ids = fields.Many2many(
string="Room Type Amenities", string="Room Type Amenities",
@@ -68,11 +61,7 @@ class PmsRoomType(models.Model):
relation="pms_room_type_amenity_rel", relation="pms_room_type_amenity_rel",
column1="room_type_id", column1="room_type_id",
column2="amenity_id", column2="amenity_id",
domain="[" check_pms_properties=True,
"'|', "
"('pms_property_ids', '=', False), "
"('pms_property_ids', 'in', pms_property_ids)"
"]",
) )
default_code = fields.Char( default_code = fields.Char(
string="Code", string="Code",
@@ -171,16 +160,6 @@ class PmsRoomType(models.Model):
) )
return self.browse(list(res.values())) return self.browse(list(res.values()))
@api.constrains("pms_property_ids", "class_id")
def _check_integrity_property_class(self):
for record in self:
if record.pms_property_ids and record.class_id.pms_property_ids:
for pms_property in record.pms_property_ids:
if pms_property.id not in record.class_id.pms_property_ids.ids:
raise ValidationError(
_("Property isn't allowed in Room Type Class")
)
@api.constrains("default_code", "pms_property_ids", "company_id") @api.constrains("default_code", "pms_property_ids", "company_id")
def _check_code_property_company_uniqueness(self): def _check_code_property_company_uniqueness(self):
msg = _("Already exists another room type with the same code and properties") msg = _("Already exists another room type with the same code and properties")
@@ -203,39 +182,6 @@ class PmsRoomType(models.Model):
if other and other != rec: if other and other != rec:
raise ValidationError(msg) raise ValidationError(msg)
@api.constrains("room_amenity_ids", "pms_property_ids")
def _check_integrity_property_amenity(self):
for record in self:
if record.room_amenity_ids.pms_property_ids and record.pms_property_ids:
for pms_property in record.pms_property_ids:
if pms_property not in record.room_amenity_ids.pms_property_ids:
raise ValidationError(_("Property not allowed in amenity"))
@api.constrains("room_ids", "pms_property_ids")
def _check_integrity_property_room(self):
for record in self:
if record.room_ids and record.pms_property_ids:
for room in record.room_ids:
if room.pms_property_id not in record.pms_property_ids:
raise ValidationError(_("Property not allowed in room"))
# TODO: Not allowed repeat boardservice on room_type with
# same properties os without properties
@api.constrains("board_service_room_type_ids", "pms_property_ids")
def _check_integrity_property_board_service_room_type(self):
for record in self:
if record.board_service_room_type_ids and record.pms_property_ids:
for board_service_room_type in record.board_service_room_type_ids:
if board_service_room_type.pms_property_ids:
for pms_property in record.pms_property_ids:
if (
pms_property
not in board_service_room_type.pms_property_ids
):
raise ValidationError(
_("Property not allowed in board service room type")
)
# ORM Overrides # ORM Overrides
# TODO: Review Check product fields default values to room # TODO: Review Check product fields default values to room
@api.model @api.model

View File

@@ -42,15 +42,19 @@ class PmsRoomTypeClass(models.Model):
column1="room_type_class_id", column1="room_type_class_id",
column2="pms_property_id", column2="pms_property_id",
ondelete="restrict", ondelete="restrict",
check_pms_properties=True,
) )
room_type_ids = fields.One2many( room_type_ids = fields.One2many(
string="Types", string="Types",
help="Room Types that belong to this Room Type Class", help="Room Types that belong to this Room Type Class",
comodel_name="pms.room.type", comodel_name="pms.room.type",
inverse_name="class_id", inverse_name="class_id",
check_pms_properties=True,
) )
default_code = fields.Char( default_code = fields.Char(
string="Code", help="Room type class identification code", required=True string="Code",
help="Room type class identification code",
required=True,
) )
@api.model @api.model

View File

@@ -4,6 +4,7 @@ from odoo import fields, models
class PmsSaleChannel(models.Model): class PmsSaleChannel(models.Model):
_name = "pms.sale.channel" _name = "pms.sale.channel"
_description = "Sales Channel" _description = "Sales Channel"
_check_pms_properties_auto = True
name = fields.Text(string="Sale Channel Name", help="The name of the sale channel") name = fields.Text(string="Sale Channel Name", help="The name of the sale channel")
channel_type = fields.Selection( channel_type = fields.Selection(
@@ -23,4 +24,17 @@ class PmsSaleChannel(models.Model):
relation="pms_sale_channel_product_pricelist_rel", relation="pms_sale_channel_product_pricelist_rel",
column1="pms_sale_channel_id", column1="pms_sale_channel_id",
column2="product_pricelist_id", column2="product_pricelist_id",
check_pms_properties=True,
)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
ondelete="restrict",
comodel_name="pms.property",
relation="pms_sale_channel_pms_property_rel",
column1="pms_sale_channel_id",
column2="pms_property_id",
check_pms_properties=True,
) )

View File

@@ -12,6 +12,7 @@ _logger = logging.getLogger(__name__)
class PmsService(models.Model): class PmsService(models.Model):
_name = "pms.service" _name = "pms.service"
_description = "Services and its charges" _description = "Services and its charges"
_check_pms_properties_auto = True
name = fields.Char( name = fields.Char(
string="Service description", string="Service description",
@@ -26,6 +27,7 @@ class PmsService(models.Model):
required=True, required=True,
comodel_name="product.product", comodel_name="product.product",
ondelete="restrict", ondelete="restrict",
check_pms_properties=True,
) )
folio_id = fields.Many2one( folio_id = fields.Many2one(
string="Folio", string="Folio",
@@ -34,6 +36,7 @@ class PmsService(models.Model):
store=True, store=True,
comodel_name="pms.folio", comodel_name="pms.folio",
compute="_compute_folio_id", compute="_compute_folio_id",
check_pms_properties=True,
) )
sale_line_ids = fields.One2many( sale_line_ids = fields.One2many(
string="Sale Lines", string="Sale Lines",
@@ -41,6 +44,7 @@ class PmsService(models.Model):
copy=False, copy=False,
comodel_name="folio.sale.line", comodel_name="folio.sale.line",
inverse_name="service_id", inverse_name="service_id",
check_pms_properties=True,
) )
reservation_id = fields.Many2one( reservation_id = fields.Many2one(
string="Room", string="Room",
@@ -48,6 +52,7 @@ class PmsService(models.Model):
default=lambda self: self._default_reservation_id(), default=lambda self: self._default_reservation_id(),
comodel_name="pms.reservation", comodel_name="pms.reservation",
ondelete="cascade", ondelete="cascade",
check_pms_properties=True,
) )
service_line_ids = fields.One2many( service_line_ids = fields.One2many(
string="Service Lines", string="Service Lines",
@@ -57,6 +62,7 @@ class PmsService(models.Model):
comodel_name="pms.service.line", comodel_name="pms.service.line",
inverse_name="service_id", inverse_name="service_id",
compute="_compute_service_line_ids", compute="_compute_service_line_ids",
check_pms_properties=True,
) )
company_id = fields.Many2one( company_id = fields.Many2one(
string="Company", string="Company",

View File

@@ -10,6 +10,7 @@ class PmsServiceLine(models.Model):
_description = "Service by day" _description = "Service by day"
_order = "date" _order = "date"
_rec_name = "service_id" _rec_name = "service_id"
_check_pms_properties_auto = True
service_id = fields.Many2one( service_id = fields.Many2one(
string="Service Room", string="Service Room",
@@ -30,6 +31,7 @@ class PmsServiceLine(models.Model):
help="Product associated with this service line", help="Product associated with this service line",
store=True, store=True,
related="service_id.product_id", related="service_id.product_id",
check_pms_properties=True,
) )
tax_ids = fields.Many2many( tax_ids = fields.Many2many(
string="Taxes", string="Taxes",
@@ -93,6 +95,7 @@ class PmsServiceLine(models.Model):
readonly=True, readonly=True,
store=True, store=True,
related="service_id.reservation_id", related="service_id.reservation_id",
check_pms_properties=True,
) )
discount = fields.Float( discount = fields.Float(
string="Discount (%)", string="Discount (%)",

View File

@@ -10,6 +10,8 @@ class PmsSharedRoom(models.Model):
_name = "pms.shared.room" _name = "pms.shared.room"
_description = "Shared Room" _description = "Shared Room"
_order = "room_type_id, name" _order = "room_type_id, name"
_check_pms_properties_auto = True
name = fields.Char( name = fields.Char(
string="Room Name", help="Name of the shared room", required=True string="Room Name", help="Name of the shared room", required=True
) )
@@ -39,6 +41,7 @@ class PmsSharedRoom(models.Model):
relation="pms_shared_room_pms_property_rel", relation="pms_shared_room_pms_property_rel",
column1="shared_room_id", column1="shared_room_id",
column2="pms_property_id", column2="pms_property_id",
check_pms_properties=True,
) )
ubication_id = fields.Many2one( ubication_id = fields.Many2one(
string="Ubication", string="Ubication",

View File

@@ -7,6 +7,7 @@ from odoo.exceptions import ValidationError
class PmsUbication(models.Model): class PmsUbication(models.Model):
_name = "pms.ubication" _name = "pms.ubication"
_description = "Ubication" _description = "Ubication"
_check_pms_properties_auto = True
name = fields.Char( name = fields.Char(
string="Ubication Name", string="Ubication Name",
@@ -27,12 +28,15 @@ class PmsUbication(models.Model):
relation="pms_ubication_pms_property_rel", relation="pms_ubication_pms_property_rel",
column1="ubication_type_id", column1="ubication_type_id",
column2="pms_property_id", column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
) )
pms_room_ids = fields.One2many( pms_room_ids = fields.One2many(
string="Rooms", string="Rooms",
help="Rooms found in this location", help="Rooms found in this location",
comodel_name="pms.room", comodel_name="pms.room",
inverse_name="ubication_id", inverse_name="ubication_id",
check_pms_properties=True,
) )
@api.constrains( @api.constrains(

View File

@@ -2,8 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging import logging
from odoo import _, api, fields, models from odoo import fields, models
from odoo.exceptions import ValidationError
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@@ -15,37 +14,44 @@ class ProductPricelist(models.Model):
""" """
_inherit = "product.pricelist" _inherit = "product.pricelist"
_check_pms_properties_auto = True
# Fields declaration # Fields declaration
pms_property_ids = fields.Many2many( pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict" string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
relation="product_pricelist_pms_property_rel",
column1="product_pricelist_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
company_id = fields.Many2one(
check_pms_properties=True,
) )
cancelation_rule_id = fields.Many2one( cancelation_rule_id = fields.Many2one(
"pms.cancelation.rule", "pms.cancelation.rule",
string="Cancelation Policy", string="Cancelation Policy",
domain=[ check_pms_properties=True,
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", pms_property_ids),
],
) )
pricelist_type = fields.Selection( pricelist_type = fields.Selection(
[("daily", "Daily Plan")], string="Pricelist Type", default="daily" [("daily", "Daily Plan")], string="Pricelist Type", default="daily"
) )
pms_sale_channel_ids = fields.Many2many( pms_sale_channel_ids = fields.Many2many(
"pms.sale.channel", string="Available Channels" "pms.sale.channel",
string="Available Channels",
check_pms_properties=True,
) )
availability_plan_id = fields.Many2one( availability_plan_id = fields.Many2one(
comodel_name="pms.availability.plan", comodel_name="pms.availability.plan",
string="Availability Plan", string="Availability Plan",
ondelete="restrict", ondelete="restrict",
domain=[ check_pms_properties=True,
"|",
("pms_property_ids", "=", False),
("pms_property_ids", "in", pms_property_ids),
],
) )
item_ids = fields.One2many(check_pms_properties=True)
# Constraints and onchanges # Constraints and onchanges
# @api.constrains("pricelist_type", "pms_property_ids") # @api.constrains("pricelist_type", "pms_property_ids")
@@ -96,9 +102,9 @@ class ProductPricelist(models.Model):
FROM product_pricelist_item item FROM product_pricelist_item item
LEFT JOIN product_category categ LEFT JOIN product_category categ
ON item.categ_id = categ.id ON item.categ_id = categ.id
LEFT JOIN pms_property_product_pricelist_rel cab LEFT JOIN product_pricelist_pms_property_rel cab
ON item.pricelist_id = cab.product_pricelist_id ON item.pricelist_id = cab.product_pricelist_id
LEFT JOIN pms_property_product_pricelist_item_rel lin LEFT JOIN product_pricelist_item_pms_property_rel lin
ON item.id = lin.product_pricelist_item_id ON item.id = lin.product_pricelist_item_id
LEFT JOIN board_service_pricelist_item_rel board LEFT JOIN board_service_pricelist_item_rel board
ON item.id = board.pricelist_item_id ON item.id = board.pricelist_item_id
@@ -121,10 +127,10 @@ class ProductPricelist(models.Model):
item.date_end - item.date_start ASC, item.date_end - item.date_start ASC,
item.date_end_overnight - item.date_start_overnight ASC, item.date_end_overnight - item.date_start_overnight ASC,
NULLIF((SELECT COUNT(1) NULLIF((SELECT COUNT(1)
FROM pms_property_product_pricelist_item_rel l FROM product_pricelist_item_pms_property_rel l
WHERE item.id = l.product_pricelist_item_id) WHERE item.id = l.product_pricelist_item_id)
+ (SELECT COUNT(1) + (SELECT COUNT(1)
FROM pms_property_product_pricelist_rel c FROM product_pricelist_pms_property_rel c
WHERE item.pricelist_id = c.product_pricelist_id),0) WHERE item.pricelist_id = c.product_pricelist_id),0)
NULLS LAST, NULLS LAST,
item.id DESC; item.id DESC;
@@ -168,25 +174,3 @@ class ProductPricelist(models.Model):
"pricelist_id": self.id, "pricelist_id": self.id,
}, },
} }
@api.constrains(
"cancelation_rule_id",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_ids:
for p in rec.pms_property_ids:
if p.id not in rec.cancelation_rule_id.pms_property_ids.ids:
raise ValidationError(
_("Property not allowed in cancelation rule")
)
@api.constrains("pms_property_ids", "availability_plan_id")
def _check_availability_plan_property_integrity(self):
for record in self:
if record.pms_property_ids and record.availability_plan_id.pms_property_ids:
for pms_property in record.pms_property_ids:
if pms_property not in record.availability_plan_id.pms_property_ids:
raise ValidationError(
_("Property not allowed availability plan")
)

View File

@@ -1,14 +1,22 @@
# Copyright 2017 Alexandre Díaz, Pablo Quesada, Darío Lodeiros # Copyright 2017 Alexandre Díaz, Pablo Quesada, Darío Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models from odoo import fields, models
from odoo.exceptions import ValidationError
class ProductPricelistItem(models.Model): class ProductPricelistItem(models.Model):
_inherit = "product.pricelist.item" _inherit = "product.pricelist.item"
_check_pms_properties_auto = True
pms_property_ids = fields.Many2many( pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict" string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
comodel_name="pms.property",
relation="product_pricelist_item_pms_property_rel",
column1="product_pricelist_item_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
) )
date_start_overnight = fields.Date( date_start_overnight = fields.Date(
string="Start Date Overnight", string="Start Date Overnight",
@@ -27,56 +35,8 @@ class ProductPricelistItem(models.Model):
string="Board Services on Room Types", string="Board Services on Room Types",
ondelete="cascade", # check_company=True, ondelete="cascade", # check_company=True,
help="""Specify a Board services on Room Types.""", help="""Specify a Board services on Room Types.""",
# domain="[('pms_property_ids', 'in', [allowed_property_ids, False])]", check_pms_properties=True,
) )
pricelist_id = fields.Many2one(check_pms_properties=True)
allowed_property_ids = fields.Many2many( product_id = fields.Many2one(check_pms_properties=True)
"pms.property", product_tmpl_id = fields.Many2one(check_pms_properties=True)
"allowed_pricelist_move_rel",
"pricelist_item_id",
"property_id",
string="Allowed Properties",
store=True,
readonly=True,
compute="_compute_allowed_property_ids",
)
@api.depends("product_id.pms_property_ids", "pricelist_id.pms_property_ids")
def _compute_allowed_property_ids(self):
for record in self:
properties = []
if record.applied_on == "0_product_variant":
product = record.product_id
elif record.applied_on == "1_product":
product = record.product_tmpl_id
else:
product = False
if not record.pricelist_id.pms_property_ids or not product:
record.allowed_property_ids = False
else:
if record.pricelist_id.pms_property_ids:
if product.pms_property_ids:
properties = list(
set(record.pricelist_id.pms_property_ids.ids)
& set(product.pms_property_ids.ids)
)
record.allowed_property_ids = self.env["pms.property"].search(
[("id", "in", properties)]
)
else:
record.allowed_property_ids = product.pms_property_ids
else:
record.allowed_property_ids = product.pms_property_ids
# else:
# record.allowed_property_ids = False
@api.constrains(
"allowed_property_ids",
"pms_property_ids",
)
def _check_property_integrity(self):
for rec in self:
if rec.pms_property_ids and rec.allowed_property_ids:
for p in rec.pms_property_ids:
if p.id not in rec.allowed_property_ids.ids:
raise ValidationError(_("Property not allowed"))

View File

@@ -1,8 +1,7 @@
# Copyright 2017 Alexandre Díaz # Copyright 2017 Alexandre Díaz
# Copyright 2017 Dario Lodeiros # Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models from odoo import fields, models
from odoo.exceptions import ValidationError
class ProductTemplate(models.Model): class ProductTemplate(models.Model):
@@ -17,6 +16,11 @@ class ProductTemplate(models.Model):
relation="product_template_pms_property_rel", relation="product_template_pms_property_rel",
column1="product_tmpl_id", column1="product_tmpl_id",
column2="pms_property_id", column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
company_id = fields.Many2one(
check_pms_properties=True,
) )
per_day = fields.Boolean( per_day = fields.Boolean(
string="Unit increment per day", string="Unit increment per day",
@@ -40,16 +44,3 @@ class ProductTemplate(models.Model):
help="Indicates if that product is a extra bed, add +1 capacity in the room", help="Indicates if that product is a extra bed, add +1 capacity in the room",
default=False, default=False,
) )
@api.constrains("pms_property_ids", "company_id")
def _check_property_company_integrity(self):
for rec in self:
if rec.company_id and rec.pms_property_ids:
property_companies = rec.pms_property_ids.mapped("company_id")
if len(property_companies) > 1 or rec.company_id != property_companies:
raise ValidationError(
_(
"The company of the properties must match "
"the company on the room type"
)
)

View File

@@ -40,6 +40,21 @@ class ResPartner(models.Model):
string="Invoice Agency", string="Invoice Agency",
help="Indicates if agency invoices partner", help="Indicates if agency invoices partner",
) )
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
relation="res_partner_pms_property_rel",
column1="res_partner_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
company_id = fields.Many2one(
check_pms_properties=True,
)
def _compute_reservations_count(self): def _compute_reservations_count(self):
# TODO: recuperar las reservas de los folios del partner # TODO: recuperar las reservas de los folios del partner

View File

@@ -1,4 +1,4 @@
from odoo.exceptions import ValidationError from odoo.exceptions import UserError
from .common import TestPms from .common import TestPms
@@ -51,7 +51,7 @@ class TestPmsAmenity(TestPms):
} }
) )
# ACT & ASSERT # ACT & ASSERT
with self.assertRaises(ValidationError), self.cr.savepoint(): with self.assertRaises(UserError), self.cr.savepoint():
Amenity.create( Amenity.create(
{ {
"name": "TestAmenity1", "name": "TestAmenity1",
@@ -69,115 +69,3 @@ class TestPmsAmenity(TestPms):
], ],
} }
) )
def test_property_allowed(self):
# Creation of a Amenity with Properties compatible with it Amenity Type
# Check Properties of Amenity are in Properties of Amenity Type
# +----------------------------------------+-----------------------------------+
# | Amenity Type (TestAmenityType1) | Amenity (TestAmenity1) |
# +----------------------------------------+-----------------------------------+
# | Property1 - Property2 - Property3 | Property1 - Property2 - Property3 |
# +----------------------------------------+-----------------------------------+
# ARRANGE
AmenityType = self.env["pms.amenity.type"]
Amenity = self.env["pms.amenity"]
amenity_type1 = AmenityType.create(
{
"name": "TestAmenityType1",
"pms_property_ids": [
(
6,
0,
[
self.pms_property1.id,
self.pms_property2.id,
self.pms_property3.id,
],
)
],
}
)
# ACT
amenity1 = Amenity.create(
{
"name": "TestAmenity1",
"pms_amenity_type_id": amenity_type1.id,
"pms_property_ids": [
(
6,
0,
[
self.pms_property1.id,
self.pms_property2.id,
self.pms_property3.id,
],
)
],
}
)
# ASSERT
self.assertEqual(
amenity1.pms_property_ids.ids,
amenity_type1.pms_property_ids.ids,
"Properties not allowed in amenity type",
)
def test_change_amenity_property(self):
# Creation of a Amenity with Properties compatible with it Amenity Type
# Delete a Property in Amenity Type, check Validation Error when do that
# 1st scenario:
# +----------------------------------------+-----------------------------------+
# | Amenity Type (TestAmenityType1) | Amenity (TestAmenity1) |
# +----------------------------------------+-----------------------------------+
# | Property1 - Property2 - Property3 | Property1 - Property2 - Property3 |
# +----------------------------------------+-----------------------------------+
# 2nd scenario(Error):
# +----------------------------------------+-----------------------------------+
# | Amenity Type (TestAmenityType1) | Amenity (TestAmenity1) |
# +----------------------------------------+-----------------------------------+
# | Property1 - Property2 | Property1 - Property2 - Property3 |
# +----------------------------------------+-----------------------------------+
# ARRANGE
AmenityType = self.env["pms.amenity.type"]
Amenity = self.env["pms.amenity"]
amenity_type1 = AmenityType.create(
{
"name": "TestAmenityType1",
"pms_property_ids": [
(4, self.pms_property1.id),
(4, self.pms_property2.id),
(4, self.pms_property3.id),
],
}
)
# ACT
Amenity.create(
{
"name": "TestAmenity1",
"pms_amenity_type_id": amenity_type1.id,
"pms_property_ids": [
(
6,
0,
[
self.pms_property1.id,
self.pms_property2.id,
self.pms_property3.id,
],
)
],
}
)
# ASSERT
with self.assertRaises(ValidationError):
amenity_type1.pms_property_ids = [
(
6,
0,
[self.pms_property1.id, self.pms_property2.id],
)
]
amenity_type1.flush()

View File

@@ -3,24 +3,42 @@ import datetime
from freezegun import freeze_time from freezegun import freeze_time
from odoo import fields from odoo import fields
from odoo.exceptions import ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.tests import common from odoo.tests import common
@freeze_time("1980-01-01") @freeze_time("1980-01-01")
class TestPmsRoomTypeAvailabilityRules(common.SavepointCase): class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
def create_common_scenario(self): def create_common_scenario(self):
# product.pricelist
self.test_pricelist1 = self.env["product.pricelist"].create(
{
"name": "test pricelist 1",
}
)
self.test_pricelist2 = self.env["product.pricelist"].create( self.test_pricelist2 = self.env["product.pricelist"].create(
{ {
"name": "test pricelist 2", "name": "test pricelist 2",
} }
) )
self.test_property1 = self.env["pms.property"].create(
{
"name": "Property 1",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
}
)
self.test_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
}
)
self.test_pricelist1 = self.env["product.pricelist"].create(
{
"name": "test pricelist 1",
"pms_property_ids": [
(4, self.test_property1.id),
(4, self.test_property2.id),
],
}
)
# pms.availability.plan # pms.availability.plan
self.test_room_type_availability1 = self.env["pms.availability.plan"].create( self.test_room_type_availability1 = self.env["pms.availability.plan"].create(
{ {
@@ -148,27 +166,6 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
def create_scenario_multiproperty(self): def create_scenario_multiproperty(self):
self.create_common_scenario() self.create_common_scenario()
self.test_property1 = self.env["pms.property"].create(
{
"name": "Property 1",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.test_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.env.ref("base.main_company").id,
"default_pricelist_id": self.test_pricelist2.id,
"folio_sequence_id": self.folio_sequence.id,
"reservation_sequence_id": self.reservation_sequence.id,
"checkin_sequence_id": self.checkin_sequence.id,
}
)
self.test_property3 = self.env["pms.property"].create( self.test_property3 = self.env["pms.property"].create(
{ {
"name": "Property 3", "name": "Property 3",
@@ -583,6 +580,11 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
"pms_property_id": self.test_property.id, "pms_property_id": self.test_property.id,
} }
) )
self.test_pricelist1.pms_property_ids = [
(4, self.test_property1.id),
(4, self.test_property2.id),
(4, self.test_property.id),
]
r1 = self.env["pms.reservation"].create( r1 = self.env["pms.reservation"].create(
{ {
"pms_property_id": self.test_property.id, "pms_property_id": self.test_property.id,
@@ -627,6 +629,11 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
"name": "test pricelist 2", "name": "test pricelist 2",
} }
) )
self.test_pricelist1.pms_property_ids = [
(4, self.test_property1.id),
(4, self.test_property2.id),
(4, self.test_property.id),
]
rule = self.env["pms.availability.plan.rule"].create( rule = self.env["pms.availability.plan.rule"].create(
{ {
"availability_plan_id": self.test_room_type_availability1.id, "availability_plan_id": self.test_room_type_availability1.id,
@@ -801,52 +808,7 @@ class TestPmsRoomTypeAvailabilityRules(common.SavepointCase):
# ASSERT # ASSERT
for test_case in test_cases: for test_case in test_cases:
with self.subTest(k=test_case): with self.subTest(k=test_case):
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
self.availability_rule1.pms_property_id = test_case[ self.availability_rule1.pms_property_id = test_case[
"pms_property_id" "pms_property_id"
] ]
def test_compute_allowed_property_ids(self):
# TEST CASE:
#
# ARRANGE
self.create_scenario_multiproperty()
# create new room_type
self.test_room_type_special = self.env["pms.room.type"].create(
{
"pms_property_ids": [
(4, self.test_property1.id),
(4, self.test_property3.id),
],
"name": "Special Room Test",
"default_code": "SP_Test",
"class_id": self.test_room_type_class.id,
}
)
# ACT
self.availability_example = self.env["pms.availability.plan"].create(
{
"name": "Availability plan for TEST",
"pms_pricelist_ids": [(6, 0, [self.test_pricelist1.id])],
"pms_property_ids": [
(4, self.test_property1.id),
(4, self.test_property2.id),
],
}
)
self.availability_rule1 = self.env["pms.availability.plan.rule"].create(
{
"availability_plan_id": self.availability_example.id,
"room_type_id": self.test_room_type_special.id,
"date": (fields.datetime.today() + datetime.timedelta(days=2)).date(),
"closed": True,
"pms_property_id": self.test_property1.id,
}
)
self.assertIn(
self.test_property1.id,
self.availability_rule1.allowed_property_ids.mapped("id"),
"error",
)

View File

@@ -1,4 +1,4 @@
from odoo.exceptions import ValidationError from odoo.exceptions import UserError
from odoo.tests import common from odoo.tests import common
@@ -63,7 +63,7 @@ class TestPmsBoardService(common.SavepointCase):
"default_code": "CB", "default_code": "CB",
} }
) )
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
board_service_line = self.board_service_line = self.env[ board_service_line = self.board_service_line = self.env[
"pms.board.service.line" "pms.board.service.line"
].create( ].create(

View File

@@ -1,4 +1,4 @@
from odoo.exceptions import ValidationError from odoo.exceptions import UserError
from odoo.tests import common from odoo.tests import common
@@ -57,19 +57,21 @@ class TestPmsBoardServiceRoomTypeLine(common.SavepointCase):
{ {
"name": "Board Service", "name": "Board Service",
"default_code": "CB", "default_code": "CB",
"pms_property_ids": self.property1,
} }
) )
self.room_type_class = self.env["pms.room.type.class"].create( self.room_type_class = self.env["pms.room.type.class"].create(
{ {
"name": "Room Type Class", "name": "Room Type Class",
"pms_property_ids": self.property1,
"default_code": "SIN1", "default_code": "SIN1",
"pms_property_ids": self.property1,
} }
) )
self.room_type = self.env["pms.room.type"].create( self.room_type = self.env["pms.room.type"].create(
{ {
"name": "Room Type", "name": "Room Type",
"default_code": "Type1", "default_code": "Type1",
"pms_property_ids": self.property1,
"class_id": self.room_type_class.id, "class_id": self.room_type_class.id,
} }
) )
@@ -84,8 +86,7 @@ class TestPmsBoardServiceRoomTypeLine(common.SavepointCase):
self.product = self.env["product.product"].create( self.product = self.env["product.product"].create(
{"name": "Product", "pms_property_ids": self.property2} {"name": "Product", "pms_property_ids": self.property2}
) )
with self.assertRaises(UserError):
with self.assertRaises(ValidationError):
self.env["pms.board.service.room.type.line"].create( self.env["pms.board.service.room.type.line"].create(
{ {
"pms_board_service_room_type_id": self.board_service_room_type.id, "pms_board_service_room_type_id": self.board_service_room_type.id,

View File

@@ -3,7 +3,7 @@ import datetime
from freezegun import freeze_time from freezegun import freeze_time
from odoo import fields from odoo import fields
from odoo.exceptions import ValidationError from odoo.exceptions import UserError
from odoo.tests import common from odoo.tests import common
freeze_time("2000-02-02") freeze_time("2000-02-02")
@@ -279,7 +279,7 @@ class TestPmsFolio(common.SavepointCase):
} }
) )
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
self.env["pms.folio"].create( self.env["pms.folio"].create(
{ {
"pms_property_id": self.property3.id, "pms_property_id": self.property3.id,

View File

@@ -1,6 +1,6 @@
import datetime import datetime
from odoo.exceptions import ValidationError from odoo.exceptions import UserError, ValidationError
from odoo.tests import common, tagged from odoo.tests import common, tagged
@@ -124,7 +124,7 @@ class TestPmsPricelist(common.SavepointCase):
# ARRANGE # ARRANGE
self.create_common_scenario() self.create_common_scenario()
# ACT & ASSERT # ACT & ASSERT
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
self.item1 = self.env["product.pricelist.item"].create( self.item1 = self.env["product.pricelist.item"].create(
{ {
"name": "item_1", "name": "item_1",
@@ -149,7 +149,7 @@ class TestPmsPricelist(common.SavepointCase):
} }
) )
# ASSERT # ASSERT
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
self.item1 = self.env["product.pricelist.item"].create( self.item1 = self.env["product.pricelist.item"].create(
{ {
"name": "item_1", "name": "item_1",
@@ -175,7 +175,7 @@ class TestPmsPricelist(common.SavepointCase):
} }
) )
# ASSERT # ASSERT
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
Pricelist.create( Pricelist.create(
{ {
"name": "Pricelist Test", "name": "Pricelist Test",
@@ -189,7 +189,7 @@ class TestPmsPricelist(common.SavepointCase):
self.availability_plan = self.env["pms.availability.plan"].create( self.availability_plan = self.env["pms.availability.plan"].create(
{"name": "Availability Plan", "pms_property_ids": [self.property1.id]} {"name": "Availability Plan", "pms_property_ids": [self.property1.id]}
) )
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
self.env["product.pricelist"].create( self.env["product.pricelist"].create(
{ {
"name": "Pricelist", "name": "Pricelist",

View File

@@ -122,7 +122,6 @@ class TestPmsPricelistRules(common.SavepointCase):
"partner_id": self.partner1.id, "partner_id": self.partner1.id,
} }
) )
# ACT # ACT
n_days = (reservation.checkout - reservation.checkin).days n_days = (reservation.checkout - reservation.checkin).days
expected_price = self.room.room_type_id.list_price * n_days expected_price = self.room.room_type_id.list_price * n_days
@@ -147,7 +146,7 @@ class TestPmsPricelistRules(common.SavepointCase):
# 5. id # 5. id
# - tie # - tie
# - no [date_start|date_end|date_start_overnight|date_end_overnight] # - no [date_start|date_end|date_start_overnight|date_end_overnight]
properties = self.room_type.product_id.pms_property_ids.ids
test_cases = [ test_cases = [
{ {
"name": "sorting applied_on", "name": "sorting applied_on",
@@ -164,6 +163,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"applied_on": "0_product_variant", "applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"fixed_price": 50.0, "fixed_price": 50.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -171,6 +171,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"product_tmpl_id": self.product_template.id, "product_tmpl_id": self.product_template.id,
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -186,6 +187,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now() "date_end": datetime.datetime.now()
+ datetime.timedelta(days=2), + datetime.timedelta(days=2),
"fixed_price": 60.0, "fixed_price": 60.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -195,6 +197,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now() "date_end": datetime.datetime.now()
+ datetime.timedelta(days=1), + datetime.timedelta(days=1),
"fixed_price": 50.0, "fixed_price": 50.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -204,6 +207,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now() "date_end": datetime.datetime.now()
+ datetime.timedelta(days=3), + datetime.timedelta(days=3),
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -219,6 +223,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now() "date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=6), + datetime.timedelta(days=6),
"fixed_price": 60.0, "fixed_price": 60.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -228,6 +233,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now() "date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=10), + datetime.timedelta(days=10),
"fixed_price": 50.0, "fixed_price": 50.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -237,6 +243,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now() "date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3), + datetime.timedelta(days=3),
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -249,6 +256,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"applied_on": "0_product_variant", "applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"fixed_price": 60.0, "fixed_price": 60.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -275,18 +283,21 @@ class TestPmsPricelistRules(common.SavepointCase):
"applied_on": "0_product_variant", "applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"fixed_price": 60.0, "fixed_price": 60.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
"applied_on": "0_product_variant", "applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"fixed_price": 50.0, "fixed_price": 50.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
"applied_on": "0_product_variant", "applied_on": "0_product_variant",
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -302,6 +313,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now() "date_end": datetime.datetime.now()
+ datetime.timedelta(days=2), + datetime.timedelta(days=2),
"fixed_price": 60.0, "fixed_price": 60.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -312,6 +324,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now() "date_end": datetime.datetime.now()
+ datetime.timedelta(days=1), + datetime.timedelta(days=1),
"fixed_price": 50.0, "fixed_price": 50.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -327,6 +340,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now() "date_end": datetime.datetime.now()
+ datetime.timedelta(days=10), + datetime.timedelta(days=10),
"fixed_price": 120.0, "fixed_price": 120.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -336,6 +350,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now() "date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3), + datetime.timedelta(days=3),
"fixed_price": 50.0, "fixed_price": 50.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -351,6 +366,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now() "date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3), + datetime.timedelta(days=3),
"fixed_price": 120.0, "fixed_price": 120.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -376,6 +392,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end_overnight": datetime.datetime.now() "date_end_overnight": datetime.datetime.now()
+ datetime.timedelta(days=3), + datetime.timedelta(days=3),
"fixed_price": 120.0, "fixed_price": 120.0,
"pms_property_ids": properties,
}, },
{ {
"pricelist_id": self.pricelist.id, "pricelist_id": self.pricelist.id,
@@ -432,6 +449,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_end": datetime.datetime.now() "date_end": datetime.datetime.now()
+ datetime.timedelta(days=1), + datetime.timedelta(days=1),
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -445,6 +463,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"date_start": datetime.datetime.now(), "date_start": datetime.datetime.now(),
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -458,6 +477,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"date_end_overnight": datetime.datetime.now(), "date_end_overnight": datetime.datetime.now(),
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -471,6 +491,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"product_id": self.room_type.product_id.id, "product_id": self.room_type.product_id.id,
"date_start_overnight": datetime.datetime.now(), "date_start_overnight": datetime.datetime.now(),
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },
@@ -485,6 +506,7 @@ class TestPmsPricelistRules(common.SavepointCase):
"date_start_overnight": datetime.datetime.now(), "date_start_overnight": datetime.datetime.now(),
"date_end_overnight": datetime.datetime.now(), "date_end_overnight": datetime.datetime.now(),
"fixed_price": 40.0, "fixed_price": 40.0,
"pms_property_ids": properties,
}, },
], ],
}, },

View File

@@ -951,7 +951,7 @@ class TestPmsReservations(common.SavepointCase):
for test_case in test_cases: for test_case in test_cases:
with self.subTest(k=test_case): with self.subTest(k=test_case):
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
self.reservation_test.write(test_case) self.reservation_test.write(test_case)
@freeze_time("1950-11-01") @freeze_time("1950-11-01")

View File

@@ -1,6 +1,6 @@
from psycopg2 import IntegrityError from psycopg2 import IntegrityError
from odoo.exceptions import ValidationError from odoo.exceptions import UserError
from odoo.tools import mute_logger from odoo.tools import mute_logger
from .common import TestPms from .common import TestPms
@@ -38,9 +38,7 @@ class TestPmsRoom(TestPms):
} }
) )
# ACT & ARRANGE # ACT & ARRANGE
with self.assertRaises( with self.assertRaises(UserError, msg="Room has been created and it should't"):
ValidationError, msg="Room has been created and it should't"
):
self.env["pms.room"].create( self.env["pms.room"].create(
{ {
"name": "Room 101", "name": "Room 101",
@@ -60,9 +58,7 @@ class TestPmsRoom(TestPms):
} }
) )
# ACT & ARRANGE # ACT & ARRANGE
with self.assertRaises( with self.assertRaises(UserError, msg="Room has been created and it should't"):
ValidationError, msg="Room has been created and it should't"
):
self.env["pms.room"].create( self.env["pms.room"].create(
{ {
"name": "Room 101", "name": "Room 101",

View File

@@ -1,7 +1,7 @@
# Copyright 2021 Eric Antones <eantones@nuobit.com> # Copyright 2021 Eric Antones <eantones@nuobit.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError from odoo.exceptions import UserError, ValidationError
from .common import TestPms from .common import TestPms
@@ -68,7 +68,7 @@ class TestRoomType(TestPms):
""" """
# ARRANGE & ACT & ASSERT # ARRANGE & ACT & ASSERT
with self.assertRaises( with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't" UserError, msg="The room type has been created and it shouldn't"
): ):
# room_type1 # room_type1
self.env["pms.room.type"].create( self.env["pms.room.type"].create(
@@ -95,7 +95,7 @@ class TestRoomType(TestPms):
""" """
# ARRANGE & ACT & ASSERT # ARRANGE & ACT & ASSERT
with self.assertRaises( with self.assertRaises(
ValidationError, msg="The room type has been created and it shouldn't" UserError, msg="The room type has been created and it shouldn't"
): ):
# room_type1 # room_type1
self.env["pms.room.type"].create( self.env["pms.room.type"].create(
@@ -728,7 +728,7 @@ class TestRoomType(TestPms):
) )
# ACT & ASSERT # ACT & ASSERT
with self.assertRaises( with self.assertRaises(
ValidationError, msg="Room Type has been created and it shouldn't" UserError, msg="Room Type has been created and it shouldn't"
): ):
room_type1 = self.env["pms.room.type"].create( room_type1 = self.env["pms.room.type"].create(
{ {
@@ -776,7 +776,7 @@ class TestRoomType(TestPms):
self.amenity1 = self.env["pms.amenity"].create( self.amenity1 = self.env["pms.amenity"].create(
{"name": "Amenity", "pms_property_ids": self.pms_property1} {"name": "Amenity", "pms_property_ids": self.pms_property1}
) )
with self.assertRaises(ValidationError): with self.assertRaises(UserError):
self.env["pms.room.type"].create( self.env["pms.room.type"].create(
{ {
"name": "Room Type", "name": "Room Type",

View File

@@ -268,7 +268,7 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
expected_price_total = days * price_today * num_double_rooms expected_price_total = days * price_today * num_double_rooms
# set pricelist item for current day # set pricelist item for current day
product_tmpl_id = self.test_room_type_double.product_id.product_tmpl_id.id product_tmpl = self.test_room_type_double.product_id.product_tmpl_id
pricelist_item = self.env["product.pricelist.item"].create( pricelist_item = self.env["product.pricelist.item"].create(
{ {
"pricelist_id": self.test_pricelist.id, "pricelist_id": self.test_pricelist.id,
@@ -276,9 +276,10 @@ class TestPmsWizardMassiveChanges(common.SavepointCase):
"date_end_overnight": checkin, "date_end_overnight": checkin,
"compute_price": "fixed", "compute_price": "fixed",
"applied_on": "1_product", "applied_on": "1_product",
"product_tmpl_id": product_tmpl_id, "product_tmpl_id": product_tmpl.id,
"fixed_price": price_today, "fixed_price": price_today,
"min_quantity": 0, "min_quantity": 0,
"pms_property_ids": product_tmpl.pms_property_ids.ids,
} }
) )
pricelist_item.flush() pricelist_item.flush()

View File

@@ -8,6 +8,7 @@
<group> <group>
<field name="amount" /> <field name="amount" />
<field name="board_service_line_ids"> <field name="board_service_line_ids">
<field name="pms_property_ids" invisible="1" />
<tree editable="bottom"> <tree editable="bottom">
<field <field
name="pms_board_service_room_type_id" name="pms_board_service_room_type_id"
@@ -15,6 +16,7 @@
/> />
<field name="product_id" /> <field name="product_id" />
<field name="amount" /> <field name="amount" />
<field name="pms_property_ids" invisible="1" />
</tree> </tree>
</field> </field>
</group> </group>

View File

@@ -18,6 +18,7 @@
<tree editable="bottom"> <tree editable="bottom">
<field name="product_id" /> <field name="product_id" />
<field name="amount" /> <field name="amount" />
<field name="pms_property_ids" invisible="1" />
</tree> </tree>
</field> </field>
<field name="show_detail_report" /> <field name="show_detail_report" />
@@ -34,6 +35,7 @@
<field name="default_code" /> <field name="default_code" />
<field name="amount" /> <field name="amount" />
<field name="show_detail_report" /> <field name="show_detail_report" />
<field name="pms_property_ids" invisible="1" />
</tree> </tree>
</field> </field>
</record> </record>

View File

@@ -41,6 +41,7 @@
<field name="reservation_id" /> <field name="reservation_id" />
<field name="folio_id" /> <field name="folio_id" />
<field name="identifier" /> <field name="identifier" />
<field name="pms_property_id" invisible="1" />
</group> </group>
</group> </group>
</sheet> </sheet>
@@ -77,6 +78,7 @@
<field name="reservation_id" invisible="1" /> <field name="reservation_id" invisible="1" />
<field name="folio_id" force_save="1" invisible="1" /> <field name="folio_id" force_save="1" invisible="1" />
<field name="state" invisible="0" /> <field name="state" invisible="0" />
<field name="pms_property_id" invisible="1" />
</tree> </tree>
</field> </field>
</record> </record>
@@ -103,6 +105,7 @@
attrs="{'invisible': [('state','!=','precheckin')]}" attrs="{'invisible': [('state','!=','precheckin')]}"
/> />
<field name="reservation_id" /> <field name="reservation_id" />
<field name="pms_property_id" invisible="1" />
<field name="partner_id" domain="[('is_company','=', False)]" /> <field name="partner_id" domain="[('is_company','=', False)]" />
<field name="name" /> <field name="name" />
<field name="mobile" /> <field name="mobile" />
@@ -142,6 +145,7 @@
<field name="arrival" /> <field name="arrival" />
<field name="departure" /> <field name="departure" />
<field name="reservation_id" /> <field name="reservation_id" />
<field name="pms_property_id" invisible="1" />
<field name="folio_id" force_save="1" invisible="1" /> <field name="folio_id" force_save="1" invisible="1" />
<field name="state" /> <field name="state" />
</tree> </tree>
@@ -218,6 +222,10 @@
name="reservation_id" name="reservation_id"
placeholder="Room Reservation" placeholder="Room Reservation"
/> />
<field
name="pms_property_id"
invisible="1"
/>
</strong> </strong>
<span <span
t-if="record.arrival.raw_value" t-if="record.arrival.raw_value"
@@ -484,6 +492,7 @@
<field name="reservation_id" /> <field name="reservation_id" />
<field name="folio_id" /> <field name="folio_id" />
<field name="state" filters="1" /> <field name="state" filters="1" />
<field name="pms_property_id" invisible="1" />
</calendar> </calendar>
</field> </field>
</record> </record>

View File

@@ -443,6 +443,7 @@
name="cancel_discount" name="cancel_discount"
attrs="{'column_invisible': [('parent.state','!=','cancelled')]}" attrs="{'column_invisible': [('parent.state','!=','cancelled')]}"
/> />
<field name="pms_property_id" invisible="1" />
</tree> </tree>
</field> </field>
<group string="Services" name="reservation_services"> <group string="Services" name="reservation_services">

View File

@@ -65,6 +65,7 @@
<field name="pms_room_type_id" invisible="1" /> <field name="pms_room_type_id" invisible="1" />
<field name="pms_board_service_id" /> <field name="pms_board_service_id" />
<field name="amount" /> <field name="amount" />
<field name="pms_property_ids" invisible="1" />
<button <button
type="object" type="object"
class="oe_stat_button" class="oe_stat_button"

View File

@@ -11,6 +11,7 @@
<field name="channel_type" /> <field name="channel_type" />
<field name="is_on_line" /> <field name="is_on_line" />
<field name="product_pricelist_ids" widget="many2many_tags" /> <field name="product_pricelist_ids" widget="many2many_tags" />
<field name="pms_property_ids" widget="many2many_tags" />
</group> </group>
</sheet> </sheet>
</form> </form>
@@ -25,6 +26,7 @@
<field name="channel_type" /> <field name="channel_type" />
<field name="is_on_line" /> <field name="is_on_line" />
<field name="product_pricelist_ids" widget="many2many_tags" /> <field name="product_pricelist_ids" widget="many2many_tags" />
<field name="pms_property_ids" />
</tree> </tree>
</field> </field>
</record> </record>

View File

@@ -6,7 +6,6 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='applied_on']" position="before"> <xpath expr="//field[@name='applied_on']" position="before">
<field name="on_board_service" /> <field name="on_board_service" />
<field name="allowed_property_ids" invisible="1" />
<field <field
name="board_service_room_type_ids" name="board_service_room_type_ids"
widget="many2many_tags" widget="many2many_tags"

View File

@@ -64,6 +64,11 @@
<field name="is_agency" /> <field name="is_agency" />
</group> </group>
</xpath> </xpath>
<xpath expr="//field[@name='company_id']" position="after">
<group>
<field name="pms_property_ids" />
</group>
</xpath>
<xpath expr="//page[@name='internal_notes']" position="after"> <xpath expr="//page[@name='internal_notes']" position="after">
<page <page
name="agency" name="agency"

View File

@@ -9,6 +9,8 @@ class FolioWizard(models.TransientModel):
"Wizard to check availability by room type and pricelist &" "Wizard to check availability by room type and pricelist &"
" creation of folios with its reservations" " creation of folios with its reservations"
) )
_check_pms_properties_auto = True
# Fields declaration # Fields declaration
start_date = fields.Date( start_date = fields.Date(
string="From:", string="From:",
@@ -24,6 +26,7 @@ class FolioWizard(models.TransientModel):
compute="_compute_pricelist_id", compute="_compute_pricelist_id",
store=True, store=True,
readonly=False, readonly=False,
check_pms_properties=True,
) )
pms_property_id = fields.Many2one( pms_property_id = fields.Many2one(
comodel_name="pms.property", comodel_name="pms.property",
@@ -35,9 +38,11 @@ class FolioWizard(models.TransientModel):
) )
partner_id = fields.Many2one( partner_id = fields.Many2one(
"res.partner", "res.partner",
check_pms_properties=True,
) )
folio_id = fields.Many2one( folio_id = fields.Many2one(
"pms.folio", "pms.folio",
check_pms_properties=True,
) )
availability_results = fields.One2many( availability_results = fields.One2many(
comodel_name="pms.folio.availability.wizard", comodel_name="pms.folio.availability.wizard",
@@ -45,6 +50,7 @@ class FolioWizard(models.TransientModel):
compute="_compute_availability_results", compute="_compute_availability_results",
store=True, store=True,
readonly=False, readonly=False,
check_pms_properties=True,
) )
agency_id = fields.Many2one( agency_id = fields.Many2one(
string="Agency", string="Agency",

View File

@@ -41,7 +41,6 @@
name="pricelist_id" name="pricelist_id"
string="Pricelist" string="Pricelist"
required="1" required="1"
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_id)]"
options="{'no_create': True,'no_open': True}" options="{'no_create': True,'no_open': True}"
/> />
<field name="channel_type_id" /> <field name="channel_type_id" />

View File

@@ -16,6 +16,7 @@ class NumRoomsSelectionModel(models.TransientModel):
class AvailabilityWizard(models.TransientModel): class AvailabilityWizard(models.TransientModel):
_name = "pms.folio.availability.wizard" _name = "pms.folio.availability.wizard"
_check_pms_properties_auto = True
# Fields declarations # Fields declarations
folio_wizard_id = fields.Many2one( folio_wizard_id = fields.Many2one(
@@ -29,7 +30,10 @@ class AvailabilityWizard(models.TransientModel):
string="To:", string="To:",
required=True, required=True,
) )
room_type_id = fields.Many2one(comodel_name="pms.room.type") room_type_id = fields.Many2one(
comodel_name="pms.room.type",
check_pms_properties=True,
)
num_rooms_available = fields.Integer( num_rooms_available = fields.Integer(
string="Available rooms", string="Available rooms",

View File

@@ -8,6 +8,7 @@ class AvailabilityWizard(models.TransientModel):
_name = "pms.massive.changes.wizard" _name = "pms.massive.changes.wizard"
_description = "Wizard for massive changes on Availability Plans & Pricelists." _description = "Wizard for massive changes on Availability Plans & Pricelists."
_check_pms_properties_auto = True
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_id") else False
@@ -32,11 +33,13 @@ class AvailabilityWizard(models.TransientModel):
availability_plan_id = fields.Many2one( availability_plan_id = fields.Many2one(
comodel_name="pms.availability.plan", comodel_name="pms.availability.plan",
string="Availability Plan to apply massive changes", string="Availability Plan to apply massive changes",
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( pricelist_id = fields.Many2one(
comodel_name="product.pricelist", comodel_name="product.pricelist",
string="Pricelist to apply massive changes", string="Pricelist to apply massive changes",
check_pms_properties=True,
) )
allowed_pricelist_ids = fields.One2many( allowed_pricelist_ids = fields.One2many(
comodel_name="product.pricelist", compute="_compute_allowed_pricelist_ids" comodel_name="product.pricelist", compute="_compute_allowed_pricelist_ids"
@@ -49,7 +52,11 @@ class AvailabilityWizard(models.TransientModel):
string="To", string="To",
required=True, required=True,
) )
room_type_id = fields.Many2one(comodel_name="pms.room.type", string="Room Type") room_type_id = fields.Many2one(
comodel_name="pms.room.type",
string="Room Type",
check_pms_properties=True,
)
price = fields.Float(string="Price") price = fields.Float(string="Price")
min_quantity = fields.Float(string="Min. Quantity") min_quantity = fields.Float(string="Min. Quantity")

View File

@@ -50,11 +50,7 @@
'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 <field name="room_type_id" default_focus="1" />
name="room_type_id"
default_focus="1"
domain="['|', ('pms_property_ids', '=', False), ('pms_property_ids', 'in', pms_property_ids)]"
/>
</group> </group>
</div> </div>

View File

@@ -13,8 +13,18 @@ class HouseKeepingTask(models.Model):
active = fields.Boolean("Active", default=True) active = fields.Boolean("Active", default=True)
name = fields.Char("Task Name", translate=True, required=True) name = fields.Char("Task Name", translate=True, required=True)
pms_property_ids = fields.Many2many( pms_property_ids = fields.Many2many(
"pms.property", string="Properties", required=False, ondelete="restrict" string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
relation="pms_housekeepink_task_pms_property_rel",
column1="pms_housekeepink_task_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
) )
clean_type = fields.Selection( clean_type = fields.Selection(
string="Clean type", string="Clean type",
selection=[ selection=[

View File

@@ -0,0 +1 @@
../../../../multi_pms_properties

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)