Skip to content

Commit 5b22f64

Browse files
committed
[MIG] pos_customer_wallet_partner_is_user: Migration to 16.0
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
1 parent f4e22e2 commit 5b22f64

File tree

9 files changed

+102
-97
lines changed

9 files changed

+102
-97
lines changed

pos_customer_wallet_partner_is_user/__manifest__.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Add a field on partners that shows whether they have used customer wallet
99
functionality, and don't show some parts of customer wallet functionality
1010
to partners who haven't already used it.""",
11-
"version": "15.0.1.0.0",
11+
"version": "16.0.1.0.0",
1212
"category": "Point of Sale",
1313
"website": "https://github.com/coopiteasy/addons",
1414
"author": "Coop IT Easy SC",
@@ -21,11 +21,8 @@
2121
"excludes": [],
2222
"assets": {
2323
"point_of_sale.assets": [
24-
"pos_customer_wallet_partner_is_user/static/src/js/models.js",
25-
"pos_customer_wallet_partner_is_user/static/src/js/screens.js",
26-
],
27-
"web.assets_qweb": [
28-
"pos_customer_wallet_partner_is_user/static/src/xml/pos.xml",
24+
"pos_customer_wallet_partner_is_user/static/src/js/**/*.js",
25+
"pos_customer_wallet_partner_is_user/static/src/xml/**/*.xml",
2926
],
3027
},
3128
"data": [

pos_customer_wallet_partner_is_user/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
#
33
# SPDX-License-Identifier: AGPL-3.0-or-later
44

5+
from . import pos_session
56
from . import res_partner
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2023 Coop IT Easy SC
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from odoo import models
6+
7+
8+
class PosSession(models.Model):
9+
_inherit = "pos.session"
10+
11+
def _loader_params_res_partner(self):
12+
result = super()._loader_params_res_partner()
13+
result["search_params"]["fields"].append("is_customer_wallet_user")
14+
return result

pos_customer_wallet_partner_is_user/models/res_partner.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@
88
class Partner(models.Model):
99
_inherit = "res.partner"
1010

11-
is_customer_wallet_user = fields.Boolean(
12-
string="Is Customer Wallet User",
13-
)
11+
is_customer_wallet_user = fields.Boolean(default=False)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
odoo.define("pos_customer_wallet_partner_is_user.PaymentScreen", function (require) {
2+
"use strict";
3+
const PaymentScreen = require("point_of_sale.PaymentScreen");
4+
5+
const Registries = require("point_of_sale.Registries");
6+
7+
const IsUserPaymentScreen = (PaymentScreen_) =>
8+
class extends PaymentScreen_ {
9+
/* eslint-disable no-unused-vars */
10+
/**
11+
* Overload function.
12+
*
13+
* - If partner hasn't enabled functionality, don't allow wallet payments.
14+
*
15+
* @param {Boolean} isForceValidate - Passed to super.
16+
* @returns {Boolean} Whether the order is valid.
17+
*/
18+
async validateOrder(isForceValidate) {
19+
var partner = this.currentOrder.get_partner();
20+
var [payment_wallet_amount, payment_lines_qty] =
21+
this.get_amount_debit_with_customer_wallet_journal();
22+
var [product_wallet_amount, product_lines_qty] =
23+
this.get_amount_credit_with_customer_wallet_product();
24+
/* eslint-enable no-unused-vars */
25+
26+
// If the partner is not a customer wallet user, and if a customer
27+
// wallet operation is being made (via the payment method or via the
28+
// wallet product), display an error.
29+
if (
30+
(payment_lines_qty || product_lines_qty) &&
31+
partner &&
32+
!partner.is_customer_wallet_user
33+
) {
34+
this.showPopup("ErrorPopup", {
35+
title: this.env._t("Customer cannot use customer wallet"),
36+
body: this.env._t(
37+
"Customer has not enabled the usage of a customer wallet. Before the user can use this payment method, they must enable it."
38+
),
39+
});
40+
return;
41+
}
42+
43+
await super.validateOrder(...arguments);
44+
}
45+
};
46+
47+
Registries.Component.extend(PaymentScreen, IsUserPaymentScreen);
48+
49+
return IsUserPaymentScreen;
50+
});

pos_customer_wallet_partner_is_user/static/src/js/models.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
odoo.define("pos_customer_wallet_partner_is_user.models", function (require) {
55
"use strict";
66

7-
var models = require("point_of_sale.models");
7+
const {Order} = require("point_of_sale.models");
8+
const Registries = require("point_of_sale.Registries");
89

9-
models.load_fields("res.partner", ["is_customer_wallet_user"]);
10+
const WalletOrder = (Order_) =>
11+
class extends Order_ {
12+
export_for_printing() {
13+
var json = super.export_for_printing(...arguments);
14+
json.is_customer_wallet_user = this.partner.is_customer_wallet_user
15+
? this.partner
16+
: false;
17+
return json;
18+
}
19+
};
1020

11-
var order_prototype = models.Order.prototype;
12-
models.Order = models.Order.extend({
13-
export_for_printing: function () {
14-
var receipt = order_prototype.export_for_printing.apply(this);
15-
var client = this.get("client");
16-
receipt.is_customer_wallet_user = client
17-
? client.is_customer_wallet_user
18-
: null;
19-
return receipt;
20-
},
21-
});
21+
Registries.Model.extend(Order, WalletOrder);
2222
});

pos_customer_wallet_partner_is_user/static/src/js/screens.js

-44
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<!--
3+
SPDX-FileCopyrightText: 2022 Coop IT Easy SC
4+
5+
SPDX-License-Identifier: AGPL-3.0-or-later
6+
-->
7+
<templates id="template" xml:space="preserve">
8+
9+
<t
10+
t-name="OrderReceipt"
11+
t-inherit="point_of_sale.OrderReceipt"
12+
t-inherit-mode="extension"
13+
owl="1"
14+
>
15+
<xpath expr="//div[hasclass('customer-wallet-balance')]" position="attributes">
16+
<attribute name="t-if">receipt.is_customer_wallet_user</attribute>
17+
</xpath>
18+
</t>
19+
20+
</templates>

pos_customer_wallet_partner_is_user/static/src/xml/pos.xml

-31
This file was deleted.

0 commit comments

Comments
 (0)