Merge branch 'develop' into make-against-field-dynamic
diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py
index d0940c7..c2188c0 100644
--- a/erpnext/accounts/deferred_revenue.py
+++ b/erpnext/accounts/deferred_revenue.py
@@ -358,9 +358,11 @@
account_currency = get_account_currency(item.expense_account or item.income_account)
if doc.doctype == "Sales Invoice":
+ against_type = "Customer"
against, project = doc.customer, doc.project
credit_account, debit_account = item.income_account, item.deferred_revenue_account
else:
+ against_type = "Supplier"
against, project = doc.supplier, item.project
credit_account, debit_account = item.deferred_expense_account, item.expense_account
@@ -413,6 +415,7 @@
doc,
credit_account,
debit_account,
+ against_type,
against,
amount,
base_amount,
@@ -494,6 +497,7 @@
doc,
credit_account,
debit_account,
+ against_type,
against,
amount,
base_amount,
@@ -515,7 +519,9 @@
doc.get_gl_dict(
{
"account": credit_account,
+ "against_type": against_type,
"against": against,
+ "against_link": against,
"credit": base_amount,
"credit_in_account_currency": amount,
"cost_center": cost_center,
@@ -534,7 +540,9 @@
doc.get_gl_dict(
{
"account": debit_account,
+ "against_type": against_type,
"against": against,
+ "against_link": against,
"debit": base_amount,
"debit_in_account_currency": amount,
"cost_center": cost_center,
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json
index 5063ec6..16df40f 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.json
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json
@@ -17,7 +17,9 @@
"account_currency",
"debit_in_account_currency",
"credit_in_account_currency",
+ "against_type",
"against",
+ "against_link",
"against_voucher_type",
"against_voucher",
"voucher_type",
@@ -129,12 +131,26 @@
"options": "account_currency"
},
{
- "fieldname": "against",
- "fieldtype": "Text",
+ "fieldname": "against_type",
+ "fieldtype": "Link",
"in_filter": 1,
- "label": "Against",
- "oldfieldname": "against",
- "oldfieldtype": "Text"
+ "label": "Against Type",
+ "options": "DocType"
+ },
+ {
+ "fieldname": "against",
+ "fieldtype": "Text",
+ "in_filter": 1,
+ "label": "Against",
+ "oldfieldname": "against",
+ "oldfieldtype": "Text"
+ },
+ {
+ "fieldname": "against_link",
+ "fieldtype": "Dynamic Link",
+ "in_filter": 1,
+ "label": "Against",
+ "options": "against_type"
},
{
"fieldname": "against_voucher_type",
@@ -286,7 +302,7 @@
"idx": 1,
"in_create": 1,
"links": [],
- "modified": "2023-08-16 21:38:44.072267",
+ "modified": "2023-11-08 12:20:23.031733",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
index 5bd4585..ebfa0de 100644
--- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
+++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py
@@ -125,7 +125,9 @@
"account": inv.debit_to,
"party_type": "Customer",
"party": d.customer,
+ "against_type": "Account",
"against": self.accounts_receivable_credit,
+ "against_link": self.accounts_receivable_credit,
"credit": outstanding_in_company_currency,
"credit_in_account_currency": outstanding_in_company_currency
if inv.party_account_currency == company_currency
@@ -145,7 +147,9 @@
"account": self.accounts_receivable_credit,
"party_type": "Customer",
"party": d.customer,
+ "against_type": "Account",
"against": inv.debit_to,
+ "against_link": inv.debit_to,
"debit": outstanding_in_company_currency,
"debit_in_account_currency": outstanding_in_company_currency
if ar_credit_account_currency == company_currency
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 1cff4c7..0b5a37f 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -230,6 +230,7 @@
"account": tax_withholding_details.get("account_head"),
rev_debit_or_credit: tax_withholding_details.get("tax_amount"),
"against_account": parties[0],
+ "against_account_link": parties[0],
},
)
@@ -676,27 +677,68 @@
)
def set_against_account(self):
- accounts_debited, accounts_credited = [], []
if self.voucher_type in ("Deferred Revenue", "Deferred Expense"):
for d in self.get("accounts"):
if d.reference_type == "Sales Invoice":
- field = "customer"
+ against_type = "Customer"
else:
- field = "supplier"
+ against_type = "Supplier"
- d.against_account = frappe.db.get_value(d.reference_type, d.reference_name, field)
+ against_account = frappe.db.get_value(d.reference_type, d.reference_name, against_type.lower())
+ d.against_type = against_type
+ d.against_account = against_account
+ d.against_account_link = against_account
else:
- for d in self.get("accounts"):
- if flt(d.debit) > 0:
- accounts_debited.append(d.party or d.account)
- if flt(d.credit) > 0:
- accounts_credited.append(d.party or d.account)
+ self.get_against_accounts()
- for d in self.get("accounts"):
- if flt(d.debit) > 0:
- d.against_account = ", ".join(list(set(accounts_credited)))
- if flt(d.credit) > 0:
- d.against_account = ", ".join(list(set(accounts_debited)))
+ def get_against_accounts(self):
+ self.against_accounts = []
+ self.split_account = {}
+ self.get_debited_credited_accounts()
+
+ if self.separate_against_account_entries:
+ no_of_credited_acc, no_of_debited_acc = len(self.accounts_credited), len(self.accounts_debited)
+ if no_of_credited_acc > 1 and no_of_debited_acc > 1:
+ frappe.msgprint(
+ _(
+ "Unable to automatically determine {0} accounts. Set them up in the {1} table if needed."
+ ).format(frappe.bold("against"), frappe.bold("Accounting Entries")),
+ alert=True,
+ )
+ elif no_of_credited_acc <= 1 and no_of_debited_acc <= 1:
+ self.set_against_accounts_for_single_dr_cr()
+ self.separate_against_account_entries = 0
+ elif no_of_credited_acc == 1:
+ self.against_accounts = self.accounts_debited
+ self.split_account = self.accounts_credited[0]
+ elif no_of_debited_acc == 1:
+ self.against_accounts = self.accounts_credited
+ self.split_account = self.accounts_debited[0]
+
+ def get_debited_credited_accounts(self):
+ self.accounts_debited, self.accounts_credited = [], []
+ self.separate_against_account_entries = 1
+ for d in self.get("accounts"):
+ if flt(d.debit) > 0:
+ self.accounts_debited.append(d)
+ elif flt(d.credit) > 0:
+ self.accounts_credited.append(d)
+
+ if d.against_account_link:
+ self.separate_against_account_entries = 0
+ break
+
+ def set_against_accounts_for_single_dr_cr(self):
+ against_account = None
+ for d in self.accounts:
+ if flt(d.debit) > 0:
+ against_account = self.accounts_credited[0]
+ elif flt(d.credit) > 0:
+ against_account = self.accounts_debited[0]
+ if against_account:
+ d.against_type = against_account.party_type or "Account"
+ d.against_account = against_account.party or against_account.account
+ d.against_account_link = against_account.party or against_account.account
def validate_debit_credit_amount(self):
if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency):
@@ -893,40 +935,83 @@
def build_gl_map(self):
gl_map = []
+ self.get_against_accounts()
for d in self.get("accounts"):
if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"):
r = [d.user_remark, self.remark]
r = [x for x in r if x]
remarks = "\n".join(r)
- gl_map.append(
- self.get_gl_dict(
- {
- "account": d.account,
- "party_type": d.party_type,
- "due_date": self.due_date,
- "party": d.party,
- "against": d.against_account,
- "debit": flt(d.debit, d.precision("debit")),
- "credit": flt(d.credit, d.precision("credit")),
- "account_currency": d.account_currency,
- "debit_in_account_currency": flt(
- d.debit_in_account_currency, d.precision("debit_in_account_currency")
- ),
- "credit_in_account_currency": flt(
- d.credit_in_account_currency, d.precision("credit_in_account_currency")
- ),
- "against_voucher_type": d.reference_type,
- "against_voucher": d.reference_name,
- "remarks": remarks,
- "voucher_detail_no": d.reference_detail_no,
- "cost_center": d.cost_center,
- "project": d.project,
- "finance_book": self.finance_book,
- },
- item=d,
- )
+ gl_dict = self.get_gl_dict(
+ {
+ "account": d.account,
+ "party_type": d.party_type,
+ "due_date": self.due_date,
+ "party": d.party,
+ "debit": flt(d.debit, d.precision("debit")),
+ "credit": flt(d.credit, d.precision("credit")),
+ "account_currency": d.account_currency,
+ "debit_in_account_currency": flt(
+ d.debit_in_account_currency, d.precision("debit_in_account_currency")
+ ),
+ "credit_in_account_currency": flt(
+ d.credit_in_account_currency, d.precision("credit_in_account_currency")
+ ),
+ "against_voucher_type": d.reference_type,
+ "against_voucher": d.reference_name,
+ "remarks": remarks,
+ "voucher_detail_no": d.reference_detail_no,
+ "cost_center": d.cost_center,
+ "project": d.project,
+ "finance_book": self.finance_book,
+ },
+ item=d,
)
+
+ if not self.separate_against_account_entries:
+ gl_dict.update(
+ {
+ "against_type": d.against_type,
+ "against": d.against_account,
+ "against_link": d.against_account,
+ }
+ )
+ gl_map.append(gl_dict)
+
+ elif d in self.against_accounts:
+ gl_dict.update(
+ {
+ "against_type": self.split_account.get("party_type") or "Account",
+ "against": self.split_account.get("party") or self.split_account.get("account"),
+ "against_link": self.split_account.get("party") or self.split_account.get("account"),
+ }
+ )
+ gl_map.append(gl_dict)
+
+ else:
+ for against_account in self.against_accounts:
+ against_account = against_account.as_dict()
+ debit = against_account.credit or against_account.credit_in_account_currency
+ credit = against_account.debit or against_account.debit_in_account_currency
+ gl_dict = gl_dict.copy()
+ gl_dict.update(
+ {
+ "against_type": against_account.party_type or "Account",
+ "against": against_account.party or against_account.account,
+ "against_link": against_account.party or against_account.account,
+ "debit": flt(debit, d.precision("debit")),
+ "credit": flt(credit, d.precision("credit")),
+ "account_currency": d.account_currency,
+ "debit_in_account_currency": flt(
+ debit / d.exchange_rate, d.precision("debit_in_account_currency")
+ ),
+ "credit_in_account_currency": flt(
+ credit / d.exchange_rate, d.precision("credit_in_account_currency")
+ ),
+ }
+ )
+ gl_map.append(gl_dict)
+
return gl_map
def make_gl_entries(self, cancel=0, adv_adj=0):
diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
index 3132fe9..2b423ac 100644
--- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
+++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
@@ -37,7 +37,9 @@
"col_break3",
"is_advance",
"user_remark",
- "against_account"
+ "against_type",
+ "against_account",
+ "against_account_link"
],
"fields": [
{
@@ -250,14 +252,21 @@
"print_hide": 1
},
{
- "fieldname": "against_account",
- "fieldtype": "Text",
- "hidden": 1,
+ "fieldname": "against_account",
+ "fieldtype": "Text",
+ "hidden": 1,
+ "label": "Against Account",
+ "no_copy": 1,
+ "oldfieldname": "against_account",
+ "oldfieldtype": "Text",
+ "print_hide": 1
+ },
+ {
+ "fieldname": "against_account_link",
+ "fieldtype": "Dynamic Link",
"label": "Against Account",
"no_copy": 1,
- "oldfieldname": "against_account",
- "oldfieldtype": "Text",
- "print_hide": 1
+ "options": "against_type"
},
{
"collapsible": 1,
@@ -280,8 +289,15 @@
"fieldtype": "Data",
"hidden": 1,
"label": "Reference Detail No",
- "no_copy": 1,
- "search_index": 1
+ "no_copy": 1
+ },
+ {
+ "fieldname": "against_type",
+ "fieldtype": "Link",
+ "hidden": 1,
+ "label": "Against Type",
+ "options": "DocType",
+ "print_hide": 1
}
],
"idx": 1,
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 0344e3d..16b32bd 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -1048,7 +1048,9 @@
"account": self.party_account,
"party_type": self.party_type,
"party": self.party,
+ "against_type": "Account",
"against": against_account,
+ "against_link": against_account,
"account_currency": self.party_account_currency,
"cost_center": self.cost_center,
},
@@ -1220,7 +1222,9 @@
{
"account": self.paid_from,
"account_currency": self.paid_from_account_currency,
+ "against_type": self.party_type if self.payment_type == "Pay" else "Account",
"against": self.party if self.payment_type == "Pay" else self.paid_to,
+ "against_link": self.party if self.payment_type == "Pay" else self.paid_to,
"credit_in_account_currency": self.paid_amount,
"credit": self.base_paid_amount,
"cost_center": self.cost_center,
@@ -1235,7 +1239,9 @@
{
"account": self.paid_to,
"account_currency": self.paid_to_account_currency,
+ "against_type": self.party_type if self.payment_type == "Receive" else "Account",
"against": self.party if self.payment_type == "Receive" else self.paid_from,
+ "against_link": self.party if self.payment_type == "Receive" else self.paid_from,
"debit_in_account_currency": self.received_amount,
"debit": self.base_received_amount,
"cost_center": self.cost_center,
@@ -1259,6 +1265,7 @@
rev_dr_or_cr = "credit" if dr_or_cr == "debit" else "debit"
against = self.party or self.paid_to
+ against_type = self.party_type or "Account"
payment_account = self.get_party_account_for_taxes()
tax_amount = d.tax_amount
base_tax_amount = d.base_tax_amount
@@ -1267,7 +1274,9 @@
self.get_gl_dict(
{
"account": d.account_head,
+ "against_type": against_type,
"against": against,
+ "against_link": against,
dr_or_cr: tax_amount,
dr_or_cr + "_in_account_currency": base_tax_amount
if account_currency == self.company_currency
@@ -1292,7 +1301,9 @@
self.get_gl_dict(
{
"account": payment_account,
+ "against_type": against_type,
"against": against,
+ "against_link": against,
rev_dr_or_cr: tax_amount,
rev_dr_or_cr + "_in_account_currency": base_tax_amount
if account_currency == self.company_currency
@@ -1317,7 +1328,9 @@
{
"account": d.account,
"account_currency": account_currency,
+ "against_type": self.party_type or "Account",
"against": self.party or self.paid_from,
+ "against_link": self.party or self.paid_from,
"debit_in_account_currency": d.amount,
"debit": d.amount,
"cost_center": d.cost_center,
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index c6ae937..e7d2972 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -647,7 +647,9 @@
"party_type": "Supplier",
"party": self.supplier,
"due_date": self.due_date,
+ "against_type": "Account",
"against": self.against_expense_account,
+ "against_link": self.against_expense_account,
"credit": base_grand_total,
"credit_in_account_currency": base_grand_total
if self.party_account_currency == self.company_currency
@@ -720,7 +722,9 @@
self.get_gl_dict(
{
"account": warehouse_account[item.warehouse]["account"],
+ "against_type": "Account",
"against": warehouse_account[item.from_warehouse]["account"],
+ "against_link": warehouse_account[item.from_warehouse]["account"],
"cost_center": item.cost_center,
"project": item.project or self.project,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
@@ -740,7 +744,9 @@
self.get_gl_dict(
{
"account": warehouse_account[item.from_warehouse]["account"],
+ "against_type": "Account",
"against": warehouse_account[item.warehouse]["account"],
+ "against_link": warehouse_account[item.warehouse]["account"],
"cost_center": item.cost_center,
"project": item.project or self.project,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
@@ -757,7 +763,9 @@
self.get_gl_dict(
{
"account": item.expense_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"debit": flt(item.base_net_amount, item.precision("base_net_amount")),
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"cost_center": item.cost_center,
@@ -774,7 +782,9 @@
self.get_gl_dict(
{
"account": item.expense_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"debit": warehouse_debit_amount,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"cost_center": item.cost_center,
@@ -793,7 +803,9 @@
self.get_gl_dict(
{
"account": account,
+ "against_type": "Account",
"against": item.expense_account,
+ "against_link": item.expense_account,
"cost_center": item.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(amount["base_amount"]),
@@ -813,7 +825,9 @@
self.get_gl_dict(
{
"account": supplier_warehouse_account,
+ "against_type": "Account",
"against": item.expense_account,
+ "against_link": item.expense_account,
"cost_center": item.cost_center,
"project": item.project or self.project,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
@@ -868,7 +882,9 @@
self.get_gl_dict(
{
"account": expense_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"debit": amount,
"cost_center": item.cost_center,
"project": item.project or self.project,
@@ -894,7 +910,9 @@
self.get_gl_dict(
{
"account": expense_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"debit": discrepancy_caused_by_exchange_rate_difference,
"cost_center": item.cost_center,
"project": item.project or self.project,
@@ -907,7 +925,9 @@
self.get_gl_dict(
{
"account": self.get_company_default("exchange_gain_loss_account"),
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"credit": discrepancy_caused_by_exchange_rate_difference,
"cost_center": item.cost_center,
"project": item.project or self.project,
@@ -952,7 +972,9 @@
self.get_gl_dict(
{
"account": stock_rbnb,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"debit": flt(item.item_tax_amount, item.precision("item_tax_amount")),
"remarks": self.remarks or _("Accounting Entry for Stock"),
"cost_center": self.cost_center,
@@ -1000,7 +1022,9 @@
self.get_gl_dict(
{
"account": cost_of_goods_sold_account,
+ "against_type": "Account",
"against": item.expense_account,
+ "against_link": item.expense_account,
"debit": stock_adjustment_amt,
"remarks": self.get("remarks") or _("Stock Adjustment"),
"cost_center": item.cost_center,
@@ -1030,7 +1054,9 @@
self.get_gl_dict(
{
"account": tax.account_head,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
dr_or_cr: base_amount,
dr_or_cr + "_in_account_currency": base_amount
if account_currency == self.company_currency
@@ -1078,8 +1104,10 @@
self.get_gl_dict(
{
"account": tax.account_head,
+ "against_type": "Supplier",
"cost_center": tax.cost_center,
"against": self.supplier,
+ "against_link": self.supplier,
"credit": applicable_amount,
"remarks": self.remarks or _("Accounting Entry for Stock"),
},
@@ -1097,7 +1125,9 @@
{
"account": tax.account_head,
"cost_center": tax.cost_center,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"credit": valuation_tax[tax.name],
"remarks": self.remarks or _("Accounting Entry for Stock"),
},
@@ -1112,7 +1142,9 @@
self.get_gl_dict(
{
"account": self.unrealized_profit_loss_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"credit": flt(self.total_taxes_and_charges),
"credit_in_account_currency": flt(self.base_total_taxes_and_charges),
"cost_center": self.cost_center,
@@ -1133,7 +1165,9 @@
"account": self.credit_to,
"party_type": "Supplier",
"party": self.supplier,
+ "against_type": "Account",
"against": self.cash_bank_account,
+ "against_link": self.cash_bank_account,
"debit": self.base_paid_amount,
"debit_in_account_currency": self.base_paid_amount
if self.party_account_currency == self.company_currency
@@ -1154,7 +1188,9 @@
self.get_gl_dict(
{
"account": self.cash_bank_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"credit": self.base_paid_amount,
"credit_in_account_currency": self.base_paid_amount
if bank_account_currency == self.company_currency
@@ -1178,7 +1214,9 @@
"account": self.credit_to,
"party_type": "Supplier",
"party": self.supplier,
+ "against_type": "Account",
"against": self.write_off_account,
+ "against_link": self.write_off_account,
"debit": self.base_write_off_amount,
"debit_in_account_currency": self.base_write_off_amount
if self.party_account_currency == self.company_currency
@@ -1198,7 +1236,9 @@
self.get_gl_dict(
{
"account": self.write_off_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"credit": flt(self.base_write_off_amount),
"credit_in_account_currency": self.base_write_off_amount
if write_off_account_currency == self.company_currency
@@ -1225,7 +1265,9 @@
self.get_gl_dict(
{
"account": round_off_account,
+ "against_type": "Supplier",
"against": self.supplier,
+ "against_link": self.supplier,
"debit_in_account_currency": self.rounding_adjustment,
"debit": self.base_rounding_adjustment,
"cost_center": round_off_cost_center
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 85cb367..cc81227 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -7,7 +7,7 @@
from frappe.contacts.doctype.address.address import get_address_display
from frappe.model.mapper import get_mapped_doc
from frappe.model.utils import get_fetch_values
-from frappe.utils import add_days, cint, cstr, flt, formatdate, get_link_to_form, getdate, nowdate
+from frappe.utils import add_days, cint, flt, formatdate, get_link_to_form, getdate, nowdate
import erpnext
from erpnext.accounts.deferred_revenue import validate_service_stop_date
@@ -1042,7 +1042,9 @@
"party_type": "Customer",
"party": self.customer,
"due_date": self.due_date,
+ "against_type": "Account",
"against": self.against_income_account,
+ "against_link": self.against_income_account,
"debit": base_grand_total,
"debit_in_account_currency": base_grand_total
if self.party_account_currency == self.company_currency
@@ -1071,7 +1073,9 @@
self.get_gl_dict(
{
"account": tax.account_head,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"credit": flt(base_amount, tax.precision("tax_amount_after_discount_amount")),
"credit_in_account_currency": (
flt(base_amount, tax.precision("base_tax_amount_after_discount_amount"))
@@ -1092,7 +1096,9 @@
self.get_gl_dict(
{
"account": self.unrealized_profit_loss_account,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"debit": flt(self.total_taxes_and_charges),
"debit_in_account_currency": flt(self.base_total_taxes_and_charges),
"cost_center": self.cost_center,
@@ -1160,7 +1166,9 @@
add_asset_activity(asset.name, _("Asset sold"))
for gle in fixed_asset_gl_entries:
+ gle["against_type"] = "Customer"
gle["against"] = self.customer
+ gle["against_link"] = self.customer
gl_entries.append(self.get_gl_dict(gle, item=item))
self.set_asset_status(asset)
@@ -1181,7 +1189,9 @@
self.get_gl_dict(
{
"account": income_account,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"credit": flt(base_amount, item.precision("base_net_amount")),
"credit_in_account_currency": (
flt(base_amount, item.precision("base_net_amount"))
@@ -1235,9 +1245,9 @@
"account": self.debit_to,
"party_type": "Customer",
"party": self.customer,
- "against": "Expense account - "
- + cstr(self.loyalty_redemption_account)
- + " for the Loyalty Program",
+ "against_type": "Account",
+ "against": self.loyalty_redemption_account,
+ "against_link": self.loyalty_redemption_account,
"credit": self.loyalty_amount,
"against_voucher": self.return_against if cint(self.is_return) else self.name,
"against_voucher_type": self.doctype,
@@ -1251,7 +1261,9 @@
{
"account": self.loyalty_redemption_account,
"cost_center": self.cost_center or self.loyalty_redemption_cost_center,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"debit": self.loyalty_amount,
"remark": "Loyalty Points redeemed by the customer",
},
@@ -1278,7 +1290,9 @@
"account": self.debit_to,
"party_type": "Customer",
"party": self.customer,
+ "against_type": "Account",
"against": payment_mode.account,
+ "against_link": payment_mode.account,
"credit": payment_mode.base_amount,
"credit_in_account_currency": payment_mode.base_amount
if self.party_account_currency == self.company_currency
@@ -1299,7 +1313,9 @@
self.get_gl_dict(
{
"account": payment_mode.account,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"debit": payment_mode.base_amount,
"debit_in_account_currency": payment_mode.base_amount
if payment_mode_account_currency == self.company_currency
@@ -1323,7 +1339,9 @@
"account": self.debit_to,
"party_type": "Customer",
"party": self.customer,
+ "against_type": "Account",
"against": self.account_for_change_amount,
+ "against_link": self.account_for_change_amount,
"debit": flt(self.base_change_amount),
"debit_in_account_currency": flt(self.base_change_amount)
if self.party_account_currency == self.company_currency
@@ -1344,7 +1362,9 @@
self.get_gl_dict(
{
"account": self.account_for_change_amount,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"credit": self.base_change_amount,
"cost_center": self.cost_center,
},
@@ -1370,7 +1390,9 @@
"account": self.debit_to,
"party_type": "Customer",
"party": self.customer,
+ "against_type": "Account",
"against": self.write_off_account,
+ "against_link": self.write_off_account,
"credit": flt(self.base_write_off_amount, self.precision("base_write_off_amount")),
"credit_in_account_currency": (
flt(self.base_write_off_amount, self.precision("base_write_off_amount"))
@@ -1390,7 +1412,9 @@
self.get_gl_dict(
{
"account": self.write_off_account,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"debit": flt(self.base_write_off_amount, self.precision("base_write_off_amount")),
"debit_in_account_currency": (
flt(self.base_write_off_amount, self.precision("base_write_off_amount"))
@@ -1418,7 +1442,9 @@
self.get_gl_dict(
{
"account": round_off_account,
+ "against_type": "Customer",
"against": self.customer,
+ "against_link": self.customer,
"credit_in_account_currency": flt(
self.rounding_adjustment, self.precision("rounding_adjustment")
),
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 9d32a03..380a044 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -635,6 +635,7 @@
new_row.set("reference_name", d["against_voucher"])
new_row.against_account = cstr(jv_detail.against_account)
+ new_row.against_account_link = cstr(jv_detail.against_account)
new_row.is_advance = cstr(jv_detail.is_advance)
new_row.docstatus = 1
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index 7b7953b..12dcc5b 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -614,7 +614,9 @@
self.get_gl_dict(
{
"account": cwip_account,
+ "against_type": "Account",
"against": fixed_asset_account,
+ "against_link": fixed_asset_account,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"posting_date": self.available_for_use_date,
"credit": self.purchase_receipt_amount,
@@ -629,7 +631,9 @@
self.get_gl_dict(
{
"account": fixed_asset_account,
+ "against_type": "Account",
"against": cwip_account,
+ "against_link": cwip_account,
"remarks": self.get("remarks") or _("Accounting Entry for Asset"),
"posting_date": self.available_for_use_date,
"debit": self.purchase_receipt_amount,
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index 9e3ec6f..536845e 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -256,7 +256,16 @@
flt(18000.0 + pro_rata_amount, asset.precision("gross_purchase_amount")),
0.0,
),
- ("_Test Fixed Asset - _TC", 0.0, 100000.0),
+ (
+ "_Test Fixed Asset - _TC",
+ 0.0,
+ flt(18000.0 + pro_rata_amount, asset.precision("gross_purchase_amount")),
+ ),
+ (
+ "_Test Fixed Asset - _TC",
+ 0.0,
+ flt(82000.0 - pro_rata_amount, asset.precision("gross_purchase_amount")),
+ ),
(
"_Test Gain/Loss on Asset Disposal - _TC",
flt(82000.0 - pro_rata_amount, asset.precision("gross_purchase_amount")),
@@ -267,7 +276,7 @@
gle = frappe.db.sql(
"""select account, debit, credit from `tabGL Entry`
where voucher_type='Journal Entry' and voucher_no = %s
- order by account""",
+ order by account, credit""",
asset.journal_entry_for_scrap,
)
self.assertSequenceEqual(gle, expected_gle)
diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py
index 728764b..31aee33 100644
--- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py
+++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py
@@ -430,7 +430,9 @@
self.get_gl_dict(
{
"account": account,
+ "against_type": "Account",
"against": target_account,
+ "against_link": target_account,
"cost_center": item_row.cost_center,
"project": item_row.get("project") or self.get("project"),
"remarks": self.get("remarks") or "Accounting Entry for Stock",
@@ -471,7 +473,9 @@
self.set_consumed_asset_status(asset)
for gle in fixed_asset_gl_entries:
+ gle["against_type"] = "Account"
gle["against"] = target_account
+ gle["against_link"] = target_account
gl_entries.append(self.get_gl_dict(gle, item=item))
target_against.add(gle["account"])
@@ -487,7 +491,9 @@
self.get_gl_dict(
{
"account": item_row.expense_account,
+ "against_type": "Account",
"against": target_account,
+ "against_link": target_account,
"cost_center": item_row.cost_center,
"project": item_row.get("project") or self.get("project"),
"remarks": self.get("remarks") or "Accounting Entry for Stock",
@@ -498,41 +504,46 @@
)
def get_gl_entries_for_target_item(self, gl_entries, target_against, precision):
- if self.target_is_fixed_asset:
- # Capitalization
- gl_entries.append(
- self.get_gl_dict(
- {
- "account": self.target_fixed_asset_account,
- "against": ", ".join(target_against),
- "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
- "debit": flt(self.total_value, precision),
- "cost_center": self.get("cost_center"),
- },
- item=self,
- )
- )
- else:
- # Target Stock Item
- sle_list = self.sle_map.get(self.name)
- for sle in sle_list:
- stock_value_difference = flt(sle.stock_value_difference, precision)
- account = self.warehouse_account[sle.warehouse]["account"]
-
+ for target_account in target_against:
+ if self.target_is_fixed_asset:
+ # Capitalization
gl_entries.append(
self.get_gl_dict(
{
- "account": account,
- "against": ", ".join(target_against),
- "cost_center": self.cost_center,
- "project": self.get("project"),
- "remarks": self.get("remarks") or "Accounting Entry for Stock",
- "debit": stock_value_difference,
+ "account": self.target_fixed_asset_account,
+ "against_type": "Account",
+ "against": target_account,
+ "against_link": target_account,
+ "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+ "debit": flt(self.total_value, precision) / len(target_against),
+ "cost_center": self.get("cost_center"),
},
- self.warehouse_account[sle.warehouse]["account_currency"],
item=self,
)
)
+ else:
+ # Target Stock Item
+ sle_list = self.sle_map.get(self.name)
+ for sle in sle_list:
+ stock_value_difference = flt(sle.stock_value_difference, precision)
+ account = self.warehouse_account[sle.warehouse]["account"]
+
+ gl_entries.append(
+ self.get_gl_dict(
+ {
+ "account": account,
+ "against_type": "Account",
+ "against": target_account,
+ "against_link": target_account,
+ "cost_center": self.cost_center,
+ "project": self.get("project"),
+ "remarks": self.get("remarks") or "Accounting Entry for Stock",
+ "debit": stock_value_difference / len(target_against),
+ },
+ self.warehouse_account[sle.warehouse]["account_currency"],
+ item=self,
+ )
+ )
def create_target_asset(self):
if (
diff --git a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py
index ac7c90d..7a7a10d 100644
--- a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py
+++ b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py
@@ -98,12 +98,12 @@
# Test General Ledger Entries
expected_gle = {
- "_Test Fixed Asset - TCP1": 3000,
+ "_Test Fixed Asset - TCP1": 2999.99,
"Expenses Included In Asset Valuation - TCP1": -1000,
"_Test Warehouse - TCP1": -2000,
+ "Round Off - TCP1": 0.01,
}
actual_gle = get_actual_gle_dict(asset_capitalization.name)
-
self.assertEqual(actual_gle, expected_gle)
# Test Stock Ledger Entries
@@ -189,9 +189,10 @@
# Test General Ledger Entries
default_expense_account = frappe.db.get_value("Company", company, "default_expense_account")
expected_gle = {
- "_Test Fixed Asset - _TC": 3000,
+ "_Test Fixed Asset - _TC": 2999.99,
"Expenses Included In Asset Valuation - _TC": -1000,
default_expense_account: -2000,
+ "Round Off - _TC": 0.01,
}
actual_gle = get_actual_gle_dict(asset_capitalization.name)
@@ -376,9 +377,10 @@
# Test General Ledger Entries
expected_gle = {
- "_Test Warehouse - TCP1": consumed_asset_value_before_disposal,
"_Test Accumulated Depreciations - TCP1": accumulated_depreciation,
"_Test Fixed Asset - TCP1": -consumed_asset_purchase_value,
+ "_Test Warehouse - TCP1": consumed_asset_value_before_disposal - 0.01,
+ "Round Off - TCP1": 0.01,
}
actual_gle = get_actual_gle_dict(asset_capitalization.name)
self.assertEqual(actual_gle, expected_gle)
diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py
index 9c2b8bc..0b072b2 100644
--- a/erpnext/assets/doctype/asset_repair/asset_repair.py
+++ b/erpnext/assets/doctype/asset_repair/asset_repair.py
@@ -241,7 +241,9 @@
"account": fixed_asset_account,
"debit": self.repair_cost,
"debit_in_account_currency": self.repair_cost,
+ "against_type": "Account",
"against": pi_expense_account,
+ "against_link": pi_expense_account,
"voucher_type": self.doctype,
"voucher_no": self.name,
"cost_center": self.cost_center,
@@ -260,7 +262,9 @@
"account": pi_expense_account,
"credit": self.repair_cost,
"credit_in_account_currency": self.repair_cost,
+ "against_type": "Account",
"against": fixed_asset_account,
+ "against_link": fixed_asset_account,
"voucher_type": self.doctype,
"voucher_no": self.name,
"cost_center": self.cost_center,
@@ -294,7 +298,9 @@
"account": item.expense_account or default_expense_account,
"credit": item.amount,
"credit_in_account_currency": item.amount,
+ "against_type": "Account",
"against": fixed_asset_account,
+ "against_link": fixed_asset_account,
"voucher_type": self.doctype,
"voucher_no": self.name,
"cost_center": self.cost_center,
@@ -311,7 +317,9 @@
"account": fixed_asset_account,
"debit": item.amount,
"debit_in_account_currency": item.amount,
+ "against_type": "Account",
"against": item.expense_account or default_expense_account,
+ "against_link": item.expense_account or default_expense_account,
"voucher_type": self.doctype,
"voucher_no": self.name,
"cost_center": self.cost_center,
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index d12d50d..154d490 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -1088,6 +1088,7 @@
)
credit_or_debit = "credit" if self.doctype == "Purchase Invoice" else "debit"
+ against_type = "Supplier" if self.doctype == "Purchase Invoice" else "Customer"
against = self.supplier if self.doctype == "Purchase Invoice" else self.customer
if precision_loss:
@@ -1095,7 +1096,9 @@
self.get_gl_dict(
{
"account": round_off_account,
+ "against_type": against_type,
"against": against,
+ "against_link": against,
credit_or_debit: precision_loss,
"cost_center": round_off_cost_center
if self.use_company_roundoff_cost_center
@@ -1444,11 +1447,13 @@
if self.doctype == "Purchase Invoice":
dr_or_cr = "credit"
rev_dr_cr = "debit"
+ against_type = "Supplier"
supplier_or_customer = self.supplier
else:
dr_or_cr = "debit"
rev_dr_cr = "credit"
+ against_type = "Customer"
supplier_or_customer = self.customer
if enable_discount_accounting:
@@ -1473,7 +1478,9 @@
self.get_gl_dict(
{
"account": item.discount_account,
+ "against_type": against_type,
"against": supplier_or_customer,
+ "against_link": supplier_or_customer,
dr_or_cr: flt(
discount_amount * self.get("conversion_rate"), item.precision("discount_amount")
),
@@ -1491,7 +1498,9 @@
self.get_gl_dict(
{
"account": income_or_expense_account,
+ "against_type": against_type,
"against": supplier_or_customer,
+ "against_link": supplier_or_customer,
rev_dr_cr: flt(
discount_amount * self.get("conversion_rate"), item.precision("discount_amount")
),
@@ -1514,7 +1523,9 @@
self.get_gl_dict(
{
"account": self.additional_discount_account,
+ "against_type": against_type,
"against": supplier_or_customer,
+ "against_link": supplier_or_customer,
dr_or_cr: self.base_discount_amount,
"cost_center": self.cost_center or erpnext.get_default_cost_center(self.company),
},
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index fc45c7a..a005c8c 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -162,7 +162,9 @@
self.get_gl_dict(
{
"account": warehouse_account[sle.warehouse]["account"],
+ "against_type": "Account",
"against": expense_account,
+ "against_link": expense_account,
"cost_center": item_row.cost_center,
"project": item_row.project or self.get("project"),
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
@@ -178,7 +180,9 @@
self.get_gl_dict(
{
"account": expense_account,
+ "against_type": "Account",
"against": warehouse_account[sle.warehouse]["account"],
+ "against_link": warehouse_account[sle.warehouse]["account"],
"cost_center": item_row.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"debit": -1 * flt(sle.stock_value_difference, precision),
@@ -210,7 +214,9 @@
self.get_gl_dict(
{
"account": expense_account,
+ "against_type": "Account",
"against": warehouse_asset_account,
+ "against_link": warehouse_asset_account,
"cost_center": item_row.cost_center,
"project": item_row.project or self.get("project"),
"remarks": _("Rounding gain/loss Entry for Stock Transfer"),
@@ -226,7 +232,9 @@
self.get_gl_dict(
{
"account": warehouse_asset_account,
+ "against_type": "Account",
"against": expense_account,
+ "against_link": expense_account,
"cost_center": item_row.cost_center,
"remarks": _("Rounding gain/loss Entry for Stock Transfer"),
"credit": sle_rounding_diff,
@@ -826,6 +834,7 @@
credit,
remarks,
against_account,
+ against_type="Account",
debit_in_account_currency=None,
credit_in_account_currency=None,
account_currency=None,
@@ -840,7 +849,9 @@
"cost_center": cost_center,
"debit": debit,
"credit": credit,
+ "against_type": against_type,
"against": against_account,
+ "against_link": against_account,
"remarks": remarks,
}
diff --git a/erpnext/regional/united_arab_emirates/utils.py b/erpnext/regional/united_arab_emirates/utils.py
index efeaeed..250a4b1 100644
--- a/erpnext/regional/united_arab_emirates/utils.py
+++ b/erpnext/regional/united_arab_emirates/utils.py
@@ -153,7 +153,9 @@
"account": tax.account_head,
"cost_center": tax.cost_center,
"posting_date": doc.posting_date,
+ "against_type": "Supplier",
"against": doc.supplier,
+ "against_link": doc.supplier,
dr_or_cr: tax.base_tax_amount_after_discount_amount,
dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount
if account_currency == doc.company_currency
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index a5940f0..e02dfed 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -406,6 +406,7 @@
debit=0.0,
credit=discrepancy_caused_by_exchange_rate_difference,
remarks=remarks,
+ against_type="Supplier",
against_account=self.supplier,
debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference,
account_currency=account_currency,
@@ -419,6 +420,7 @@
debit=discrepancy_caused_by_exchange_rate_difference,
credit=0.0,
remarks=remarks,
+ against_type="Supplier",
against_account=self.supplier,
debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference,
account_currency=account_currency,
@@ -684,7 +686,7 @@
# Backward compatibility:
# and charges added via Landed Cost Voucher,
# post valuation related charges on "Stock Received But Not Billed"
- against_account = ", ".join([d.account for d in gl_entries if flt(d.debit) > 0])
+ against_accounts = [d.account for d in gl_entries if flt(d.debit) > 0]
total_valuation_amount = sum(valuation_tax.values())
amount_including_divisional_loss = negative_expense_to_be_booked
stock_rbnb = (
@@ -716,16 +718,17 @@
)
amount_including_divisional_loss -= applicable_amount
- self.add_gl_entry(
- gl_entries=gl_entries,
- account=account,
- cost_center=tax.cost_center,
- debit=0.0,
- credit=applicable_amount,
- remarks=self.remarks or _("Accounting Entry for Stock"),
- against_account=against_account,
- item=tax,
- )
+ for against in against_accounts:
+ self.add_gl_entry(
+ gl_entries=gl_entries,
+ account=account,
+ cost_center=tax.cost_center,
+ debit=0.0,
+ credit=flt(applicable_amount) / len(against_accounts),
+ remarks=self.remarks or _("Accounting Entry for Stock"),
+ against_account=against,
+ item=tax,
+ )
i += 1
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index b06de2e..b9e1af5 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -1386,7 +1386,9 @@
self.get_gl_dict(
{
"account": account,
+ "against_type": "Account",
"against": d.expense_account,
+ "against_link": d.expense_account,
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit_in_account_currency": flt(amount["amount"]),
@@ -1400,7 +1402,9 @@
self.get_gl_dict(
{
"account": d.expense_account,
+ "against_type": "Account",
"against": account,
+ "against_link": account,
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": -1