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 authored and maq-adhoc committed Nov 1, 2024
1 parent efd3e44 commit 0359f1e
Show file tree
Hide file tree
Showing 41 changed files with 817 additions and 620 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
3 changes: 3 additions & 0 deletions pos_event_sale/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from . import event_event
from . import event_mail
from . import event_registration
from . import event_ticket
from . import pos_order
from . import pos_order_line
from . import pos_config
from . import pos_session
from . import res_config_settings
38 changes: 10 additions & 28 deletions pos_event_sale/models/event_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,24 @@ def _compute_pos_price_subtotal(self):
date_now = fields.Datetime.now()
sale_price_by_event = {}
if self.ids:
event_subtotals = self.env["pos.order.line"]._read_group(
line_ids = self.env["pos.order.line"].search(
[
("event_id", "in", self.ids),
("order_id.state", "!=", "cancel"),
("price_subtotal", "!=", 0),
],
["event_id", "currency_id"],
["price_subtotal:sum"],
]
)
currency_ids = [
event_subtotal["currency_id"][0] for event_subtotal in event_subtotals
]
company_by_event = {
event._origin.id or event.id: event.company_id for event in self
}
currency_by_event = {
event._origin.id or event.id: event.currency_id for event in self
}
currency_by_id = {
currency.id: currency
for currency in self.env["res.currency"].browse(currency_ids)
}
for event_subtotal in event_subtotals:
price_subtotal = event_subtotal["price_subtotal"]
event_id = event_subtotal["event_id"][0]
currency_id = event_subtotal["currency_id"][0]
sale_price = currency_by_event[event_id]._convert(
price_subtotal,
currency_by_id[currency_id],
company_by_event[event_id],
for line_id in line_ids:
sale_price = line_id.event_id.currency_id._convert(
line_id.price_subtotal,
line_id.currency_id,
line_id.event_id.company_id,
date_now,
)
if event_id in sale_price_by_event:
sale_price_by_event[event_id] += sale_price
if line_id.event_id.id in sale_price_by_event:
sale_price_by_event[line_id.event_id.id] += sale_price

Check warning on line 60 in pos_event_sale/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/event_event.py#L60

Added line #L60 was not covered by tests
else:
sale_price_by_event[event_id] = sale_price
sale_price_by_event[line_id.event_id.id] = sale_price

for rec in self:
rec.pos_price_subtotal = sale_price_by_event.get(
Expand Down
22 changes: 22 additions & 0 deletions pos_event_sale/models/event_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
##############################################################################
# Copyright (c) 2023 braintec 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 models


class EventMail(models.Model):
_inherit = "event.mail"

def _create_missing_mail_registrations(self, registrations):
"""Create mail registrations just for those partners with email.
This way we also prevent long delays in the POS, at the time of the order validation.
"""
return super()._create_missing_mail_registrations(
registrations.filtered("email")
)
2 changes: 1 addition & 1 deletion pos_event_sale/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class PosOrder(models.Model):
def _compute_event_registrations_count(self):
count = self.env["event.registration"]._read_group(

Check warning on line 23 in pos_event_sale/models/pos_order.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_order.py#L23

Added line #L23 was not covered by tests
[("pos_order_id", "in", self.ids)],
fields=["pos_order_id"],
groupby=["pos_order_id"],
aggregates=["__count"],
)
count_map = {x["pos_order_id"][0]: x["pos_order_id_count"] for x in count}
for rec in self:
Expand Down
148 changes: 148 additions & 0 deletions pos_event_sale/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
##############################################################################
# Copyright (c) 2023 braintec 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 []

Check warning on line 32 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L32

Added line #L32 was not covered by tests

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))

Check warning on line 47 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L46-L47

Added lines #L46 - L47 were not covered by tests

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))

Check warning on line 51 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L50-L51

Added lines #L50 - L51 were not covered by tests

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(

Check warning on line 60 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L60

Added line #L60 was not covered by tests
fields.Date.today(), self.config_id.iface_event_load_days_after, "days"
)
domain.append(("date_start", "<=", date_start))

Check warning on line 63 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L63

Added line #L63 was not covered by tests

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 []

Check warning on line 88 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L88

Added line #L88 was not covered by tests

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 []

Check warning on line 116 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L116

Added line #L116 was not covered by tests

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 []

Check warning on line 131 in pos_event_sale/models/pos_session.py

View check run for this annotation

Codecov / codecov/patch

pos_event_sale/models/pos_session.py#L131

Added line #L131 was not covered by tests

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
Loading

0 comments on commit 0359f1e

Please sign in to comment.