Skip to content

Commit a4d8c27

Browse files
committed
[IMP]Added partner birthdate warning in pos.
1 parent afae91c commit a4d8c27

File tree

10 files changed

+217
-0
lines changed

10 files changed

+217
-0
lines changed

pos_partner_birthdate_warning/README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ Contributors
108108
------------
109109

110110
- Vehiana Tepuhiarii <[email protected]>
111+
- `SerpentCS <https://www.serpentcs.com>`__:
112+
113+
- Parvez Qureshi <[email protected]>
111114

112115
Maintainers
113116
-----------

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

pos_partner_birthdate_warning/static/description/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ <h1>Authors</h1>
453453
<h1>Contributors</h1>
454454
<ul class="simple">
455455
<li>Vehiana Tepuhiarii &lt;<a class="reference external" href="mailto:vehi&#64;invitu.com">vehi&#64;invitu.com</a>&gt;</li>
456+
<li><a class="reference external" href="https://www.serpentcs.com">SerpentCS</a>:<ul>
457+
<li>Parvez Qureshi &lt;<a class="reference external" href="mailto:parvez.qureshi&#64;serpentcs.com">parvez.qureshi&#64;serpentcs.com</a>&gt;</li>
458+
</ul>
459+
</li>
456460
</ul>
457461
</div>
458462
<div class="section" id="maintainers">
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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(
27+
_t("%s is under %s years old!"),
28+
partner.name,
29+
this.pos.company.age_warning
30+
),
31+
});
32+
}
33+
34+
return super.clickPartner(partner);
35+
},
36+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 =
27+
now.month > birthDate.month ||
28+
(now.month === birthDate.month && now.day >= birthDate.day);
29+
if (!hasBirthdayPassed) {
30+
age--;
31+
}
32+
return age;
33+
},
34+
35+
/**
36+
* Check if the partner is underage based on the company's age warning threshold.
37+
*
38+
* @param {Object} partner - The partner object.
39+
* @returns {Boolean} - True if the partner is underage, otherwise false.
40+
*/
41+
isUnderagePartner(partner) {
42+
if (!partner || !partner.birthdate_date) return false;
43+
return (
44+
this.evaluatePartnerAge(partner.birthdate_date) <= this.company.age_warning
45+
);
46+
},
47+
48+
/**
49+
* Get the partner's age as a formatted string.
50+
*
51+
* @param {Object} partner - The partner object.
52+
* @returns {String} - Formatted age string, e.g., "(25 y)".
53+
*/
54+
formatPartnerAge(partner) {
55+
if (!partner || !partner.birthdate_date) return "";
56+
return sprintf(_t("(%s y)"), this.evaluatePartnerAge(partner.birthdate_date));
57+
},
58+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates id="template" xml:space="preserve">
3+
<t
4+
t-name="ActionpadWidget"
5+
t-inherit="point_of_sale.ActionpadWidget"
6+
t-inherit-mode="extension"
7+
>
8+
<xpath expr="//div[@t-if='props.partner']" position="replace">
9+
<div
10+
t-if="props.partner"
11+
t-attf-class="{{pos.isUnderagePartner(props.partner) ? 'text-danger' : ' text-action'}}"
12+
class="text-truncate fw-bolder"
13+
>
14+
<t t-esc="props.partner.name" />
15+
<t t-if="pos.formatPartnerAge(props.partner)">
16+
<t t-esc="pos.formatPartnerAge(props.partner)" />
17+
</t>
18+
</div>
19+
</xpath>
20+
</t>
21+
</templates>

0 commit comments

Comments
 (0)