fix: Using one field for both advance liability accounts
This commit is contained in:
@@ -7,8 +7,7 @@
|
|||||||
"field_order": [
|
"field_order": [
|
||||||
"company",
|
"company",
|
||||||
"account",
|
"account",
|
||||||
"advances_received_account",
|
"advance_account"
|
||||||
"advances_paid_account"
|
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -28,22 +27,16 @@
|
|||||||
"options": "Account"
|
"options": "Account"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "advances_received_account",
|
"fieldname": "advance_account",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Advances Received Account",
|
"label": "Advance Account",
|
||||||
"options": "Account"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"fieldname": "advances_paid_account",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"label": "Advances Paid Account",
|
|
||||||
"options": "Account"
|
"options": "Account"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-06-02 13:00:06.885744",
|
"modified": "2023-06-05 14:15:42.053150",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Party Account",
|
"name": "Party Account",
|
||||||
|
|||||||
@@ -18,20 +18,14 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": frm.doc.company}, "book_advance_payments_as_liability");
|
|
||||||
|
|
||||||
if(advance_payments_as_liability && frm.doc.payment_type == 'Receive'){
|
|
||||||
account_type = "Payable";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
account_type = "Receivable";
|
|
||||||
}
|
|
||||||
|
|
||||||
frm.set_query("paid_from", function() {
|
frm.set_query("paid_from", function() {
|
||||||
frm.events.validate_company(frm);
|
frm.events.validate_company(frm);
|
||||||
|
|
||||||
|
var account_types = in_list(["Pay", "Internal Transfer"], frm.doc.payment_type) ?
|
||||||
|
["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]];
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
"account_type": account_type,
|
"account_type": ["in", account_types],
|
||||||
"is_group": 0,
|
"is_group": 0,
|
||||||
"company": frm.doc.company
|
"company": frm.doc.company
|
||||||
}
|
}
|
||||||
@@ -80,15 +74,12 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
|
|
||||||
frm.set_query("paid_to", function() {
|
frm.set_query("paid_to", function() {
|
||||||
frm.events.validate_company(frm);
|
frm.events.validate_company(frm);
|
||||||
if(advance_payments_as_liability && in_list(['Receive', 'Internal Transfer'], cur_frm.doc.payment_type)){
|
|
||||||
account_type = ["Bank", "Cash"];
|
var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ?
|
||||||
}
|
["Bank", "Cash"] : [frappe.boot.party_account_types[frm.doc.party_type]];
|
||||||
else{
|
|
||||||
account_type = "Receivable";
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
"account_type": ["in", account_type],
|
"account_type": ["in", account_types],
|
||||||
"is_group": 0,
|
"is_group": 0,
|
||||||
"company": frm.doc.company
|
"company": frm.doc.company
|
||||||
}
|
}
|
||||||
@@ -279,25 +270,6 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
},
|
},
|
||||||
|
|
||||||
payment_type: function(frm) {
|
payment_type: function(frm) {
|
||||||
advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": frm.doc.company}, "book_advance_payments_as_liability");
|
|
||||||
|
|
||||||
if(advance_payments_as_liability && frm.doc.payment_type == 'Receive'){
|
|
||||||
account_type = ["Payable"];
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
account_type = ["Bank", "Cash"];
|
|
||||||
}
|
|
||||||
|
|
||||||
frm.set_query("paid_from", function() {
|
|
||||||
frm.events.validate_company(frm);
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"account_type": ["in", account_type],
|
|
||||||
"is_group": 0,
|
|
||||||
"company": frm.doc.company
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(frm.doc.payment_type == "Internal Transfer") {
|
if(frm.doc.payment_type == "Internal Transfer") {
|
||||||
$.each(["party", "party_balance", "paid_from", "paid_to",
|
$.each(["party", "party_balance", "paid_from", "paid_to",
|
||||||
"references", "total_allocated_amount"], function(i, field) {
|
"references", "total_allocated_amount"], function(i, field) {
|
||||||
@@ -372,8 +344,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
party_type: frm.doc.party_type,
|
party_type: frm.doc.party_type,
|
||||||
party: frm.doc.party,
|
party: frm.doc.party,
|
||||||
date: frm.doc.posting_date,
|
date: frm.doc.posting_date,
|
||||||
cost_center: frm.doc.cost_center,
|
cost_center: frm.doc.cost_center
|
||||||
is_advance: !(frm.doc.references)
|
|
||||||
},
|
},
|
||||||
callback: function(r, rt) {
|
callback: function(r, rt) {
|
||||||
if(r.message) {
|
if(r.message) {
|
||||||
@@ -741,7 +712,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
if(r.message) {
|
if(r.message) {
|
||||||
var total_positive_outstanding = 0;
|
var total_positive_outstanding = 0;
|
||||||
var total_negative_outstanding = 0;
|
var total_negative_outstanding = 0;
|
||||||
|
console.log(r.message);
|
||||||
$.each(r.message, function(i, d) {
|
$.each(r.message, function(i, d) {
|
||||||
var c = frm.add_child("references");
|
var c = frm.add_child("references");
|
||||||
c.reference_doctype = d.voucher_type;
|
c.reference_doctype = d.voucher_type;
|
||||||
@@ -752,6 +723,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
c.bill_no = d.bill_no;
|
c.bill_no = d.bill_no;
|
||||||
c.payment_term = d.payment_term;
|
c.payment_term = d.payment_term;
|
||||||
c.allocated_amount = d.allocated_amount;
|
c.allocated_amount = d.allocated_amount;
|
||||||
|
c.account = d.account;
|
||||||
|
|
||||||
if(!in_list(frm.events.get_order_doctypes(frm), d.voucher_type)) {
|
if(!in_list(frm.events.get_order_doctypes(frm), d.voucher_type)) {
|
||||||
if(flt(d.outstanding_amount) > 0)
|
if(flt(d.outstanding_amount) > 0)
|
||||||
|
|||||||
@@ -733,7 +733,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-02-14 04:52:30.478523",
|
"modified": "2023-06-07 14:36:50.521884",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Entry",
|
"name": "Payment Entry",
|
||||||
|
|||||||
@@ -86,12 +86,36 @@ class PaymentEntry(AccountsController):
|
|||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
if self.difference_amount:
|
if self.difference_amount:
|
||||||
frappe.throw(_("Difference Amount must be zero"))
|
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.make_gl_entries()
|
||||||
self.update_outstanding_amounts()
|
self.update_outstanding_amounts()
|
||||||
self.update_advance_paid()
|
self.update_advance_paid()
|
||||||
self.update_payment_schedule()
|
self.update_payment_schedule()
|
||||||
self.set_status()
|
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":
|
||||||
|
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(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
|
||||||
|
|
||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
self.ignore_linked_doctypes = (
|
self.ignore_linked_doctypes = (
|
||||||
"GL Entry",
|
"GL Entry",
|
||||||
@@ -869,10 +893,14 @@ class PaymentEntry(AccountsController):
|
|||||||
if self.party_account:
|
if self.party_account:
|
||||||
if self.payment_type == "Receive":
|
if self.payment_type == "Receive":
|
||||||
against_account = self.paid_to
|
against_account = self.paid_to
|
||||||
|
self.party_account = self.paid_from
|
||||||
|
dr_or_cr = "credit"
|
||||||
else:
|
else:
|
||||||
against_account = self.paid_from
|
against_account = self.paid_from
|
||||||
|
self.party_account = self.paid_to
|
||||||
|
dr_or_cr = "debit"
|
||||||
|
|
||||||
party_gl_dict = self.get_gl_dict(
|
party_dict = self.get_gl_dict(
|
||||||
{
|
{
|
||||||
"account": self.party_account,
|
"account": self.party_account,
|
||||||
"party_type": self.party_type,
|
"party_type": self.party_type,
|
||||||
@@ -883,30 +911,24 @@ class PaymentEntry(AccountsController):
|
|||||||
},
|
},
|
||||||
item=self,
|
item=self,
|
||||||
)
|
)
|
||||||
|
|
||||||
dr_or_cr = (
|
|
||||||
"credit" if erpnext.get_party_account_type(self.party_type) == "Receivable" else "debit"
|
|
||||||
)
|
|
||||||
|
|
||||||
for d in self.get("references"):
|
for d in self.get("references"):
|
||||||
cost_center = self.cost_center
|
book_advance_payments_as_liability = frappe.get_value(
|
||||||
if d.reference_doctype == "Sales Invoice" and not cost_center:
|
"Company", {"company_name": self.company}, "book_advance_payments_as_liability"
|
||||||
cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center")
|
|
||||||
gle = party_gl_dict.copy()
|
|
||||||
gle.update(
|
|
||||||
{
|
|
||||||
"against_voucher_type": d.reference_doctype,
|
|
||||||
"against_voucher": d.reference_name,
|
|
||||||
"cost_center": cost_center,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
if (
|
||||||
|
d.reference_doctype in ["Sales Invoice", "Purchase Invoice"]
|
||||||
|
and book_advance_payments_as_liability
|
||||||
|
):
|
||||||
|
self.make_invoice_liability_entry(gl_entries, d)
|
||||||
|
|
||||||
allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)
|
allocated_amount_in_company_currency = self.calculate_base_allocated_amount_for_reference(d)
|
||||||
|
gle = party_dict.copy()
|
||||||
gle.update(
|
gle.update(
|
||||||
{
|
{
|
||||||
dr_or_cr + "_in_account_currency": d.allocated_amount,
|
|
||||||
dr_or_cr: allocated_amount_in_company_currency,
|
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,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -916,8 +938,7 @@ class PaymentEntry(AccountsController):
|
|||||||
exchange_rate = self.get_exchange_rate()
|
exchange_rate = self.get_exchange_rate()
|
||||||
base_unallocated_amount = self.unallocated_amount * exchange_rate
|
base_unallocated_amount = self.unallocated_amount * exchange_rate
|
||||||
|
|
||||||
gle = party_gl_dict.copy()
|
gle = party_dict.copy()
|
||||||
|
|
||||||
gle.update(
|
gle.update(
|
||||||
{
|
{
|
||||||
dr_or_cr + "_in_account_currency": self.unallocated_amount,
|
dr_or_cr + "_in_account_currency": self.unallocated_amount,
|
||||||
@@ -927,6 +948,40 @@ class PaymentEntry(AccountsController):
|
|||||||
|
|
||||||
gl_entries.append(gle)
|
gl_entries.append(gle)
|
||||||
|
|
||||||
|
def make_invoice_liability_entry(self, gl_entries, invoice):
|
||||||
|
args_dict = {
|
||||||
|
"party_type": self.party_type,
|
||||||
|
"party": self.party,
|
||||||
|
"account_currency": self.party_account_currency,
|
||||||
|
"cost_center": self.cost_center,
|
||||||
|
"voucher_type": invoice.reference_doctype,
|
||||||
|
"voucher_no": invoice.reference_name,
|
||||||
|
"against_voucher_type": invoice.reference_doctype,
|
||||||
|
"against_voucher": invoice.reference_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount
|
||||||
|
gle = self.get_gl_dict(
|
||||||
|
args_dict,
|
||||||
|
item=self,
|
||||||
|
)
|
||||||
|
gl_entries.append(gle)
|
||||||
|
|
||||||
|
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[dr_or_cr] = invoice.allocated_amount
|
||||||
|
args_dict[dr_or_cr + "_in_account_currency"] = invoice.allocated_amount
|
||||||
|
gle = self.get_gl_dict(
|
||||||
|
args_dict,
|
||||||
|
item=self,
|
||||||
|
)
|
||||||
|
gl_entries.append(gle)
|
||||||
|
|
||||||
def add_bank_gl_entries(self, gl_entries):
|
def add_bank_gl_entries(self, gl_entries):
|
||||||
if self.payment_type in ("Pay", "Internal Transfer"):
|
if self.payment_type in ("Pay", "Internal Transfer"):
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
@@ -1401,6 +1456,7 @@ def split_invoices_based_on_payment_terms(outstanding_invoices):
|
|||||||
"outstanding_amount": flt(d.outstanding_amount),
|
"outstanding_amount": flt(d.outstanding_amount),
|
||||||
"payment_amount": payment_term.payment_amount,
|
"payment_amount": payment_term.payment_amount,
|
||||||
"payment_term": payment_term.payment_term,
|
"payment_term": payment_term.payment_term,
|
||||||
|
"account": d.account,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -1449,7 +1505,7 @@ def get_orders_to_be_billed(
|
|||||||
if voucher_type:
|
if voucher_type:
|
||||||
doc = frappe.get_doc({"doctype": voucher_type})
|
doc = frappe.get_doc({"doctype": voucher_type})
|
||||||
condition = ""
|
condition = ""
|
||||||
if doc and hasattr(doc, "cost_center"):
|
if cost_center and doc and hasattr(doc, "cost_center"):
|
||||||
condition = " and cost_center='%s'" % cost_center
|
condition = " and cost_center='%s'" % cost_center
|
||||||
|
|
||||||
orders = []
|
orders = []
|
||||||
@@ -1495,9 +1551,13 @@ def get_orders_to_be_billed(
|
|||||||
|
|
||||||
order_list = []
|
order_list = []
|
||||||
for d in orders:
|
for d in orders:
|
||||||
if not (
|
if filters.get("oustanding_amt_greater_than") and flt(d.outstanding_amount) < flt(
|
||||||
flt(d.outstanding_amount) >= flt(filters.get("outstanding_amt_greater_than"))
|
filters.get("outstanding_amt_greater_than")
|
||||||
and flt(d.outstanding_amount) <= flt(filters.get("outstanding_amt_less_than"))
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if filters.get("oustanding_amt_less_than") and flt(d.outstanding_amount) > flt(
|
||||||
|
filters.get("outstanding_amt_less_than")
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -1519,6 +1579,7 @@ def get_negative_outstanding_invoices(
|
|||||||
condition=None,
|
condition=None,
|
||||||
):
|
):
|
||||||
voucher_type = "Sales Invoice" if party_type == "Customer" else "Purchase Invoice"
|
voucher_type = "Sales Invoice" if party_type == "Customer" else "Purchase Invoice"
|
||||||
|
account = "debit_to" if voucher_type == "Sales Invoice" else "credit_to"
|
||||||
supplier_condition = ""
|
supplier_condition = ""
|
||||||
if voucher_type == "Purchase Invoice":
|
if voucher_type == "Purchase Invoice":
|
||||||
supplier_condition = "and (release_date is null or release_date <= CURRENT_DATE)"
|
supplier_condition = "and (release_date is null or release_date <= CURRENT_DATE)"
|
||||||
@@ -1532,7 +1593,7 @@ def get_negative_outstanding_invoices(
|
|||||||
return frappe.db.sql(
|
return frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
select
|
select
|
||||||
"{voucher_type}" as voucher_type, name as voucher_no,
|
"{voucher_type}" as voucher_type, name as voucher_no, {account} as account,
|
||||||
if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) as invoice_amount,
|
if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) as invoice_amount,
|
||||||
outstanding_amount, posting_date,
|
outstanding_amount, posting_date,
|
||||||
due_date, conversion_rate as exchange_rate
|
due_date, conversion_rate as exchange_rate
|
||||||
@@ -1555,6 +1616,7 @@ def get_negative_outstanding_invoices(
|
|||||||
"party_type": scrub(party_type),
|
"party_type": scrub(party_type),
|
||||||
"party_account": "debit_to" if party_type == "Customer" else "credit_to",
|
"party_account": "debit_to" if party_type == "Customer" else "credit_to",
|
||||||
"cost_center": cost_center,
|
"cost_center": cost_center,
|
||||||
|
"account": account,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
(party, party_account),
|
(party, party_account),
|
||||||
@@ -1563,12 +1625,12 @@ def get_negative_outstanding_invoices(
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_party_details(company, party_type, party, date, cost_center=None, is_advance=False):
|
def get_party_details(company, party_type, party, date, cost_center=None):
|
||||||
bank_account = ""
|
bank_account = ""
|
||||||
if not frappe.db.exists(party_type, party):
|
if not frappe.db.exists(party_type, party):
|
||||||
frappe.throw(_("Invalid {0}: {1}").format(party_type, party))
|
frappe.throw(_("Invalid {0}: {1}").format(party_type, party))
|
||||||
|
|
||||||
party_account = get_party_account(party_type, party, company, is_advance)
|
party_account = get_party_account(party_type, party, company)
|
||||||
account_currency = get_account_currency(party_account)
|
account_currency = get_account_currency(party_account)
|
||||||
account_balance = get_balance_on(party_account, date, cost_center=cost_center)
|
account_balance = get_balance_on(party_account, date, cost_center=cost_center)
|
||||||
_party_name = "title" if party_type == "Shareholder" else party_type.lower() + "_name"
|
_party_name = "title" if party_type == "Shareholder" else party_type.lower() + "_name"
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
"outstanding_amount",
|
"outstanding_amount",
|
||||||
"allocated_amount",
|
"allocated_amount",
|
||||||
"exchange_rate",
|
"exchange_rate",
|
||||||
"exchange_gain_loss"
|
"exchange_gain_loss",
|
||||||
|
"account"
|
||||||
],
|
],
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
@@ -101,12 +102,18 @@
|
|||||||
"label": "Exchange Gain/Loss",
|
"label": "Exchange Gain/Loss",
|
||||||
"options": "Company:company:default_currency",
|
"options": "Company:company:default_currency",
|
||||||
"read_only": 1
|
"read_only": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "account",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Account",
|
||||||
|
"options": "Account"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2022-12-12 12:31:44.919895",
|
"modified": "2023-06-07 14:35:06.166907",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Entry Reference",
|
"name": "Payment Entry Reference",
|
||||||
|
|||||||
@@ -29,22 +29,12 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
this.frm.set_query('default_advances_received_account', () => {
|
this.frm.set_query('default_advance_account', () => {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
"company": this.frm.doc.company,
|
"company": this.frm.doc.company,
|
||||||
"is_group": 0,
|
"is_group": 0,
|
||||||
"root_type": "Liability"
|
"root_type": (this.frm.party_type == 'Customer') ? "Liability": "Asset"
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
this.frm.set_query('default_advances_paid_account', () => {
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"company": this.frm.doc.company,
|
|
||||||
"is_group": 0,
|
|
||||||
"root_type": "Asset"
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -169,23 +159,7 @@ erpnext.accounts.PaymentReconciliationController = class PaymentReconciliationCo
|
|||||||
},
|
},
|
||||||
callback: (r) => {
|
callback: (r) => {
|
||||||
if (!r.exc && r.message) {
|
if (!r.exc && r.message) {
|
||||||
this.frm.set_value("default_advances_received_account", r.message);
|
this.frm.set_value("default_advance_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 == 'Customer')?'Supplier':'Customer',
|
|
||||||
party: this.frm.doc.party,
|
|
||||||
is_advance: 1
|
|
||||||
},
|
|
||||||
callback: (r) => {
|
|
||||||
if (!r.exc && r.message) {
|
|
||||||
this.frm.set_value("default_advances_paid_account", r.message);
|
|
||||||
}
|
}
|
||||||
this.frm.refresh();
|
this.frm.refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,7 @@
|
|||||||
"party",
|
"party",
|
||||||
"column_break_4",
|
"column_break_4",
|
||||||
"receivable_payable_account",
|
"receivable_payable_account",
|
||||||
"default_advances_received_account",
|
"default_advance_account",
|
||||||
"default_advances_paid_account",
|
|
||||||
"col_break1",
|
"col_break1",
|
||||||
"from_invoice_date",
|
"from_invoice_date",
|
||||||
"from_payment_date",
|
"from_payment_date",
|
||||||
@@ -190,27 +189,19 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"depends_on": "eval:doc.party_type",
|
"depends_on": "eval:doc.party_type",
|
||||||
"fieldname": "default_advances_received_account",
|
"fieldname": "default_advance_account",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"label": "Default Advances Received Account",
|
"label": "Default Advance Account",
|
||||||
"mandatory_depends_on": "doc.party_type",
|
"mandatory_depends_on": "doc.party_type",
|
||||||
"options": "Account",
|
"options": "Account",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
|
||||||
{
|
|
||||||
"depends_on": "eval:doc.party_type",
|
|
||||||
"fieldname": "default_advances_paid_account",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"label": "Default Advances Paid Account",
|
|
||||||
"mandatory_depends_on": "doc.party_type",
|
|
||||||
"options": "Account"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hide_toolbar": 1,
|
"hide_toolbar": 1,
|
||||||
"icon": "icon-resize-horizontal",
|
"icon": "icon-resize-horizontal",
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-06-02 14:32:27.276083",
|
"modified": "2023-06-05 20:09:58.925427",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Payment Reconciliation",
|
"name": "Payment Reconciliation",
|
||||||
|
|||||||
@@ -13,14 +13,17 @@ import erpnext
|
|||||||
from erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation import (
|
from erpnext.accounts.doctype.process_payment_reconciliation.process_payment_reconciliation import (
|
||||||
is_any_doc_running,
|
is_any_doc_running,
|
||||||
)
|
)
|
||||||
|
from erpnext.accounts.general_ledger import make_gl_entries
|
||||||
from erpnext.accounts.utils import (
|
from erpnext.accounts.utils import (
|
||||||
QueryPaymentLedger,
|
QueryPaymentLedger,
|
||||||
get_outstanding_invoices,
|
get_outstanding_invoices,
|
||||||
reconcile_against_document,
|
reconcile_against_document,
|
||||||
)
|
)
|
||||||
from erpnext.controllers.accounts_controller import get_advance_payment_entries
|
from erpnext.controllers.accounts_controller import (
|
||||||
from erpnext.controllers.accounts_controller import make_advance_liability_entry
|
get_advance_payment_entries,
|
||||||
from erpnext.accounts.general_ledger import make_gl_entries
|
make_advance_liability_entry,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PaymentReconciliation(Document):
|
class PaymentReconciliation(Document):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@@ -57,9 +60,17 @@ class PaymentReconciliation(Document):
|
|||||||
self.add_payment_entries(non_reconciled_payments)
|
self.add_payment_entries(non_reconciled_payments)
|
||||||
|
|
||||||
def get_payment_entries(self):
|
def get_payment_entries(self):
|
||||||
receivable_payable_account = self.receivable_payable_account
|
advance_accounts = []
|
||||||
default_advances_account = self.default_advances_received_account
|
if self.party_type == "Customer":
|
||||||
party_account = [receivable_payable_account, default_advances_account]
|
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
|
||||||
|
|
||||||
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
|
order_doctype = "Sales Order" if self.party_type == "Customer" else "Purchase Order"
|
||||||
condition = frappe._dict(
|
condition = frappe._dict(
|
||||||
{
|
{
|
||||||
@@ -69,7 +80,7 @@ class PaymentReconciliation(Document):
|
|||||||
"from_payment_date": self.get("from_payment_date"),
|
"from_payment_date": self.get("from_payment_date"),
|
||||||
"to_payment_date": self.get("to_payment_date"),
|
"to_payment_date": self.get("to_payment_date"),
|
||||||
"maximum_payment_amount": self.get("maximum_payment_amount"),
|
"maximum_payment_amount": self.get("maximum_payment_amount"),
|
||||||
"minimum_payment_amount": self.get("minimum_payment_amount")
|
"minimum_payment_amount": self.get("minimum_payment_amount"),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -336,7 +347,9 @@ class PaymentReconciliation(Document):
|
|||||||
if row.invoice_number and row.allocated_amount:
|
if row.invoice_number and row.allocated_amount:
|
||||||
if row.invoice_type in ["Sales Invoice", "Purchase Invoice"]:
|
if row.invoice_type in ["Sales Invoice", "Purchase Invoice"]:
|
||||||
gl_entries = []
|
gl_entries = []
|
||||||
make_advance_liability_entry(gl_entries, row.reference_name, row.allocated_amount, row.invoice_number, self.party_type)
|
make_advance_liability_entry(
|
||||||
|
gl_entries, row.reference_name, row.allocated_amount, row.invoice_number, self.party_type
|
||||||
|
)
|
||||||
make_gl_entries(gl_entries)
|
make_gl_entries(gl_entries)
|
||||||
if row.reference_type in ["Sales Invoice", "Purchase Invoice"]:
|
if row.reference_type in ["Sales Invoice", "Purchase Invoice"]:
|
||||||
reconciled_entry = dr_or_cr_notes
|
reconciled_entry = dr_or_cr_notes
|
||||||
|
|||||||
@@ -1086,6 +1086,7 @@
|
|||||||
"fieldtype": "Button",
|
"fieldtype": "Button",
|
||||||
"label": "Get Advances Paid",
|
"label": "Get Advances Paid",
|
||||||
"oldfieldtype": "Button",
|
"oldfieldtype": "Button",
|
||||||
|
"options": "set_advances",
|
||||||
"print_hide": 1
|
"print_hide": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1364,12 +1365,12 @@
|
|||||||
"depends_on": "eval:doc.update_stock && doc.is_internal_supplier",
|
"depends_on": "eval:doc.update_stock && doc.is_internal_supplier",
|
||||||
"fieldname": "set_from_warehouse",
|
"fieldname": "set_from_warehouse",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
|
"ignore_user_permissions": 1,
|
||||||
"label": "Set From Warehouse",
|
"label": "Set From Warehouse",
|
||||||
"no_copy": 1,
|
"no_copy": 1,
|
||||||
"options": "Warehouse",
|
"options": "Warehouse",
|
||||||
"print_hide": 1,
|
"print_hide": 1,
|
||||||
"print_width": "50px",
|
"print_width": "50px",
|
||||||
"ignore_user_permissions": 1,
|
|
||||||
"width": "50px"
|
"width": "50px"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1573,7 +1574,7 @@
|
|||||||
"idx": 204,
|
"idx": 204,
|
||||||
"is_submittable": 1,
|
"is_submittable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-04-29 12:57:50.832598",
|
"modified": "2023-06-05 17:40:35.320635",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Purchase Invoice",
|
"name": "Purchase Invoice",
|
||||||
|
|||||||
@@ -3353,14 +3353,16 @@ def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
|||||||
gl_entries = frappe.db.sql(
|
gl_entries = frappe.db.sql(
|
||||||
"""select account, debit, credit, posting_date
|
"""select account, debit, credit, posting_date
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where voucher_type='Sales Invoice' and voucher_no=%s and posting_date > %s
|
where voucher_type='Sales Invoice' and voucher_no=%s and posting_date >= %s
|
||||||
and is_cancelled = 0
|
and is_cancelled = 0
|
||||||
order by posting_date asc, account asc""",
|
order by posting_date asc, account asc""",
|
||||||
(voucher_no, posting_date),
|
(voucher_no, posting_date),
|
||||||
as_dict=1,
|
as_dict=1,
|
||||||
|
debug=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, gle in enumerate(gl_entries):
|
for i, gle in enumerate(gl_entries):
|
||||||
|
print(i, gle)
|
||||||
doc.assertEqual(expected_gle[i][0], gle.account)
|
doc.assertEqual(expected_gle[i][0], gle.account)
|
||||||
doc.assertEqual(expected_gle[i][1], gle.debit)
|
doc.assertEqual(expected_gle[i][1], gle.debit)
|
||||||
doc.assertEqual(expected_gle[i][2], gle.credit)
|
doc.assertEqual(expected_gle[i][2], gle.credit)
|
||||||
|
|||||||
@@ -380,9 +380,7 @@ def get_party_account(party_type, party=None, company=None, is_advance=False):
|
|||||||
|
|
||||||
return frappe.get_cached_value("Company", company, default_account_name)
|
return frappe.get_cached_value("Company", company, default_account_name)
|
||||||
|
|
||||||
advance_payments_as_liability = frappe.db.get_value("Company", {"company_name": company}, "book_advance_payments_as_liability")
|
if is_advance and party_type in ["Customer", "Supplier"]:
|
||||||
|
|
||||||
if is_advance and advance_payments_as_liability and party_type in ["Customer", "Supplier"]:
|
|
||||||
return get_party_advance_account(party_type, party, company)
|
return get_party_advance_account(party_type, party, company)
|
||||||
|
|
||||||
account = frappe.db.get_value(
|
account = frappe.db.get_value(
|
||||||
@@ -415,9 +413,10 @@ def get_party_account(party_type, party=None, company=None, is_advance=False):
|
|||||||
|
|
||||||
|
|
||||||
def get_party_advance_account(party_type, party, company):
|
def get_party_advance_account(party_type, party, company):
|
||||||
account_name = 'advances_received_account' if party_type == 'Customer' else 'advances_paid_account'
|
|
||||||
account = frappe.db.get_value(
|
account = frappe.db.get_value(
|
||||||
"Party Account", {"parenttype": party_type, "parent": party, "company": company}, account_name
|
"Party Account",
|
||||||
|
{"parenttype": party_type, "parent": party, "company": company},
|
||||||
|
"advance_account",
|
||||||
)
|
)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
@@ -426,14 +425,15 @@ def get_party_advance_account(party_type, party, company):
|
|||||||
account = frappe.db.get_value(
|
account = frappe.db.get_value(
|
||||||
"Party Account",
|
"Party Account",
|
||||||
{"parenttype": party_group_doctype, "parent": group, "company": company},
|
{"parenttype": party_group_doctype, "parent": group, "company": company},
|
||||||
account_name,
|
"advance_account",
|
||||||
)
|
)
|
||||||
|
|
||||||
if not account:
|
if not account:
|
||||||
account = frappe.get_cached_value("Company", company, "default_" + account_name)
|
account = frappe.get_cached_value("Company", company, "default_advance_account")
|
||||||
|
|
||||||
return account
|
return account
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_party_bank_account(party_type, party):
|
def get_party_bank_account(party_type, party):
|
||||||
return frappe.db.get_value(
|
return frappe.db.get_value(
|
||||||
|
|||||||
@@ -498,20 +498,25 @@ def check_if_advance_entry_modified(args):
|
|||||||
journal_entry = frappe.qb.DocType("Journal Entry")
|
journal_entry = frappe.qb.DocType("Journal Entry")
|
||||||
journal_acc = frappe.qb.DocType("Journal Entry Account")
|
journal_acc = frappe.qb.DocType("Journal Entry Account")
|
||||||
|
|
||||||
q = (frappe.qb.from_(journal_entry)
|
q = (
|
||||||
|
frappe.qb.from_(journal_entry)
|
||||||
.innerjoin(journal_acc)
|
.innerjoin(journal_acc)
|
||||||
.on(journal_entry.name == journal_acc.parent)
|
.on(journal_entry.name == journal_acc.parent)
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.get("dr_or_cr") == 'debit_in_account_currency':
|
if args.get("dr_or_cr") == "debit_in_account_currency":
|
||||||
q = q.select(journal_acc.debit_in_account_currency)
|
q = q.select(journal_acc.debit_in_account_currency)
|
||||||
else:
|
else:
|
||||||
q = q.select(journal_acc.credit_in_account_currency)
|
q = q.select(journal_acc.credit_in_account_currency)
|
||||||
|
|
||||||
q = q.where((journal_acc.account == args.get("account"))
|
q = q.where(
|
||||||
|
(journal_acc.account == args.get("account"))
|
||||||
& ((journal_acc.party_type == args.get("party_type")))
|
& ((journal_acc.party_type == args.get("party_type")))
|
||||||
& ((journal_acc.party == args.get("party")))
|
& ((journal_acc.party == args.get("party")))
|
||||||
&((journal_acc.reference_type == None) | (journal_acc.reference_type.isin(['', 'Sales Order', 'Purchase Order'])))
|
& (
|
||||||
|
(journal_acc.reference_type == None)
|
||||||
|
| (journal_acc.reference_type.isin(["", "Sales Order", "Purchase Order"]))
|
||||||
|
)
|
||||||
& ((journal_entry.name == args.get("voucher_no")))
|
& ((journal_entry.name == args.get("voucher_no")))
|
||||||
& ((journal_acc.name == args.get("voucher_detail_no")))
|
& ((journal_acc.name == args.get("voucher_detail_no")))
|
||||||
& ((journal_entry.docstatus == 1))
|
& ((journal_entry.docstatus == 1))
|
||||||
@@ -521,7 +526,8 @@ def check_if_advance_entry_modified(args):
|
|||||||
payment_entry = frappe.qb.DocType("Payment Entry")
|
payment_entry = frappe.qb.DocType("Payment Entry")
|
||||||
payment_ref = frappe.qb.DocType("Payment Entry Reference")
|
payment_ref = frappe.qb.DocType("Payment Entry Reference")
|
||||||
|
|
||||||
q = (frappe.qb.from_(payment_entry)
|
q = (
|
||||||
|
frappe.qb.from_(payment_entry)
|
||||||
.select(payment_entry.name)
|
.select(payment_entry.name)
|
||||||
.where(payment_entry.name == args.get("voucher_no"))
|
.where(payment_entry.name == args.get("voucher_no"))
|
||||||
.where(payment_entry.docstatus == 1)
|
.where(payment_entry.docstatus == 1)
|
||||||
@@ -530,10 +536,11 @@ def check_if_advance_entry_modified(args):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if args.voucher_detail_no:
|
if args.voucher_detail_no:
|
||||||
q = ( q.inner_join(payment_ref)
|
q = (
|
||||||
|
q.inner_join(payment_ref)
|
||||||
.on(payment_entry.name == payment_ref.parent)
|
.on(payment_entry.name == payment_ref.parent)
|
||||||
.where(payment_ref.name == args.get("voucher_detail_no"))
|
.where(payment_ref.name == args.get("voucher_detail_no"))
|
||||||
.where(payment_ref.reference_doctype.isin(('', 'Sales Order', 'Purchase Order')))
|
.where(payment_ref.reference_doctype.isin(("", "Sales Order", "Purchase Order")))
|
||||||
.where(payment_ref.allocated_amount == args.get("unreconciled_amount"))
|
.where(payment_ref.allocated_amount == args.get("unreconciled_amount"))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -921,6 +928,7 @@ def get_outstanding_invoices(
|
|||||||
"outstanding_amount": outstanding_amount,
|
"outstanding_amount": outstanding_amount,
|
||||||
"due_date": d.due_date,
|
"due_date": d.due_date,
|
||||||
"currency": d.currency,
|
"currency": d.currency,
|
||||||
|
"account": d.account,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ frappe.ui.form.on("Supplier", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query('advances_received_account', 'accounts', function (doc, cdt, cdn) {
|
frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) {
|
||||||
var d = locals[cdt][cdn];
|
var d = locals[cdt][cdn];
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
@@ -29,17 +29,6 @@ frappe.ui.form.on("Supplier", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query('advances_paid_account', 'accounts', function (doc, cdt, cdn) {
|
|
||||||
var d = locals[cdt][cdn];
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"root_type": 'Liability',
|
|
||||||
"company": d.company,
|
|
||||||
"is_group": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
frm.set_query("default_bank_account", function() {
|
frm.set_query("default_bank_account", function() {
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ import json
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, bold, throw
|
from frappe import _, bold, throw
|
||||||
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
from frappe.model.workflow import get_workflow_name, is_transition_condition_satisfied
|
||||||
from frappe.query_builder.functions import Abs, Sum
|
|
||||||
from frappe.query_builder.custom import ConstantColumn
|
from frappe.query_builder.custom import ConstantColumn
|
||||||
|
from frappe.query_builder.functions import Abs, Sum
|
||||||
from frappe.utils import (
|
from frappe.utils import (
|
||||||
add_days,
|
add_days,
|
||||||
add_months,
|
add_months,
|
||||||
@@ -859,7 +858,6 @@ class AccountsController(TransactionBase):
|
|||||||
amount = self.get("base_rounded_total") or self.base_grand_total
|
amount = self.get("base_rounded_total") or self.base_grand_total
|
||||||
else:
|
else:
|
||||||
amount = self.get("rounded_total") or self.grand_total
|
amount = self.get("rounded_total") or self.grand_total
|
||||||
|
|
||||||
allocated_amount = min(amount - advance_allocated, d.amount)
|
allocated_amount = min(amount - advance_allocated, d.amount)
|
||||||
advance_allocated += flt(allocated_amount)
|
advance_allocated += flt(allocated_amount)
|
||||||
|
|
||||||
@@ -887,16 +885,18 @@ class AccountsController(TransactionBase):
|
|||||||
amount_field = "credit_in_account_currency"
|
amount_field = "credit_in_account_currency"
|
||||||
order_field = "sales_order"
|
order_field = "sales_order"
|
||||||
order_doctype = "Sales Order"
|
order_doctype = "Sales Order"
|
||||||
party_account = frappe.db.get_values("Company", {"company_name": self.company}, ["default_receivable_account", "default_advances_received_account"])
|
party_account = [
|
||||||
|
get_party_account(party_type, party=party, company=self.company, is_advance=True)
|
||||||
|
]
|
||||||
else:
|
else:
|
||||||
party_type = "Supplier"
|
party_type = "Supplier"
|
||||||
party = self.supplier
|
party = self.supplier
|
||||||
amount_field = "debit_in_account_currency"
|
amount_field = "debit_in_account_currency"
|
||||||
order_field = "purchase_order"
|
order_field = "purchase_order"
|
||||||
order_doctype = "Purchase Order"
|
order_doctype = "Purchase Order"
|
||||||
party_account = frappe.db.get_values("Company", {"company_name": self.company}, ["default_receivable_account", "default_advances_paid_account"])
|
party_account = [
|
||||||
|
get_party_account(party_type, party=party, company=self.company, is_advance=True)
|
||||||
party_account = list(party_account[0])
|
]
|
||||||
|
|
||||||
order_list = list(set(d.get(order_field) for d in self.get("items") if d.get(order_field)))
|
order_list = list(set(d.get(order_field) for d in self.get("items") if d.get(order_field)))
|
||||||
|
|
||||||
@@ -2144,35 +2144,43 @@ def get_advance_journal_entries(
|
|||||||
order_list,
|
order_list,
|
||||||
include_unallocated=True,
|
include_unallocated=True,
|
||||||
):
|
):
|
||||||
journal_entry = frappe.qb.DocType('Journal Entry')
|
journal_entry = frappe.qb.DocType("Journal Entry")
|
||||||
journal_acc = frappe.qb.DocType('Journal Entry Account')
|
journal_acc = frappe.qb.DocType("Journal Entry Account")
|
||||||
q = (frappe.qb.from_(journal_entry)
|
q = (
|
||||||
|
frappe.qb.from_(journal_entry)
|
||||||
.inner_join(journal_acc)
|
.inner_join(journal_acc)
|
||||||
.on(journal_entry.name == journal_acc.parent)
|
.on(journal_entry.name == journal_acc.parent)
|
||||||
.select(
|
.select(
|
||||||
ConstantColumn('Journal Entry').as_('reference_type'),
|
ConstantColumn("Journal Entry").as_("reference_type"),
|
||||||
(journal_entry.name).as_('reference_name'),
|
(journal_entry.name).as_("reference_name"),
|
||||||
(journal_entry.remark).as_('remarks'),
|
(journal_entry.remark).as_("remarks"),
|
||||||
(journal_acc.debit_in_account_currency if party_type == 'Supplier' else journal_acc.credit_in_account_currency).as_('amount'),
|
(
|
||||||
(journal_acc.name).as_('reference_row'),
|
journal_acc.debit_in_account_currency
|
||||||
(journal_acc.reference_name).as_('against_order'),
|
if party_type == "Supplier"
|
||||||
(journal_acc.exchange_rate)
|
else journal_acc.credit_in_account_currency
|
||||||
|
).as_("amount"),
|
||||||
|
(journal_acc.name).as_("reference_row"),
|
||||||
|
(journal_acc.reference_name).as_("against_order"),
|
||||||
|
(journal_acc.exchange_rate),
|
||||||
)
|
)
|
||||||
.where(journal_acc.account.isin(party_account)
|
.where(
|
||||||
|
journal_acc.account.isin(party_account)
|
||||||
& (journal_acc.party_type == party_type)
|
& (journal_acc.party_type == party_type)
|
||||||
& (journal_acc.party == party)
|
& (journal_acc.party == party)
|
||||||
& (journal_acc.is_advance == 'Yes')
|
& (journal_acc.is_advance == "Yes")
|
||||||
& (journal_entry.docstatus == 1)
|
& (journal_entry.docstatus == 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if party_type == "Customer":
|
if party_type == "Customer":
|
||||||
q = q.where(journal_acc.credit_in_account_currency > 0)
|
q = q.where(journal_acc.credit_in_account_currency > 0)
|
||||||
|
|
||||||
|
else:
|
||||||
|
q = q.where(journal_acc.debit_in_account_currency > 0)
|
||||||
|
|
||||||
if order_list:
|
if order_list:
|
||||||
q = q.where(journal_acc.reference_type == order_doctype)
|
q = q.where(journal_acc.reference_type == order_doctype)
|
||||||
if include_unallocated:
|
if include_unallocated:
|
||||||
q = q.where(journal_acc.reference_name.isin(order_list)
|
q = q.where(journal_acc.reference_name.isin(order_list) | (journal_acc.reference_name == ""))
|
||||||
|(journal_acc.reference_name == ''))
|
|
||||||
else:
|
else:
|
||||||
q = q.where(journal_acc.reference_name.isin(order_list))
|
q = q.where(journal_acc.reference_name.isin(order_list))
|
||||||
|
|
||||||
@@ -2194,23 +2202,45 @@ def get_advance_payment_entries(
|
|||||||
condition=None,
|
condition=None,
|
||||||
):
|
):
|
||||||
|
|
||||||
q = build_query(party_type, party, party_account, order_doctype, order_list, include_unallocated, against_all_orders, limit, condition)
|
q = build_query(
|
||||||
|
party_type,
|
||||||
|
party,
|
||||||
|
party_account,
|
||||||
|
order_doctype,
|
||||||
|
order_list,
|
||||||
|
include_unallocated,
|
||||||
|
against_all_orders,
|
||||||
|
limit,
|
||||||
|
condition,
|
||||||
|
)
|
||||||
|
|
||||||
payment_entries = q.run(as_dict=True)
|
payment_entries = q.run(as_dict=True)
|
||||||
|
|
||||||
return list(payment_entries)
|
return list(payment_entries)
|
||||||
|
|
||||||
def build_query(party_type, party, party_account, order_doctype, order_list, include_unallocated, against_all_orders, limit, condition):
|
|
||||||
payment_type = "Receive" if party_type == "Customer" else "Pay"
|
|
||||||
payment_entry = frappe.qb.DocType('Payment Entry')
|
|
||||||
payment_ref = frappe.qb.DocType('Payment Entry Reference')
|
|
||||||
|
|
||||||
q = (frappe.qb.from_(payment_entry)
|
def build_query(
|
||||||
|
party_type,
|
||||||
|
party,
|
||||||
|
party_account,
|
||||||
|
order_doctype,
|
||||||
|
order_list,
|
||||||
|
include_unallocated,
|
||||||
|
against_all_orders,
|
||||||
|
limit,
|
||||||
|
condition,
|
||||||
|
):
|
||||||
|
payment_type = "Receive" if party_type == "Customer" else "Pay"
|
||||||
|
payment_entry = frappe.qb.DocType("Payment Entry")
|
||||||
|
payment_ref = frappe.qb.DocType("Payment Entry Reference")
|
||||||
|
|
||||||
|
q = (
|
||||||
|
frappe.qb.from_(payment_entry)
|
||||||
.select(
|
.select(
|
||||||
ConstantColumn('Payment Entry').as_('reference_type'),
|
ConstantColumn("Payment Entry").as_("reference_type"),
|
||||||
(payment_entry.name).as_('reference_name'),
|
(payment_entry.name).as_("reference_name"),
|
||||||
payment_entry.posting_date,
|
payment_entry.posting_date,
|
||||||
(payment_entry.remarks).as_('remarks')
|
(payment_entry.remarks).as_("remarks"),
|
||||||
)
|
)
|
||||||
.where(payment_entry.payment_type == payment_type)
|
.where(payment_entry.payment_type == payment_type)
|
||||||
.where(payment_entry.party_type == party_type)
|
.where(payment_entry.party_type == party_type)
|
||||||
@@ -2233,28 +2263,56 @@ def build_query(party_type, party, party_account, order_doctype, order_list, inc
|
|||||||
q.select(payment_entry.target_exchange_rate)
|
q.select(payment_entry.target_exchange_rate)
|
||||||
|
|
||||||
if include_unallocated:
|
if include_unallocated:
|
||||||
q = q.select((payment_entry.unallocated_amount).as_('amount'))
|
q = q.select((payment_entry.unallocated_amount).as_("amount"))
|
||||||
q = q.where(payment_entry.unallocated_amount > 0)
|
q = q.where(payment_entry.unallocated_amount > 0)
|
||||||
|
|
||||||
if condition:
|
if condition:
|
||||||
q = q.where(payment_entry.company == condition["company"])
|
q = q.where(payment_entry.company == condition["company"])
|
||||||
q = q.where(payment_entry.posting_date >= condition["from_payment_date"]) if condition.get("from_payment_date") else q
|
q = (
|
||||||
q = q.where(payment_entry.posting_date <= condition["to_payment_date"]) if condition.get("to_payment_date") else q
|
q.where(payment_entry.posting_date >= condition["from_payment_date"])
|
||||||
|
if condition.get("from_payment_date")
|
||||||
|
else q
|
||||||
|
)
|
||||||
|
q = (
|
||||||
|
q.where(payment_entry.posting_date <= condition["to_payment_date"])
|
||||||
|
if condition.get("to_payment_date")
|
||||||
|
else q
|
||||||
|
)
|
||||||
if condition.get("get_payments") == True:
|
if condition.get("get_payments") == True:
|
||||||
q = q.where(payment_entry.cost_center == condition["cost_center"]) if condition.get("cost_center") else q
|
q = (
|
||||||
q = q.where(payment_entry.unallocated_amount >= condition["minimum_payment_amount"]) if condition.get("minimum_payment_amount") else q
|
q.where(payment_entry.cost_center == condition["cost_center"])
|
||||||
q = q.where(payment_entry.unallocated_amount <= condition["maximum_payment_amount"]) if condition.get("maximum_payment_amount") else q
|
if condition.get("cost_center")
|
||||||
|
else q
|
||||||
|
)
|
||||||
|
q = (
|
||||||
|
q.where(payment_entry.unallocated_amount >= condition["minimum_payment_amount"])
|
||||||
|
if condition.get("minimum_payment_amount")
|
||||||
|
else q
|
||||||
|
)
|
||||||
|
q = (
|
||||||
|
q.where(payment_entry.unallocated_amount <= condition["maximum_payment_amount"])
|
||||||
|
if condition.get("maximum_payment_amount")
|
||||||
|
else q
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
q = q.where(payment_entry.total_debit >= condition["minimum_payment_amount"]) if condition.get("minimum_payment_amount") else q
|
q = (
|
||||||
q = q.where(payment_entry.total_debit <= condition["maximum_payment_amount"]) if condition.get("maximum_payment_amount") else q
|
q.where(payment_entry.total_debit >= condition["minimum_payment_amount"])
|
||||||
|
if condition.get("minimum_payment_amount")
|
||||||
|
else q
|
||||||
|
)
|
||||||
|
q = (
|
||||||
|
q.where(payment_entry.total_debit <= condition["maximum_payment_amount"])
|
||||||
|
if condition.get("maximum_payment_amount")
|
||||||
|
else q
|
||||||
|
)
|
||||||
|
|
||||||
elif order_list or against_all_orders:
|
elif order_list or against_all_orders:
|
||||||
q = q.inner_join(payment_ref).on(payment_entry.name == payment_ref.parent)
|
q = q.inner_join(payment_ref).on(payment_entry.name == payment_ref.parent)
|
||||||
q = q.select(
|
q = q.select(
|
||||||
(payment_ref.allocated_amount).as_('amount'),
|
(payment_ref.allocated_amount).as_("amount"),
|
||||||
(payment_ref.name).as_('reference_row'),
|
(payment_ref.name).as_("reference_row"),
|
||||||
(payment_ref.reference_name).as_('against_order'),
|
(payment_ref.reference_name).as_("against_order"),
|
||||||
payment_ref.reference_doctype == order_doctype
|
payment_ref.reference_doctype == order_doctype,
|
||||||
)
|
)
|
||||||
|
|
||||||
if order_list:
|
if order_list:
|
||||||
@@ -2862,7 +2920,10 @@ def validate_regional(doc):
|
|||||||
def validate_einvoice_fields(doc):
|
def validate_einvoice_fields(doc):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def make_advance_liability_entry(gl_entries, pe, allocated_amount, invoice, party_type):
|
|
||||||
|
def make_advance_liability_entry(
|
||||||
|
gl_entries, pe, allocated_amount, invoice, party_type, references=False
|
||||||
|
):
|
||||||
pe = frappe.get_doc("Payment Entry", pe)
|
pe = frappe.get_doc("Payment Entry", pe)
|
||||||
if party_type == "Customer":
|
if party_type == "Customer":
|
||||||
invoice = frappe.get_doc("Sales Invoice", invoice)
|
invoice = frappe.get_doc("Sales Invoice", invoice)
|
||||||
@@ -2880,7 +2941,8 @@ def make_advance_liability_entry(gl_entries, pe, allocated_amount, invoice, part
|
|||||||
against = invoice.credit_to
|
against = invoice.credit_to
|
||||||
party = invoice.supplier
|
party = invoice.supplier
|
||||||
voucher_type = "Purchase Invoice"
|
voucher_type = "Purchase Invoice"
|
||||||
gl_entries.append(invoice.get_gl_dict(
|
gl_entries.append(
|
||||||
|
invoice.get_gl_dict(
|
||||||
{
|
{
|
||||||
"account": account,
|
"account": account,
|
||||||
"party_type": party_type,
|
"party_type": party_type,
|
||||||
@@ -2898,14 +2960,16 @@ def make_advance_liability_entry(gl_entries, pe, allocated_amount, invoice, part
|
|||||||
"cost_center": invoice.cost_center,
|
"cost_center": invoice.cost_center,
|
||||||
"project": invoice.project,
|
"project": invoice.project,
|
||||||
"voucher_type": voucher_type,
|
"voucher_type": voucher_type,
|
||||||
"voucher_no": invoice.name
|
"voucher_no": invoice.name,
|
||||||
},
|
},
|
||||||
invoice.party_account_currency,
|
invoice.party_account_currency,
|
||||||
item=invoice,
|
item=invoice,
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
(dr_or_cr, rev) = ("credit", "debit") if party_type == "Customer" else ("debit", "credit")
|
(dr_or_cr, rev) = ("credit", "debit") if party_type == "Customer" else ("debit", "credit")
|
||||||
gl_entries.append(invoice.get_gl_dict(
|
gl_entries.append(
|
||||||
|
invoice.get_gl_dict(
|
||||||
{
|
{
|
||||||
"account": against,
|
"account": against,
|
||||||
"party_type": party_type,
|
"party_type": party_type,
|
||||||
@@ -2922,11 +2986,10 @@ def make_advance_liability_entry(gl_entries, pe, allocated_amount, invoice, part
|
|||||||
"against_voucher_type": invoice.doctype,
|
"against_voucher_type": invoice.doctype,
|
||||||
"cost_center": invoice.cost_center,
|
"cost_center": invoice.cost_center,
|
||||||
"project": invoice.project,
|
"project": invoice.project,
|
||||||
"voucher_type": voucher_type,
|
"voucher_type": "Payment Entry" if references else voucher_type,
|
||||||
"voucher_no": invoice.name
|
"voucher_no": pe.name if references else invoice.name,
|
||||||
},
|
},
|
||||||
invoice.party_account_currency,
|
invoice.party_account_currency,
|
||||||
item=invoice,
|
item=invoice,
|
||||||
))
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ frappe.ui.form.on("Customer", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query('advances_received_account', 'accounts', function (doc, cdt, cdn) {
|
frm.set_query('advance_account', 'accounts', function (doc, cdt, cdn) {
|
||||||
var d = locals[cdt][cdn];
|
var d = locals[cdt][cdn];
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
@@ -46,16 +46,6 @@ frappe.ui.form.on("Customer", {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frm.set_query('advances_paid_account', 'accounts', function (doc, cdt, cdn) {
|
|
||||||
var d = locals[cdt][cdn];
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"root_type": 'Asset',
|
|
||||||
"company": d.company,
|
|
||||||
"is_group": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (frm.doc.__islocal == 1) {
|
if (frm.doc.__islocal == 1) {
|
||||||
frm.set_value("represents_company", "");
|
frm.set_value("represents_company", "");
|
||||||
|
|||||||
@@ -337,7 +337,7 @@
|
|||||||
"label": "Default Accounts"
|
"label": "Default Accounts"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "Mention if a non-standard receivable account",
|
"description": "Mention if non-standard Receivable account",
|
||||||
"fieldname": "accounts",
|
"fieldname": "accounts",
|
||||||
"fieldtype": "Table",
|
"fieldtype": "Table",
|
||||||
"label": "Accounts",
|
"label": "Accounts",
|
||||||
@@ -568,7 +568,7 @@
|
|||||||
"link_fieldname": "party"
|
"link_fieldname": "party"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"modified": "2023-05-29 14:29:17.789578",
|
"modified": "2023-06-05 13:48:46.152659",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Customer",
|
"name": "Customer",
|
||||||
|
|||||||
@@ -227,8 +227,7 @@ erpnext.company.setup_queries = function(frm) {
|
|||||||
["asset_received_but_not_billed", {"account_type": "Asset Received But Not Billed"}],
|
["asset_received_but_not_billed", {"account_type": "Asset Received But Not Billed"}],
|
||||||
["unrealized_profit_loss_account", {"root_type": ["in", ["Liability", "Asset"]]}],
|
["unrealized_profit_loss_account", {"root_type": ["in", ["Liability", "Asset"]]}],
|
||||||
["default_provisional_account", {"root_type": ["in", ["Liability", "Asset"]]}],
|
["default_provisional_account", {"root_type": ["in", ["Liability", "Asset"]]}],
|
||||||
["default_advances_received_account", {"root_type": "Liability"}],
|
["default_advance_account", {"root_type": ["in", ["Liability", "Asset"]]}],
|
||||||
["default_advances_paid_account", {"root_type": "Asset"}],
|
|
||||||
], function(i, v) {
|
], function(i, v) {
|
||||||
erpnext.company.set_custom_query(frm, v);
|
erpnext.company.set_custom_query(frm, v);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -72,9 +72,8 @@
|
|||||||
"default_finance_book",
|
"default_finance_book",
|
||||||
"advance_payments_section",
|
"advance_payments_section",
|
||||||
"book_advance_payments_as_liability",
|
"book_advance_payments_as_liability",
|
||||||
"default_advances_received_account",
|
"default_advance_account",
|
||||||
"column_break_cui0",
|
"column_break_cui0",
|
||||||
"default_advances_paid_account",
|
|
||||||
"auto_accounting_for_stock_settings",
|
"auto_accounting_for_stock_settings",
|
||||||
"enable_perpetual_inventory",
|
"enable_perpetual_inventory",
|
||||||
"enable_provisional_accounting_for_non_stock_items",
|
"enable_provisional_accounting_for_non_stock_items",
|
||||||
@@ -711,25 +710,17 @@
|
|||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
"label": "Advance Payments"
|
"label": "Advance Payments"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"depends_on": "eval:doc.book_advance_payments_as_liability",
|
|
||||||
"fieldname": "default_advances_received_account",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"label": "Default Advances Received Account",
|
|
||||||
"mandatory_depends_on": "book_advance_payments_as_liability",
|
|
||||||
"options": "Account"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"depends_on": "eval:doc.book_advance_payments_as_liability",
|
|
||||||
"fieldname": "default_advances_paid_account",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"label": "Default Advances Paid Account",
|
|
||||||
"mandatory_depends_on": "book_advance_payments_as_liability",
|
|
||||||
"options": "Account"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"fieldname": "column_break_cui0",
|
"fieldname": "column_break_cui0",
|
||||||
"fieldtype": "Column Break"
|
"fieldtype": "Column Break"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"depends_on": "eval:doc.book_advance_payments_as_liability",
|
||||||
|
"fieldname": "default_advance_account",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"label": "Default Account",
|
||||||
|
"mandatory_depends_on": "book_advance_payments_as_liability",
|
||||||
|
"options": "Account"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"icon": "fa fa-building",
|
"icon": "fa fa-building",
|
||||||
@@ -737,7 +728,7 @@
|
|||||||
"image_field": "company_logo",
|
"image_field": "company_logo",
|
||||||
"is_tree": 1,
|
"is_tree": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-06-02 13:11:41.939016",
|
"modified": "2023-06-05 14:12:37.946451",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Company",
|
"name": "Company",
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(d
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.fields_dict['accounts'].grid.get_field('advances_received_account').get_query = function(doc, cdt, cdn) {
|
cur_frm.fields_dict['accounts'].grid.get_field('advance_account').get_query = function(doc, cdt, cdn) {
|
||||||
var d = locals[cdt][cdn];
|
var d = locals[cdt][cdn];
|
||||||
return {
|
return {
|
||||||
filters: {
|
filters: {
|
||||||
@@ -47,14 +47,3 @@ cur_frm.fields_dict['accounts'].grid.get_field('advances_received_account').get_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur_frm.fields_dict['accounts'].grid.get_field('advances_paid_account').get_query = function(doc, cdt, cdn) {
|
|
||||||
var d = locals[cdt][cdn];
|
|
||||||
return {
|
|
||||||
filters: {
|
|
||||||
"root_type": 'Asset',
|
|
||||||
"company": d.company,
|
|
||||||
"is_group": 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -36,3 +36,14 @@ cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(d
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cur_frm.fields_dict['accounts'].grid.get_field('advance_account').get_query = function(doc, cdt, cdn) {
|
||||||
|
var d = locals[cdt][cdn];
|
||||||
|
return {
|
||||||
|
filters: {
|
||||||
|
"root_type": 'Asset',
|
||||||
|
"company": d.company,
|
||||||
|
"is_group": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user