fix(expense claim): fetch outstanding documents based on party account type
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 5c53d26..ba7ad37 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -357,7 +357,7 @@
return
if not gl_entries:
gl_entries = self.get_gl_entries()
-
+
if gl_entries:
update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"
@@ -504,7 +504,7 @@
asset_category)):
expense_account = (item.expense_account
if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account)
-
+
if not item.is_fixed_asset:
amount = flt(item.base_net_amount, item.precision("base_net_amount"))
else:
@@ -517,7 +517,7 @@
"cost_center": item.cost_center,
"project": item.project
}, account_currency, item=item))
-
+
# If asset is bought through this document and not linked to PR
if self.update_stock and item.landed_cost_voucher_amount:
expenses_included_in_asset_valuation = self.get_company_default("expenses_included_in_asset_valuation")
@@ -539,9 +539,9 @@
"debit": flt(item.landed_cost_voucher_amount),
"project": item.project
}, item=item))
-
+
# update gross amount of asset bought through this document
- assets = frappe.db.get_all('Asset',
+ assets = frappe.db.get_all('Asset',
filters={ 'purchase_invoice': self.name, 'item_code': item.item_code }
)
for asset in assets:
@@ -633,7 +633,7 @@
if asset_eiiav_currency == self.company_currency else
item.item_tax_amount / self.conversion_rate)
}, item=item))
-
+
# When update stock is checked
# Assets are bought through this document then it will be linked to this document
if self.update_stock:
@@ -655,9 +655,9 @@
"debit": flt(item.landed_cost_voucher_amount),
"project": item.project
}, item=item))
-
+
# update gross amount of assets bought through this document
- assets = frappe.db.get_all('Asset',
+ assets = frappe.db.get_all('Asset',
filters={ 'purchase_invoice': self.name, 'item_code': item.item_code }
)
for asset in assets:
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 382a89b..94697be 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -630,7 +630,7 @@
'select name from `tabPurchase Invoice` where release_date IS NOT NULL and release_date > CURDATE()',
as_dict=1
)
- held_invoices = [d['name'] for d in held_invoices]
+ held_invoices = set([d['name'] for d in held_invoices])
return held_invoices
@@ -639,14 +639,19 @@
outstanding_invoices = []
precision = frappe.get_precision("Sales Invoice", "outstanding_amount") or 2
- if erpnext.get_party_account_type(party_type) == 'Receivable':
+ if account:
+ root_type = frappe.get_cached_value("Account", account, "root_type")
+ party_account_type = "Receivable" if root_type == "Asset" else "Payable"
+ else:
+ party_account_type = erpnext.get_party_account_type(party_type)
+
+ if party_account_type == 'Receivable':
dr_or_cr = "debit_in_account_currency - credit_in_account_currency"
payment_dr_or_cr = "credit_in_account_currency - debit_in_account_currency"
else:
dr_or_cr = "credit_in_account_currency - debit_in_account_currency"
payment_dr_or_cr = "debit_in_account_currency - credit_in_account_currency"
- invoice = 'Sales Invoice' if erpnext.get_party_account_type(party_type) == 'Receivable' else 'Purchase Invoice'
held_invoices = get_held_invoices(party_type, party)
invoice_list = frappe.db.sql("""
@@ -665,7 +670,6 @@
group by voucher_type, voucher_no
order by posting_date, name""".format(
dr_or_cr=dr_or_cr,
- invoice = invoice,
condition=condition or ""
), {
"party_type": party_type,
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index f003627..5939150 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -140,32 +140,6 @@
"against": ",".join([d.default_account for d in self.expenses]),
"party_type": "Employee",
"party": self.employee,
- "against_voucher_type": self.doctype,
- "against_voucher": self.name
- })
- )
-
- gl_entry.append(
- self.get_gl_dict({
- "account": data.advance_account,
- "debit": data.allocated_amount,
- "debit_in_account_currency": data.allocated_amount,
- "against": self.payable_account,
- "party_type": "Employee",
- "party": self.employee,
- "against_voucher_type": self.doctype,
- "against_voucher": self.name
- })
- )
-
- gl_entry.append(
- self.get_gl_dict({
- "account": self.payable_account,
- "credit": data.allocated_amount,
- "credit_in_account_currency": data.allocated_amount,
- "against": data.advance_account,
- "party_type": "Employee",
- "party": self.employee,
"against_voucher_type": "Employee Advance",
"against_voucher": data.employee_advance
})