Merge pull request #14061 from rohitwaghchaure/budget_validation_enhance_in_mr_po
[Enhance] Budget validation on material request, purchase order
diff --git a/erpnext/accounts/doctype/account/account_tree.js b/erpnext/accounts/doctype/account/account_tree.js
index fe1977c..a71c4f2 100644
--- a/erpnext/accounts/doctype/account/account_tree.js
+++ b/erpnext/accounts/doctype/account/account_tree.js
@@ -32,9 +32,7 @@
options: ['Asset', 'Liability', 'Equity', 'Income', 'Expense'].join('\n'),
depends_on: 'eval:doc.is_group && !doc.parent_account'},
{fieldtype:'Select', fieldname:'account_type', label:__('Account Type'),
- options: ['', 'Accumulated Depreciation', 'Bank', 'Cash', 'Chargeable', 'Cost of Goods Sold', 'Depreciation',
- 'Equity', 'Expense Account', 'Expenses Included In Valuation', 'Fixed Asset', 'Income Account', 'Payable', 'Receivable',
- 'Round Off', 'Stock', 'Stock Adjustment', 'Stock Received But Not Billed', 'Tax', 'Temporary'].join('\n'),
+ options: frappe.get_meta("Account").fields.filter(d => d.fieldname=='account_type')[0].options,
description: __("Optional. This setting will be used to filter in various transactions.")
},
{fieldtype:'Float', fieldname:'tax_rate', label:__('Tax Rate'),
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index be6078a..4789464 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -97,7 +97,7 @@
doc.conversion_rate = 1.0
if doc.currency != company_data.default_currency:
- doc.conversion_rate = get_exchange_rate(doc.currency, company_data.default_currency, doc.posting_date)
+ doc.conversion_rate = get_exchange_rate(doc.currency, company_data.default_currency, doc.posting_date, args="for_selling")
doc.selling_price_list = pos_profile.get('selling_price_list') or \
frappe.db.get_value('Selling Settings', None, 'selling_price_list')
diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js
index 7fae7b9..d9032c8 100644
--- a/erpnext/buying/doctype/supplier/supplier.js
+++ b/erpnext/buying/doctype/supplier/supplier.js
@@ -4,6 +4,9 @@
frappe.ui.form.on("Supplier", {
setup: function (frm) {
frm.set_query('default_price_list', { 'buying': 1 });
+ if (frm.doc.__islocal == 1) {
+ frm.set_value("represents_company", "");
+ }
frm.set_query('account', 'accounts', function (doc, cdt, cdn) {
var d = locals[cdt][cdn];
return {
@@ -45,4 +48,13 @@
erpnext.utils.set_party_dashboard_indicators(frm);
}
},
+
+ is_internal_supplier: function(frm) {
+ if (frm.doc.is_internal_supplier == 1) {
+ frm.toggle_reqd("represents_company", true);
+ }
+ else {
+ frm.toggle_reqd("represents_company", false);
+ }
+ }
});
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 050a143..0c8e485 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -148,8 +148,13 @@
if self.meta.get_field("currency"):
# price list part
- fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
- else "buying_price_list"
+ if buying_or_selling.lower() == "selling":
+ fieldname = "selling_price_list"
+ args = "for_selling"
+ else:
+ fieldname = "buying_price_list"
+ args = "for_buying"
+
if self.meta.get_field(fieldname) and self.get(fieldname):
self.price_list_currency = frappe.db.get_value("Price List",
self.get(fieldname), "currency")
@@ -159,7 +164,7 @@
elif not self.plc_conversion_rate:
self.plc_conversion_rate = get_exchange_rate(self.price_list_currency,
- self.company_currency, transaction_date)
+ self.company_currency, transaction_date, args)
# currency
if not self.currency:
@@ -169,7 +174,7 @@
self.conversion_rate = 1.0
elif not self.conversion_rate:
self.conversion_rate = get_exchange_rate(self.currency,
- self.company_currency, transaction_date)
+ self.company_currency, transaction_date, args)
def set_missing_item_details(self, for_validate=False):
"""set missing item values"""
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index fc886ac..5c203d9 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -227,7 +227,7 @@
exchange_rate = 1
else:
exchange_rate = get_exchange_rate(quotation.currency, company_currency,
- quotation.transaction_date)
+ quotation.transaction_date, args="for_selling")
quotation.conversion_rate = exchange_rate
diff --git a/erpnext/demo/user/purchase.py b/erpnext/demo/user/purchase.py
index d9fc1f3..327f617 100644
--- a/erpnext/demo/user/purchase.py
+++ b/erpnext/demo/user/purchase.py
@@ -56,7 +56,7 @@
if company_currency == party_account_currency:
exchange_rate = 1
else:
- exchange_rate = get_exchange_rate(party_account_currency, company_currency)
+ exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_buying")
# make supplier quotations
if random.random() < 0.2:
diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py
index 2fd2565..02e1d42 100644
--- a/erpnext/demo/user/sales.py
+++ b/erpnext/demo/user/sales.py
@@ -89,7 +89,7 @@
if company_currency == party_account_currency:
exchange_rate = 1
else:
- exchange_rate = get_exchange_rate(party_account_currency, company_currency)
+ exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_selling")
qtn = frappe.get_doc({
"creation": frappe.flags.current_date,
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index d8a2fe3..48d9b87 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -9,13 +9,10 @@
from erpnext.hr.utils import set_employee_name, get_leave_period
from erpnext.hr.doctype.leave_block_list.leave_block_list import get_applicable_block_dates
from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee
-from erpnext.hr.doctype.employee_leave_approver.employee_leave_approver import get_approver_list
from erpnext.buying.doctype.supplier_scorecard.supplier_scorecard import daterange
class LeaveDayBlockedError(frappe.ValidationError): pass
class OverlapError(frappe.ValidationError): pass
-class InvalidLeaveApproverError(frappe.ValidationError): pass
-class LeaveApproverIdentityError(frappe.ValidationError): pass
class AttendanceAlreadyMarkedError(frappe.ValidationError): pass
class NotAnOptionalHoliday(frappe.ValidationError): pass
diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py
index 5c64b2e..df720c4 100644
--- a/erpnext/hr/utils.py
+++ b/erpnext/hr/utils.py
@@ -21,11 +21,11 @@
def on_submit(self):
# create the project for the given employee onboarding
- project_name = _(self.doctype) + " : " + self.employee_name
+ project_name = _(self.doctype) + " : "
if self.doctype == "Employee Onboarding":
- project_name += " (" + self.job_applicant + ")"
+ project_name += self.job_applicant
else:
- project_name += " (" + self.employee + ")"
+ project_name += self.employee
project = frappe.get_doc({
"doctype": "Project",
"project_name": project_name,
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index 73c8ca0..1fbc806 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -303,7 +303,7 @@
if self.currency == self.company_currency():
self.conversion_rate = 1
elif self.conversion_rate == 1 or flt(self.conversion_rate) <= 0:
- self.conversion_rate = get_exchange_rate(self.currency, self.company_currency())
+ self.conversion_rate = get_exchange_rate(self.currency, self.company_currency(), args="for_buying")
def validate_materials(self):
""" Validate raw material entries """
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index cdea9e7..fa2251f 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -537,3 +537,4 @@
erpnext.patches.v11_0.create_department_records_for_each_company
erpnext.patches.v11_0.make_location_from_warehouse
erpnext.patches.v11_0.make_asset_finance_book_against_old_entries
+erpnext.patches.v11_0.check_buying_selling_in_currency_exchange
diff --git a/erpnext/patches/v11_0/check_buying_selling_in_currency_exchange.py b/erpnext/patches/v11_0/check_buying_selling_in_currency_exchange.py
new file mode 100644
index 0000000..ee336be
--- /dev/null
+++ b/erpnext/patches/v11_0/check_buying_selling_in_currency_exchange.py
@@ -0,0 +1,5 @@
+import frappe
+
+def execute():
+ frappe.reload_doc('setup', 'doctype', 'currency_exchange')
+ frappe.db.sql("""update `tabCurrency Exchange` set for_buying = 1, for_selling = 1""")
\ No newline at end of file
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 27afe01..7adb38e 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -599,14 +599,13 @@
/* manqala 19/09/2016: let the translation date be whichever of the transaction_date or posting_date is available */
var transaction_date = this.frm.doc.transaction_date || this.frm.doc.posting_date;
/* end manqala */
-
var me = this;
this.set_dynamic_labels();
-
var company_currency = this.get_company_currency();
// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
if(this.frm.doc.currency && this.frm.doc.currency !== company_currency
&& !this.frm.doc.ignore_pricing_rule) {
+
this.get_exchange_rate(transaction_date, this.frm.doc.currency, company_currency,
function(exchange_rate) {
me.frm.set_value("conversion_rate", exchange_rate);
@@ -668,13 +667,22 @@
},
get_exchange_rate: function(transaction_date, from_currency, to_currency, callback) {
+ var args;
+ if (["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].includes(this.frm.doctype)) {
+ args = "for_selling";
+ }
+ else if (["Purchase Order", "Purchase Receipt", "Purchase Invoice"].includes(this.frm.doctype)) {
+ args = "for_buying";
+ }
+
if (!transaction_date || !from_currency || !to_currency) return;
return frappe.call({
method: "erpnext.setup.utils.get_exchange_rate",
args: {
transaction_date: transaction_date,
from_currency: from_currency,
- to_currency: to_currency
+ to_currency: to_currency,
+ args: args
},
callback: function(r) {
callback(flt(r.message));
diff --git a/erpnext/setup/doctype/currency_exchange/currency_exchange.json b/erpnext/setup/doctype/currency_exchange/currency_exchange.json
index 76e1a6b..89c3736 100644
--- a/erpnext/setup/doctype/currency_exchange/currency_exchange.json
+++ b/erpnext/setup/doctype/currency_exchange/currency_exchange.json
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
+ "allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 0,
"beta": 0,
@@ -13,6 +14,7 @@
"engine": "InnoDB",
"fields": [
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -23,7 +25,9 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
+ "in_global_search": 0,
"in_list_view": 1,
+ "in_standard_filter": 0,
"label": "Date",
"length": 0,
"no_copy": 0,
@@ -32,14 +36,17 @@
"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,
"width": "5"
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -50,6 +57,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
+ "in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "From Currency",
@@ -65,10 +73,12 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0,
"width": "3"
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -79,6 +89,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
+ "in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 1,
"label": "To Currency",
@@ -94,10 +105,12 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0,
"width": "3"
},
{
+ "allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -108,6 +121,7 @@
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
+ "in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Exchange Rate",
@@ -123,22 +137,117 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
+ "translatable": 0,
"unique": 0,
"width": "3"
+ },
+ {
+ "allow_bulk_edit": 0,
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
+ "fieldname": "column_break_5",
+ "fieldtype": "Column Break",
+ "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,
+ "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": "for_buying",
+ "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": "For Buying",
+ "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": "for_selling",
+ "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": "For Selling",
+ "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
}
],
+ "has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"icon": "fa fa-exchange",
"idx": 1,
"image_view": 0,
"in_create": 0,
- "in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2016-11-08 05:28:09.772560",
+ "modified": "2018-05-15 11:23:35.639039",
"modified_by": "Administrator",
"module": "Setup",
"name": "Currency Exchange",
@@ -146,7 +255,6 @@
"permissions": [
{
"amend": 0,
- "apply_user_permissions": 0,
"cancel": 0,
"create": 1,
"delete": 1,
@@ -154,7 +262,6 @@
"export": 0,
"if_owner": 0,
"import": 0,
- "is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@@ -167,7 +274,6 @@
},
{
"amend": 0,
- "apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
@@ -175,7 +281,6 @@
"export": 0,
"if_owner": 0,
"import": 0,
- "is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@@ -188,7 +293,6 @@
},
{
"amend": 0,
- "apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
@@ -196,7 +300,6 @@
"export": 0,
"if_owner": 0,
"import": 0,
- "is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@@ -209,7 +312,6 @@
},
{
"amend": 0,
- "apply_user_permissions": 0,
"cancel": 0,
"create": 0,
"delete": 0,
@@ -217,7 +319,6 @@
"export": 0,
"if_owner": 0,
"import": 0,
- "is_custom": 0,
"permlevel": 0,
"print": 1,
"read": 1,
@@ -232,8 +333,10 @@
"quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
+ "show_name_in_global_search": 0,
"sort_field": "name",
"sort_order": "DESC",
"title_field": "",
+ "track_changes": 0,
"track_seen": 0
}
\ No newline at end of file
diff --git a/erpnext/setup/doctype/currency_exchange/currency_exchange.py b/erpnext/setup/doctype/currency_exchange/currency_exchange.py
index ab892fb..4effb5a 100644
--- a/erpnext/setup/doctype/currency_exchange/currency_exchange.py
+++ b/erpnext/setup/doctype/currency_exchange/currency_exchange.py
@@ -5,9 +5,9 @@
from __future__ import unicode_literals
import frappe
-from frappe import _
+from frappe import _, throw
from frappe.model.document import Document
-from frappe.utils import get_datetime_str, formatdate, nowdate
+from frappe.utils import get_datetime_str, formatdate, nowdate, cint
class CurrencyExchange(Document):
def autoname(self):
@@ -20,4 +20,7 @@
self.validate_value("exchange_rate", ">", 0)
if self.from_currency == self.to_currency:
- frappe.throw(_("From Currency and To Currency cannot be same"))
+ throw(_("From Currency and To Currency cannot be same"))
+
+ if not cint(self.for_buying) and not cint(self.for_selling):
+ throw(_("Currency Exchange must be applicable for Buying or for Selling."))
\ No newline at end of file
diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.js b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.js
new file mode 100644
index 0000000..19fde2e
--- /dev/null
+++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.js
@@ -0,0 +1,23 @@
+/* eslint-disable */
+// rename this file from _test_[name] to test_[name] to activate
+// and remove above this line
+
+QUnit.test("test: Currency Exchange", function (assert) {
+ let done = assert.async();
+
+ // number of asserts
+ assert.expect(1);
+
+ frappe.run_serially([
+ // insert a new Currency Exchange
+ () => frappe.tests.make('Currency Exchange', [
+ // values to be set
+ {key: 'value'}
+ ]),
+ () => {
+ assert.equal(cur_frm.doc.key, 'value');
+ },
+ () => done()
+ ]);
+
+});
diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py
index 8d9bba3..bc17f88 100644
--- a/erpnext/setup/utils.py
+++ b/erpnext/setup/utils.py
@@ -55,17 +55,15 @@
frappe.db.commit()
@frappe.whitelist()
-def get_exchange_rate(from_currency, to_currency, transaction_date=None):
+def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=None):
if not (from_currency and to_currency):
# manqala 19/09/2016: Should this be an empty return or should it throw and exception?
return
-
if from_currency == to_currency:
return 1
if not transaction_date:
transaction_date = nowdate()
-
currency_settings = frappe.get_doc("Accounts Settings").as_dict()
allow_stale_rates = currency_settings.get("allow_stale")
@@ -75,6 +73,11 @@
["to_currency", "=", to_currency]
]
+ if args == "for_buying":
+ filters.append(["for_buying", "=", "1"])
+ elif args == "for_selling":
+ filters.append(["for_selling", "=", "1"])
+
if not allow_stale_rates:
stale_days = currency_settings.get("stale_days")
checkpoint_date = add_days(transaction_date, -stale_days)
@@ -84,7 +87,6 @@
entries = frappe.get_all(
"Currency Exchange", fields=["exchange_rate"], filters=filters, order_by="date desc",
limit=1)
-
if entries:
return flt(entries[0].exchange_rate)
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 340f03d..b336565 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -648,6 +648,11 @@
if not args.price_list:
return {}
+ if args.doctype in ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']:
+ args.update({"exchange_rate": "for_selling"})
+ elif args.doctype in ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']:
+ args.update({"exchange_rate": "for_buying"})
+
price_list_currency = get_price_list_currency(args.price_list)
price_list_uom_dependant = get_price_list_uom_dependant(args.price_list)
plc_conversion_rate = args.plc_conversion_rate
@@ -657,7 +662,7 @@
and price_list_currency != args.price_list_currency):
# cksgb 19/09/2016: added args.transaction_date as posting_date argument for get_exchange_rate
plc_conversion_rate = get_exchange_rate(price_list_currency, company_currency,
- args.transaction_date) or plc_conversion_rate
+ args.transaction_date, args.exchange_rate) or plc_conversion_rate
return frappe._dict({
"price_list_currency": price_list_currency,