fix: Use advance account from Reconciliation document for fetching Payment Entries
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 5249f17..7012eac 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -106,6 +106,12 @@
root_type == "Asset" and self.party_type == "Supplier"
):
return
+ if self.unallocated_amount == 0:
+ for d in self.references:
+ if d.reference_doctype in ["Sales Order", "Purchase Order"]:
+ break
+ else:
+ return
liability_account = get_party_account(
self.party_type, self.party, self.company, include_advance=True
)[1]
@@ -1694,7 +1700,7 @@
@frappe.whitelist()
def get_reference_details(reference_doctype, reference_name, party_account_currency):
- total_amount = outstanding_amount = exchange_rate = None
+ total_amount = outstanding_amount = exchange_rate = account = None
ref_doc = frappe.get_doc(reference_doctype, reference_name)
company_currency = ref_doc.get("company_currency") or erpnext.get_company_currency(
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
index a40e6f2..e46c81b 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
@@ -34,7 +34,7 @@
filters: {
"company": this.frm.doc.company,
"is_group": 0,
- "root_type": (this.frm.party_type == 'Customer') ? "Liability": "Asset"
+ "root_type": this.frm.doc.party_type == 'Customer' ? "Liability": "Asset"
}
};
});
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
index e7d7f2c..e5fb3df 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
@@ -60,16 +60,7 @@
self.add_payment_entries(non_reconciled_payments)
def get_payment_entries(self):
- advance_accounts = []
- if self.party_type == "Customer":
- advance_accounts = frappe.db.get_list(
- "Account", filters={"root_type": "Liability", "company": self.company}, pluck="name"
- )
- elif self.party_type == "Supplier":
- advance_accounts = frappe.db.get_list(
- "Account", filters={"root_type": "Asset", "company": self.company}, pluck="name"
- )
- party_account = [self.receivable_payable_account] + advance_accounts
+ party_account = [self.receivable_payable_account, self.default_advance_account]
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
condition = frappe._dict(
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index dfea8e9..0f3b12b 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -33,8 +33,10 @@
from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accounting_enabled
from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account
from erpnext.buying.utils import check_on_hold_or_closed_status
-from erpnext.controllers.accounts_controller import validate_account_head
-from erpnext.controllers.accounts_controller import make_advance_liability_entry
+from erpnext.controllers.accounts_controller import (
+ check_advance_liability_entry,
+ validate_account_head,
+)
from erpnext.controllers.buying_controller import BuyingController
from erpnext.stock import get_warehouse_account_map
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
@@ -581,11 +583,14 @@
gl_entries = []
self.make_supplier_gl_entry(gl_entries)
-
- advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": self.company}, "book_advance_payments_as_liability")
- if advance_payments_as_liability:
- for advance_entry in self.advances:
- make_advance_liability_entry(gl_entries, advance_entry.reference_name, advance_entry.allocated_amount, invoice=self.name, party_type="Supplier")
+
+ check_advance_liability_entry(
+ gl_entries,
+ company=self.company,
+ advances=self.advances,
+ invoice=self.name,
+ party_type="Supplier",
+ )
self.make_item_gl_entries(gl_entries)
self.make_precision_loss_gl_entry(gl_entries)
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
index 9ade46e..c15692b 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
@@ -1669,7 +1669,7 @@
frappe.db.set_value(
"Company",
"_Test Company",
- {"book_advance_payments_as_liability": 1, "default_advance_account": "Debtors - _TC"},
+ {"book_advance_payments_as_liability": 1, "default_advance_paid_account": "Debtors - _TC"},
)
pe = create_payment_entry(
company="_Test Company",
@@ -1722,6 +1722,7 @@
doc.assertEqual(expected_gle[i][0], gle.account)
doc.assertEqual(expected_gle[i][1], gle.debit)
doc.assertEqual(expected_gle[i][2], gle.credit)
+ doc.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)
def create_tax_witholding_category(category_name, company, account):
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 419628e..d43e6e8 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -32,8 +32,10 @@
reset_depreciation_schedule,
reverse_depreciation_entry_made_after_disposal,
)
-from erpnext.controllers.accounts_controller import validate_account_head
-from erpnext.controllers.accounts_controller import make_advance_liability_entry
+from erpnext.controllers.accounts_controller import (
+ check_advance_liability_entry,
+ validate_account_head,
+)
from erpnext.controllers.selling_controller import SellingController
from erpnext.projects.doctype.timesheet.timesheet import get_projectwise_timesheet_data
from erpnext.setup.doctype.company.company import update_company_current_month_sales
@@ -1065,11 +1067,14 @@
gl_entries = []
self.make_customer_gl_entry(gl_entries)
-
- advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": self.company}, "book_advance_payments_as_liability")
- if advance_payments_as_liability:
- for advance_entry in self.advances:
- make_advance_liability_entry(gl_entries, advance_entry.reference_name, advance_entry.allocated_amount, invoice=self.name, party_type="Customer")
+
+ check_advance_liability_entry(
+ gl_entries,
+ company=self.company,
+ advances=self.advances,
+ invoice=self.name,
+ party_type="Customer",
+ )
self.make_tax_gl_entries(gl_entries)
self.make_exchange_gain_loss_gl_entries(gl_entries)
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 364bf68..54c8b84 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -3320,7 +3320,10 @@
frappe.db.set_value(
"Company",
"_Test Company",
- {"book_advance_payments_as_liability": 1, "default_advance_account": "Creditors - _TC"},
+ {
+ "book_advance_payments_as_liability": 1,
+ "default_advance_received_account": "Creditors - _TC",
+ },
)
pe = create_payment_entry(
company="_Test Company",
@@ -3408,6 +3411,7 @@
doc.assertEqual(expected_gle[i][0], gle.account)
doc.assertEqual(expected_gle[i][1], gle.debit)
doc.assertEqual(expected_gle[i][2], gle.credit)
+ doc.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)
def create_sales_invoice(**args):
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index ccd54b3..1e38217 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -429,7 +429,12 @@
)
if not account:
- account = frappe.get_cached_value("Company", company, "default_advance_account")
+ account_name = (
+ "default_advance_received_account"
+ if party_type == "Customer"
+ else "default_advance_paid_account"
+ )
+ account = frappe.get_cached_value("Company", company, account_name)
return account
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index d8c4135..3fac56c 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -2908,16 +2908,6 @@
parent.create_stock_reservation_entries()
-@erpnext.allow_regional
-def validate_regional(doc):
- pass
-
-
-@erpnext.allow_regional
-def validate_einvoice_fields(doc):
- pass
-
-
def make_advance_liability_entry(
gl_entries, pe, allocated_amount, invoice, party_type, references=False
):
@@ -2990,3 +2980,33 @@
item=invoice,
)
)
+
+
+def check_advance_liability_entry(gl_entries, company, advances, invoice, party_type):
+ advance_payments_as_liability = frappe.db.get_value(
+ "Company", {"company_name": company}, "book_advance_payments_as_liability"
+ )
+ if advance_payments_as_liability:
+ for advance_entry in advances:
+ make_advance_liability_entry(
+ gl_entries,
+ advance_entry.reference_name,
+ advance_entry.allocated_amount,
+ invoice=invoice,
+ party_type=party_type,
+ )
+
+
+@erpnext.allow_regional
+def validate_regional(doc):
+ pass
+
+
+@erpnext.allow_regional
+def validate_einvoice_fields(doc):
+ pass
+
+
+@erpnext.allow_regional
+def update_gl_dict_with_regional_fields(doc, gl_dict):
+ pass
diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js
index fb0ee7f..436fe05 100644
--- a/erpnext/setup/doctype/company/company.js
+++ b/erpnext/setup/doctype/company/company.js
@@ -227,7 +227,8 @@
["asset_received_but_not_billed", {"account_type": "Asset Received But Not Billed"}],
["unrealized_profit_loss_account", {"root_type": ["in", ["Liability", "Asset"]]}],
["default_provisional_account", {"root_type": ["in", ["Liability", "Asset"]]}],
- ["default_advance_account", {"root_type": ["in", ["Liability", "Asset"]]}],
+ ["default_advance_received_account", {"root_type": "Liability"}],
+ ["default_advance_paid_account", {"root_type": "Asset"}],
], function(i, v) {
erpnext.company.set_custom_query(frm, v);
});
diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json
index 5b3d3bb..3523af1 100644
--- a/erpnext/setup/doctype/company/company.json
+++ b/erpnext/setup/doctype/company/company.json
@@ -72,7 +72,8 @@
"default_finance_book",
"advance_payments_section",
"book_advance_payments_as_liability",
- "default_advance_account",
+ "default_advance_received_account",
+ "default_advance_paid_account",
"column_break_cui0",
"auto_accounting_for_stock_settings",
"enable_perpetual_inventory",
@@ -716,9 +717,17 @@
},
{
"depends_on": "eval:doc.book_advance_payments_as_liability",
- "fieldname": "default_advance_account",
+ "fieldname": "default_advance_received_account",
"fieldtype": "Link",
- "label": "Default Account",
+ "label": "Default Advance Received Account",
+ "mandatory_depends_on": "book_advance_payments_as_liability",
+ "options": "Account"
+ },
+ {
+ "depends_on": "eval:doc.book_advance_payments_as_liability",
+ "fieldname": "default_advance_paid_account",
+ "fieldtype": "Link",
+ "label": "Default Advance Paid Account",
"mandatory_depends_on": "book_advance_payments_as_liability",
"options": "Account"
}
@@ -728,7 +737,7 @@
"image_field": "company_logo",
"is_tree": 1,
"links": [],
- "modified": "2023-06-05 14:12:37.946451",
+ "modified": "2023-06-12 12:51:12.007410",
"modified_by": "Administrator",
"module": "Setup",
"name": "Company",