Skip to content

Commit 096d74b

Browse files
committed
[IMP]Added partner birthdate warning in pos.
1 parent 6022990 commit 096d74b

File tree

8 files changed

+198
-0
lines changed

8 files changed

+198
-0
lines changed

pos_partner_birthdate_warning/__manifest__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@
1313
"data": [
1414
"views/res_config_settings.xml",
1515
],
16+
"assets": {
17+
"point_of_sale._assets_pos": [
18+
"pos_partner_birthdate_warning/static/src/xml/actionpad_widget.xml",
19+
"pos_partner_birthdate_warning/static/src/js/PartnerListScreen.esm.js",
20+
"pos_partner_birthdate_warning/static/src/js/pos_store.esm.js"
21+
]
22+
},
1623
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * pos_partner_birthdate_warning
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 17.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2025-03-18 10:40+0000\n"
10+
"PO-Revision-Date: 2025-03-18 10:40+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: pos_partner_birthdate_warning
19+
#. odoo-javascript
20+
#: code:addons/pos_partner_birthdate_warning/static/src/js/PartnerListScreen.esm.js:0
21+
#, python-format
22+
msgid "%s is under %s years old!"
23+
msgstr ""
24+
25+
#. module: pos_partner_birthdate_warning
26+
#. odoo-javascript
27+
#: code:addons/pos_partner_birthdate_warning/static/src/js/pos_store.esm.js:0
28+
#, python-format
29+
msgid "(%s y)"
30+
msgstr "(%s a)"
31+
32+
#. module: pos_partner_birthdate_warning
33+
#. odoo-javascript
34+
#: code:addons/pos_partner_birthdate_warning/static/src/js/PartnerListScreen.esm.js:0
35+
#, python-format
36+
msgid "Age Restriction"
37+
msgstr ""
38+
39+
#. module: pos_partner_birthdate_warning
40+
#: model:ir.model.fields,field_description:pos_partner_birthdate_warning.field_res_company__age_warning
41+
#: model:ir.model.fields,field_description:pos_partner_birthdate_warning.field_res_config_settings__age_warning
42+
msgid "Age Warning"
43+
msgstr ""
44+
45+
#. module: pos_partner_birthdate_warning
46+
#: model_terms:ir.ui.view,arch_db:pos_partner_birthdate_warning.view_res_config_settings_birthdate_warning
47+
msgid "Age warning"
48+
msgstr ""
49+
50+
#. module: pos_partner_birthdate_warning
51+
#: model:ir.model.fields,help:pos_partner_birthdate_warning.field_res_config_settings__age_warning
52+
msgid "Choose the age max for the warning"
53+
msgstr ""
54+
55+
#. module: pos_partner_birthdate_warning
56+
#: model:ir.model,name:pos_partner_birthdate_warning.model_res_company
57+
msgid "Companies"
58+
msgstr ""
59+
60+
#. module: pos_partner_birthdate_warning
61+
#: model:ir.model,name:pos_partner_birthdate_warning.model_res_config_settings
62+
msgid "Config Settings"
63+
msgstr ""
64+
65+
#. module: pos_partner_birthdate_warning
66+
#: model_terms:ir.ui.view,arch_db:pos_partner_birthdate_warning.view_res_config_settings_birthdate_warning
67+
msgid "POS warning for customer with this age or younger."
68+
msgstr ""
69+
70+
#. module: pos_partner_birthdate_warning
71+
#: model:ir.model,name:pos_partner_birthdate_warning.model_pos_session
72+
msgid "Point of Sale Session"
73+
msgstr ""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import res_config_settings
22
from . import res_company
3+
from . import pos_session
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from odoo import models
4+
5+
6+
class POSSession(models.Model):
7+
_inherit = "pos.session"
8+
9+
def _loader_params_res_company(self):
10+
res = super()._loader_params_res_company()
11+
res["search_params"]["fields"].append("age_warning")
12+
return res
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
- Vehiana Tepuhiarii \<<[email protected]>\>
2+
- [SerpentCS](https://www.serpentcs.com):
3+
- Parvez Qureshi \<<[email protected]>\>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/** @odoo-module **/
2+
3+
import { PartnerListScreen } from "@point_of_sale/app/screens/partner_list/partner_list";
4+
import { patch } from "@web/core/utils/patch";
5+
import { _t } from "@web/core/l10n/translation";
6+
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
7+
import { sprintf } from "@web/core/utils/strings";
8+
9+
patch(PartnerListScreen.prototype, {
10+
/**
11+
* Handles partner selection in the POS.
12+
* If the selected partner is underage, displays an alert.
13+
*
14+
* @param {Object} partner - The partner object being selected.
15+
*/
16+
clickPartner(partner) {
17+
// If the same partner is selected again, proceed with the default behavior
18+
if (this.state.selectedPartner?.id === partner.id) {
19+
return super.clickPartner(partner);
20+
}
21+
22+
// Show warning if the partner is under the age restriction
23+
if (this.pos.isUnderagePartner(partner)) {
24+
this.env.services.dialog.add(AlertDialog, {
25+
title: _t("Age Restriction"),
26+
body: sprintf(_t("%s is under %s years old!"), partner.name, this.pos.company.age_warning),
27+
});
28+
}
29+
30+
return super.clickPartner(partner);
31+
},
32+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/** @odoo-module */
2+
3+
const { DateTime } = luxon;
4+
import { PosStore } from "@point_of_sale/app/store/pos_store";
5+
import { patch } from "@web/core/utils/patch";
6+
import { parseDate } from "@web/core/l10n/dates";
7+
import { _t } from "@web/core/l10n/translation";
8+
import { sprintf } from "@web/core/utils/strings";
9+
10+
patch(PosStore.prototype, {
11+
/**
12+
* Compute the partner's exact age based on birthdate.
13+
*
14+
* @param {string} birthdate_date - The birth date in string format (YYYY-MM-DD).
15+
* @returns {number} - The calculated age.
16+
*/
17+
evaluatePartnerAge(birthdate_date) {
18+
if (!birthdate_date) return 0;
19+
const birthDate = parseDate(birthdate_date);
20+
if (!birthDate.isValid) return 0; // Handle invalid dates
21+
22+
const now = DateTime.now();
23+
let age = now.year - birthDate.year;
24+
25+
// Adjust age if the birthday hasn't occurred yet this year
26+
const hasBirthdayPassed = now.month > birthDate.month ||
27+
(now.month === birthDate.month && now.day >= birthDate.day);
28+
if (!hasBirthdayPassed) {
29+
age--;
30+
}
31+
return age;
32+
},
33+
34+
/**
35+
* Check if the partner is underage based on the company's age warning threshold.
36+
*
37+
* @param {Object} partner - The partner object.
38+
* @returns {boolean} - True if the partner is underage, otherwise false.
39+
*/
40+
isUnderagePartner(partner) {
41+
if (!partner || !partner.birthdate_date) return false;
42+
return this.evaluatePartnerAge(partner.birthdate_date) <= this.company.age_warning;
43+
},
44+
45+
/**
46+
* Get the partner's age as a formatted string.
47+
*
48+
* @param {Object} partner - The partner object.
49+
* @returns {string} - Formatted age string, e.g., "(25 y)".
50+
*/
51+
formatPartnerAge(partner) {
52+
if (!partner || !partner.birthdate_date) return "";
53+
return sprintf(_t("(%s y)"), this.evaluatePartnerAge(partner.birthdate_date));
54+
},
55+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates id="template" xml:space="preserve">
3+
<t t-name="ActionpadWidget" t-inherit="point_of_sale.ActionpadWidget" t-inherit-mode="extension">
4+
<xpath expr="//div[@t-if='props.partner']" position="replace">
5+
<div t-if="props.partner"
6+
t-attf-class="{{pos.isUnderagePartner(props.partner) ? 'text-danger' : ' text-action'}}"
7+
class="text-truncate fw-bolder">
8+
<t t-esc="props.partner.name" />
9+
<t t-if="pos.formatPartnerAge(props.partner)">
10+
<t t-esc="pos.formatPartnerAge(props.partner)" />
11+
</t>
12+
</div>
13+
</xpath>
14+
</t>
15+
</templates>
16+

0 commit comments

Comments
 (0)