11frappe . provide ( 'erpnext.PointOfSale' ) ;
22frappe . 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