@@ -592,6 +592,8 @@ frappe.ui.form.on("Payment Entry", {
592592 paid_from : function ( frm ) {
593593 if ( frm . set_party_account_based_on_party ) return ;
594594
595+ frm . events . set_company_bank_account ( frm ) ;
596+
595597 frm . events . set_account_currency_and_balance (
596598 frm ,
597599 frm . doc . paid_from ,
@@ -609,6 +611,8 @@ frappe.ui.form.on("Payment Entry", {
609611 paid_to : function ( frm ) {
610612 if ( frm . set_party_account_based_on_party ) return ;
611613
614+ frm . events . set_company_bank_account ( frm ) ;
615+
612616 frm . events . set_account_currency_and_balance (
613617 frm ,
614618 frm . doc . paid_to ,
@@ -1350,6 +1354,8 @@ frappe.ui.form.on("Payment Entry", {
13501354 } ,
13511355
13521356 bank_account : function ( frm ) {
1357+ if ( frm . set_company_bank_account_based_on_coa ) return ;
1358+
13531359 const field = frm . doc . payment_type == "Pay" ? "paid_from" : "paid_to" ;
13541360 if ( frm . doc . bank_account && [ "Pay" , "Receive" ] . includes ( frm . doc . payment_type ) ) {
13551361 frappe . call ( {
@@ -1388,6 +1394,34 @@ frappe.ui.form.on("Payment Entry", {
13881394 }
13891395 } ,
13901396
1397+ set_company_bank_account : function ( frm ) {
1398+ if ( ! [ "Pay" , "Receive" ] . includes ( frm . doc . payment_type ) ) return ;
1399+
1400+ const field = frm . doc . payment_type == "Pay" ? "paid_from" : "paid_to" ;
1401+
1402+ if ( ! frm . doc . company || ! frm . doc [ field ] ) return ;
1403+
1404+ frm . set_company_bank_account_based_on_coa = true ;
1405+
1406+ frappe . call ( {
1407+ method : "frappe.client.get_value" ,
1408+ args : {
1409+ doctype : "Bank Account" ,
1410+ filters : {
1411+ company : frm . doc . company ,
1412+ account : frm . doc [ field ] ,
1413+ disabled : 0 ,
1414+ } ,
1415+ fieldname : [ "name" ] ,
1416+ } ,
1417+ callback : async function ( r ) {
1418+ if ( r . message ) await frm . set_value ( "bank_account" , r . message . name ) ;
1419+
1420+ frm . set_company_bank_account_based_on_coa = false ;
1421+ } ,
1422+ } ) ;
1423+ } ,
1424+
13911425 sales_taxes_and_charges_template : function ( frm ) {
13921426 frm . trigger ( "fetch_taxes_from_template" ) ;
13931427 } ,
0 commit comments