perf: reduce number of queries to get party link

This commit is contained in:
Saqib Ansari 2021-08-25 20:15:23 +05:30
parent a2f8d6c31a
commit 7254368fc5

View File

@ -1375,9 +1375,12 @@ class AccountsController(TransactionBase):
def get_common_party_link(self): def get_common_party_link(self):
party_type, party = self.get_party() party_type, party = self.get_party()
party_link = frappe.db.exists('Party Link', {'secondary_role': party_type, 'secondary_party': party}) return frappe.db.get_value(
if party_link: doctype='Party Link',
return frappe.db.get_value('Party Link', party_link, ['primary_role', 'primary_party'], as_dict=True) filters={'secondary_role': party_type, 'secondary_party': party},
fieldname=['primary_role', 'primary_party'],
as_dict=True
)
def create_advance_and_reconcile(self, party_link): def create_advance_and_reconcile(self, party_link):
secondary_party_type, secondary_party = self.get_party() secondary_party_type, secondary_party = self.get_party()