Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Несколько исправлений различных модулей #8

Open
wants to merge 2 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pos_event_registration/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
"event_sale",
],
"data": ["views/product_view.xml"],
"assets": {
"point_of_sale._assets_pos": [
"pos_event_registration/static/src/**/*",
],
},
}
1 change: 1 addition & 0 deletions pos_event_registration/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import product_template
from . import pos_order
from . import pos_session
10 changes: 10 additions & 0 deletions pos_event_registration/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import models


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

def _loader_params_product_product(self):
res = super()._loader_params_product_product()
res["search_params"]["fields"].append("has_pos_event_ticket")
return res
16 changes: 16 additions & 0 deletions pos_event_registration/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ class ProductTemplate(models.Model):
string="Linked Event Ticket",
help="When customer buys this product in POS, he is automatically registered as attendee with given ticket", # noqa: E501
)
has_pos_event_ticket = fields.Boolean(
compute="_compute_has_pos_event_ticket", store=False
)

@api.depends("pos_event_ticket")
def _compute_has_pos_event_ticket(self):
self.env.cr.execute(
"""
SELECT array_agg(id)
FROM product_template
WHERE pos_event_ticket IS NOT NULL
"""
)
has_pos_event_ticket_ids = set(self.env.cr.fetchone()[0] or [])
for record in self:
record.has_pos_event_ticket = record.id in has_pos_event_ticket_ids

@api.onchange("pos_event")
def _onchange_pos_event(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/** @odoo-module */

import {ErrorPopup} from "@point_of_sale/app/errors/popups/error_popup";
import {PaymentScreen} from "@point_of_sale/app/screens/payment_screen/payment_screen";
import {_t} from "@web/core/l10n/translation";
import {patch} from "@web/core/utils/patch";

patch(PaymentScreen.prototype, {
async _isOrderValid(isForceValidate) {
if (this.currentOrder.has_pos_event_tickets()) {
const partner = this.currentOrder.get_partner();

if (!partner) {
await this.popup.add(ErrorPopup, {
title: _t("Unknown customer"),
body: _t(
"You cannot sell a ticket with unselected customer. Create / Select customer first."
),
});
return false;
} else if (!partner.email) {
await this.popup.add(ErrorPopup, {
title: _t("Customers email is not set"),
body: _t(
"You cannot sell a ticket to a customer with unspecified email."
),
});
return false;
}

if (this.currentOrder.check_for_multiple_tickets()) {
await this.popup.add(ErrorPopup, {
title: _t("Multiple tickets per customer"),
body: _t(
"Unable to buy several tickets on the same event for the same partner."
),
});
return false;
}
}

return await super._isOrderValid(isForceValidate);
},
});
31 changes: 31 additions & 0 deletions pos_event_registration/static/src/app/store/models.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @odoo-module */

import {Order} from "@point_of_sale/app/store/models";
import {patch} from "@web/core/utils/patch";

patch(Order.prototype, {
has_pos_event_tickets: function () {
return this.orderlines.find((ol) => ol.product.has_pos_event_ticket);
},

check_for_multiple_tickets() {
const orderlines = this.orderlines;
const ticket_products = new Set(
orderlines
.filter((o) => o.product.has_pos_event_ticket)
.map((o) => o.product.id)
);
for (const pr_id of ticket_products) {
const same_product_lines = orderlines.filter(
(ol) => ol.product.id === pr_id
);
if (
same_product_lines.length > 1 ||
(same_product_lines.length === 1 && same_product_lines[0].quantity > 1)
) {
return true;
}
}
return false;
},
});
8 changes: 7 additions & 1 deletion pos_partner_deselection/static/src/js/partner_deselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ odoo.define("pos_partner_deselection.partner_deselection", [], function (require
},

setupCustomerDeselection(interval) {
setTimeout(() => {
if (this.partner_deselect_timer) {
clearTimeout(this.partner_deselect_timer);
}
this.partner_deselect_timer = setTimeout(() => {
if (!this.finalized) {
this.set_partner(null);
}
Expand All @@ -25,8 +28,11 @@ odoo.define("pos_partner_deselection.partner_deselection", [], function (require

const customer_deselection_interval =
this.pos.config.customer_deselection_interval;

if (customer_deselection_interval && partner && !this.finalized) {
this.setupCustomerDeselection(customer_deselection_interval);
} else if (!partner && this.partner_deselect_timer) {
clearTimeout(this.partner_deselect_timer);
}
},
});
Expand Down
Loading