Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion wallete/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.1.0"
__version__ = "0.1.1"
43 changes: 27 additions & 16 deletions wallete/public/js/custom_point_of_sale.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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() {
Expand All @@ -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')
Expand All @@ -76,6 +87,6 @@ frappe.require('point-of-sale.bundle.js', function () {
}
};

wrapper.pos = new erpnext.PointOfSale.Controller(wrapper);
window.cur_pos = wrapper.pos;


});
Loading