Skip to content

Commit

Permalink
[MIG] pos_customer_wallet_partner_is_user: Migration to 16.0
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Sep 18, 2023
1 parent f4e22e2 commit 5b22f64
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 97 deletions.
9 changes: 3 additions & 6 deletions pos_customer_wallet_partner_is_user/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Add a field on partners that shows whether they have used customer wallet
functionality, and don't show some parts of customer wallet functionality
to partners who haven't already used it.""",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Point of Sale",
"website": "https://github.com/coopiteasy/addons",
"author": "Coop IT Easy SC",
Expand All @@ -21,11 +21,8 @@
"excludes": [],
"assets": {
"point_of_sale.assets": [
"pos_customer_wallet_partner_is_user/static/src/js/models.js",
"pos_customer_wallet_partner_is_user/static/src/js/screens.js",
],
"web.assets_qweb": [
"pos_customer_wallet_partner_is_user/static/src/xml/pos.xml",
"pos_customer_wallet_partner_is_user/static/src/js/**/*.js",
"pos_customer_wallet_partner_is_user/static/src/xml/**/*.xml",
],
},
"data": [
Expand Down
1 change: 1 addition & 0 deletions pos_customer_wallet_partner_is_user/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from . import pos_session
from . import res_partner
14 changes: 14 additions & 0 deletions pos_customer_wallet_partner_is_user/models/pos_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2023 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import models


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

def _loader_params_res_partner(self):
result = super()._loader_params_res_partner()
result["search_params"]["fields"].append("is_customer_wallet_user")
return result
4 changes: 1 addition & 3 deletions pos_customer_wallet_partner_is_user/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
class Partner(models.Model):
_inherit = "res.partner"

is_customer_wallet_user = fields.Boolean(
string="Is Customer Wallet User",
)
is_customer_wallet_user = fields.Boolean(default=False)
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
odoo.define("pos_customer_wallet_partner_is_user.PaymentScreen", function (require) {
"use strict";
const PaymentScreen = require("point_of_sale.PaymentScreen");

const Registries = require("point_of_sale.Registries");

const IsUserPaymentScreen = (PaymentScreen_) =>
class extends PaymentScreen_ {
/* eslint-disable no-unused-vars */
/**
* Overload function.
*
* - If partner hasn't enabled functionality, don't allow wallet payments.
*
* @param {Boolean} isForceValidate - Passed to super.
* @returns {Boolean} Whether the order is valid.
*/
async validateOrder(isForceValidate) {
var partner = this.currentOrder.get_partner();
var [payment_wallet_amount, payment_lines_qty] =
this.get_amount_debit_with_customer_wallet_journal();
var [product_wallet_amount, product_lines_qty] =
this.get_amount_credit_with_customer_wallet_product();
/* eslint-enable no-unused-vars */

// If the partner is not a customer wallet user, and if a customer
// wallet operation is being made (via the payment method or via the
// wallet product), display an error.
if (
(payment_lines_qty || product_lines_qty) &&
partner &&
!partner.is_customer_wallet_user
) {
this.showPopup("ErrorPopup", {
title: this.env._t("Customer cannot use customer wallet"),
body: this.env._t(
"Customer has not enabled the usage of a customer wallet. Before the user can use this payment method, they must enable it."
),
});
return;
}

await super.validateOrder(...arguments);
}
};

Registries.Component.extend(PaymentScreen, IsUserPaymentScreen);

return IsUserPaymentScreen;
});
26 changes: 13 additions & 13 deletions pos_customer_wallet_partner_is_user/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
odoo.define("pos_customer_wallet_partner_is_user.models", function (require) {
"use strict";

var models = require("point_of_sale.models");
const {Order} = require("point_of_sale.models");
const Registries = require("point_of_sale.Registries");

models.load_fields("res.partner", ["is_customer_wallet_user"]);
const WalletOrder = (Order_) =>
class extends Order_ {
export_for_printing() {
var json = super.export_for_printing(...arguments);
json.is_customer_wallet_user = this.partner.is_customer_wallet_user
? this.partner
: false;
return json;
}
};

var order_prototype = models.Order.prototype;
models.Order = models.Order.extend({
export_for_printing: function () {
var receipt = order_prototype.export_for_printing.apply(this);
var client = this.get("client");
receipt.is_customer_wallet_user = client
? client.is_customer_wallet_user
: null;
return receipt;
},
});
Registries.Model.extend(Order, WalletOrder);
});
44 changes: 0 additions & 44 deletions pos_customer_wallet_partner_is_user/static/src/js/screens.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
SPDX-FileCopyrightText: 2022 Coop IT Easy SC
SPDX-License-Identifier: AGPL-3.0-or-later
-->
<templates id="template" xml:space="preserve">

<t
t-name="OrderReceipt"
t-inherit="point_of_sale.OrderReceipt"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//div[hasclass('customer-wallet-balance')]" position="attributes">
<attribute name="t-if">receipt.is_customer_wallet_user</attribute>
</xpath>
</t>

</templates>
31 changes: 0 additions & 31 deletions pos_customer_wallet_partner_is_user/static/src/xml/pos.xml

This file was deleted.

0 comments on commit 5b22f64

Please sign in to comment.