diff --git a/erpnext/__init__.py b/erpnext/__init__.py index aa52b834f3e..eb3d0a77be7 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -4,7 +4,7 @@ import inspect import frappe from erpnext.hooks import regional_overrides -__version__ = '9.2.9' +__version__ = '9.2.10' def get_default_company(user=None): '''Get default company for user''' diff --git a/erpnext/accounts/doctype/asset/depreciation.py b/erpnext/accounts/doctype/asset/depreciation.py index 495433a8b1d..c72cb968daf 100644 --- a/erpnext/accounts/doctype/asset/depreciation.py +++ b/erpnext/accounts/doctype/asset/depreciation.py @@ -151,11 +151,14 @@ def restore_asset(asset_name): asset.set_status() @frappe.whitelist() -def get_gl_entries_on_asset_disposal(asset, selling_amount=0): +def get_gl_entries_on_asset_disposal(asset, is_sale=False): fixed_asset_account, accumulated_depr_account, depr_expense_account = get_depreciation_accounts(asset) - disposal_account, depreciation_cost_center = get_disposal_account_and_cost_center(asset.company) accumulated_depr_amount = flt(asset.gross_purchase_amount) - flt(asset.value_after_depreciation) + expense_account, cost_center = get_disposal_account_and_cost_center(asset.company) + if is_sale: + expense_account = depr_expense_account + gl_entries = [ { "account": fixed_asset_account, @@ -169,14 +172,12 @@ def get_gl_entries_on_asset_disposal(asset, selling_amount=0): } ] - profit_amount = flt(selling_amount) - flt(asset.value_after_depreciation) - if flt(asset.value_after_depreciation) and profit_amount: - debit_or_credit = "debit" if profit_amount < 0 else "credit" + if flt(asset.value_after_depreciation): gl_entries.append({ - "account": disposal_account, - "cost_center": depreciation_cost_center, - debit_or_credit: abs(profit_amount), - debit_or_credit + "_in_account_currency": abs(profit_amount) + "account": expense_account, + "cost_center": cost_center, + "debit": flt(asset.value_after_depreciation), + "debit_in_account_currency": flt(asset.value_after_depreciation) }) return gl_entries diff --git a/erpnext/accounts/doctype/asset/test_asset.py b/erpnext/accounts/doctype/asset/test_asset.py index 831373a9c99..fd66d1fb679 100644 --- a/erpnext/accounts/doctype/asset/test_asset.py +++ b/erpnext/accounts/doctype/asset/test_asset.py @@ -188,7 +188,6 @@ class TestAsset(unittest.TestCase): asset.load_from_db() depr_entry = asset.get("schedules")[0].journal_entry self.assertFalse(depr_entry) - def test_scrap_asset(self): asset = frappe.get_doc("Asset", "Macbook Pro 1") @@ -234,8 +233,9 @@ class TestAsset(unittest.TestCase): expected_gle = ( ("_Test Accumulated Depreciations - _TC", 30000.0, 0.0), + ("_Test Depreciations - _TC", 70000.0, 0.0), ("_Test Fixed Asset - _TC", 0.0, 100000.0), - ("_Test Gain/Loss on Asset Disposal - _TC", 45000.0, 0.0), + ("_Test Gain/Loss on Asset Disposal - _TC", 0.0, 25000.0), ("Debtors - _TC", 25000.0, 0.0) ) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 52d8a2d5ceb..c5e03064862 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -252,7 +252,6 @@ frappe.ui.form.on('Payment Entry', { date: frm.doc.posting_date }, callback: function(r, rt) { - console.log(r, rt); if(r.message) { if(frm.doc.payment_type == "Receive") { frm.set_value("paid_from", r.message.party_account); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 995a333ebad..db9969d133e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -670,28 +670,28 @@ class SalesInvoice(SellingController): # income account gl entries for item in self.get("items"): if flt(item.base_net_amount): + account_currency = get_account_currency(item.income_account) + gl_entries.append( + self.get_gl_dict({ + "account": item.income_account, + "against": self.customer, + "credit": item.base_net_amount, + "credit_in_account_currency": item.base_net_amount \ + if account_currency==self.company_currency else item.net_amount, + "cost_center": item.cost_center + }, account_currency) + ) + if item.is_fixed_asset: asset = frappe.get_doc("Asset", item.asset) - fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset, item.base_net_amount) + fixed_asset_gl_entries = get_gl_entries_on_asset_disposal(asset, is_sale=True) for gle in fixed_asset_gl_entries: gle["against"] = self.customer gl_entries.append(self.get_gl_dict(gle)) asset.db_set("disposal_date", self.posting_date) asset.set_status("Sold" if self.docstatus==1 else None) - else: - account_currency = get_account_currency(item.income_account) - gl_entries.append( - self.get_gl_dict({ - "account": item.income_account, - "against": self.customer, - "credit": item.base_net_amount, - "credit_in_account_currency": item.base_net_amount \ - if account_currency==self.company_currency else item.net_amount, - "cost_center": item.cost_center - }, account_currency) - ) # expense account gl entries if cint(self.update_stock) and \ diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index ce049f5d872..f6558308642 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -176,29 +176,34 @@ def get_party_account(party_type, party, company): if not company: frappe.throw(_("Please select a Company")) - if party: + if not party: + return + + account = frappe.db.get_value("Party Account", + {"parenttype": party_type, "parent": party, "company": company}, "account") + + if not account and party_type in ['Customer', 'Supplier']: + party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type" + group = frappe.db.get_value(party_type, party, scrub(party_group_doctype)) account = frappe.db.get_value("Party Account", - {"parenttype": party_type, "parent": party, "company": company}, "account") + {"parenttype": party_group_doctype, "parent": group, "company": company}, "account") - if not account and party_type in ['Customer', 'Supplier']: - party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type" - group = frappe.db.get_value(party_type, party, scrub(party_group_doctype)) - account = frappe.db.get_value("Party Account", - {"parenttype": party_group_doctype, "parent": group, "company": company}, "account") + if not account and party_type in ['Customer', 'Supplier']: + default_account_name = "default_receivable_account" \ + if party_type=="Customer" else "default_payable_account" + account = frappe.db.get_value("Company", company, default_account_name) - if not account and party_type in ['Customer', 'Supplier']: - default_account_name = "default_receivable_account" \ - if party_type=="Customer" else "default_payable_account" - account = frappe.db.get_value("Company", company, default_account_name) + existing_gle_currency = get_party_gle_currency(party_type, party, company) + if existing_gle_currency: + if account: + account_currency = frappe.db.get_value("Account", account, "account_currency") + if (account and account_currency != existing_gle_currency) or not account: + account = get_party_gle_account(party_type, party, company) - existing_gle_currency = get_party_gle_currency(party_type, party, company) - if existing_gle_currency: - if account: - account_currency = frappe.db.get_value("Account", account, "account_currency") - if (account and account_currency != existing_gle_currency) or not account: - account = get_party_gle_account(party_type, party, company) + if not account: + frappe.throw(_("Party account not specified, please setup default party account in company")) - return account + return account def get_party_account_currency(party_type, party, company): def generator(): diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 0003990e2c8..a8fd5e9589f 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -593,7 +593,7 @@ def get_outstanding_invoices(party_type, party, account, condition=None): select ifnull(sum({payment_dr_or_cr}), 0) from `tabGL Entry` payment_gl_entry where payment_gl_entry.against_voucher_type = invoice_gl_entry.voucher_type - and payment_gl_entry.against_voucher = invoice_gl_entry.voucher_no + and payment_gl_entry.against_voucher = invoice_gl_entry.against_voucher and payment_gl_entry.party_type = invoice_gl_entry.party_type and payment_gl_entry.party = invoice_gl_entry.party and payment_gl_entry.account = invoice_gl_entry.account diff --git a/erpnext/schools/doctype/fee_schedule/fee_schedule.py b/erpnext/schools/doctype/fee_schedule/fee_schedule.py index fc2907aaaf2..3e1dd0ccb9e 100644 --- a/erpnext/schools/doctype/fee_schedule/fee_schedule.py +++ b/erpnext/schools/doctype/fee_schedule/fee_schedule.py @@ -9,6 +9,7 @@ from frappe.model.mapper import get_mapped_doc from frappe.utils import money_in_words from frappe.utils import cint, flt, cstr from frappe.utils.background_jobs import enqueue +from frappe import _ class FeeSchedule(Document): @@ -57,6 +58,10 @@ def generate_fee(fee_schedule): error = False total_records = sum([int(d.total_students) for d in doc.student_groups]) created_records = 0 + + if not total_records: + frappe.throw(_("Please setup Students under Student Groups")) + for d in doc.student_groups: students = frappe.db.sql(""" select sg.program, sg.batch, sgs.student, sgs.student_name from `tabStudent Group` sg, `tabStudent Group Student` sgs