Skip to content

Commit 983438c

Browse files
authored
Fix: POS Render (#14)
* refactor: pass all options to super * fix: improve customer wallet handling and payment mode checks * chore: update version to 0.1.1 * Upgrade pre-commit action to version 3.0.0
1 parent a34d0d7 commit 983438c

3 files changed

Lines changed: 29 additions & 18 deletions

File tree

.github/workflows/linters.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
python-version: 3.8
1818

1919
- name: Install and Run Pre-commit
20-
uses: pre-commit/action@v2.0.3
20+
uses: pre-commit/action@v3.0.0
2121

2222
- name: Download Semgrep rules
2323
run: git clone --depth 1 https://github.com/frappe/semgrep-rules.git frappe-semgrep-rules

wallete/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.1.0"
1+
__version__ = "0.1.1"

wallete/public/js/custom_point_of_sale.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
frappe.provide('erpnext.PointOfSale');
22
frappe.require('point-of-sale.bundle.js', function () {
33

4-
erpnext.PointOfSale.Payment = class CustomPayment extends erpnext.PointOfSale.Payment {
5-
constructor({ events, wrapper }) {
6-
super({ events, wrapper });
7-
this.bind_event_show_customer_wallet()
4+
const BasePayment = erpnext.PointOfSale.Payment;
5+
erpnext.PointOfSale.Payment = class CustomPayment extends BasePayment {
6+
constructor(options) {
7+
super(options);
8+
89
}
910

1011
set_customer_wallet() {
1112
// THIS IS OUR FUNCTION
1213
const pos_invoice = this.events.get_frm().doc;
1314
const customer = pos_invoice.customer;
15+
if (!customer) {
16+
this.customer_wallet = 0;
17+
return Promise.resolve();
18+
}
1419
return new Promise((resolve) => {
1520
frappe.call({
1621
method: "wallete.wallete.doctype.wallet.wallet.get_customer_wallet_balance",
@@ -28,28 +33,34 @@ frappe.require('point-of-sale.bundle.js', function () {
2833
set_payment_modes_is_wallet() {
2934
// THIS IS OUR FUNCTION
3035
const pos_invoice = this.events.get_frm().doc;
31-
const payments = pos_invoice.payments;
36+
const payments = (pos_invoice.payments || []);
3237
payments.forEach(payment => {
38+
if (!payment || !payment.mode_of_payment) return;
3339
frappe.db.get_value('Mode of Payment', payment.mode_of_payment, ["is_wallet_payment"], function (value) {
34-
payment.is_wallet_payment = value.is_wallet_payment;
40+
payment.is_wallet_payment = value && (value.is_wallet_payment || 0);
3541
});
36-
})
42+
});
3743
}
3844

3945
render_payment_mode_dom() {
4046
super.render_payment_mode_dom();
4147
// THIS IS OUR CODE
42-
this.set_customer_wallet();
48+
this.bind_event_show_customer_wallet();
4349
this.set_payment_modes_is_wallet();
4450
const pos_invoice = this.events.get_frm().doc;
4551
const customer = pos_invoice.customer;
4652
const currency = pos_invoice.currency;
47-
const payments = pos_invoice.payments;
48-
const customer_wallet = this.customer_wallet > 0 ? format_currency(this.customer_wallet, currency) : '';
53+
const payments = (pos_invoice.payments || []);
54+
this.set_customer_wallet()
55+
.then(() => {
56+
const customer_wallet = this.customer_wallet > 0 ? format_currency(this.customer_wallet, currency) : '';
4957

50-
payments.forEach(payment => {
51-
this.attach_customer_wallet(payment, customer, customer_wallet);
52-
});
58+
payments.forEach(payment => {
59+
this.attach_customer_wallet(payment, customer, customer_wallet);
60+
});
61+
})
62+
.catch(() => {
63+
});
5364
}
5465

5566
bind_event_show_customer_wallet() {
@@ -66,7 +77,7 @@ frappe.require('point-of-sale.bundle.js', function () {
6677
attach_customer_wallet(payment, customer, customer_wallet) {
6778
// THIS IS OUR FUNCTION
6879
if (
69-
this.customer_wallet !== undefined && this.customer_wallet > 0.0 && payment.is_wallet_payment === 1
80+
this.customer_wallet !== undefined && this.customer_wallet > 0.0 && !!payment.is_wallet_payment
7081
) {
7182
this.$payment_modes.find('.customer-wallet').remove();
7283
this.$payment_modes.find(`[data-payment-type="${payment.type}"]`).find('.mode-of-payment-control')
@@ -76,6 +87,6 @@ frappe.require('point-of-sale.bundle.js', function () {
7687
}
7788
};
7889

79-
wrapper.pos = new erpnext.PointOfSale.Controller(wrapper);
80-
window.cur_pos = wrapper.pos;
90+
91+
8192
});

0 commit comments

Comments
 (0)