mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pos_pms_link:
- Adds allowed properties field. - Adds context to force sudo on search_read methdos to bypass user rights on pos. - Forces sudo on to set pms_reservation_id on pos.order and to create services in pos.order.line.
This commit is contained in:
@@ -21,4 +21,7 @@
|
||||
from . import pos_order
|
||||
from . import pms_service_line
|
||||
from . import pos_config
|
||||
from . import pos_payment
|
||||
from . import pos_payment
|
||||
from . import pms_reservation
|
||||
from . import pms_service
|
||||
from . import product_pricelist
|
||||
31
pos_pms_link/models/pms_reservation.py
Normal file
31
pos_pms_link/models/pms_reservation.py
Normal file
@@ -0,0 +1,31 @@
|
||||
##############################################################################
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
# Copyright (C) 2022 Comunitea Servicios Tecnológicos S.L. All Rights Reserved
|
||||
# Vicente Ángel Gutiérrez <vicente@comunitea.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from odoo import models, api
|
||||
|
||||
|
||||
class PMSReservation(models.Model):
|
||||
_inherit = 'pms.reservation'
|
||||
|
||||
@api.model
|
||||
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
|
||||
if self.env.context.get("pos_user_force", False):
|
||||
return super().sudo().with_context(pos_user_force=False).search_read(domain, fields, offset, limit, order)
|
||||
else:
|
||||
return super(PMSReservation, self).search_read(domain, fields, offset, limit, order)
|
||||
30
pos_pms_link/models/pms_service.py
Normal file
30
pos_pms_link/models/pms_service.py
Normal file
@@ -0,0 +1,30 @@
|
||||
##############################################################################
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
# Copyright (C) 2022 Comunitea Servicios Tecnológicos S.L. All Rights Reserved
|
||||
# Vicente Ángel Gutiérrez <vicente@comunitea.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from odoo import models, api
|
||||
|
||||
class PMSService(models.Model):
|
||||
_inherit = 'pms.service'
|
||||
|
||||
@api.model
|
||||
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
|
||||
if self.env.context.get("pos_user_force", False):
|
||||
return super().sudo().with_context(pos_user_force=False).search_read(domain, fields, offset, limit, order)
|
||||
else:
|
||||
return super(PMSService, self).search_read(domain, fields, offset, limit, order)
|
||||
@@ -31,3 +31,10 @@ class PMSServiceLine(models.Model):
|
||||
comodel_name="pos.order.line",
|
||||
inverse_name="pms_service_line_id",
|
||||
)
|
||||
|
||||
@api.model
|
||||
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
|
||||
if self.env.context.get("pos_user_force", False):
|
||||
return super().sudo().with_context(pos_user_force=False).search_read(domain, fields, offset, limit, order)
|
||||
else:
|
||||
return super(PMSServiceLine, self).search_read(domain, fields, offset, limit, order)
|
||||
|
||||
@@ -31,3 +31,11 @@ class PosConfig(models.Model):
|
||||
|
||||
pay_on_reservation = fields.Boolean('Pay on reservation', default=False)
|
||||
pay_on_reservation_method_id = fields.Many2one('pos.payment.method', string='Pay on reservation method')
|
||||
reservation_allowed_propertie_ids = fields.Many2many('pms.property', string='Reservation allowed properties')
|
||||
|
||||
@api.model
|
||||
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
|
||||
if self.env.context.get("pos_user_force", False):
|
||||
return super().sudo().with_context(pos_user_force=False).search_read(domain, fields, offset, limit, order)
|
||||
else:
|
||||
return super(PosConfig, self).search_read(domain, fields, offset, limit, order)
|
||||
|
||||
@@ -59,17 +59,19 @@ class PosOrder(models.Model):
|
||||
def _process_order(self, pos_order, draft, existing_order):
|
||||
data = pos_order.get('data', False)
|
||||
if data and data.get("paid_on_reservation", False) and data.get("pms_reservation_id", False):
|
||||
res = super()._process_order(pos_order, draft, existing_order)
|
||||
pms_reservation_id = data.pop('pms_reservation_id')
|
||||
res = super(PosOrder, self)._process_order(pos_order, draft, existing_order)
|
||||
order_id = self.env['pos.order'].browse(res)
|
||||
order_id.add_order_lines_to_reservation(data.get("pms_reservation_id"))
|
||||
pms_reservation_id = self.sudo().env['pms.reservation'].browse(pms_reservation_id)
|
||||
if not pms_reservation_id:
|
||||
raise UserError(_("Reservation does not exists."))
|
||||
order_id.pms_reservation_id = pms_reservation_id.id
|
||||
order_id.add_order_lines_to_reservation(pms_reservation_id)
|
||||
return res
|
||||
else:
|
||||
return super()._process_order(pos_order, draft, existing_order)
|
||||
|
||||
def add_order_lines_to_reservation(self, reservation_id):
|
||||
pms_reservation_id = self.env['pms.reservation'].browse(reservation_id)
|
||||
if not pms_reservation_id:
|
||||
raise UserError(_("Reservation does not exists."))
|
||||
def add_order_lines_to_reservation(self, pms_reservation_id):
|
||||
self.lines.filtered(lambda x: not x.pms_service_line_id)._generate_pms_service(pms_reservation_id)
|
||||
|
||||
class PosOrderLine(models.Model):
|
||||
@@ -96,7 +98,7 @@ class PosOrderLine(models.Model):
|
||||
)
|
||||
],
|
||||
}
|
||||
service = self.env["pms.service"].create(vals)
|
||||
service = self.sudo().env["pms.service"].create(vals)
|
||||
|
||||
line.write({
|
||||
'pms_service_line_id': service.service_line_ids.id
|
||||
|
||||
40
pos_pms_link/models/product_pricelist.py
Normal file
40
pos_pms_link/models/product_pricelist.py
Normal file
@@ -0,0 +1,40 @@
|
||||
##############################################################################
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
# Copyright (C) 2022 Comunitea Servicios Tecnológicos S.L. All Rights Reserved
|
||||
# Vicente Ángel Gutiérrez <vicente@comunitea.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from odoo import models, api
|
||||
|
||||
class ProductPricelist(models.Model):
|
||||
_inherit = 'product.pricelist'
|
||||
|
||||
@api.model
|
||||
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
|
||||
if self.env.context.get("pos_user_force", False):
|
||||
return super().sudo().with_context(pos_user_force=False).search_read(domain, fields, offset, limit, order)
|
||||
else:
|
||||
return super(ProductPricelist, self).search_read(domain, fields, offset, limit, order)
|
||||
|
||||
class ProductPricelistItem(models.Model):
|
||||
_inherit = 'product.pricelist.item'
|
||||
|
||||
@api.model
|
||||
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None):
|
||||
if self.env.context.get("pos_user_force", False):
|
||||
return super().sudo().with_context(pos_user_force=False).search_read(domain, fields, offset, limit, order)
|
||||
else:
|
||||
return super(ProductPricelistItem, self).search_read(domain, fields, offset, limit, order)
|
||||
@@ -29,6 +29,7 @@ odoo.define('pos_pms_link.models', function (require) {
|
||||
var core = require('web.core');
|
||||
const { Gui } = require('point_of_sale.Gui');
|
||||
var QWeb = core.qweb;
|
||||
const session = require('web.session');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
@@ -276,18 +277,32 @@ odoo.define('pos_pms_link.models', function (require) {
|
||||
models.load_models({
|
||||
model: 'pms.reservation',
|
||||
fields: ['name', 'id', 'state', 'service_ids', 'partner_name', 'adults', 'children'],
|
||||
context: function(self){
|
||||
var ctx_copy = session.user_context
|
||||
ctx_copy['pos_user_force'] = true;
|
||||
return ctx_copy;
|
||||
},
|
||||
domain: function(self){
|
||||
return [['state', '=', 'onboard']];
|
||||
var domain = [
|
||||
['state', '!=', 'cancel']
|
||||
];
|
||||
if (self.config_id && self.config.reservation_allowed_propertie_ids) domain.push(['pms_property_id', 'in', self.config.reservation_allowed_propertie_ids]);
|
||||
return domain;
|
||||
},
|
||||
loaded: function(self, reservations) {
|
||||
self.reservations = reservations;
|
||||
self.db.add_reservations(reservations);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
models.load_models({
|
||||
model: 'pms.service',
|
||||
fields: ['name', 'id', 'service_line_ids', 'product_id', 'reservation_id'],
|
||||
context: function(self){
|
||||
var ctx_copy = session.user_context
|
||||
ctx_copy['pos_user_force'] = true;
|
||||
return ctx_copy;
|
||||
},
|
||||
domain: function(self){
|
||||
return [['reservation_id', 'in', self.reservations.map(x => x.id)]];
|
||||
},
|
||||
@@ -307,6 +322,11 @@ odoo.define('pos_pms_link.models', function (require) {
|
||||
models.load_models({
|
||||
model: 'pms.service.line',
|
||||
fields: ['date', 'service_id', 'id', 'product_id', 'day_qty', 'pos_order_line_ids'],
|
||||
context: function(self){
|
||||
var ctx_copy = session.user_context
|
||||
ctx_copy['pos_user_force'] = true;
|
||||
return ctx_copy;
|
||||
},
|
||||
domain: function(self){
|
||||
return [['service_id', 'in', self.services.map(x => x.id)]];
|
||||
},
|
||||
@@ -351,4 +371,36 @@ odoo.define('pos_pms_link.models', function (require) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
var existing_models = models.PosModel.prototype.models;
|
||||
var pos_index = _.findIndex(existing_models, function (model) {
|
||||
return model.model === "pos.config";
|
||||
});
|
||||
var pos_model = existing_models[pos_index];
|
||||
var ctx_copy = session.user_context
|
||||
ctx_copy['pos_user_force'] = true;
|
||||
|
||||
models.load_models([{
|
||||
model: pos_model.model,
|
||||
fields: pos_model.fields,
|
||||
condition: pos_model.condition,
|
||||
domain: pos_model.domain,
|
||||
context: ctx_copy,
|
||||
loaded: pos_model.loaded,
|
||||
}]);
|
||||
|
||||
var pli_index = _.findIndex(existing_models, function (model) {
|
||||
return model.model === "product.pricelist.item";
|
||||
});
|
||||
var pli_model = existing_models[pli_index];
|
||||
|
||||
models.load_models([{
|
||||
model: pli_model.model,
|
||||
fields: pli_model.fields,
|
||||
condition: pli_model.condition,
|
||||
domain: pli_model.domain,
|
||||
context: ctx_copy,
|
||||
loaded: pli_model.loaded,
|
||||
}]);
|
||||
|
||||
});
|
||||
|
||||
@@ -13,14 +13,22 @@
|
||||
<div class="o_setting_left_pane">
|
||||
<field name="pay_on_reservation"/>
|
||||
</div>
|
||||
<div class="o_setting_right_pane">
|
||||
<div class="o_setting_right_pane" attrs="{'invisible': [('pay_on_reservation', '=', False)]}">
|
||||
<label for="pay_on_reservation"/>
|
||||
<div class="text-muted">
|
||||
Allow pay on reservations
|
||||
</div>
|
||||
<div class="content-group mt16" attrs="{'invisible': [('pay_on_reservation', '=', False)]}">
|
||||
<div class="content-group mt16">
|
||||
<field name="pay_on_reservation_method_id"/>
|
||||
</div>
|
||||
|
||||
<label for="pay_on_reservation"/>
|
||||
<div class="text-muted">
|
||||
Allowed properties
|
||||
</div>
|
||||
<div class="content-group mt16">
|
||||
<field name="reservation_allowed_propertie_ids" widget="many2many_tags"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
|
||||
Reference in New Issue
Block a user