fix: Make get party account method return a list instead of a single default account.
This commit is contained in:
parent
b65e58c1ae
commit
7591f1010b
@ -36,7 +36,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2023-06-05 14:15:42.053150",
|
||||
"modified": "2023-06-06 14:15:42.053150",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Party Account",
|
||||
|
@ -712,7 +712,6 @@ frappe.ui.form.on('Payment Entry', {
|
||||
if(r.message) {
|
||||
var total_positive_outstanding = 0;
|
||||
var total_negative_outstanding = 0;
|
||||
console.log(r.message);
|
||||
$.each(r.message, function(i, d) {
|
||||
var c = frm.add_child("references");
|
||||
c.reference_doctype = d.voucher_type;
|
||||
|
@ -60,6 +60,7 @@ class PaymentEntry(AccountsController):
|
||||
def validate(self):
|
||||
self.setup_party_account_field()
|
||||
self.set_missing_values()
|
||||
self.set_liability_account()
|
||||
self.set_missing_ref_details()
|
||||
self.validate_payment_type()
|
||||
self.validate_party_details()
|
||||
@ -86,35 +87,34 @@ class PaymentEntry(AccountsController):
|
||||
def on_submit(self):
|
||||
if self.difference_amount:
|
||||
frappe.throw(_("Difference Amount must be zero"))
|
||||
book_advance_payments_as_liability = frappe.get_value(
|
||||
"Company", {"company_name": self.company}, "book_advance_payments_as_liability"
|
||||
)
|
||||
if book_advance_payments_as_liability:
|
||||
self.get_liability_account()
|
||||
self.make_gl_entries()
|
||||
self.update_outstanding_amounts()
|
||||
self.update_advance_paid()
|
||||
self.update_payment_schedule()
|
||||
self.set_status()
|
||||
|
||||
def get_liability_account(self):
|
||||
liability_account = get_party_account(self.party_type, self.party, self.company, is_advance=True)
|
||||
if self.party_type == "Customer":
|
||||
def set_liability_account(self):
|
||||
book_advance_payments_as_liability = frappe.get_value(
|
||||
"Company", {"company_name": self.company}, "book_advance_payments_as_liability"
|
||||
)
|
||||
if not book_advance_payments_as_liability:
|
||||
return
|
||||
root_type = frappe.get_value(
|
||||
"Account", {"name": self.party_account, "company": self.company}, "root_type"
|
||||
)
|
||||
if (root_type == "Liability" and self.party_type == "Customer") or (
|
||||
root_type == "Asset" and self.party_type == "Supplier"
|
||||
):
|
||||
return
|
||||
liability_account = get_party_account(
|
||||
self.party_type, self.party, self.company, include_advance=True
|
||||
)[1]
|
||||
self.set(self.party_account_field, liability_account)
|
||||
msg = "Book Advance Payments as Liability option is chosen. Paid From account changed from {0} to {1}.".format(
|
||||
frappe.bold(self.paid_from),
|
||||
frappe.bold(self.party_account),
|
||||
frappe.bold(liability_account),
|
||||
)
|
||||
frappe.db.set_value("Payment Entry", self.name, "paid_from", liability_account)
|
||||
self.paid_from = liability_account
|
||||
else:
|
||||
msg = "Book Advance Payments as Liability option is chosen. Paid To account changed from {0} to {1}.".format(
|
||||
frappe.bold(self.paid_to),
|
||||
frappe.bold(liability_account),
|
||||
)
|
||||
frappe.db.set_value("Payment Entry", self.name, "paid_to", liability_account)
|
||||
self.paid_to = liability_account
|
||||
frappe.msgprint(_(msg), title="Warning", indicator="orange")
|
||||
return liability_account
|
||||
frappe.msgprint(_(msg), alert=True)
|
||||
|
||||
def on_cancel(self):
|
||||
self.ignore_linked_doctypes = (
|
||||
@ -354,13 +354,6 @@ class PaymentEntry(AccountsController):
|
||||
elif self.party_type == "Employee":
|
||||
ref_party_account = ref_doc.payable_account
|
||||
|
||||
if ref_party_account != self.party_account:
|
||||
frappe.throw(
|
||||
_("{0} {1} is associated with {2}, but Party Account is {3}").format(
|
||||
d.reference_doctype, d.reference_name, ref_party_account, self.party_account
|
||||
)
|
||||
)
|
||||
|
||||
if ref_doc.doctype == "Purchase Invoice" and ref_doc.get("on_hold"):
|
||||
frappe.throw(
|
||||
_("{0} {1} is on hold").format(d.reference_doctype, d.reference_name),
|
||||
@ -893,11 +886,9 @@ class PaymentEntry(AccountsController):
|
||||
if self.party_account:
|
||||
if self.payment_type == "Receive":
|
||||
against_account = self.paid_to
|
||||
self.party_account = self.paid_from
|
||||
dr_or_cr = "credit"
|
||||
else:
|
||||
against_account = self.paid_from
|
||||
self.party_account = self.paid_to
|
||||
dr_or_cr = "debit"
|
||||
|
||||
party_dict = self.get_gl_dict(
|
||||
@ -927,8 +918,8 @@ class PaymentEntry(AccountsController):
|
||||
{
|
||||
dr_or_cr: allocated_amount_in_company_currency,
|
||||
dr_or_cr + "_in_account_currency": d.allocated_amount,
|
||||
"against_voucher_type": d.reference_doctype,
|
||||
"against_voucher": d.reference_name,
|
||||
"against_voucher_type": "Payment Entry",
|
||||
"against_voucher": self.name,
|
||||
}
|
||||
)
|
||||
|
||||
@ -973,7 +964,7 @@ class PaymentEntry(AccountsController):
|
||||
args_dict[dr_or_cr] = 0
|
||||
args_dict[dr_or_cr + "_in_account_currency"] = 0
|
||||
dr_or_cr = "debit" if dr_or_cr == "credit" else "credit"
|
||||
args_dict["account"] = self.get_liability_account()
|
||||
args_dict["account"] = self.party_account
|
||||
args_dict[dr_or_cr] = invoice.allocated_amount
|
||||
args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount
|
||||
gle = self.get_gl_dict(
|
||||
|
@ -134,32 +134,18 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
||||
this.frm.trigger("clear_child_tables");
|
||||
|
||||
if (!this.frm.doc.receivable_payable_account && this.frm.doc.party_type && this.frm.doc.party) {
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.party.get_party_account",
|
||||
args: {
|
||||
company: this.frm.doc.company,
|
||||
party_type: this.frm.doc.party_type,
|
||||
party: this.frm.doc.party
|
||||
},
|
||||
callback: (r) => {
|
||||
if (!r.exc && r.message) {
|
||||
this.frm.set_value("receivable_payable_account", r.message);
|
||||
}
|
||||
this.frm.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.party.get_party_account",
|
||||
args: {
|
||||
company: this.frm.doc.company,
|
||||
party_type: this.frm.doc.party_type,
|
||||
party: this.frm.doc.party,
|
||||
is_advance: 1
|
||||
include_advance: 1
|
||||
},
|
||||
callback: (r) => {
|
||||
if (!r.exc && r.message) {
|
||||
this.frm.set_value("default_advance_account", r.message);
|
||||
this.frm.set_value("receivable_payable_account", r.message[0]);
|
||||
this.frm.set_value("default_advance_account", r.message[1]);
|
||||
}
|
||||
this.frm.refresh();
|
||||
}
|
||||
|
@ -7,8 +7,8 @@
|
||||
"field_order": [
|
||||
"company",
|
||||
"party_type",
|
||||
"party",
|
||||
"column_break_4",
|
||||
"party",
|
||||
"receivable_payable_account",
|
||||
"default_advance_account",
|
||||
"col_break1",
|
||||
@ -188,20 +188,19 @@
|
||||
"options": "Cost Center"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.party_type",
|
||||
"depends_on": "eval:doc.party",
|
||||
"fieldname": "default_advance_account",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Advance Account",
|
||||
"mandatory_depends_on": "doc.party_type",
|
||||
"options": "Account",
|
||||
"reqd": 1
|
||||
"options": "Account"
|
||||
}
|
||||
],
|
||||
"hide_toolbar": 1,
|
||||
"icon": "icon-resize-horizontal",
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-06-05 20:09:58.925427",
|
||||
"modified": "2023-06-09 13:02:48.718362",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Payment Reconciliation",
|
||||
|
@ -1677,7 +1677,7 @@ class TestPurchaseInvoice(unittest.TestCase, StockTestMixin):
|
||||
party_type="Supplier",
|
||||
party="_Test Supplier",
|
||||
paid_from="Cash - _TC",
|
||||
paid_to=get_party_account("Supplier", "_Test Supplier", "_Test Company", is_advance=True),
|
||||
paid_to="Creditors - _TC",
|
||||
paid_amount=1000,
|
||||
)
|
||||
pe.submit()
|
||||
|
@ -3327,7 +3327,7 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
payment_type="Receive",
|
||||
party_type="Customer",
|
||||
party="_Test Customer",
|
||||
paid_from=get_party_account("Customer", "_Test Customer", "_Test Company", is_advance=True),
|
||||
paid_from="Debtors - _TC",
|
||||
paid_to="Cash - _TC",
|
||||
paid_amount=1000,
|
||||
)
|
||||
|
@ -365,7 +365,7 @@ def set_account_and_due_date(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_account(party_type, party=None, company=None, is_advance=False):
|
||||
def get_party_account(party_type, party=None, company=None, include_advance=False):
|
||||
"""Returns the account for the given `party`.
|
||||
Will first search in party (Customer / Supplier) record, if not found,
|
||||
will search in group (Customer Group / Supplier Group),
|
||||
@ -380,9 +380,6 @@ def get_party_account(party_type, party=None, company=None, is_advance=False):
|
||||
|
||||
return frappe.get_cached_value("Company", company, default_account_name)
|
||||
|
||||
if is_advance and party_type in ["Customer", "Supplier"]:
|
||||
return get_party_advance_account(party_type, party, company)
|
||||
|
||||
account = frappe.db.get_value(
|
||||
"Party Account", {"parenttype": party_type, "parent": party, "company": company}, "account"
|
||||
)
|
||||
@ -409,6 +406,9 @@ def get_party_account(party_type, party=None, company=None, is_advance=False):
|
||||
if (account and account_currency != existing_gle_currency) or not account:
|
||||
account = get_party_gle_account(party_type, party, company)
|
||||
|
||||
if include_advance and party_type in ["Customer", "Supplier"]:
|
||||
advance_account = get_party_advance_account(party_type, party, company)
|
||||
return [account, advance_account]
|
||||
return account
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ frappe.ui.form.on("Supplier", {
|
||||
frm.set_value("represents_company", "");
|
||||
}
|
||||
frm.set_query('account', 'accounts', function (doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
let d = locals[cdt][cdn];
|
||||
return {
|
||||
filters: {
|
||||
'account_type': 'Payable',
|
||||
@ -19,7 +19,7 @@ frappe.ui.form.on("Supplier", {
|
||||
});
|
||||
|
||||
frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
let d = locals[cdt][cdn];
|
||||
return {
|
||||
filters: {
|
||||
"root_type": 'Asset',
|
||||
|
@ -885,9 +885,6 @@ class AccountsController(TransactionBase):
|
||||
amount_field = "credit_in_account_currency"
|
||||
order_field = "sales_order"
|
||||
order_doctype = "Sales Order"
|
||||
party_account = [
|
||||
get_party_account(party_type, party=party, company=self.company, is_advance=True)
|
||||
]
|
||||
else:
|
||||
party_type = "Supplier"
|
||||
party = self.supplier
|
||||
@ -895,7 +892,7 @@ class AccountsController(TransactionBase):
|
||||
order_field = "purchase_order"
|
||||
order_doctype = "Purchase Order"
|
||||
party_account = [
|
||||
get_party_account(party_type, party=party, company=self.company, is_advance=True)
|
||||
get_party_account(party_type, party=party, company=self.company, include_advance=True)[1]
|
||||
]
|
||||
|
||||
order_list = list(set(d.get(order_field) for d in self.get("items") if d.get(order_field)))
|
||||
|
@ -20,8 +20,8 @@ frappe.ui.form.on("Customer", {
|
||||
frm.set_query('customer_group', {'is_group': 0});
|
||||
frm.set_query('default_price_list', { 'selling': 1});
|
||||
frm.set_query('account', 'accounts', function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
var filters = {
|
||||
let d = locals[cdt][cdn];
|
||||
let filters = {
|
||||
'account_type': 'Receivable',
|
||||
'company': d.company,
|
||||
"is_group": 0
|
||||
@ -36,7 +36,7 @@ frappe.ui.form.on("Customer", {
|
||||
});
|
||||
|
||||
frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
let d = locals[cdt][cdn];
|
||||
return {
|
||||
filters: {
|
||||
"root_type": 'Liability',
|
||||
|
@ -16,34 +16,35 @@ cur_frm.cscript.set_root_readonly = function(doc) {
|
||||
}
|
||||
}
|
||||
|
||||
//get query select Customer Group
|
||||
cur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) {
|
||||
frappe.ui.form.on("Customer Group", {
|
||||
setup: function(frm){
|
||||
frm.set_query('parent_customer_group', function (doc) {
|
||||
return {
|
||||
filters: {
|
||||
'is_group': 1,
|
||||
'name': ['!=', cur_frm.doc.customer_group_name]
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
frm.set_query('account', 'accounts', function (doc, cdt, cdn) {
|
||||
return {
|
||||
filters: {
|
||||
"account_type": 'Receivable',
|
||||
"company": d.company,
|
||||
"company": locals[cdt][cdn].company,
|
||||
"is_group": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.fields_dict['accounts'].grid.get_field('advance_account').get_query = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) {
|
||||
return {
|
||||
filters: {
|
||||
"root_type": 'Liability',
|
||||
"company": d.company,
|
||||
"company": locals[cdt][cdn].company,
|
||||
"is_group": 0
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -16,34 +16,35 @@ cur_frm.cscript.set_root_readonly = function(doc) {
|
||||
}
|
||||
};
|
||||
|
||||
// get query select Customer Group
|
||||
cur_frm.fields_dict['parent_supplier_group'].get_query = function() {
|
||||
frappe.ui.form.on("Supplier Group", {
|
||||
setup: function(frm){
|
||||
frm.set_query('parent_supplier_group', function (doc) {
|
||||
return {
|
||||
filters: {
|
||||
'is_group': 1,
|
||||
'name': ['!=', cur_frm.doc.supplier_group_name]
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
frm.set_query('account', 'accounts', function (doc, cdt, cdn) {
|
||||
return {
|
||||
filters: {
|
||||
'account_type': 'Payable',
|
||||
'company': d.company,
|
||||
'company': locals[cdt][cdn].company,
|
||||
"is_group": 0
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
cur_frm.fields_dict['accounts'].grid.get_field('advance_account').get_query = function(doc, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) {
|
||||
return {
|
||||
filters: {
|
||||
"root_type": 'Asset',
|
||||
"company": d.company,
|
||||
"company": locals[cdt][cdn].company,
|
||||
"is_group": 0
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user