@@ -577,6 +577,8 @@ frappe.ui.form.on("Payment Entry", {
577577 paid_from : function ( frm ) {
578578 if ( frm . set_party_account_based_on_party ) return ;
579579
580+ frm . events . set_company_bank_account ( frm ) ;
581+
580582 frm . events . set_account_currency_and_balance (
581583 frm ,
582584 frm . doc . paid_from ,
@@ -593,6 +595,8 @@ frappe.ui.form.on("Payment Entry", {
593595 paid_to : function ( frm ) {
594596 if ( frm . set_party_account_based_on_party ) return ;
595597
598+ frm . events . set_company_bank_account ( frm ) ;
599+
596600 frm . events . set_account_currency_and_balance (
597601 frm ,
598602 frm . doc . paid_to ,
@@ -1325,6 +1329,8 @@ frappe.ui.form.on("Payment Entry", {
13251329 } ,
13261330
13271331 bank_account : function ( frm ) {
1332+ if ( frm . set_company_bank_account_based_on_coa ) return ;
1333+
13281334 const field = frm . doc . payment_type == "Pay" ? "paid_from" : "paid_to" ;
13291335 if ( frm . doc . bank_account && [ "Pay" , "Receive" ] . includes ( frm . doc . payment_type ) ) {
13301336 frappe . call ( {
@@ -1363,6 +1369,34 @@ frappe.ui.form.on("Payment Entry", {
13631369 }
13641370 } ,
13651371
1372+ set_company_bank_account : function ( frm ) {
1373+ if ( ! [ "Pay" , "Receive" ] . includes ( frm . doc . payment_type ) ) return ;
1374+
1375+ const field = frm . doc . payment_type == "Pay" ? "paid_from" : "paid_to" ;
1376+
1377+ if ( ! frm . doc . company || ! frm . doc [ field ] ) return ;
1378+
1379+ frm . set_company_bank_account_based_on_coa = true ;
1380+
1381+ frappe . call ( {
1382+ method : "frappe.client.get_value" ,
1383+ args : {
1384+ doctype : "Bank Account" ,
1385+ filters : {
1386+ company : frm . doc . company ,
1387+ account : frm . doc [ field ] ,
1388+ disabled : 0 ,
1389+ } ,
1390+ fieldname : [ "name" ] ,
1391+ } ,
1392+ callback : async function ( r ) {
1393+ if ( r . message ) await frm . set_value ( "bank_account" , r . message . name ) ;
1394+
1395+ frm . set_company_bank_account_based_on_coa = false ;
1396+ } ,
1397+ } ) ;
1398+ } ,
1399+
13661400 sales_taxes_and_charges_template : function ( frm ) {
13671401 frm . trigger ( "fetch_taxes_from_template" ) ;
13681402 } ,
0 commit comments