diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index ebb88c9..9994e7b 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -17,7 +17,7 @@ jobs: python-version: 3.8 - name: Install and Run Pre-commit - uses: pre-commit/action@v2.0.3 + uses: pre-commit/action@v3.0.0 - name: Download Semgrep rules run: git clone --depth 1 https://github.com/frappe/semgrep-rules.git frappe-semgrep-rules diff --git a/wallete/__init__.py b/wallete/__init__.py index 3dc1f76..485f44a 100644 --- a/wallete/__init__.py +++ b/wallete/__init__.py @@ -1 +1 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" diff --git a/wallete/public/js/custom_point_of_sale.js b/wallete/public/js/custom_point_of_sale.js index 4e01316..9fbd472 100644 --- a/wallete/public/js/custom_point_of_sale.js +++ b/wallete/public/js/custom_point_of_sale.js @@ -1,16 +1,21 @@ frappe.provide('erpnext.PointOfSale'); frappe.require('point-of-sale.bundle.js', function () { - erpnext.PointOfSale.Payment = class CustomPayment extends erpnext.PointOfSale.Payment { - constructor({ events, wrapper }) { - super({ events, wrapper }); - this.bind_event_show_customer_wallet() + const BasePayment = erpnext.PointOfSale.Payment; + erpnext.PointOfSale.Payment = class CustomPayment extends BasePayment { + constructor(options) { + super(options); + } set_customer_wallet() { // THIS IS OUR FUNCTION const pos_invoice = this.events.get_frm().doc; const customer = pos_invoice.customer; + if (!customer) { + this.customer_wallet = 0; + return Promise.resolve(); + } return new Promise((resolve) => { frappe.call({ method: "wallete.wallete.doctype.wallet.wallet.get_customer_wallet_balance", @@ -28,28 +33,34 @@ frappe.require('point-of-sale.bundle.js', function () { set_payment_modes_is_wallet() { // THIS IS OUR FUNCTION const pos_invoice = this.events.get_frm().doc; - const payments = pos_invoice.payments; + const payments = (pos_invoice.payments || []); payments.forEach(payment => { + if (!payment || !payment.mode_of_payment) return; frappe.db.get_value('Mode of Payment', payment.mode_of_payment, ["is_wallet_payment"], function (value) { - payment.is_wallet_payment = value.is_wallet_payment; + payment.is_wallet_payment = value && (value.is_wallet_payment || 0); }); - }) + }); } render_payment_mode_dom() { super.render_payment_mode_dom(); // THIS IS OUR CODE - this.set_customer_wallet(); + this.bind_event_show_customer_wallet(); this.set_payment_modes_is_wallet(); const pos_invoice = this.events.get_frm().doc; const customer = pos_invoice.customer; const currency = pos_invoice.currency; - const payments = pos_invoice.payments; - const customer_wallet = this.customer_wallet > 0 ? format_currency(this.customer_wallet, currency) : ''; + const payments = (pos_invoice.payments || []); + this.set_customer_wallet() + .then(() => { + const customer_wallet = this.customer_wallet > 0 ? format_currency(this.customer_wallet, currency) : ''; - payments.forEach(payment => { - this.attach_customer_wallet(payment, customer, customer_wallet); - }); + payments.forEach(payment => { + this.attach_customer_wallet(payment, customer, customer_wallet); + }); + }) + .catch(() => { + }); } bind_event_show_customer_wallet() { @@ -66,7 +77,7 @@ frappe.require('point-of-sale.bundle.js', function () { attach_customer_wallet(payment, customer, customer_wallet) { // THIS IS OUR FUNCTION if ( - this.customer_wallet !== undefined && this.customer_wallet > 0.0 && payment.is_wallet_payment === 1 + this.customer_wallet !== undefined && this.customer_wallet > 0.0 && !!payment.is_wallet_payment ) { this.$payment_modes.find('.customer-wallet').remove(); 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 () { } }; - wrapper.pos = new erpnext.PointOfSale.Controller(wrapper); - window.cur_pos = wrapper.pos; + + }); \ No newline at end of file