Merge pull request #14134 from manassolanki/fix-salary-patch
[fix] patch for the salary structure assignment for old employees
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index e388601..786ade1 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -79,6 +79,19 @@
return frappe.local.enable_perpetual_inventory[company]
+def get_default_finance_book(company=None):
+ if not company:
+ company = get_default_company()
+
+ if not hasattr(frappe.local, 'default_finance_book'):
+ frappe.local.default_finance_book = {}
+
+ if not company in frappe.local.default_finance_book:
+ frappe.local.default_finance_book[company] = frappe.db.get_value("Company",
+ company, "default_finance_book")
+
+ return frappe.local.default_finance_book[company]
+
def get_party_account_type(party_type):
if not hasattr(frappe.local, 'party_account_types'):
frappe.local.party_account_types = {}
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index c1a2c97..9a6dead 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -115,7 +115,6 @@
}
this.frm.toggle_reqd("supplier_warehouse", this.frm.doc.is_subcontracted==="Yes");
- var me = this;
if (doc.docstatus == 1 && !doc.inter_company_invoice_reference) {
frappe.model.with_doc("Supplier", me.frm.doc.supplier, function() {
var supplier = frappe.model.get_doc("Supplier", me.frm.doc.supplier);
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 84367de..545967e 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -81,7 +81,6 @@
self.validate_write_off_account()
self.validate_multiple_billing("Purchase Receipt", "pr_detail", "amount", "items")
self.validate_fixed_asset()
- self.validate_fixed_asset_account()
self.create_remarks()
self.set_status()
validate_inter_company_party(self.doctype, self.supplier, self.company, self.inter_company_invoice_reference)
@@ -176,7 +175,8 @@
if self.update_stock:
for d in self.get('items'):
if not d.warehouse:
- frappe.throw(_("Warehouse required at Row No {0}").format(d.idx))
+ frappe.throw(_("Warehouse required at Row No {0}, please set default warehouse for the item {1} for the company {2}").
+ format(d.idx, d.item_code, self.company))
super(PurchaseInvoice, self).validate_warehouse()
@@ -352,6 +352,7 @@
self.make_supplier_gl_entry(gl_entries)
self.make_item_gl_entries(gl_entries)
+ self.get_asset_gl_entry(gl_entries)
self.make_tax_gl_entries(gl_entries)
gl_entries = merge_similar_entries(gl_entries)
@@ -434,51 +435,7 @@
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(item.rm_supp_cost)
}, warehouse_account[self.supplier_warehouse]["account_currency"]))
-
- elif item.is_fixed_asset:
- asset_accounts = self.get_company_default(["asset_received_but_not_billed",
- "expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
-
- asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
- base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
-
- if not self.update_stock:
- asset_rbnb_currency = get_account_currency(asset_accounts[0])
- gl_entries.append(self.get_gl_dict({
- "account": asset_accounts[0],
- "against": self.supplier,
- "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
- "debit": base_asset_amount,
- "debit_in_account_currency": (base_asset_amount
- if asset_rbnb_currency == self.company_currency else asset_amount)
- }))
- else:
- cwip_account = get_asset_category_account(item.asset,
- 'capital_work_in_progress_account') or asset_accounts[2]
-
- cwip_account_currency = get_account_currency(cwip_account)
- gl_entries.append(self.get_gl_dict({
- "account": cwip_account,
- "against": self.supplier,
- "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
- "debit": base_asset_amount,
- "debit_in_account_currency": (base_asset_amount
- if cwip_account_currency == self.company_currency else asset_amount)
- }))
-
- if item.item_tax_amount:
- asset_eiiav_currency = get_account_currency(asset_accounts[0])
- gl_entries.append(self.get_gl_dict({
- "account": asset_accounts[1],
- "against": self.supplier,
- "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
- "cost_center": item.cost_center,
- "credit": item.item_tax_amount,
- "credit_in_account_currency": (item.item_tax_amount
- if asset_eiiav_currency == self.company_currency else
- item.item_tax_amount / self.conversion_rate)
- }))
- else:
+ elif not item.is_fixed_asset:
gl_entries.append(
self.get_gl_dict({
"account": item.expense_account,
@@ -513,6 +470,73 @@
self.negative_expense_to_be_booked += flt(item.item_tax_amount, \
item.precision("item_tax_amount"))
+ def get_asset_gl_entry(self, gl_entries):
+ for item in self.get("items"):
+ if item.is_fixed_asset:
+ asset_accounts = self.get_company_default(["asset_received_but_not_billed",
+ "expenses_included_in_asset_valuation", "capital_work_in_progress_account"])
+
+ asset_amount = flt(item.net_amount) + flt(item.item_tax_amount/self.conversion_rate)
+ base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
+ item.expense_account = item.expense_account or asset_accounts[0]
+
+ if (not item.expense_account or frappe.db.get_value('Account',
+ item.expense_account, 'account_type') != 'Asset Received But Not Billed'):
+ frappe.throw(_("Row {0}: Expense account must be of type Asset Received But Not Billed").
+ format(item.idx))
+
+ if not self.update_stock:
+ asset_rbnb_currency = get_account_currency(item.expense_account)
+ gl_entries.append(self.get_gl_dict({
+ "account": item.expense_account,
+ "against": self.supplier,
+ "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+ "debit": base_asset_amount,
+ "debit_in_account_currency": (base_asset_amount
+ if asset_rbnb_currency == self.company_currency else asset_amount)
+ }))
+
+ if item.item_tax_amount:
+ asset_eiiav_currency = get_account_currency(asset_accounts[0])
+ gl_entries.append(self.get_gl_dict({
+ "account": asset_accounts[1],
+ "against": self.supplier,
+ "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+ "cost_center": item.cost_center,
+ "credit": item.item_tax_amount,
+ "credit_in_account_currency": (item.item_tax_amount
+ if asset_eiiav_currency == self.company_currency else
+ item.item_tax_amount / self.conversion_rate)
+ }))
+ else:
+ cwip_account = get_asset_category_account(item.asset,
+ 'capital_work_in_progress_account') or asset_accounts[2]
+
+ cwip_account_currency = get_account_currency(cwip_account)
+ gl_entries.append(self.get_gl_dict({
+ "account": cwip_account,
+ "against": self.supplier,
+ "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+ "debit": base_asset_amount,
+ "debit_in_account_currency": (base_asset_amount
+ if cwip_account_currency == self.company_currency else asset_amount)
+ }))
+
+ if item.item_tax_amount and not cint(erpnext.is_perpetual_inventory_enabled(self.company)):
+ asset_eiiav_currency = get_account_currency(asset_accounts[1])
+ gl_entries.append(self.get_gl_dict({
+ "account": asset_accounts[1],
+ "against": self.supplier,
+ "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+ "cost_center": item.cost_center,
+ "credit": item.item_tax_amount,
+ "credit_in_account_currency": (item.item_tax_amount
+ if asset_eiiav_currency == self.company_currency else
+ item.item_tax_amount / self.conversion_rate)
+ }))
+
+ return gl_entries
+
def make_tax_gl_entries(self, gl_entries):
# tax table gl entries
valuation_tax = {}
@@ -732,13 +756,6 @@
for pr in set(updated_pr):
frappe.get_doc("Purchase Receipt", pr).update_billing_percentage(update_modified=update_modified)
- def validate_fixed_asset_account(self):
- for d in self.get('items'):
- if d.is_fixed_asset:
- account_type = frappe.db.get_value("Account", d.expense_account, "account_type")
- if account_type != 'Fixed Asset':
- frappe.throw(_("Row {0}# Account must be of type 'Fixed Asset'").format(d.idx))
-
def on_recurring(self, reference_doc, auto_repeat_doc):
self.due_date = None
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index ef9b2f6..eb77024 100755
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -2033,6 +2033,39 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "depends_on": "is_fixed_asset",
+ "fieldname": "asset_location",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Asset Location",
+ "length": 0,
+ "no_copy": 0,
+ "options": "Location",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "po_detail",
"fieldtype": "Data",
"hidden": 1,
@@ -2258,7 +2291,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2018-04-23 14:07:33.576495",
+ "modified": "2018-05-16 17:50:21.957780",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
old mode 100644
new mode 100755
index c07b851..2146ace
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -1051,6 +1051,7 @@
item_name: obj.name === obj.item_name ? "" : obj.item_name,
item_image: obj.image,
item_stock: __('Stock Qty') + ": " + me.get_actual_qty(obj),
+ item_uom: obj.stock_uom,
color: frappe.get_palette(obj.item_name),
abbr: frappe.get_abbr(obj.item_name)
})).tooltip().appendTo($wrap);
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 69b369f..2222f1f 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -487,7 +487,7 @@
if tax.valid_till and date_diff(tax.valid_till, ref_doc.posting_date) > 0:
tax_mapper.update({
- "rate": tax.applicable_percentage
+ "rate": tax.applicable_percent
})
prepare_tax_withholding_details(tax_mapper, tax_withholding_details)
diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
index 8581a25..bf906ce 100644
--- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
+++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py
@@ -2,7 +2,7 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
+import frappe, erpnext
from frappe import _, scrub
from frappe.utils import getdate, nowdate, flt, cint
@@ -332,12 +332,14 @@
conditions.append("company=%s")
values.append(self.filters.company)
- if self.filters.finance_book:
- conditions.append("finance_book in (%s, '')")
+ company_finance_book = erpnext.get_default_finance_book(self.filters.company)
+
+ if not self.filters.finance_book or (self.filters.finance_book == company_finance_book):
+ conditions.append("ifnull(finance_book,'') in (%s, '')")
+ values.append(company_finance_book)
+ elif self.filters.finance_book:
+ conditions.append("ifnull(finance_book,'') = %s")
values.append(self.filters.finance_book)
- else:
- conditions.append("ifnull(finance_book,'')=%s")
- values.append('')
if self.filters.get(party_type_field):
conditions.append("party=%s")
diff --git a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js
index 9fa99c7..126cd03 100644
--- a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js
+++ b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.js
@@ -32,6 +32,12 @@
"options": "Asset"
},
{
+ "fieldname":"finance_book",
+ "label": __("Finance Book"),
+ "fieldtype": "Link",
+ "options": "Finance Book"
+ },
+ {
"fieldname":"asset_category",
"label": __("Asset Category"),
"fieldtype": "Link",
diff --git a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py
index 5497384..fb59882 100644
--- a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py
+++ b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py
@@ -2,7 +2,7 @@
# For license information, please see license.txt
from __future__ import unicode_literals
-import frappe
+import frappe, erpnext
from frappe import _
def execute(filters=None):
@@ -13,7 +13,7 @@
data = frappe.db.sql("""
select
a.name as asset, a.asset_category, a.status,
- a.depreciation_method, a.purchase_date, a.gross_purchase_amount,
+ ds.depreciation_method, a.purchase_date, a.gross_purchase_amount,
ds.schedule_date as depreciation_date, ds.depreciation_amount,
ds.accumulated_depreciation_amount,
(a.gross_purchase_amount - ds.accumulated_depreciation_amount) as amount_after_depreciation,
@@ -30,9 +30,9 @@
order by
a.name asc, ds.schedule_date asc
""".format(conditions=get_filter_conditions(filters)), filters, as_dict=1)
-
+
return data
-
+
def get_filter_conditions(filters):
conditions = ""
@@ -42,6 +42,14 @@
if filters.get("asset_category"):
conditions += " and a.asset_category = %(asset_category)s"
+ company_finance_book = erpnext.get_default_finance_book(filters.get("company"))
+
+ if (not filters.get('finance_book') or (filters.get('finance_book') == company_finance_book)):
+ filters['finance_book'] = company_finance_book
+ conditions += " and ifnull(ds.finance_book, '') in (%(finance_book)s, '') "
+ elif filters.get("finance_book"):
+ conditions += " and ifnull(ds.finance_book, '') = %(finance_book)s"
+
return conditions
def get_columns():
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js
index 63f263f..91a06f4 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js
@@ -29,6 +29,12 @@
"reqd": 1
},
{
+ "fieldname":"finance_book",
+ "label": __("Finance Book"),
+ "fieldtype": "Link",
+ "options": "Finance Book"
+ },
+ {
"fieldname":"report",
"label": __("Report"),
"fieldtype": "Select",
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
index 0b1fc6d..39f4771 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
@@ -2,7 +2,7 @@
# For license information, please see license.txt
from __future__ import unicode_literals
-import frappe
+import frappe, erpnext
from frappe import _
from frappe.utils import flt, cint
from erpnext.accounts.report.financial_statements import get_fiscal_year_data, sort_accounts
@@ -15,6 +15,10 @@
def execute(filters=None):
columns, data, message, chart = [], [], [], []
+
+ if not filters.get('company'):
+ return columns, data, message, chart
+
fiscal_year = get_fiscal_year_data(filters.get('from_fiscal_year'), filters.get('to_fiscal_year'))
companies_column, companies = get_companies(filters)
columns = get_columns(companies_column)
@@ -318,7 +322,7 @@
company_lft, company_rgt = frappe.db.get_value('Company',
filters.get('company'), ["lft", "rgt"])
- additional_conditions = get_additional_conditions(from_date, ignore_closing_entries)
+ additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters)
gl_entries = frappe.db.sql("""select gl.posting_date, gl.account, gl.debit, gl.credit, gl.is_opening, gl.company,
gl.fiscal_year, gl.debit_in_account_currency, gl.credit_in_account_currency, gl.account_currency,
@@ -349,7 +353,7 @@
field = "Account number" if entry.account_number else "Account name"
frappe.throw(_("{0} {1} is not present in the parent company").format(field, key))
-def get_additional_conditions(from_date, ignore_closing_entries):
+def get_additional_conditions(from_date, ignore_closing_entries, filters):
additional_conditions = []
if ignore_closing_entries:
@@ -358,6 +362,15 @@
if from_date:
additional_conditions.append("gl.posting_date >= %(from_date)s")
+ company_finance_book = erpnext.get_default_finance_book(filters.get("company"))
+
+ if not filters.get('finance_book') or (filters.get('finance_book') == company_finance_book):
+ additional_conditions.append("finance_book in ('%s', '')" %
+ frappe.db.escape(company_finance_book))
+ elif filters.get("finance_book"):
+ additional_conditions.append("finance_book = '%s' " %
+ frappe.db.escape(filters.get("finance_book")))
+
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
def add_total_row(out, root_type, balance_must_be, companies, company_currency):
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index ea22bac..41abc3f 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -7,7 +7,7 @@
from past.builtins import cmp
import functools
-import frappe
+import frappe, erpnext
from erpnext.accounts.report.utils import get_currency, convert_to_presentation_currency
from erpnext.accounts.utils import get_fiscal_year
from frappe import _
@@ -375,12 +375,15 @@
additional_conditions.append("project = '%s'" % (frappe.db.escape(filters.get("project"))))
if filters.get("cost_center"):
additional_conditions.append(get_cost_center_cond(filters.get("cost_center")))
- if filters.get("finance_book"):
- additional_conditions.append("finance_book in ('%s', '')" %
- frappe.db.escape(filters.get("finance_book")))
- else:
- additional_conditions.append("ifnull(finance_book, '') = ''")
+ company_finance_book = erpnext.get_default_finance_book(filters.get("company"))
+
+ if not filters.get('finance_book') or (filters.get('finance_book') == company_finance_book):
+ additional_conditions.append("finance_book in ('%s', '')" %
+ frappe.db.escape(company_finance_book))
+ elif filters.get("finance_book"):
+ additional_conditions.append("finance_book = '%s' " %
+ frappe.db.escape(filters.get("finance_book")))
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index 2d0bd52..6aecab9 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -2,7 +2,7 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
+import frappe, erpnext
from erpnext import get_company_currency, get_default_company
from erpnext.accounts.report.utils import get_currency, convert_to_presentation_currency
from frappe.utils import getdate, cstr, flt, fmt_money
@@ -11,6 +11,9 @@
def execute(filters=None):
+ if not filters:
+ return [], []
+
account_details = {}
if filters and filters.get('print_in_account_currency') and \
@@ -164,10 +167,12 @@
if filters.get("project"):
conditions.append("project=%(project)s")
- if filters.get("finance_book"):
- conditions.append("finance_book in (%(finance_book)s, '')")
- else:
- conditions.append("ifnull(finance_book, '')=''")
+ company_finance_book = erpnext.get_default_finance_book(filters.get("company"))
+ if not filters.get("finance_book") or (filters.get("finance_book") == company_finance_book):
+ filters['finance_book'] = company_finance_book
+ conditions.append("ifnull(finance_book, '') in (%(finance_book)s, '')")
+ elif filters.get("finance_book"):
+ conditions.append("ifnull(finance_book, '') = %(finance_book)s")
from frappe.desk.reportview import build_match_conditions
match_conditions = build_match_conditions("GL Entry")
diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js
index c05667a..658107b 100644
--- a/erpnext/assets/doctype/asset/asset.js
+++ b/erpnext/assets/doctype/asset/asset.js
@@ -82,7 +82,7 @@
}
if (frm.doc.status != 'Fully Depreciated') {
frm.add_custom_button(__("Asset Adjustment"), function() {
- frm.trigger("create_asset_maintenance");
+ frm.trigger("create_asset_adjustment");
}, __("Make"));
}
@@ -157,6 +157,13 @@
}
},
+ available_for_use_date: function(frm) {
+ $.each(frm.doc.finance_books || [], function(i, d) {
+ if(!d.depreciation_start_date) d.depreciation_start_date = frm.doc.available_for_use_date;
+ });
+ refresh_field("finance_books");
+ },
+
is_existing_asset: function(frm) {
// frm.toggle_reqd("next_depreciation_date", (!frm.doc.is_existing_asset && frm.doc.calculate_depreciation));
},
@@ -226,6 +233,22 @@
})
},
+ create_asset_adjustment: function(frm) {
+ frappe.call({
+ args: {
+ "asset": frm.doc.name,
+ "asset_category": frm.doc.asset_category,
+ "company": frm.doc.company
+ },
+ method: "erpnext.assets.doctype.asset.asset.create_asset_adjustment",
+ freeze: 1,
+ callback: function(r) {
+ var doclist = frappe.model.sync(r.message);
+ frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
+ }
+ })
+ },
+
calculate_depreciation: function(frm) {
frappe.db.get_value("Asset Settings", {'name':"Asset Settings"}, 'schedule_based_on_fiscal_year', (data) => {
if (data.schedule_based_on_fiscal_year == 1) {
@@ -322,6 +345,42 @@
"reqd": 1
},
{
+ "label": __("Select Serial No"),
+ "fieldname": "serial_nos",
+ "fieldtype": "Link",
+ "options": "Serial No",
+ "get_query": function () {
+ return {
+ filters: {
+ 'asset': frm.doc.name
+ }
+ }
+ },
+ "onchange": function() {
+ let val = this.get_value();
+ if (val) {
+ let serial_nos = dialog.get_value("serial_no") || val;
+ if (serial_nos) {
+ serial_nos = serial_nos.split('\n');
+ serial_nos.push(val);
+
+ const unique_sn = serial_nos.filter(function(elem, index, self) {
+ return index === self.indexOf(elem);
+ });
+
+ dialog.set_value("serial_no", unique_sn.join('\n'));
+ dialog.set_value("serial_nos", "");
+ }
+ }
+ }
+ },
+ {
+ "label": __("Serial No"),
+ "fieldname": "serial_no",
+ "read_only": 1,
+ "fieldtype": "Small Text"
+ },
+ {
"label": __("Date"),
"fieldname": "transfer_date",
"fieldtype": "Datetime",
@@ -342,8 +401,9 @@
args: {
"asset": frm.doc.name,
"transaction_date": args.transfer_date,
- "source_warehouse": frm.doc.location,
- "target_warehouse": args.target_location,
+ "source_location": frm.doc.location,
+ "target_location": args.target_location,
+ "serial_no": args.serial_no,
"company": frm.doc.company
}
},
diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json
index 49a010d..4dc5ff6 100644
--- a/erpnext/assets/doctype/asset/asset.json
+++ b/erpnext/assets/doctype/asset/asset.json
@@ -42,6 +42,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -57,7 +58,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 0,
+ "in_list_view": 1,
"in_standard_filter": 0,
"label": "Asset Name",
"length": 0,
@@ -72,6 +73,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -103,6 +105,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -134,6 +137,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -149,7 +153,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 1,
- "in_list_view": 0,
+ "in_list_view": 1,
"in_standard_filter": 1,
"label": "Asset Category",
"length": 0,
@@ -165,6 +169,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -196,6 +201,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -228,6 +234,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -260,6 +267,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -292,6 +300,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -322,6 +331,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -351,6 +361,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -382,6 +393,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -397,7 +409,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 0,
+ "in_list_view": 1,
"in_standard_filter": 0,
"label": "Location",
"length": 0,
@@ -413,6 +425,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -444,6 +457,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -475,6 +489,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -505,6 +520,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -535,6 +551,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -566,6 +583,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -595,6 +613,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -626,6 +645,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -656,6 +676,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -685,6 +706,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -715,6 +737,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -745,6 +768,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -777,6 +801,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -808,6 +833,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -839,6 +865,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -870,6 +897,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -899,6 +927,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -932,6 +961,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -963,6 +993,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -993,6 +1024,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1022,6 +1054,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1052,6 +1085,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1083,6 +1117,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1114,6 +1149,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1145,6 +1181,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1175,6 +1212,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1205,6 +1243,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1235,6 +1274,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1265,6 +1305,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1294,6 +1335,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1324,6 +1366,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1354,6 +1397,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1384,6 +1428,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1414,6 +1459,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1445,6 +1491,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1475,6 +1522,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1507,6 +1555,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1538,6 +1587,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1567,6 +1617,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1598,6 +1649,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1628,6 +1680,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1659,6 +1712,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -1689,6 +1743,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
}
],
@@ -1703,7 +1758,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-05-11 10:41:45.972686",
+ "modified": "2018-05-16 08:45:31.659647",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
@@ -1712,7 +1767,6 @@
"permissions": [
{
"amend": 1,
- "apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
@@ -1732,7 +1786,6 @@
},
{
"amend": 0,
- "apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
@@ -1757,6 +1810,7 @@
"show_name_in_global_search": 1,
"sort_field": "modified",
"sort_order": "DESC",
+ "title_field": "asset_name",
"track_changes": 0,
"track_seen": 0
}
\ No newline at end of file
diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py
index 55a29bc..84094ce 100644
--- a/erpnext/assets/doctype/asset/asset.py
+++ b/erpnext/assets/doctype/asset/asset.py
@@ -28,6 +28,7 @@
self.validate_expected_value_after_useful_life()
def on_submit(self):
+ self.validate_in_use_date()
self.set_status()
self.update_stock_movement()
@@ -48,6 +49,10 @@
elif item.is_stock_item:
frappe.throw(_("Item {0} must be a non-stock item").format(self.item_code))
+ def validate_in_use_date(self):
+ if not self.available_for_use_date:
+ frappe.throw(_("Available for use date is required"))
+
def set_missing_values(self):
if not self.asset_category:
self.asset_category = frappe.db.get_value("Item", self.item_code, "asset_category")
@@ -135,6 +140,8 @@
if d.depreciation_method in ("Straight Line", "Manual"):
days = date_diff(schedule_date, from_date)
+ if n == 0: days += 1
+
depreciation_amount = days * rate_per_day
from_date = schedule_date
else:
@@ -157,6 +164,9 @@
frappe.throw(_("Row {0}: Expected Value After Useful Life must be less than Gross Purchase Amount")
.format(row.idx))
+ if not row.depreciation_start_date:
+ frappe.throw(_("Row {0}: Depreciation Start Date is required").format(row.idx))
+
if not self.is_existing_asset:
self.opening_accumulated_depreciation = 0
self.number_of_depreciations_booked = 0
@@ -414,9 +424,23 @@
return asset_maintenance
@frappe.whitelist()
+def create_asset_adjustment(asset, asset_category, company):
+ asset_maintenance = frappe.new_doc("Asset Adjustment")
+ asset_maintenance.update({
+ "asset": asset,
+ "company": company,
+ "asset_category": asset_category
+ })
+ return asset_maintenance
+
+@frappe.whitelist()
def transfer_asset(args):
import json
args = json.loads(args)
+
+ if args.get('serial_no'):
+ args['quantity'] = len(args.get('serial_no').split('\n'))
+
movement_entry = frappe.new_doc("Asset Movement")
movement_entry.update(args)
movement_entry.insert()
diff --git a/erpnext/assets/doctype/asset_adjustment/asset_adjustment.js b/erpnext/assets/doctype/asset_adjustment/asset_adjustment.js
index 11c02e1..346a2f1 100644
--- a/erpnext/assets/doctype/asset_adjustment/asset_adjustment.js
+++ b/erpnext/assets/doctype/asset_adjustment/asset_adjustment.js
@@ -2,6 +2,18 @@
// For license information, please see license.txt
frappe.ui.form.on('Asset Adjustment', {
+ setup: function(frm) {
+ frm.add_fetch('company', 'cost_center', 'cost_center');
+ frm.set_query('cost_center', function() {
+ return {
+ filters: {
+ company: frm.doc.company,
+ is_group: 0
+ }
+ }
+ });
+ },
+
asset: function(frm) {
frm.trigger("set_current_asset_value");
},
@@ -11,7 +23,6 @@
},
set_current_asset_value: function(frm) {
- debugger
if (frm.doc.finance_book && frm.doc.asset) {
frm.call({
method: "erpnext.assets.doctype.asset_adjustment.asset_adjustment.get_current_asset_value",
diff --git a/erpnext/assets/doctype/asset_adjustment/asset_adjustment.json b/erpnext/assets/doctype/asset_adjustment/asset_adjustment.json
index faa36ef..3f4f77c 100644
--- a/erpnext/assets/doctype/asset_adjustment/asset_adjustment.json
+++ b/erpnext/assets/doctype/asset_adjustment/asset_adjustment.json
@@ -41,6 +41,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -72,6 +73,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -103,6 +105,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -134,6 +137,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -165,6 +169,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -194,6 +199,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -203,7 +209,7 @@
"collapsible": 0,
"columns": 0,
"fieldname": "date",
- "fieldtype": "Datetime",
+ "fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@@ -224,6 +230,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -254,6 +261,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -284,6 +292,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -314,6 +323,39 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "cost_center",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Cost Center",
+ "length": 0,
+ "no_copy": 0,
+ "options": "Cost Center",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -344,6 +386,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
}
],
@@ -357,7 +400,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-05-11 21:45:03.459696",
+ "modified": "2018-05-17 11:12:38.110774",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Adjustment",
@@ -366,7 +409,6 @@
"permissions": [
{
"amend": 1,
- "apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
@@ -386,7 +428,6 @@
},
{
"amend": 1,
- "apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
@@ -406,7 +447,6 @@
},
{
"amend": 1,
- "apply_user_permissions": 0,
"cancel": 1,
"create": 1,
"delete": 1,
diff --git a/erpnext/assets/doctype/asset_adjustment/asset_adjustment.py b/erpnext/assets/doctype/asset_adjustment/asset_adjustment.py
index 6b4b752..af806e4 100644
--- a/erpnext/assets/doctype/asset_adjustment/asset_adjustment.py
+++ b/erpnext/assets/doctype/asset_adjustment/asset_adjustment.py
@@ -16,12 +16,14 @@
def on_submit(self):
self.make_depreciation_entry()
- self.reschedule_depreciations()
+ self.reschedule_depreciations(self.new_asset_value)
def on_cancel(self):
if self.journal_entry:
frappe.throw(_("Cancel the journal entry {0} first").format(self.journal_entry))
+ self.reschedule_depreciations(self.current_asset_value)
+
def set_difference_amount(self):
self.difference_amount = flt(self.current_asset_value - self.new_asset_value)
@@ -47,12 +49,13 @@
je.append("accounts", {
"account": accumulated_depreciation_account,
"credit_in_account_currency": self.difference_amount,
+ "cost_center": depreciation_cost_center or self.cost_center
})
je.append("accounts", {
"account": depreciation_expense_account,
"debit_in_account_currency": self.difference_amount,
- "cost_center": depreciation_cost_center
+ "cost_center": depreciation_cost_center or self.cost_center
})
je.flags.ignore_permissions = True
@@ -60,11 +63,11 @@
self.db_set("journal_entry", je.name)
- def reschedule_depreciations(self):
+ def reschedule_depreciations(self, asset_value):
asset = frappe.get_doc('Asset', self.asset)
for d in asset.finance_books:
- d.value_after_depreciation = self.new_asset_value
+ d.value_after_depreciation = asset_value
if d.depreciation_method in ("Straight Line", "Manual"):
end_date = max([s.schedule_date for s in asset.schedules if cint(s.finance_book_id) == d.idx])
diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.py b/erpnext/assets/doctype/asset_movement/asset_movement.py
index e34d2a3..638987e 100644
--- a/erpnext/assets/doctype/asset_movement/asset_movement.py
+++ b/erpnext/assets/doctype/asset_movement/asset_movement.py
@@ -55,7 +55,5 @@
frappe.db.set_value("Asset", self.asset, "location", location)
if self.serial_no:
- serial_nos = get_serial_nos(self.serial_no)
-
- frappe.db.sql(""" update `tabSerial No` set location = %s where name in (%s)"""
- %('%s', ','.join(['%s'] * len(serial_nos))), (location, tuple(serial_nos)))
+ for d in get_serial_nos(self.serial_no):
+ frappe.db.set_value('Serial No', d, 'location', location)
diff --git a/erpnext/config/hr.py b/erpnext/config/hr.py
index ef28ee8..9e893c0 100644
--- a/erpnext/config/hr.py
+++ b/erpnext/config/hr.py
@@ -142,7 +142,7 @@
]
},
{
- "label": _("Expense Claim"),
+ "label": _("Travel and Expense Claim"),
"items": [
{
"type": "doctype",
@@ -156,6 +156,10 @@
"type": "doctype",
"name": "Expense Claim Type",
},
+ {
+ "type": "doctype",
+ "name": "Travel Request",
+ },
]
},
{
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 4802e02..adab972 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -621,8 +621,8 @@
def validate_fixed_asset(self):
for d in self.get("items"):
if d.is_fixed_asset:
- if d.qty > 1:
- frappe.throw(_("Row #{0}: Qty must be 1, as item is a fixed asset. Please use separate row for multiple qty.").format(d.idx))
+ # if d.qty > 1:
+# frappe.throw(_("Row #{0}: Qty must be 1, as item is a fixed asset. Please use separate row for multiple qty.").format(d.idx))
if d.meta.get_field("asset") and d.asset:
asset = frappe.get_doc("Asset", d.asset)
@@ -635,14 +635,14 @@
frappe.throw(_("Row #{0}: Asset {1} does not linked to Item {2}")
.format(d.idx, d.asset, d.item_code))
- elif asset.docstatus != 1:
- frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
+ # elif asset.docstatus != 1:
+# frappe.throw(_("Row #{0}: Asset {1} must be submitted").format(d.idx, d.asset))
elif self.doctype == "Purchase Invoice":
- if asset.status != "Submitted":
- frappe.throw(_("Row #{0}: Asset {1} is already {2}")
- .format(d.idx, d.asset, asset.status))
- elif getdate(asset.purchase_date) != getdate(self.posting_date):
+ # if asset.status != "Submitted":
+# frappe.throw(_("Row #{0}: Asset {1} is already {2}")
+# .format(d.idx, d.asset, asset.status))
+ if getdate(asset.purchase_date) != getdate(self.posting_date):
frappe.throw(_("Row #{0}: Posting Date must be same as purchase date {1} of asset {2}").format(d.idx, asset.purchase_date, d.asset))
elif asset.is_existing_asset:
frappe.throw(_("Row #{0}: Purchase Invoice cannot be made against an existing asset {1}").format(d.idx, d.asset))
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 8b6dd17..a4e95a1 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -366,7 +366,7 @@
return frappe.db.sql("""select tabAccount.name from `tabAccount`
where (tabAccount.report_type = "Profit and Loss"
- or tabAccount.account_type in ("Expense Account", "Fixed Asset", "Temporary"))
+ or tabAccount.account_type in ("Expense Account", "Fixed Asset", "Temporary", "Asset Received But Not Billed"))
and tabAccount.is_group=0
and tabAccount.docstatus!=2
and tabAccount.{key} LIKE %(txt)s
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index 8b0ea3e..31c034d 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -33,6 +33,10 @@
items, warehouses = self.get_items_and_warehouses()
update_gl_entries_after(self.posting_date, self.posting_time, warehouses, items,
warehouse_account)
+ elif self.doctype in ['Purchase Receipt', 'Purchase Invoice']:
+ gl_entries = []
+ gl_entries = self.get_asset_gl_entry(gl_entries)
+ make_gl_entries(gl_entries, from_repost=from_repost)
def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
default_cost_center=None):
diff --git a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js
index 8cf6909..7859a47 100644
--- a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js
+++ b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.js
@@ -2,7 +2,55 @@
// For license information, please see license.txt
frappe.ui.form.on('Employee Benefit Application', {
- refresh: function(frm) {
-
+ setup: function(frm) {
+ frm.set_query("earning_component", "employee_benefits", function() {
+ return {
+ filters: {
+ type: "Earning",
+ is_flexible_benefit: true,
+ disabled: false
+ }
+ };
+ });
+ },
+ employee: function(frm) {
+ frappe.call({
+ method: "erpnext.hr.doctype.employee_benefit_application.employee_benefit_application.get_max_benefits",
+ args:{
+ employee: frm.doc.employee,
+ on_date: frm.doc.date
+ },
+ callback: function (data) {
+ if(!data.exc){
+ if(data.message){
+ frm.set_value("max_benefits", data.message);
+ }
+ }
+ }
+ });
}
});
+
+frappe.ui.form.on("Employee Benefit Application Detail",{
+ amount: function(frm, cdt, cdn) {
+ calculate_all(frm.doc, cdt, cdn);
+ }
+});
+
+var calculate_all = function(doc, dt, dn) {
+ var tbl = doc.employee_benefits || [];
+ var pro_rata_dispensed_amount = 0;
+ var total_amount = 0;
+ for(var i = 0; i < tbl.length; i++){
+ if(cint(tbl[i].amount) > 0) {
+ total_amount += flt(tbl[i].amount);
+ }
+ if(tbl[i].is_pro_rata_applicable == 1){
+ pro_rata_dispensed_amount += flt(tbl[i].amount)
+ }
+ }
+ doc.total_amount = total_amount;
+ doc.remainig_benefits = doc.max_benefits - total_amount;
+ doc.pro_rata_dispensed_amount = pro_rata_dispensed_amount;
+ refresh_many(['pro_rata_dispensed_amount', 'total_amount','remainig_benefits']);
+};
diff --git a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json
index 0fff4fd..3c1c8aa 100644
--- a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json
+++ b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.json
@@ -83,6 +83,68 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "max_benefits",
+ "fieldtype": "Currency",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Max Benefits (Yearly)",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "remainig_benefits",
+ "fieldtype": "Currency",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Remainig Benefits (Yearly)",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "column_break_2",
"fieldtype": "Column Break",
"hidden": 0,
@@ -113,6 +175,38 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "default": "Today",
+ "fieldname": "date",
+ "fieldtype": "Date",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Date",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 1,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "payroll_period",
"fieldtype": "Link",
"hidden": 0,
@@ -145,6 +239,68 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "pro_rata_dispensed_amount",
+ "fieldtype": "Currency",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Pro Rata Dispensed Amount",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "total_amount",
+ "fieldtype": "Currency",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Total Amount",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "amended_from",
"fieldtype": "Link",
"hidden": 0,
@@ -243,7 +399,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-04-14 15:35:20.748301",
+ "modified": "2018-05-11 16:58:31.662866",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Benefit Application",
diff --git a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py
index 9282d98..8e59bf5 100644
--- a/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py
+++ b/erpnext/hr/doctype/employee_benefit_application/employee_benefit_application.py
@@ -4,7 +4,132 @@
from __future__ import unicode_literals
import frappe
+from frappe import _
+from frappe.utils import nowdate, date_diff, getdate
from frappe.model.document import Document
+from erpnext.hr.doctype.payroll_period.payroll_period import get_payroll_period_days
class EmployeeBenefitApplication(Document):
- pass
+ def validate(self):
+ if self.max_benefits <= 0:
+ frappe.throw(_("Employee {0} has no maximum benefit amount").format(self.employee))
+ self.validate_max_benefit_for_component()
+
+ def before_submit(self):
+ self.validate_duplicate_on_payroll_period()
+
+ def validate_max_benefit_for_component(self):
+ if self.employee_benefits:
+ max_benefit_amount = 0
+ for employee_benefit in self.employee_benefits:
+ self.validate_max_benefit(employee_benefit.earning_component)
+ max_benefit_amount += employee_benefit.amount
+ if max_benefit_amount > self.max_benefits:
+ frappe.throw(_("Maximum benefit amount of employee {0} exceeds {1}").format(self.employee, self.max_benefits))
+
+ def validate_max_benefit(self, earning_component_name):
+ max_benefit_amount = frappe.db.get_value("Salary Component", earning_component_name, "max_benefit_amount")
+ benefit_amount = 0
+ for employee_benefit in self.employee_benefits:
+ if employee_benefit.earning_component == earning_component_name:
+ benefit_amount += employee_benefit.amount
+ if benefit_amount > max_benefit_amount:
+ frappe.throw(_("Maximum benefit amount of component {0} exceeds {1}").format(earning_component_name, max_benefit_amount))
+
+ def validate_duplicate_on_payroll_period(self):
+ application = frappe.db.exists(
+ "Employee Benefit Application",
+ {
+ 'employee': self.employee,
+ 'payroll_period': self.payroll_period,
+ 'docstatus': 1
+ }
+ )
+ if application:
+ frappe.throw(_("Employee {0} already submited an apllication {1} for the payroll period {2}").format(self.employee, application, self.payroll_period))
+
+@frappe.whitelist()
+def get_max_benefits(employee, on_date):
+ sal_struct = get_assigned_salary_sturecture(employee, on_date)
+ if sal_struct:
+ max_benefits = frappe.db.get_value("Salary Structure", sal_struct[0][0], "max_benefits")
+ if max_benefits > 0:
+ return max_benefits
+ else:
+ frappe.throw(_("Employee {0} has no max benefits in salary structure {1}").format(employee, sal_struct[0][0]))
+ else:
+ frappe.throw(_("Employee {0} has no salary structure assigned").format(employee))
+
+
+@frappe.whitelist()
+def get_assigned_salary_sturecture(employee, _date):
+ if not _date:
+ _date = nowdate()
+ salary_structure = frappe.db.sql("""
+ select salary_structure from `tabSalary Structure Assignment`
+ where employee=%(employee)s
+ and docstatus = 1
+ and (
+ (%(_date)s between from_date and ifnull(to_date, '2199-12-31'))
+ )""", {
+ 'employee': employee,
+ '_date': _date,
+ })
+ if salary_structure:
+ return salary_structure
+
+def get_employee_benefit_application(salary_slip):
+ employee_benefits = frappe.db.sql("""
+ select name from `tabEmployee Benefit Application`
+ where employee=%(employee)s
+ and docstatus = 1
+ and (date between %(start_date)s and %(end_date)s)
+ """, {
+ 'employee': salary_slip.employee,
+ 'start_date': salary_slip.start_date,
+ 'end_date': salary_slip.end_date
+ })
+
+ if employee_benefits:
+ for employee_benefit in employee_benefits:
+ employee_benefit_obj = frappe.get_doc("Employee Benefit Application", employee_benefit[0])
+ return get_components(employee_benefit_obj, salary_slip)
+
+def get_components(employee_benefit_application, salary_slip):
+ salary_components_array = []
+ group_component_amount = {}
+ payroll_period_days = get_payroll_period_days(salary_slip.start_date, salary_slip.end_date, salary_slip.company)
+ for employee_benefit in employee_benefit_application.employee_benefits:
+ if employee_benefit.is_pro_rata_applicable == 1:
+ struct_row = {}
+ salary_components_dict = {}
+ amount = get_amount(payroll_period_days, salary_slip.start_date, salary_slip.end_date, employee_benefit.amount)
+ sc = frappe.get_doc("Salary Component", employee_benefit.earning_component)
+ salary_component = sc
+ if sc.earning_component_group and not sc.is_group and not sc.flexi_default:
+ salary_component = frappe.get_doc("Salary Component", sc.earning_component_group)
+ if group_component_amount and group_component_amount.has_key(sc.earning_component_group):
+ group_component_amount[sc.earning_component_group] += amount
+ else:
+ group_component_amount[sc.earning_component_group] = amount
+ amount = group_component_amount[sc.earning_component_group]
+ struct_row['depends_on_lwp'] = salary_component.depends_on_lwp
+ struct_row['salary_component'] = salary_component.name
+ struct_row['abbr'] = salary_component.salary_component_abbr
+ struct_row['do_not_include_in_total'] = salary_component.do_not_include_in_total
+ salary_components_dict['amount'] = amount
+ salary_components_dict['struct_row'] = struct_row
+ salary_components_array.append(salary_components_dict)
+
+ if len(salary_components_array) > 0:
+ return salary_components_array
+ return False
+
+def get_amount(payroll_period_days, start_date, end_date, amount):
+ salary_slip_days = date_diff(getdate(end_date), getdate(start_date)) + 1
+ amount_per_day = amount / payroll_period_days
+ total_amount = amount_per_day * salary_slip_days
+ if total_amount > amount:
+ return amount
+ else:
+ return total_amount
diff --git a/erpnext/hr/doctype/employee_benefit_application/test_employee_benefit_application.py b/erpnext/hr/doctype/employee_benefit_application/test_employee_benefit_application.py
index 9b915a6..34e1a8f 100644
--- a/erpnext/hr/doctype/employee_benefit_application/test_employee_benefit_application.py
+++ b/erpnext/hr/doctype/employee_benefit_application/test_employee_benefit_application.py
@@ -2,8 +2,6 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals
-
-import frappe
import unittest
class TestEmployeeBenefitApplication(unittest.TestCase):
diff --git a/erpnext/hr/doctype/employee_benefit_application_detail/employee_benefit_application_detail.json b/erpnext/hr/doctype/employee_benefit_application_detail/employee_benefit_application_detail.json
index 35918e1..37f3242 100644
--- a/erpnext/hr/doctype/employee_benefit_application_detail/employee_benefit_application_detail.json
+++ b/erpnext/hr/doctype/employee_benefit_application_detail/employee_benefit_application_detail.json
@@ -51,6 +51,38 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "is_pro_rata_applicable",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Is Pro-rata Applicable",
+ "length": 0,
+ "no_copy": 0,
+ "options": "earning_component.is_pro_rata_applicable",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "amount",
"fieldtype": "Currency",
"hidden": 0,
@@ -87,7 +119,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2018-04-13 19:32:35.064272",
+ "modified": "2018-05-15 12:03:25.545041",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Benefit Application Detail",
diff --git a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.js b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.js
index 816b1bd..64fde03 100644
--- a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.js
+++ b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.js
@@ -2,7 +2,15 @@
// For license information, please see license.txt
frappe.ui.form.on('Employee Benefit Claim', {
- refresh: function(frm) {
-
+ setup: function(frm) {
+ frm.set_query("earning_component", function() {
+ return {
+ filters: {
+ type: "Earning",
+ is_flexible_benefit: true,
+ disabled: false
+ }
+ };
+ });
}
});
diff --git a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.json b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.json
index 00d5159..9da7cdb 100644
--- a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.json
+++ b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.json
@@ -188,6 +188,7 @@
"label": "Max Amount Eligible",
"length": 0,
"no_copy": 0,
+ "options": "earning_component.max_benefit_amount",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -207,6 +208,38 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "is_pro_rata_applicable",
+ "fieldtype": "Check",
+ "hidden": 1,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Is Pro-Rata Applicable",
+ "length": 0,
+ "no_copy": 0,
+ "options": "earning_component.is_pro_rata_applicable",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "claimed_amount",
"fieldtype": "Currency",
"hidden": 0,
@@ -367,7 +400,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-04-14 15:38:41.538646",
+ "modified": "2018-05-16 17:21:25.598531",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Benefit Claim",
@@ -460,4 +493,4 @@
"title_field": "employee_name",
"track_changes": 1,
"track_seen": 0
-}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py
index 551d1ac..39b3540 100644
--- a/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py
+++ b/erpnext/hr/doctype/employee_benefit_claim/employee_benefit_claim.py
@@ -4,7 +4,62 @@
from __future__ import unicode_literals
import frappe
+from frappe import _
from frappe.model.document import Document
+from erpnext.hr.doctype.employee_benefit_application.employee_benefit_application import get_max_benefits
class EmployeeBenefitClaim(Document):
- pass
+ def validate(self):
+ if not self.is_pro_rata_applicable:
+ self.validate_max_benefit_for_sal_struct()
+ # TODO: Validate all cases
+
+ def validate_max_benefit_for_sal_struct(self):
+ max_benefits = get_max_benefits(self.employee, self.claim_date)
+ if self.claimed_amount > max_benefits:
+ frappe.throw(_("Maximum benefit amount of employee {0} exceeds {1}").format(self.employee, max_benefits))
+
+
+def get_employee_benefit_claim(salary_slip):
+ employee_benefits = frappe.db.sql("""
+ select name from `tabEmployee Benefit Claim`
+ where employee=%(employee)s
+ and docstatus = 1 and is_pro_rata_applicable = 0
+ and (claim_date between %(start_date)s and %(end_date)s)
+ """, {
+ 'employee': salary_slip.employee,
+ 'start_date': salary_slip.start_date,
+ 'end_date': salary_slip.end_date
+ })
+
+ if employee_benefits:
+ salary_components_array = []
+ for employee_benefit in employee_benefits:
+ struct_row = {}
+ salary_components_dict = {}
+ group_component_amount = {}
+
+ employee_benefit_claim = frappe.get_doc("Employee Benefit Claim", employee_benefit[0])
+ amount = employee_benefit_claim.claimed_amount
+ sc = frappe.get_doc("Salary Component", employee_benefit_claim.earning_component)
+
+ salary_component = sc
+ if sc.earning_component_group and not sc.is_group and not sc.flexi_default:
+ salary_component = frappe.get_doc("Salary Component", sc.earning_component_group)
+ if group_component_amount and group_component_amount.has_key(sc.earning_component_group):
+ group_component_amount[sc.earning_component_group] += amount
+ else:
+ group_component_amount[sc.earning_component_group] = amount
+ amount = group_component_amount[sc.earning_component_group]
+
+ struct_row['depends_on_lwp'] = salary_component.depends_on_lwp
+ struct_row['salary_component'] = salary_component.name
+ struct_row['abbr'] = salary_component.salary_component_abbr
+ struct_row['do_not_include_in_total'] = salary_component.do_not_include_in_total
+ salary_components_dict['amount'] = amount
+ salary_components_dict['struct_row'] = struct_row
+ salary_components_array.append(salary_components_dict)
+
+ if len(salary_components_array) > 0:
+ return salary_components_array
+ return False
diff --git a/erpnext/hr/doctype/employee_benefit_claim/test_employee_benefit_claim.py b/erpnext/hr/doctype/employee_benefit_claim/test_employee_benefit_claim.py
index e8dc0da..aff73e5 100644
--- a/erpnext/hr/doctype/employee_benefit_claim/test_employee_benefit_claim.py
+++ b/erpnext/hr/doctype/employee_benefit_claim/test_employee_benefit_claim.py
@@ -2,8 +2,6 @@
# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals
-
-import frappe
import unittest
class TestEmployeeBenefitClaim(unittest.TestCase):
diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json
index 9dee848..c5691f7 100644
--- a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json
+++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.json
@@ -145,6 +145,37 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "total_exemption_amount",
+ "fieldtype": "Currency",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Total Exemption Amount",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 1,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "amended_from",
"fieldtype": "Link",
"hidden": 0,
@@ -243,7 +274,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-05-15 16:16:46.075493",
+ "modified": "2018-05-16 19:03:57.624215",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Tax Exemption Declaration",
diff --git a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py
index 52746d4..22e1638 100644
--- a/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py
+++ b/erpnext/hr/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py
@@ -19,3 +19,6 @@
"docstatus": 1}):
frappe.throw(_("Tax Declaration of {0} for period {1} already submitted.")\
.format(self.employee, self.payroll_period), frappe.DocstatusTransitionError)
+ self.total_exemption_amount = 0
+ for item in self.declarations:
+ self.total_exemption_amount += item.amount
diff --git a/erpnext/hr/doctype/employee_transfer/employee_transfer.py b/erpnext/hr/doctype/employee_transfer/employee_transfer.py
index b58d334..6cdd22f 100644
--- a/erpnext/hr/doctype/employee_transfer/employee_transfer.py
+++ b/erpnext/hr/doctype/employee_transfer/employee_transfer.py
@@ -14,7 +14,7 @@
if frappe.get_value("Employee", self.employee, "status") == "Left":
frappe.throw(_("Cannot transfer Employee with status Left"))
if self.new_company and self.company == self.new_company:
- frappe.throw_("New Company must be different from current company")
+ frappe.throw(_("New Company must be different from current company"))
def before_submit(self):
if getdate(self.transfer_date) > getdate():
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index 5f1c883..7a6b246 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -50,8 +50,11 @@
date: frm.doc.posting_date
},
callback: function(r) {
- if (!r.exc && r.message) {
- leave_details = r.message;
+ if (!r.exc && r.message['leave_allocation']) {
+ leave_details = r.message['leave_allocation'];
+ }
+ if (!r.exc && r.message['leave_approver']) {
+ frm.set_value('leave_approver', r.message['leave_approver']);
}
}
});
@@ -74,6 +77,13 @@
if(frm.doc.__islocal && !in_list(frappe.user_roles, "Employee")) {
frm.set_intro(__("Fill the form and save it"));
}
+
+ if (!frm.doc.employee && frappe.defaults.get_user_permissions()) {
+ const perm = frappe.defaults.get_user_permissions();
+ if (perm && perm['Employee']) {
+ frm.set_value('employee', perm['Employee']["docs"][0])
+ }
+ }
},
employee: function(frm) {
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index d0305c3..c58e0cf 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -374,7 +374,12 @@
"pending_leaves": leaves_pending,
"remaining_leaves": remaining_leaves}
- return leave_allocation
+ ret = {
+ 'leave_allocation': leave_allocation,
+ 'leave_approver': get_leave_approver(employee)
+ }
+
+ return ret
@frappe.whitelist()
def get_leave_balance_on(employee, leave_type, date, allocation_records=None,
@@ -603,3 +608,10 @@
return leave_days
+def get_leave_approver(employee, department=None):
+ if not department:
+ department = frappe.db.get_value('Employee', employee, 'department')
+
+ if department:
+ return frappe.db.get_value('Department Approver', {'parent': department,
+ 'parentfield': 'leave_approver', 'idx': 1}, 'approver')
diff --git a/erpnext/hr/doctype/payroll_period/payroll_period.py b/erpnext/hr/doctype/payroll_period/payroll_period.py
index 1e18388..a818bc4 100644
--- a/erpnext/hr/doctype/payroll_period/payroll_period.py
+++ b/erpnext/hr/doctype/payroll_period/payroll_period.py
@@ -4,7 +4,26 @@
from __future__ import unicode_literals
import frappe
+from frappe.utils import date_diff, getdate
from frappe.model.document import Document
class PayrollPeriod(Document):
pass
+
+def get_payroll_period_days(start_date, end_date, company):
+ payroll_period_dates = frappe.db.sql("""
+ select ppd.start_date, ppd.end_date from `tabPayroll Period Date` ppd, `tabPayroll Period` pp
+ where pp.company=%(company)s
+ and ppd.parent = pp.name
+ and (
+ (%(start_date)s between ppd.start_date and ppd.end_date)
+ or (%(end_date)s between ppd.start_date and ppd.end_date)
+ or (ppd.start_date between %(start_date)s and %(end_date)s)
+ )""", {
+ 'company': company,
+ 'start_date': start_date,
+ 'end_date': end_date
+ })
+
+ if len(payroll_period_dates) > 0:
+ return date_diff(getdate(payroll_period_dates[0][1]), getdate(payroll_period_dates[0][0])) + 1
diff --git a/erpnext/hr/doctype/salary_component/salary_component.js b/erpnext/hr/doctype/salary_component/salary_component.js
index 86203ab..e58a05e 100644
--- a/erpnext/hr/doctype/salary_component/salary_component.js
+++ b/erpnext/hr/doctype/salary_component/salary_component.js
@@ -12,7 +12,15 @@
"is_group": 0,
"company": d.company
}
- }
- })
+ };
+ });
+ frm.set_query("earning_component_group", function(frm) {
+ return {
+ filters: {
+ "is_group": 1,
+ "is_flexible_benefit": 1
+ }
+ };
+ });
}
-});
\ No newline at end of file
+});
diff --git a/erpnext/hr/doctype/salary_component/salary_component.json b/erpnext/hr/doctype/salary_component/salary_component.json
index cf85af4..6764e0c 100644
--- a/erpnext/hr/doctype/salary_component/salary_component.json
+++ b/erpnext/hr/doctype/salary_component/salary_component.json
@@ -114,70 +114,6 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "depends_on": "eval:doc.type==\"Earning\"",
- "fieldname": "is_tax_applicable",
- "fieldtype": "Check",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Is Tax Applicable",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
- {
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "default": "1",
- "fieldname": "is_payable",
- "fieldtype": "Check",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Is Payable",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
- {
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
"fieldname": "column_break_4",
"fieldtype": "Column Break",
"hidden": 0,
@@ -366,6 +302,38 @@
"collapsible": 0,
"columns": 0,
"depends_on": "is_flexible_benefit",
+ "fieldname": "is_group",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Is Group",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "depends_on": "eval:doc.is_flexible_benefit && !doc.is_group && !doc.flexi_default",
"fieldname": "earning_component_group",
"fieldtype": "Link",
"hidden": 0,
@@ -460,6 +428,38 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "depends_on": "eval:doc.is_flexible_benefit && doc.is_pro_rata_applicable",
+ "fieldname": "flexi_default",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Default Flexible Component",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"depends_on": "is_flexible_benefit",
"fieldname": "only_tax_impact",
"fieldtype": "Check",
@@ -618,7 +618,6 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "depends_on": "is_payable",
"fieldname": "section_break_5",
"fieldtype": "Section Break",
"hidden": 0,
@@ -1002,7 +1001,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-05-16 12:15:43.117948",
+ "modified": "2018-05-16 12:27:03.005070",
"modified_by": "Administrator",
"module": "HR",
"name": "Salary Component",
@@ -1037,4 +1036,4 @@
"sort_order": "DESC",
"track_changes": 0,
"track_seen": 0
-}
\ No newline at end of file
+}
diff --git a/erpnext/hr/doctype/salary_component/salary_component.py b/erpnext/hr/doctype/salary_component/salary_component.py
index 9108f31..132930f 100644
--- a/erpnext/hr/doctype/salary_component/salary_component.py
+++ b/erpnext/hr/doctype/salary_component/salary_component.py
@@ -4,12 +4,27 @@
from __future__ import unicode_literals
import frappe
+from frappe import _
from frappe.model.document import Document
from frappe.model.naming import append_number_if_name_exists
class SalaryComponent(Document):
def validate(self):
self.validate_abbr()
+ self.validate_flexi_default()
+
+ def validate_flexi_default(self):
+ if self.is_flexible_benefit and self.is_pro_rata_applicable and self.flexi_default:
+ salary_component = frappe.db.exists(
+ 'Salary Component',
+ {
+ 'is_flexible_benefit': 1,
+ 'is_pro_rata_applicable': 1,
+ 'flexi_default': 1
+ }
+ )
+ if salary_component and salary_component != self.name:
+ frappe.throw(_("{0} is already marked as default flexible component").format(salary_component))
def validate_abbr(self):
if not self.salary_component_abbr:
@@ -18,4 +33,13 @@
self.salary_component_abbr = self.salary_component_abbr.strip()
self.salary_component_abbr = append_number_if_name_exists('Salary Component', self.salary_component_abbr,
- 'salary_component_abbr', separator='_', filters={"name": ["!=", self.name]})
\ No newline at end of file
+ 'salary_component_abbr', separator='_', filters={"name": ["!=", self.name]})
+
+ def calculate_tax(self, annual_earning):
+ taxable_amount = 0
+ for slab in self.taxable_salary_slabs:
+ if annual_earning > slab.from_amount and annual_earning < slab.to_amount:
+ taxable_amount += (annual_earning - slab.from_amount) * slab.percent_deduction *.01
+ elif annual_earning > slab.from_amount and annual_earning > slab.to_amount:
+ taxable_amount += (slab.to_amount - slab.from_amount) * slab.percent_deduction * .01
+ return taxable_amount
diff --git a/erpnext/hr/doctype/salary_detail/salary_detail.json b/erpnext/hr/doctype/salary_detail/salary_detail.json
index 01d0277..862728a 100644
--- a/erpnext/hr/doctype/salary_detail/salary_detail.json
+++ b/erpnext/hr/doctype/salary_detail/salary_detail.json
@@ -40,6 +40,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -72,6 +73,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -101,6 +103,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -132,6 +135,100 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "is_tax_applicable",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Is Tax Applicable",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "is_flexible_benefit",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Is Flexible Benefit",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "variable_based_on_taxable_salary",
+ "fieldtype": "Check",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Variable Based On Taxable Salary",
+ "length": 0,
+ "no_copy": 0,
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -161,6 +258,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -192,6 +290,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -225,6 +324,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -258,6 +358,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -290,6 +391,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -321,6 +423,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -351,6 +454,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -383,6 +487,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -413,6 +518,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
},
{
@@ -445,6 +551,7 @@
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0
}
],
@@ -458,7 +565,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2017-10-02 13:57:22.769751",
+ "modified": "2018-05-16 22:42:59.974450",
"modified_by": "Administrator",
"module": "HR",
"name": "Salary Detail",
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index 984a78c..87511b6 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -13,6 +13,10 @@
from erpnext.utilities.transaction_base import TransactionBase
from frappe.utils.background_jobs import enqueue
from erpnext.hr.doctype.additional_salary_component.additional_salary_component import get_additional_salary_component
+from erpnext.hr.doctype.employee_benefit_application.employee_benefit_application import get_employee_benefit_application, get_amount
+from erpnext.hr.doctype.payroll_period.payroll_period import get_payroll_period_days
+from erpnext.hr.doctype.employee_benefit_claim.employee_benefit_claim import get_employee_benefit_claim
+from erpnext.hr.utils import get_payroll_period
class SalarySlip(TransactionBase):
def autoname(self):
@@ -58,12 +62,66 @@
amount = self.eval_condition_and_formula(struct_row, data)
if amount and struct_row.statistical_component == 0:
self.update_component_row(struct_row, amount, key)
+ if key=="deductions" and struct_row.variable_based_on_taxable_salary:
+ tax_row, amount = self.calculate_pro_rata_tax(struct_row.salary_component)
+ if tax_row and amount:
+ self.update_component_row(frappe._dict(tax_row), amount, key)
additional_components = get_additional_salary_component(self.employee, self.start_date, self.end_date)
if additional_components:
for additional_component in additional_components:
additional_component = frappe._dict(additional_component)
- self.update_component_row(frappe._dict(additional_component.struct_row), additional_component.amount, "earnings")
+ amount = self.update_amount_for_other_component(frappe._dict(additional_component.struct_row).salary_component, additional_component.amount)
+ self.update_component_row(frappe._dict(additional_component.struct_row), amount, "earnings")
+
+ max_benefits = self._salary_structure_doc.get("max_benefits")
+ if max_benefits > 0:
+ employee_benefits = get_employee_benefit_application(self)
+ if employee_benefits:
+ for employee_benefit in employee_benefits:
+ benefit_component = frappe._dict(employee_benefit)
+ amount = self.update_amount_for_other_component(frappe._dict(benefit_component.struct_row).salary_component, benefit_component.amount)
+ self.update_component_row(frappe._dict(benefit_component.struct_row), amount, "earnings")
+ else:
+ default_flexi_compenent = frappe.db.exists(
+ 'Salary Component',
+ {
+ 'is_flexible_benefit': 1,
+ 'is_pro_rata_applicable': 1,
+ 'flexi_default': 1
+ }
+ )
+ if default_flexi_compenent:
+ flexi_struct_row = self.create_flexi_struct_row(default_flexi_compenent)
+ payroll_period_days = get_payroll_period_days(self.start_date, self.end_date, self.company)
+ amount = self.update_amount_for_other_component(default_flexi_compenent, get_amount(payroll_period_days, self.start_date, self.end_date, max_benefits))
+ self.update_component_row(flexi_struct_row, amount, "earnings")
+ else:
+ frappe.throw(_("Configure default flexible benefit salary component for apply pro-rata benefit"))
+
+ benefit_claims = get_employee_benefit_claim(self)
+ if benefit_claims:
+ for benefit_claim in benefit_claims:
+ benefit_component = frappe._dict(benefit_claim)
+ amount = self.update_amount_for_other_component(frappe._dict(benefit_component.struct_row).salary_component, benefit_component.amount)
+ self.update_component_row(frappe._dict(benefit_component.struct_row), amount, "earnings")
+
+ def update_amount_for_other_component(self, salary_component, new_amount):
+ amount = new_amount
+ for d in self.get("earnings"):
+ if d.salary_component == salary_component:
+ d.amount += new_amount
+ amount = d.amount
+ return amount
+
+ def create_flexi_struct_row(self, default_flexi_compenent):
+ salary_component = frappe.get_doc("Salary Component", default_flexi_compenent)
+ flexi_struct_row = {}
+ flexi_struct_row['depends_on_lwp'] = salary_component.depends_on_lwp
+ flexi_struct_row['salary_component'] = salary_component.name
+ flexi_struct_row['abbr'] = salary_component.salary_component_abbr
+ flexi_struct_row['do_not_include_in_total'] = salary_component.do_not_include_in_total
+ return frappe._dict(flexi_struct_row)
def update_component_row(self, struct_row, amount, key):
component_row = None
@@ -176,6 +234,7 @@
st_name = frappe.db.sql("""select salary_structure from `tabSalary Structure Assignment`
where employee=%s and (from_date <= %s or from_date <= %s)
and (to_date is null or to_date >= %s or to_date >= %s)
+ and docstatus = 1
and salary_structure in (select name from `tabSalary Structure`
where is_active = 'Yes'%s)
"""% ('%s', '%s', '%s','%s','%s', cond),(self.employee, self.start_date, joining_date, self.end_date, relieving_date))
@@ -464,6 +523,52 @@
status = "Cancelled"
return status
+ def calculate_pro_rata_tax(self, salary_component):
+ # Calculate total tax payable earnings
+ tax_applicable_components = []
+ for earning in self._salary_structure_doc.earnings:
+ #all tax applicable earnings which are not flexi
+ if earning.is_tax_applicable and not earning.is_flexible_benefit:
+ tax_applicable_components.append(earning.salary_component)
+ total_taxable_earning = 0
+ for earning in self.earnings:
+ if earning.salary_component in tax_applicable_components:
+ total_taxable_earning += earning.amount
+
+ # Get payroll period, prorata frequency
+ days = date_diff(self.end_date, self.start_date) + 1
+ payroll_period = get_payroll_period(self.start_date, self.end_date, self.company)
+ if not payroll_period:
+ frappe.throw(_("Start and end dates not in a valid Payroll Period"))
+ total_days = date_diff(payroll_period.end_date, payroll_period.start_date) + 1
+ prorata_frequency = flt(total_days)/flt(days)
+ annual_earning = total_taxable_earning * prorata_frequency
+
+ # Calculate total exemption declaration
+ exemption_amount = 0
+ if frappe.db.exists("Employee Tax Exemption Declaration", {"employee": self.employee,
+ "payroll_period": payroll_period.name, "docstatus": 1}):
+ exemption_amount = frappe.db.get_value("Employee Tax Exemption Declaration",
+ {"employee": self.employee, "payroll_period": payroll_period.name, "docstatus": 1}, #fix period
+ "total_exemption_amount")
+ annual_earning = annual_earning - exemption_amount
+
+ # Get tax calc by component
+ component = frappe.get_doc("Salary Component", salary_component)
+ annual_tax = component.calculate_tax(annual_earning)
+
+ # Calc prorata tax
+ pro_rata_tax = annual_tax/prorata_frequency
+
+ # Data for update_component_row
+ struct_row = {}
+ struct_row['depends_on_lwp'] = 0
+ struct_row['salary_component'] = component.name
+ struct_row['abbr'] = component.salary_component_abbr
+ struct_row['do_not_include_in_total'] = 0
+
+ return struct_row, pro_rata_tax
+
def unlink_ref_doc_from_salary_slip(ref_no):
linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip`
where journal_entry=%s and docstatus < 2""", (ref_no))
diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.js b/erpnext/hr/doctype/salary_structure/salary_structure.js
index ca92234..9e62b66 100755
--- a/erpnext/hr/doctype/salary_structure/salary_structure.js
+++ b/erpnext/hr/doctype/salary_structure/salary_structure.js
@@ -123,15 +123,6 @@
}
});
-frappe.ui.form.on('Salary Structure Employee', {
- from_date: function(frm, cdt, cdn) {
- validate_date(frm, cdt, cdn);
- },
- to_date: function(frm, cdt, cdn) {
- validate_date(frm, cdt, cdn);
- }
-});
-
var validate_date = function(frm, cdt, cdn) {
var doc = locals[cdt][cdn];
if(doc.to_date && doc.from_date) {
@@ -201,17 +192,20 @@
callback: function(data) {
if(data.message){
var result = data.message;
- frappe.model.set_value(cdt, cdn, 'condition',result.condition);
- frappe.model.set_value(cdt, cdn, 'amount_based_on_formula',result.amount_based_on_formula);
+ frappe.model.set_value(cdt, cdn, 'condition', result.condition);
+ frappe.model.set_value(cdt, cdn, 'amount_based_on_formula', result.amount_based_on_formula);
if(result.amount_based_on_formula == 1){
- frappe.model.set_value(cdt, cdn, 'formula',result.formula);
+ frappe.model.set_value(cdt, cdn, 'formula', result.formula);
}
else{
- frappe.model.set_value(cdt, cdn, 'amount',result.amount);
+ frappe.model.set_value(cdt, cdn, 'amount', result.amount);
}
- frappe.model.set_value(cdt, cdn, 'statistical_component',result.statistical_component);
- frappe.model.set_value(cdt, cdn, 'depends_on_lwp',result.depends_on_lwp);
- frappe.model.set_value(cdt, cdn, 'do_not_include_in_total',result.do_not_include_in_total);
+ frappe.model.set_value(cdt, cdn, 'statistical_component', result.statistical_component);
+ frappe.model.set_value(cdt, cdn, 'depends_on_lwp', result.depends_on_lwp);
+ frappe.model.set_value(cdt, cdn, 'do_not_include_in_total', result.do_not_include_in_total);
+ frappe.model.set_value(cdt, cdn, 'variable_based_on_taxable_salary', result.variable_based_on_taxable_salary);
+ frappe.model.set_value(cdt, cdn, 'is_tax_applicable', result.is_tax_applicable);
+ frappe.model.set_value(cdt, cdn, 'is_flexible_benefit', result.is_flexible_benefit);
refresh_field("earnings");
refresh_field("deductions");
}
diff --git a/erpnext/hr/doctype/taxable_salary_slab/taxable_salary_slab.json b/erpnext/hr/doctype/taxable_salary_slab/taxable_salary_slab.json
index bd0ec6b..8e6c1d8 100644
--- a/erpnext/hr/doctype/taxable_salary_slab/taxable_salary_slab.json
+++ b/erpnext/hr/doctype/taxable_salary_slab/taxable_salary_slab.json
@@ -50,7 +50,7 @@
"collapsible": 0,
"columns": 0,
"fieldname": "to_amount",
- "fieldtype": "Data",
+ "fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
@@ -147,7 +147,7 @@
"issingle": 0,
"istable": 1,
"max_attachments": 0,
- "modified": "2018-04-13 20:09:36.675987",
+ "modified": "2018-05-16 18:18:23.802576",
"modified_by": "Administrator",
"module": "HR",
"name": "Taxable Salary Slab",
diff --git a/erpnext/hr/doctype/travel_request/travel_request.json b/erpnext/hr/doctype/travel_request/travel_request.json
index 2f22bbc..fffb50a 100644
--- a/erpnext/hr/doctype/travel_request/travel_request.json
+++ b/erpnext/hr/doctype/travel_request/travel_request.json
@@ -151,7 +151,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 0,
+ "in_list_view": 1,
"in_standard_filter": 0,
"label": "Purpose of Travel",
"length": 0,
@@ -307,7 +307,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
- "in_list_view": 0,
+ "in_list_view": 1,
"in_standard_filter": 0,
"label": "Employee",
"length": 0,
@@ -871,7 +871,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2018-05-16 04:35:56.819570",
+ "modified": "2018-05-16 08:38:22.543808",
"modified_by": "Administrator",
"module": "HR",
"name": "Travel Request",
diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py
index df720c4..20fe666 100644
--- a/erpnext/hr/utils.py
+++ b/erpnext/hr/utils.py
@@ -234,3 +234,10 @@
if leave_period:
return leave_period
+
+def get_payroll_period(from_date, to_date, company):
+ payroll_period = frappe.db.sql("""select pp.name, pd.start_date, pd.end_date from
+ `tabPayroll Period Date` pd join `tabPayroll Period` pp on
+ pd.parent=pp.name where pd.start_date<=%s and pd.end_date>= %s
+ and pp.company=%s""", (from_date, to_date, company), as_dict=1)
+ return payroll_period[0] if payroll_period else None
diff --git a/erpnext/patches/v11_0/create_department_records_for_each_company.py b/erpnext/patches/v11_0/create_department_records_for_each_company.py
index 6f869b0..bef524c 100644
--- a/erpnext/patches/v11_0/create_department_records_for_each_company.py
+++ b/erpnext/patches/v11_0/create_department_records_for_each_company.py
@@ -67,6 +67,9 @@
THEN "%s"
'''%(employee.name, department, records[department]))
+ if not when_then:
+ return
+
frappe.db.sql("""
update
`tabInstructor`
diff --git a/erpnext/public/js/pos/pos_item.html b/erpnext/public/js/pos/pos_item.html
old mode 100644
new mode 100755
index f6ef5a4..52f3cf6
--- a/erpnext/public/js/pos/pos_item.html
+++ b/erpnext/public/js/pos/pos_item.html
@@ -25,7 +25,7 @@
{% } %}
</div>
<span class="price-info">
- {{item_price}}
+ {{item_price}} / {{item_uom}}
</span>
</a>
</div>
diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json
index e2f6adf..8501dc2 100644
--- a/erpnext/setup/doctype/company/company.json
+++ b/erpnext/setup/doctype/company/company.json
@@ -178,6 +178,38 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "default_finance_book",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Default Finance Book",
+ "length": 0,
+ "no_copy": 0,
+ "options": "Finance Book",
+ "permlevel": 0,
+ "precision": "",
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "translatable": 0,
+ "unique": 0
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"fieldname": "cb0",
"fieldtype": "Column Break",
"hidden": 0,
@@ -456,26 +488,26 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "default_currency",
+ "fieldname": "default_currency",
"fieldtype": "Link",
"hidden": 0,
- "ignore_user_permissions": 1,
+ "ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
- "label": "Default Currency",
+ "label": "Default Currency",
"length": 0,
"no_copy": 0,
- "options": "Currency",
+ "options": "Currency",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
- "reqd": 1,
+ "reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
@@ -487,7 +519,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "default_letter_head",
+ "fieldname": "default_letter_head",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
@@ -496,10 +528,10 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
- "label": "Default Letter Head",
+ "label": "Default Letter Head",
"length": 0,
"no_copy": 0,
- "options": "Letter Head",
+ "options": "Letter Head",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@@ -519,7 +551,7 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "default_holiday_list",
+ "fieldname": "default_holiday_list",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
@@ -528,12 +560,12 @@
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
- "label": "Default Holiday List",
+ "label": "Default Holiday List",
"length": 0,
"no_copy": 0,
- "options": "Holiday List",
+ "options": "Holiday List",
"permlevel": 0,
- "precision": "",
+ "precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
@@ -551,26 +583,26 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "default_terms",
+ "fieldname": "default_terms",
"fieldtype": "Link",
"hidden": 0,
- "ignore_user_permissions": 0,
+ "ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
- "label": "Default Terms",
+ "label": "Default Terms",
"length": 0,
"no_copy": 0,
- "options": "Terms and Conditions",
+ "options": "Terms and Conditions",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
- "reqd": 0,
+ "reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
@@ -2529,7 +2561,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
- "modified": "2018-05-14 06:02:22.105952",
+ "modified": "2018-05-17 21:59:33.594245",
"modified_by": "Administrator",
"module": "Setup",
"name": "Company",
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index c55013e..9289d69 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -35,6 +35,10 @@
},
+ onload_post_render: function(frm) {
+ frm.get_field("items").grid.set_multiple_add("item_code", "qty");
+ },
+
refresh: function(frm) {
if(frm.doc.company) {
frm.trigger("toggle_display_account_head");
@@ -62,9 +66,8 @@
this._super();
if(this.frm.doc.docstatus===1) {
this.show_stock_ledger();
- if (erpnext.is_perpetual_inventory_enabled(this.frm.doc.company)) {
- this.show_general_ledger();
- }
+ //removed for temporary
+ this.show_general_ledger();
this.frm.add_custom_button(__('Asset'), function() {
frappe.route_options = {
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 573f7ed..a91d39f 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -254,40 +254,7 @@
d.rejected_warehouse not in warehouse_with_no_account:
warehouse_with_no_account.append(d.warehouse)
- elif d.is_fixed_asset:
- asset_accounts = self.get_company_default(["capital_work_in_progress_account",
- "asset_received_but_not_billed"])
-
- # CWIP entry
- cwip_account = get_asset_category_account(d.asset,
- 'capital_work_in_progress_account') or asset_accounts[0]
-
- asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate)
- base_asset_amount = flt(d.base_net_amount + d.item_tax_amount)
-
- cwip_account_currency = get_account_currency(cwip_account)
- gl_entries.append(self.get_gl_dict({
- "account": cwip_account,
- "against": asset_accounts[1],
- "cost_center": d.cost_center,
- "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
- "debit": base_asset_amount,
- "debit_in_account_currency": (base_asset_amount
- if cwip_account_currency == self.company_currency else asset_amount)
- }))
-
- # Asset received but not billed
- asset_rbnb_currency = get_account_currency(asset_accounts[1])
- gl_entries.append(self.get_gl_dict({
- "account": asset_accounts[1],
- "against": asset_accounts[0],
- "cost_center": d.cost_center,
- "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
- "credit": base_asset_amount,
- "credit_in_account_currency": (base_asset_amount
- if asset_rbnb_currency == self.company_currency else asset_amount)
- }))
-
+ self.get_asset_gl_entry(gl_entries)
# Cost center-wise amount breakup for other charges included for valuation
valuation_tax = {}
for tax in self.get("taxes"):
@@ -340,6 +307,44 @@
"\n".join(warehouse_with_no_account))
return process_gl_map(gl_entries)
+
+ def get_asset_gl_entry(self, gl_entries):
+ for d in self.get("items"):
+ if d.is_fixed_asset:
+ asset_accounts = self.get_company_default(["capital_work_in_progress_account",
+ "asset_received_but_not_billed"])
+
+ # CWIP entry
+ cwip_account = get_asset_category_account(d.asset,
+ 'capital_work_in_progress_account') or asset_accounts[0]
+
+ asset_amount = flt(d.net_amount) + flt(d.item_tax_amount/self.conversion_rate)
+ base_asset_amount = flt(d.base_net_amount + d.item_tax_amount)
+
+ cwip_account_currency = get_account_currency(cwip_account)
+ gl_entries.append(self.get_gl_dict({
+ "account": cwip_account,
+ "against": asset_accounts[1],
+ "cost_center": d.cost_center,
+ "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+ "debit": base_asset_amount,
+ "debit_in_account_currency": (base_asset_amount
+ if cwip_account_currency == self.company_currency else asset_amount)
+ }))
+
+ # Asset received but not billed
+ asset_rbnb_currency = get_account_currency(asset_accounts[1])
+ gl_entries.append(self.get_gl_dict({
+ "account": asset_accounts[1],
+ "against": asset_accounts[0],
+ "cost_center": d.cost_center,
+ "remarks": self.get("remarks") or _("Accounting Entry for Asset"),
+ "credit": base_asset_amount,
+ "credit_in_account_currency": (base_asset_amount
+ if asset_rbnb_currency == self.company_currency else asset_amount)
+ }))
+
+ return gl_entries
def update_status(self, status):
self.set_status(update=True, status = status)