@@ -112,15 +112,15 @@ erpnext.payments = erpnext.stock.StockController.extend({
112
112
$ ( this . $body ) . find ( '.form-control' ) . click ( function ( ) {
113
113
me . idx = $ ( this ) . attr ( "idx" ) ;
114
114
me . set_outstanding_amount ( ) ;
115
- me . update_paid_amount ( ) ;
115
+ me . update_paid_amount ( true ) ;
116
116
} )
117
117
118
118
$ ( this . $body ) . find ( '.write_off_amount' ) . change ( function ( ) {
119
- me . write_off_amount ( flt ( $ ( this ) . val ( ) ) ) ;
119
+ me . write_off_amount ( flt ( $ ( this ) . val ( ) ) , precision ( "write_off_amount" ) ) ;
120
120
} )
121
121
122
122
$ ( this . $body ) . find ( '.change_amount' ) . change ( function ( ) {
123
- me . change_amount ( flt ( $ ( this ) . val ( ) ) ) ;
123
+ me . change_amount ( flt ( $ ( this ) . val ( ) ) , precision ( "change_amount" ) ) ;
124
124
} )
125
125
} ,
126
126
@@ -139,7 +139,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
139
139
me . payment_val += $ ( this ) . text ( ) ;
140
140
me . selected_mode . val ( format_number ( me . payment_val , 2 ) )
141
141
me . idx = me . selected_mode . attr ( "idx" )
142
- me . selected_mode . change ( )
142
+ me . update_paid_amount ( )
143
143
} )
144
144
145
145
$ ( this . $body ) . find ( '.delete-btn' ) . click ( function ( ) {
@@ -177,31 +177,29 @@ erpnext.payments = erpnext.stock.StockController.extend({
177
177
write_off_amount : function ( write_off_amount ) {
178
178
var me = this ;
179
179
180
- if ( this . frm . doc . paid_amount > 0 ) {
181
- this . frm . doc . write_off_amount = write_off_amount ;
182
- this . frm . doc . base_write_off_amount = flt ( this . frm . doc . write_off_amount * this . frm . doc . conversion_rate ,
183
- precision ( "base_write_off_amount" ) ) ;
184
- this . calculate_outstanding_amount ( false )
185
- this . show_amounts ( )
186
- }
180
+ this . frm . doc . write_off_amount = flt ( write_off_amount , precision ( "write_off_amount" ) ) ;
181
+ this . frm . doc . base_write_off_amount = flt ( this . frm . doc . write_off_amount * this . frm . doc . conversion_rate ,
182
+ precision ( "base_write_off_amount" ) ) ;
183
+ this . calculate_outstanding_amount ( false )
184
+ this . show_amounts ( )
187
185
} ,
188
186
189
187
change_amount : function ( change_amount ) {
190
188
var me = this ;
191
189
192
- this . frm . doc . change_amount = change_amount ;
190
+ this . frm . doc . change_amount = flt ( change_amount , precision ( "change_amount" ) ) ;
193
191
this . calculate_write_off_amount ( )
194
192
this . show_amounts ( )
195
193
} ,
196
194
197
- update_paid_amount : function ( ) {
195
+ update_paid_amount : function ( update_write_off ) {
198
196
var me = this ;
199
197
if ( in_list ( [ 'change_amount' , 'write_off_amount' ] , this . idx ) ) {
200
- value = flt ( me . selected_mode . val ( ) , 2 )
198
+ value = me . selected_mode . val ( ) ;
201
199
if ( me . idx == 'change_amount' ) {
202
200
me . change_amount ( value )
203
201
} else {
204
- if ( value == 0 ) {
202
+ if ( value == 0 && update_write_off ) {
205
203
value = me . frm . doc . outstanding_amount ;
206
204
}
207
205
me . write_off_amount ( value )
@@ -226,9 +224,9 @@ erpnext.payments = erpnext.stock.StockController.extend({
226
224
227
225
show_amounts : function ( ) {
228
226
var me = this ;
229
- $ ( this . $body ) . find ( ".write_off_amount" ) . val ( format_number ( this . frm . doc . write_off_amount , 2 ) ) ;
227
+ $ ( this . $body ) . find ( ".write_off_amount" ) . val ( format_number ( this . frm . doc . write_off_amount , precision ( "write_off_amount" ) ) ) ;
230
228
$ ( this . $body ) . find ( '.paid_amount' ) . text ( format_currency ( this . frm . doc . paid_amount , this . frm . doc . currency ) ) ;
231
- $ ( this . $body ) . find ( '.change_amount' ) . val ( format_number ( this . frm . doc . change_amount , 2 ) )
229
+ $ ( this . $body ) . find ( '.change_amount' ) . val ( format_number ( this . frm . doc . change_amount , precision ( "change_amount" ) ) )
232
230
$ ( this . $body ) . find ( '.outstanding_amount' ) . text ( format_currency ( this . frm . doc . outstanding_amount , this . frm . doc . currency ) )
233
231
this . update_invoice ( ) ;
234
232
}
0 commit comments