Skip to content

Commit

Permalink
[16.0][MIG] pos_event_sale: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BT-dmoreno committed Jul 6, 2023
1 parent 84d65f2 commit fad2db1
Show file tree
Hide file tree
Showing 31 changed files with 738 additions and 587 deletions.
4 changes: 1 addition & 3 deletions pos_event_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"views/event_registration.xml",
"views/event_event.xml",
"views/pos_order.xml",
"views/pos_config.xml",
"views/res_config_settings.xml",
],
"assets": {
"point_of_sale.assets": [
Expand All @@ -29,8 +29,6 @@
"web/static/lib/fullcalendar/interaction/main.js",
"pos_event_sale/static/src/js/**/*.js",
"pos_event_sale/static/src/scss/**/*.scss",
],
"web.assets_qweb": [
"pos_event_sale/static/src/xml/**/*.xml",
],
"web.assets_tests": [
Expand Down
2 changes: 2 additions & 0 deletions pos_event_sale/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
from . import pos_order
from . import pos_order_line
from . import pos_config
from . import pos_session
from . import res_config_settings
147 changes: 147 additions & 0 deletions pos_event_sale/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
##############################################################################
# Copyright (c) 2023 brain-tec AG (https://braintec.com)
# All Rights Reserved
#
# Licensed under the AGPL-3.0 (http://www.gnu.org/licenses/agpl.html).
# See LICENSE file for full licensing details.
##############################################################################
from odoo import api, fields, models
from odoo.tools import date_utils


class PosSession(models.Model):
_inherit = "pos.session"

@api.model
def _pos_ui_models_to_load(self):
models_to_load = super()._pos_ui_models_to_load()
models_to_load.extend(
[
"event.event",
"event.event.ticket",
"event.tag.category",
"event.tag",
]
)
return models_to_load

def _get_pos_ui_event_event(self, params):
if self.config_id.iface_event_sale:
return self.env["event.event"].search_read(**params["search_params"])
return []

def _loader_params_event_event(self):
domain = [
("company_id", "in", (False, self.config_id.company_id[0].id)),
("event_ticket_ids.product_id.active", "=", True),
("event_ticket_ids.available_in_pos", "=", True),
]

if self.config_id.iface_available_event_stage_ids:
event_stage_ids = self.config_id.iface_available_event_stage_ids
domain.append(("stage_id", "in", event_stage_ids.ids))

if self.config_id.iface_available_event_type_ids:
event_type_ids = self.config_id.iface_available_event_type_ids
domain.append(("event_type_id", "in", event_type_ids))

if self.config_id.iface_available_event_tag_ids:
event_tag_ids = self.config_id.iface_available_event_tag_ids
domain.append(("tag_ids", "in", event_tag_ids))

if self.config_id.iface_event_load_days_before >= 0:
date_end = date_utils.subtract(
fields.Date.today(), self.config_id.iface_event_load_days_before, "days"
)
domain.append(("date_end", ">=", date_end))

if self.config_id.iface_event_load_days_after >= 0:
date_start = date_utils.add(
fields.Date.today(), self.config_id.iface_event_load_days_after, "days"
)
domain.append(("date_start", "<=", date_start))

fields_list = [
"name",
"display_name",
"event_type_id",
"tag_ids",
"country_id",
"date_begin",
"date_end",
"date_tz",
"seats_limited",
"seats_available",
]

return {
"search_params": {
"domain": domain,
"fields": fields_list,
},
}

def _get_pos_ui_event_event_ticket(self, params):
if self.config_id.iface_event_sale:
return self.env["event.event.ticket"].search_read(**params["search_params"])
return []

def _loader_params_event_event_ticket(self):
domain = [
("product_id.active", "=", True),
("available_in_pos", "=", True),
]

fields_list = [
"name",
"description",
"event_id",
"product_id",
"price",
"seats_limited",
"seats_available",
]

return {
"search_params": {
"domain": domain,
"fields": fields_list,
},
}

def _get_pos_ui_event_tag_category(self, params):
if self.config_id.iface_event_sale:
return self.env["event.tag.category"].search_read(**params["search_params"])
return []

def _loader_params_event_tag_category(self):
return {
"search_params": {
"domain": [],
"fields": [
"name",
],
},
}

def _get_pos_ui_event_tag(self, params):
if self.config_id.iface_event_sale:
return self.env["event.tag"].search_read(**params["search_params"])
return []

def _loader_params_event_tag(self):
return {
"search_params": {
"domain": [],
"fields": [
"name",
"category_id",
"color",
],
},
}

def _loader_params_product_product(self):
params = super()._loader_params_product_product()
params["search_params"]["fields"].append("detailed_type")
return params
31 changes: 31 additions & 0 deletions pos_event_sale/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2021 Camptocamp (https://www.camptocamp.com).
# @author Iván Todorovich <ivan.todorovich@camptocamp.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

pos_iface_event_sale = fields.Boolean(
related="pos_config_id.iface_event_sale", readonly=False
)
pos_iface_available_event_stage_ids = fields.Many2many(
related="pos_config_id.iface_available_event_stage_ids", readonly=False
)
pos_iface_available_event_type_ids = fields.Many2many(
related="pos_config_id.iface_available_event_type_ids", readonly=False
)
pos_iface_available_event_tag_ids = fields.Many2many(
related="pos_config_id.iface_available_event_tag_ids", readonly=False
)
pos_iface_event_seats_available_warning = fields.Integer(
related="pos_config_id.iface_event_seats_available_warning", readonly=False
)
pos_iface_event_load_days_before = fields.Integer(
related="pos_config_id.iface_event_load_days_before", readonly=False
)
pos_iface_event_load_days_after = fields.Integer(
related="pos_config_id.iface_event_load_days_after", readonly=False
)
6 changes: 3 additions & 3 deletions pos_event_sale/static/src/js/ControlButtons/AddEventButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ odoo.define("pos_event_sale.AddEventButton", function (require) {

const PosComponent = require("point_of_sale.PosComponent");
const ProductScreen = require("point_of_sale.ProductScreen");
const {useListener} = require("web.custom_hooks");
const {useListener} = require("@web/core/utils/hooks");
const Registries = require("point_of_sale.Registries");

class AddEventButton extends PosComponent {
constructor() {
super(...arguments);
setup() {
super.setup();
useListener("click", this.onClick);
}
async onClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ odoo.define("pos_event_sale.EventAvailabilityBadge", function (require) {
label: this.env._t("Oversold"),
addedClasses: {"bg-danger": true},
};
} else if (seatsAvailable == 0) {
} else if (seatsAvailable === 0) {
return {
label: this.env._t("Sold out"),
addedClasses: {"bg-danger": true},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ odoo.define("pos_event_sale.EventCalendar", function (require) {

const PosComponent = require("point_of_sale.PosComponent");
const Registries = require("point_of_sale.Registries");
const {onMounted, onWillUnmount, onWillUpdateProps} = owl;

class EventCalendar extends PosComponent {
/**
* @param {Object} props.eventsByDate Mapping events to their dates.
*/
constructor() {
super(...arguments);
setup() {
super.setup();
this.eventsByDate = this.props.eventsByDate;
onMounted(this.mounted);
onWillUnmount(this.willUnmount);
onWillUpdateProps(this.willUpdateProps);
}
/**
* Documentation here: https://fullcalendar.io/docs/v4/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ odoo.define("pos_event_sale.EventFilters", function (require) {

const PosComponent = require("point_of_sale.PosComponent");
const Registries = require("point_of_sale.Registries");
const {useState} = owl.hooks;
const {useState} = owl;

class EventFilters extends PosComponent {
constructor() {
super(...arguments);
setup() {
super.setup();
this.state = useState({
filters: this.props.filters,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@
odoo.define("pos_event_sale.EventItem", function (require) {
"use strict";

const {useState} = owl.hooks;
const {useState} = owl;
const PosComponent = require("point_of_sale.PosComponent");
const Registries = require("point_of_sale.Registries");
const {onWillRender} = owl;

class EventItem extends PosComponent {
/**
* @param {Object} props
* @param {Object} props.event
*/
constructor() {
super(...arguments);
setup() {
super.setup();
this.state = useState({
seatsAvailable: this.props.event.getSeatsAvailableReal(),
});
onWillRender(this.willRender);
}
willRender() {
this.state.seatsAvailable = this.props.event.getSeatsAvailableReal();
}
get disabled() {
return this.state.seatsAvailable <= 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
odoo.define("pos_event_sale.EventSelectorPopup", function (require) {
"use strict";

const {useState} = owl.hooks;
const {useListener} = require("web.custom_hooks");
const {useState} = owl;
const {useListener} = require("@web/core/utils/hooks");
const {getDatesInRange} = require("pos_event_sale.utils");
const AbstractAwaitablePopup = require("point_of_sale.AbstractAwaitablePopup");
const Registries = require("point_of_sale.Registries");
const {onWillStart} = owl;

class EventSelectorPopup extends AbstractAwaitablePopup {
/**
Expand All @@ -21,8 +22,8 @@ odoo.define("pos_event_sale.EventSelectorPopup", function (require) {
* @confirmed {Boolean}
* @payload {Object} Selected event.
*/
constructor() {
super(...arguments);
setup() {
super.setup();
this.state = useState({
selectedStartDate: moment().startOf("day").toDate(),
selectedEndDate: moment().endOf("day").toDate(),
Expand All @@ -43,6 +44,7 @@ odoo.define("pos_event_sale.EventSelectorPopup", function (require) {
// Cached properties
this._events = null;
this._eventsByDate = null;
onWillStart(this.willStart);
}
/**
* @override
Expand Down Expand Up @@ -119,19 +121,13 @@ odoo.define("pos_event_sale.EventSelectorPopup", function (require) {
* @property {Array} events List of filtered events
*/
get events() {
if (this._events !== null) {
return this._events;
}
this._events = this.env.pos.db.events.filter(this._compileFilters());
return this._events;
}
/**
* @property {Object} eventsByDate Mapping of dates and filtered events
*/
get eventsByDate() {
if (this._eventsByDate !== null) {
return this._eventsByDate;
}
this._eventsByDate = {};
for (const event of this.events) {
for (const eventDate of event.getEventDates()) {
Expand Down
Loading

0 comments on commit fad2db1

Please sign in to comment.