Skip to content

Commit

Permalink
Merge pull request #37041 from vorasmit/fix-advances
Browse files Browse the repository at this point in the history
fix: multiple fixes for booking advances in seperate account
  • Loading branch information
deepeshgarg007 authored Sep 13, 2023
2 parents 78905e3 + c098078 commit 6664bc9
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 9 deletions.
14 changes: 11 additions & 3 deletions erpnext/accounts/doctype/payment_entry/payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def on_submit(self):
if self.difference_amount:
frappe.throw(_("Difference Amount must be zero"))
self.make_gl_entries()
self.make_advance_gl_entries()
self.update_outstanding_amounts()
self.update_advance_paid()
self.update_payment_schedule()
Expand Down Expand Up @@ -152,7 +151,6 @@ def on_cancel(self):
)
super(PaymentEntry, self).on_cancel()
self.make_gl_entries(cancel=1)
self.make_advance_gl_entries(cancel=1)
self.update_outstanding_amounts()
self.update_advance_paid()
self.delink_advance_entry_references()
Expand Down Expand Up @@ -1060,6 +1058,8 @@ def make_gl_entries(self, cancel=0, adv_adj=0):
else:
self.make_exchange_gain_loss_journal()

self.make_advance_gl_entries(cancel=cancel)

def add_party_gl_entries(self, gl_entries):
if self.party_account:
if self.payment_type == "Receive":
Expand Down Expand Up @@ -1128,7 +1128,7 @@ def make_advance_gl_entries(self, against_voucher_type=None, against_voucher=Non
if self.book_advance_payments_in_separate_party_account:
gl_entries = []
for d in self.get("references"):
if d.reference_doctype in ("Sales Invoice", "Purchase Invoice"):
if d.reference_doctype in ("Sales Invoice", "Purchase Invoice", "Journal Entry"):
if not (against_voucher_type and against_voucher) or (
d.reference_doctype == against_voucher_type and d.reference_name == against_voucher
):
Expand Down Expand Up @@ -1164,6 +1164,13 @@ def make_invoice_liability_entry(self, gl_entries, invoice):
"voucher_detail_no": invoice.name,
}

posting_date = frappe.db.get_value(
invoice.reference_doctype, invoice.reference_name, "posting_date"
)

if getdate(posting_date) < getdate(self.posting_date):
posting_date = self.posting_date

dr_or_cr = "credit" if invoice.reference_doctype == "Sales Invoice" else "debit"
args_dict["account"] = invoice.account
args_dict[dr_or_cr] = invoice.allocated_amount
Expand All @@ -1172,6 +1179,7 @@ def make_invoice_liability_entry(self, gl_entries, invoice):
{
"against_voucher_type": invoice.reference_doctype,
"against_voucher": invoice.reference_name,
"posting_date": posting_date,
}
)
gle = self.get_gl_dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
filters: {
"company": this.frm.doc.company,
"is_group": 0,
"account_type": frappe.boot.party_account_types[this.frm.doc.party_type]
"account_type": frappe.boot.party_account_types[this.frm.doc.party_type],
"root_type": this.frm.doc.party_type == 'Customer' ? "Asset" : "Liability"
}
};
});
Expand Down
5 changes: 2 additions & 3 deletions erpnext/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,14 +491,13 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
gl_map = doc.build_gl_map()
create_payment_ledger_entry(gl_map, update_outstanding="No", cancel=0, adv_adj=1)

if voucher_type == "Payment Entry":
doc.make_advance_gl_entries()

# Only update outstanding for newly linked vouchers
for entry in entries:
update_voucher_outstanding(
entry.against_voucher_type, entry.against_voucher, entry.account, entry.party_type, entry.party
)
if voucher_type == "Payment Entry":
doc.make_advance_gl_entries(entry.against_voucher_type, entry.against_voucher)

frappe.flags.ignore_party_validation = False

Expand Down
1 change: 1 addition & 0 deletions erpnext/buying/doctype/supplier/supplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ frappe.ui.form.on("Supplier", {
return {
filters: {
'account_type': 'Payable',
'root_type': 'Liability',
'company': d.company,
"is_group": 0
}
Expand Down
1 change: 1 addition & 0 deletions erpnext/selling/doctype/customer/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ frappe.ui.form.on("Customer", {
let d = locals[cdt][cdn];
let filters = {
'account_type': 'Receivable',
'root_type': 'Asset',
'company': d.company,
"is_group": 0
};
Expand Down
4 changes: 2 additions & 2 deletions erpnext/setup/doctype/company/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ erpnext.company.setup_queries = function(frm) {
$.each([
["default_bank_account", {"account_type": "Bank"}],
["default_cash_account", {"account_type": "Cash"}],
["default_receivable_account", {"account_type": "Receivable"}],
["default_payable_account", {"account_type": "Payable"}],
["default_receivable_account", { "root_type": "Asset", "account_type": "Receivable" }],
["default_payable_account", { "root_type": "Liability", "account_type": "Payable" }],
["default_expense_account", {"root_type": "Expense"}],
["default_income_account", {"root_type": "Income"}],
["round_off_account", {"root_type": "Expense"}],
Expand Down
1 change: 1 addition & 0 deletions erpnext/setup/doctype/customer_group/customer_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frappe.ui.form.on("Customer Group", {
frm.set_query('account', 'accounts', function (doc, cdt, cdn) {
return {
filters: {
'root_type': 'Asset',
"account_type": 'Receivable',
"company": locals[cdt][cdn].company,
"is_group": 0
Expand Down
1 change: 1 addition & 0 deletions erpnext/setup/doctype/supplier_group/supplier_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frappe.ui.form.on("Supplier Group", {
frm.set_query('account', 'accounts', function (doc, cdt, cdn) {
return {
filters: {
'root_type': 'Liability',
'account_type': 'Payable',
'company': locals[cdt][cdn].company,
"is_group": 0
Expand Down

0 comments on commit 6664bc9

Please sign in to comment.