Merge branch 'master' into develop

This commit is contained in:
Nabin Hait
2017-11-13 15:10:17 +05:30
8 changed files with 55 additions and 45 deletions

View File

@@ -4,7 +4,7 @@ import inspect
import frappe import frappe
from erpnext.hooks import regional_overrides from erpnext.hooks import regional_overrides
__version__ = '9.2.9' __version__ = '9.2.10'
def get_default_company(user=None): def get_default_company(user=None):
'''Get default company for user''' '''Get default company for user'''

View File

@@ -151,11 +151,14 @@ def restore_asset(asset_name):
asset.set_status() asset.set_status()
@frappe.whitelist() @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) 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) 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 = [ gl_entries = [
{ {
"account": fixed_asset_account, "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):
if flt(asset.value_after_depreciation) and profit_amount:
debit_or_credit = "debit" if profit_amount < 0 else "credit"
gl_entries.append({ gl_entries.append({
"account": disposal_account, "account": expense_account,
"cost_center": depreciation_cost_center, "cost_center": cost_center,
debit_or_credit: abs(profit_amount), "debit": flt(asset.value_after_depreciation),
debit_or_credit + "_in_account_currency": abs(profit_amount) "debit_in_account_currency": flt(asset.value_after_depreciation)
}) })
return gl_entries return gl_entries

View File

@@ -188,7 +188,6 @@ class TestAsset(unittest.TestCase):
asset.load_from_db() asset.load_from_db()
depr_entry = asset.get("schedules")[0].journal_entry depr_entry = asset.get("schedules")[0].journal_entry
self.assertFalse(depr_entry) self.assertFalse(depr_entry)
def test_scrap_asset(self): def test_scrap_asset(self):
asset = frappe.get_doc("Asset", "Macbook Pro 1") asset = frappe.get_doc("Asset", "Macbook Pro 1")
@@ -234,8 +233,9 @@ class TestAsset(unittest.TestCase):
expected_gle = ( expected_gle = (
("_Test Accumulated Depreciations - _TC", 30000.0, 0.0), ("_Test Accumulated Depreciations - _TC", 30000.0, 0.0),
("_Test Depreciations - _TC", 70000.0, 0.0),
("_Test Fixed Asset - _TC", 0.0, 100000.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) ("Debtors - _TC", 25000.0, 0.0)
) )

View File

@@ -252,7 +252,6 @@ frappe.ui.form.on('Payment Entry', {
date: frm.doc.posting_date date: frm.doc.posting_date
}, },
callback: function(r, rt) { callback: function(r, rt) {
console.log(r, rt);
if(r.message) { if(r.message) {
if(frm.doc.payment_type == "Receive") { if(frm.doc.payment_type == "Receive") {
frm.set_value("paid_from", r.message.party_account); frm.set_value("paid_from", r.message.party_account);

View File

@@ -670,28 +670,28 @@ class SalesInvoice(SellingController):
# income account gl entries # income account gl entries
for item in self.get("items"): for item in self.get("items"):
if flt(item.base_net_amount): 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: if item.is_fixed_asset:
asset = frappe.get_doc("Asset", item.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: for gle in fixed_asset_gl_entries:
gle["against"] = self.customer gle["against"] = self.customer
gl_entries.append(self.get_gl_dict(gle)) gl_entries.append(self.get_gl_dict(gle))
asset.db_set("disposal_date", self.posting_date) asset.db_set("disposal_date", self.posting_date)
asset.set_status("Sold" if self.docstatus==1 else None) 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 # expense account gl entries
if cint(self.update_stock) and \ if cint(self.update_stock) and \

View File

@@ -176,29 +176,34 @@ def get_party_account(party_type, party, company):
if not company: if not company:
frappe.throw(_("Please select a 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", 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']: if not account and party_type in ['Customer', 'Supplier']:
party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type" default_account_name = "default_receivable_account" \
group = frappe.db.get_value(party_type, party, scrub(party_group_doctype)) if party_type=="Customer" else "default_payable_account"
account = frappe.db.get_value("Party Account", account = frappe.db.get_value("Company", company, default_account_name)
{"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
if not account and party_type in ['Customer', 'Supplier']: existing_gle_currency = get_party_gle_currency(party_type, party, company)
default_account_name = "default_receivable_account" \ if existing_gle_currency:
if party_type=="Customer" else "default_payable_account" if account:
account = frappe.db.get_value("Company", company, default_account_name) 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 not account:
if existing_gle_currency: frappe.throw(_("Party account not specified, please setup default party account in company"))
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)
return account return account
def get_party_account_currency(party_type, party, company): def get_party_account_currency(party_type, party, company):
def generator(): def generator():

View File

@@ -593,7 +593,7 @@ def get_outstanding_invoices(party_type, party, account, condition=None):
select ifnull(sum({payment_dr_or_cr}), 0) select ifnull(sum({payment_dr_or_cr}), 0)
from `tabGL Entry` payment_gl_entry from `tabGL Entry` payment_gl_entry
where payment_gl_entry.against_voucher_type = invoice_gl_entry.voucher_type 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_type = invoice_gl_entry.party_type
and payment_gl_entry.party = invoice_gl_entry.party and payment_gl_entry.party = invoice_gl_entry.party
and payment_gl_entry.account = invoice_gl_entry.account and payment_gl_entry.account = invoice_gl_entry.account

View File

@@ -9,6 +9,7 @@ from frappe.model.mapper import get_mapped_doc
from frappe.utils import money_in_words from frappe.utils import money_in_words
from frappe.utils import cint, flt, cstr from frappe.utils import cint, flt, cstr
from frappe.utils.background_jobs import enqueue from frappe.utils.background_jobs import enqueue
from frappe import _
class FeeSchedule(Document): class FeeSchedule(Document):
@@ -57,6 +58,10 @@ def generate_fee(fee_schedule):
error = False error = False
total_records = sum([int(d.total_students) for d in doc.student_groups]) total_records = sum([int(d.total_students) for d in doc.student_groups])
created_records = 0 created_records = 0
if not total_records:
frappe.throw(_("Please setup Students under Student Groups"))
for d in doc.student_groups: for d in doc.student_groups:
students = frappe.db.sql(""" select sg.program, sg.batch, sgs.student, sgs.student_name students = frappe.db.sql(""" select sg.program, sg.batch, sgs.student, sgs.student_name
from `tabStudent Group` sg, `tabStudent Group Student` sgs from `tabStudent Group` sg, `tabStudent Group Student` sgs