fix(expense claim): fetch outstanding documents based on party account type

This commit is contained in:
Nabin Hait 2019-11-19 18:44:32 +05:30
parent 3f854fce2e
commit 9db9edca2c
3 changed files with 16 additions and 38 deletions

View File

@ -357,7 +357,7 @@ class PurchaseInvoice(BuyingController):
return return
if not gl_entries: if not gl_entries:
gl_entries = self.get_gl_entries() gl_entries = self.get_gl_entries()
if gl_entries: if gl_entries:
update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes" update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"
@ -504,7 +504,7 @@ class PurchaseInvoice(BuyingController):
asset_category)): asset_category)):
expense_account = (item.expense_account expense_account = (item.expense_account
if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account) if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account)
if not item.is_fixed_asset: if not item.is_fixed_asset:
amount = flt(item.base_net_amount, item.precision("base_net_amount")) amount = flt(item.base_net_amount, item.precision("base_net_amount"))
else: else:
@ -517,7 +517,7 @@ class PurchaseInvoice(BuyingController):
"cost_center": item.cost_center, "cost_center": item.cost_center,
"project": item.project "project": item.project
}, account_currency, item=item)) }, account_currency, item=item))
# If asset is bought through this document and not linked to PR # If asset is bought through this document and not linked to PR
if self.update_stock and item.landed_cost_voucher_amount: if self.update_stock and item.landed_cost_voucher_amount:
expenses_included_in_asset_valuation = self.get_company_default("expenses_included_in_asset_valuation") expenses_included_in_asset_valuation = self.get_company_default("expenses_included_in_asset_valuation")
@ -539,9 +539,9 @@ class PurchaseInvoice(BuyingController):
"debit": flt(item.landed_cost_voucher_amount), "debit": flt(item.landed_cost_voucher_amount),
"project": item.project "project": item.project
}, item=item)) }, item=item))
# update gross amount of asset bought through this document # 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 } filters={ 'purchase_invoice': self.name, 'item_code': item.item_code }
) )
for asset in assets: for asset in assets:
@ -633,7 +633,7 @@ class PurchaseInvoice(BuyingController):
if asset_eiiav_currency == self.company_currency else if asset_eiiav_currency == self.company_currency else
item.item_tax_amount / self.conversion_rate) item.item_tax_amount / self.conversion_rate)
}, item=item)) }, item=item))
# When update stock is checked # When update stock is checked
# Assets are bought through this document then it will be linked to this document # Assets are bought through this document then it will be linked to this document
if self.update_stock: if self.update_stock:
@ -655,9 +655,9 @@ class PurchaseInvoice(BuyingController):
"debit": flt(item.landed_cost_voucher_amount), "debit": flt(item.landed_cost_voucher_amount),
"project": item.project "project": item.project
}, item=item)) }, item=item))
# update gross amount of assets bought through this document # 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 } filters={ 'purchase_invoice': self.name, 'item_code': item.item_code }
) )
for asset in assets: for asset in assets:

View File

@ -630,7 +630,7 @@ def get_held_invoices(party_type, party):
'select name from `tabPurchase Invoice` where release_date IS NOT NULL and release_date > CURDATE()', 'select name from `tabPurchase Invoice` where release_date IS NOT NULL and release_date > CURDATE()',
as_dict=1 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 return held_invoices
@ -639,14 +639,19 @@ def get_outstanding_invoices(party_type, party, account, condition=None, filters
outstanding_invoices = [] outstanding_invoices = []
precision = frappe.get_precision("Sales Invoice", "outstanding_amount") or 2 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" dr_or_cr = "debit_in_account_currency - credit_in_account_currency"
payment_dr_or_cr = "credit_in_account_currency - debit_in_account_currency" payment_dr_or_cr = "credit_in_account_currency - debit_in_account_currency"
else: else:
dr_or_cr = "credit_in_account_currency - debit_in_account_currency" dr_or_cr = "credit_in_account_currency - debit_in_account_currency"
payment_dr_or_cr = "debit_in_account_currency - credit_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) held_invoices = get_held_invoices(party_type, party)
invoice_list = frappe.db.sql(""" invoice_list = frappe.db.sql("""
@ -665,7 +670,6 @@ def get_outstanding_invoices(party_type, party, account, condition=None, filters
group by voucher_type, voucher_no group by voucher_type, voucher_no
order by posting_date, name""".format( order by posting_date, name""".format(
dr_or_cr=dr_or_cr, dr_or_cr=dr_or_cr,
invoice = invoice,
condition=condition or "" condition=condition or ""
), { ), {
"party_type": party_type, "party_type": party_type,

View File

@ -140,32 +140,6 @@ class ExpenseClaim(AccountsController):
"against": ",".join([d.default_account for d in self.expenses]), "against": ",".join([d.default_account for d in self.expenses]),
"party_type": "Employee", "party_type": "Employee",
"party": self.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_type": "Employee Advance",
"against_voucher": data.employee_advance "against_voucher": data.employee_advance
}) })