From ff1911367744093203071baa9e2ada0aa29d9c37 Mon Sep 17 00:00:00 2001 From: rtdany10 Date: Thu, 2 Sep 2021 19:52:12 +0530 Subject: [PATCH 01/50] feat: currency exchange settings --- .../currency_exchange_settings/__init__.py | 0 .../currency_exchange_settings.js | 8 ++ .../currency_exchange_settings.json | 86 +++++++++++++++++++ .../currency_exchange_settings.py | 38 ++++++++ .../test_currency_exchange_settings.py | 8 ++ .../__init__.py | 0 .../currency_exchange_settings_details.json | 40 +++++++++ .../currency_exchange_settings_details.py | 8 ++ .../__init__.py | 0 ...rency_exchange_settings_extra_details.json | 39 +++++++++ ...urrency_exchange_settings_extra_details.py | 8 ++ 11 files changed, 235 insertions(+) create mode 100644 erpnext/setup/doctype/currency_exchange_settings/__init__.py create mode 100644 erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js create mode 100644 erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json create mode 100644 erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py create mode 100644 erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py create mode 100644 erpnext/setup/doctype/currency_exchange_settings_details/__init__.py create mode 100644 erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json create mode 100644 erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py create mode 100644 erpnext/setup/doctype/currency_exchange_settings_extra_details/__init__.py create mode 100644 erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json create mode 100644 erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py diff --git a/erpnext/setup/doctype/currency_exchange_settings/__init__.py b/erpnext/setup/doctype/currency_exchange_settings/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js new file mode 100644 index 0000000000..6b0ccb7713 --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Currency Exchange Settings', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json new file mode 100644 index 0000000000..b010437271 --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -0,0 +1,86 @@ +{ + "actions": [], + "creation": "2021-09-02 14:53:50.923529", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "api_details_section", + "api_endpoint", + "column_break_3", + "result_key", + "section_break_2", + "req_params", + "column_break_4", + "extra_params" + ], + "fields": [ + { + "fieldname": "api_endpoint", + "fieldtype": "Data", + "in_list_view": 1, + "label": "API Endpoint", + "reqd": 1 + }, + { + "fieldname": "section_break_2", + "fieldtype": "Section Break", + "label": "Request Parameters" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "req_params", + "fieldtype": "Table", + "label": "Mandatory Parameters", + "options": "Currency Exchange Settings Details", + "reqd": 1 + }, + { + "fieldname": "extra_params", + "fieldtype": "Table", + "label": "Additional Parameters", + "options": "Currency Exchange Settings Extra Details" + }, + { + "fieldname": "api_details_section", + "fieldtype": "Section Break", + "label": "API Details" + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "result_key", + "fieldtype": "Data", + "label": "Result Key", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2021-09-02 15:18:29.198210", + "modified_by": "Administrator", + "module": "Setup", + "name": "Currency Exchange Settings", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py new file mode 100644 index 0000000000..b726d755e4 --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -0,0 +1,38 @@ +# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +import frappe +from frappe import _ +from frappe.model.document import Document + +class CurrencyExchangeSettings(Document): + def validate(self): + if len(self.req_params) != 3: + frappe.throw(_("Make sure all the three mandatory parameters are filled.")) + req_params = { + 'transaction_date': '2021-08-01', + 'from_currency': 'USD', + 'to_currency': 'INR' + } + params = {} + for row in self.req_params: + try: + params[row.key] = req_params[row.value] + req_params.pop(row.value) + except: + frappe.throw(_("Make sure all the three mandatory parameters are filled.")) + import requests + api_url = self.api_endpoint + try: + response = requests.get(api_url, params=params) + except requests.exceptions.RequestException as e: + frappe.throw("Error: " + str(e)) + response.raise_for_status() + value = response.json() + try: + rate = value[str(self.result_key)] + except KeyError: + frappe.throw(_("Invalid result key.")) + if not isinstance(rate, (int, float)): + frappe.throw(_("Returned exchange rate is neither integer not float.")) + frappe.msgprint(_("Exchange rate of USD to INR on 01-08-2021 is ") + str(rate)) diff --git a/erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py new file mode 100644 index 0000000000..80a9a1768d --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +# import frappe +import unittest + +class TestCurrencyExchangeSettings(unittest.TestCase): + pass diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/__init__.py b/erpnext/setup/doctype/currency_exchange_settings_details/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json new file mode 100644 index 0000000000..9d49daa1eb --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json @@ -0,0 +1,40 @@ +{ + "actions": [], + "creation": "2021-09-02 14:54:49.033512", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "key", + "value" + ], + "fields": [ + { + "fieldname": "key", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Key", + "reqd": 1 + }, + { + "fieldname": "value", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Value", + "options": "\ntransaction_date\nfrom_currency\nto_currency", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-09-02 15:24:24.675019", + "modified_by": "Administrator", + "module": "Setup", + "name": "Currency Exchange Settings Details", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py new file mode 100644 index 0000000000..f870b11c5a --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CurrencyExchangeSettingsDetails(Document): + pass diff --git a/erpnext/setup/doctype/currency_exchange_settings_extra_details/__init__.py b/erpnext/setup/doctype/currency_exchange_settings_extra_details/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json new file mode 100644 index 0000000000..fb85bb167d --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json @@ -0,0 +1,39 @@ +{ + "actions": [], + "creation": "2021-09-02 15:18:17.888667", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "key", + "value" + ], + "fields": [ + { + "fieldname": "key", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Key", + "reqd": 1 + }, + { + "fieldname": "value", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Value", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-09-02 15:18:17.888667", + "modified_by": "Administrator", + "module": "Setup", + "name": "Currency Exchange Settings Extra Details", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py new file mode 100644 index 0000000000..ee51533091 --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CurrencyExchangeSettingsExtraDetails(Document): + pass From e093863c9e41d97a169afb6b58d4a3f33edcb41a Mon Sep 17 00:00:00 2001 From: rtdany10 Date: Fri, 3 Sep 2021 15:03:47 +0530 Subject: [PATCH 02/50] feat: fetch api details from settings --- .../currency_exchange_settings.json | 5 +-- .../currency_exchange_settings.py | 32 +++++++++++++------ .../__init__.py | 0 .../currency_exchange_settings_result.json | 31 ++++++++++++++++++ .../currency_exchange_settings_result.py | 8 +++++ erpnext/setup/utils.py | 30 +++++++++++++---- 6 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 erpnext/setup/doctype/currency_exchange_settings_result/__init__.py create mode 100644 erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json create mode 100644 erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json index b010437271..a0dfe73504 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -55,15 +55,16 @@ }, { "fieldname": "result_key", - "fieldtype": "Data", + "fieldtype": "Table", "label": "Result Key", + "options": "Currency Exchange Settings Result", "reqd": 1 } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-09-02 15:18:29.198210", + "modified": "2021-09-03 13:21:16.397695", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings", diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py index b726d755e4..1993c9bab8 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -9,10 +9,13 @@ class CurrencyExchangeSettings(Document): def validate(self): if len(self.req_params) != 3: frappe.throw(_("Make sure all the three mandatory parameters are filled.")) - req_params = { - 'transaction_date': '2021-08-01', - 'from_currency': 'USD', - 'to_currency': 'INR' + transaction_date = '2021-08-01' + from_currency = 'USD' + to_currency = 'INR' + req_params={ + "transaction_date": transaction_date, + "from_currency": from_currency, + "to_currency": to_currency } params = {} for row in self.req_params: @@ -21,8 +24,14 @@ class CurrencyExchangeSettings(Document): req_params.pop(row.value) except: frappe.throw(_("Make sure all the three mandatory parameters are filled.")) + for eparam in self.extra_params: + params[eparam.key] = eparam.value import requests - api_url = self.api_endpoint + api_url = self.api_endpoint.format( + transaction_date=transaction_date, + to_currency=to_currency, + from_currency=from_currency + ) try: response = requests.get(api_url, params=params) except requests.exceptions.RequestException as e: @@ -30,9 +39,14 @@ class CurrencyExchangeSettings(Document): response.raise_for_status() value = response.json() try: - rate = value[str(self.result_key)] + for key in self.result_key: + value = value[str(key.key).format( + transaction_date=transaction_date, + to_currency=to_currency, + from_currency=from_currency + )] except KeyError: - frappe.throw(_("Invalid result key.")) - if not isinstance(rate, (int, float)): + frappe.throw(_("Invalid result key. Response: ") + response.text) + if not isinstance(value, (int, float)): frappe.throw(_("Returned exchange rate is neither integer not float.")) - frappe.msgprint(_("Exchange rate of USD to INR on 01-08-2021 is ") + str(rate)) + frappe.msgprint(_("Exchange rate of USD to INR on 01-08-2021 is ") + str(value)) diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/__init__.py b/erpnext/setup/doctype/currency_exchange_settings_result/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json new file mode 100644 index 0000000000..4203b802fd --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json @@ -0,0 +1,31 @@ +{ + "actions": [], + "creation": "2021-09-03 13:17:22.088259", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "key" + ], + "fields": [ + { + "fieldname": "key", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Key", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-09-03 13:17:22.088259", + "modified_by": "Administrator", + "module": "Setup", + "name": "Currency Exchange Settings Result", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py new file mode 100644 index 0000000000..2c4fb61ab9 --- /dev/null +++ b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class CurrencyExchangeSettingsResult(Document): + pass diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 409f776a4e..76e52cdea3 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -98,15 +98,31 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No if not value: import requests - api_url = "https://api.exchangerate.host/convert" - response = requests.get(api_url, params={ - "date": transaction_date, - "from": from_currency, - "to": to_currency - }) + settings = frappe.get_single('Currency Exchange Settings') + req_params={ + "transaction_date": transaction_date, + "from_currency": from_currency, + "to_currency": to_currency + } + params = {} + for row in settings.req_params: + params[row.key] = req_params[row.value] + for eparam in settings.extra_params: + params[eparam.key] = eparam.value + response = requests.get(settings.api_endpoint.format( + transaction_date=transaction_date, + to_currency=to_currency, + from_currency=from_currency + ), params=params) # expire in 6 hours response.raise_for_status() - value = response.json()["result"] + value = response.json() + for res_key in settings.result_key: + value = value[str(res_key.key).format( + transaction_date=transaction_date, + to_currency=to_currency, + from_currency=from_currency + )] cache.setex(name=key, time=21600, value=flt(value)) return flt(value) except Exception: From d8b8032de15c53ec484260f6d72c1f4041adfd68 Mon Sep 17 00:00:00 2001 From: rtdany10 Date: Fri, 3 Sep 2021 15:50:05 +0530 Subject: [PATCH 03/50] feat: init CES default values --- .../currency_exchange_settings.py | 8 ++++---- .../currency_exchange_settings_result.json | 5 +++-- erpnext/setup/install.py | 8 +++++++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py index 1993c9bab8..92828e60b1 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -7,8 +7,8 @@ from frappe.model.document import Document class CurrencyExchangeSettings(Document): def validate(self): - if len(self.req_params) != 3: - frappe.throw(_("Make sure all the three mandatory parameters are filled.")) + if len(self.req_params) > 3: + frappe.throw(_("Make sure no mandatory parameters are repeated.")) transaction_date = '2021-08-01' from_currency = 'USD' to_currency = 'INR' @@ -23,7 +23,7 @@ class CurrencyExchangeSettings(Document): params[row.key] = req_params[row.value] req_params.pop(row.value) except: - frappe.throw(_("Make sure all the three mandatory parameters are filled.")) + frappe.throw(_("Make sure no mandatory parameters are repeated.")) for eparam in self.extra_params: params[eparam.key] = eparam.value import requests @@ -42,7 +42,7 @@ class CurrencyExchangeSettings(Document): for key in self.result_key: value = value[str(key.key).format( transaction_date=transaction_date, - to_currency=to_currency, + to_currency=to_currency, from_currency=from_currency )] except KeyError: diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json index 4203b802fd..1b2c623867 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json +++ b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json @@ -13,13 +13,14 @@ "fieldtype": "Data", "in_list_view": 1, "label": "Key", - "reqd": 1 + "reqd": 1, + "unique": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-03 13:17:22.088259", + "modified": "2021-09-03 15:41:09.997576", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings Result", diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index bbee74cafb..239733a48d 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -57,7 +57,13 @@ def set_single_defaults(): pass except frappe.ValidationError: pass - + ces = frappe.get_single('Currency Exchange Settings') + ces.api_endpoint = "https://api.exchangerate.host/convert" + ces.append('result_key', {'key': 'result'}) + ces.append('req_params', {'key': 'date', 'value': 'transaction_date'}) + ces.append('req_params', {'key': 'from', 'value': 'from_currency'}) + ces.append('req_params', {'key': 'to', 'value': 'to_currency'}) + ces.save() frappe.db.set_default("date_format", "dd-mm-yyyy") From a86d9c91d0661f741bba9f3e051c9888a6207f87 Mon Sep 17 00:00:00 2001 From: rtdany10 Date: Fri, 3 Sep 2021 19:21:06 +0530 Subject: [PATCH 04/50] chore: code clean up --- .../currency_exchange_settings.json | 9 +++++++- .../currency_exchange_settings.py | 13 +++++++---- .../currency_exchange_settings_details.json | 5 ++-- ...rency_exchange_settings_extra_details.json | 5 ++-- erpnext/setup/utils.py | 23 +++++++++---------- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json index a0dfe73504..bd862429ac 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -7,6 +7,7 @@ "field_order": [ "api_details_section", "api_endpoint", + "url", "column_break_3", "result_key", "section_break_2", @@ -59,12 +60,18 @@ "label": "Result Key", "options": "Currency Exchange Settings Result", "reqd": 1 + }, + { + "fieldname": "url", + "fieldtype": "Data", + "label": "URL", + "read_only": 1 } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-09-03 13:21:16.397695", + "modified": "2021-09-03 19:09:02.741016", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings", diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py index 92828e60b1..1ecb0ffe31 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -12,7 +12,7 @@ class CurrencyExchangeSettings(Document): transaction_date = '2021-08-01' from_currency = 'USD' to_currency = 'INR' - req_params={ + req_params = { "transaction_date": transaction_date, "from_currency": from_currency, "to_currency": to_currency @@ -25,7 +25,11 @@ class CurrencyExchangeSettings(Document): except: frappe.throw(_("Make sure no mandatory parameters are repeated.")) for eparam in self.extra_params: - params[eparam.key] = eparam.value + params[eparam.key] = eparam.value.format( + transaction_date=transaction_date, + to_currency=to_currency, + from_currency=from_currency + ) import requests api_url = self.api_endpoint.format( transaction_date=transaction_date, @@ -46,7 +50,8 @@ class CurrencyExchangeSettings(Document): from_currency=from_currency )] except KeyError: - frappe.throw(_("Invalid result key. Response: ") + response.text) + frappe.throw("Invalid result key. Response: " + response.text) if not isinstance(value, (int, float)): frappe.throw(_("Returned exchange rate is neither integer not float.")) - frappe.msgprint(_("Exchange rate of USD to INR on 01-08-2021 is ") + str(value)) + self.url = response.url + frappe.msgprint("Exchange rate of USD to INR on 01-08-2021 is " + str(value)) diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json index 9d49daa1eb..dbb886fe60 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json +++ b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json @@ -14,7 +14,8 @@ "fieldtype": "Data", "in_list_view": 1, "label": "Key", - "reqd": 1 + "reqd": 1, + "unique": 1 }, { "fieldname": "value", @@ -28,7 +29,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-02 15:24:24.675019", + "modified": "2021-09-03 18:50:47.145457", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings Details", diff --git a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json index fb85bb167d..f21f9cef0b 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json +++ b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json @@ -14,7 +14,8 @@ "fieldtype": "Data", "in_list_view": 1, "label": "Key", - "reqd": 1 + "reqd": 1, + "unique": 1 }, { "fieldname": "value", @@ -27,7 +28,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-02 15:18:17.888667", + "modified": "2021-09-03 18:50:28.482851", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings Extra Details", diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index c54f62d09b..9146566f65 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -101,7 +101,7 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No if not value: import requests settings = frappe.get_single('Currency Exchange Settings') - req_params={ + req_params = { "transaction_date": transaction_date, "from_currency": from_currency, "to_currency": to_currency @@ -110,21 +110,13 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No for row in settings.req_params: params[row.key] = req_params[row.value] for eparam in settings.extra_params: - params[eparam.key] = eparam.value - response = requests.get(settings.api_endpoint.format( - transaction_date=transaction_date, - to_currency=to_currency, - from_currency=from_currency - ), params=params) + params[eparam.key] = format_ces_api(eparam.value, req_params) + response = requests.get(format_ces_api(settings.api_endpoint, req_params), params=params) # expire in 6 hours response.raise_for_status() value = response.json() for res_key in settings.result_key: - value = value[str(res_key.key).format( - transaction_date=transaction_date, - to_currency=to_currency, - from_currency=from_currency - )] + value = value[format_ces_api(str(res_key.key), req_params)] cache.setex(name=key, time=21600, value=flt(value)) return flt(value) except Exception: @@ -132,6 +124,13 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}. Please create a Currency Exchange record manually").format(from_currency, to_currency, transaction_date)) return 0.0 +def format_ces_api(data="", param={}): + return data.format( + transaction_date=param["transaction_date"], + to_currency=param["to_currency"], + from_currency=param["from_currency"] + ) + def enable_all_roles_and_domains(): """ enable all roles and domain for testing """ # add all roles to users From 227466c36539f5c6448233e3ea51c72a7367ed30 Mon Sep 17 00:00:00 2001 From: rtdany10 Date: Sat, 4 Sep 2021 14:04:56 +0530 Subject: [PATCH 05/50] chore: clean up layout and code --- .../currency_exchange_settings.json | 22 +++++----- .../currency_exchange_settings.py | 20 ++-------- .../currency_exchange_settings_details.json | 5 +-- .../__init__.py | 0 ...rency_exchange_settings_extra_details.json | 40 ------------------- ...urrency_exchange_settings_extra_details.py | 8 ---- erpnext/setup/install.py | 19 +++++---- erpnext/setup/utils.py | 4 +- 8 files changed, 29 insertions(+), 89 deletions(-) delete mode 100644 erpnext/setup/doctype/currency_exchange_settings_extra_details/__init__.py delete mode 100644 erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json delete mode 100644 erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json index bd862429ac..d3d23043c4 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -9,11 +9,11 @@ "api_endpoint", "url", "column_break_3", - "result_key", + "help", "section_break_2", "req_params", "column_break_4", - "extra_params" + "result_key" ], "fields": [ { @@ -35,16 +35,10 @@ { "fieldname": "req_params", "fieldtype": "Table", - "label": "Mandatory Parameters", + "label": "Parameters", "options": "Currency Exchange Settings Details", "reqd": 1 }, - { - "fieldname": "extra_params", - "fieldtype": "Table", - "label": "Additional Parameters", - "options": "Currency Exchange Settings Extra Details" - }, { "fieldname": "api_details_section", "fieldtype": "Section Break", @@ -64,14 +58,20 @@ { "fieldname": "url", "fieldtype": "Data", - "label": "URL", + "label": "Example URL", "read_only": 1 + }, + { + "fieldname": "help", + "fieldtype": "HTML", + "label": "Help", + "options": "

Currency Exchange Settings Help

\n

There are 3 variables that could be used within the endpoint, result key and in values of the parameter.

\n

Exchange rate between {from_currency} and {to_currency} on {transaction_date} is fetched by the API.

\n

Example: If your endpoint is exchange.com/2021-08-01, then, you will have to input exchange.com/{transaction_date}

" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-09-03 19:09:02.741016", + "modified": "2021-09-04 11:41:34.375637", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings", diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py index 1ecb0ffe31..badd14f159 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -3,29 +3,17 @@ import frappe from frappe import _ +from frappe.utils import nowdate from frappe.model.document import Document class CurrencyExchangeSettings(Document): def validate(self): - if len(self.req_params) > 3: - frappe.throw(_("Make sure no mandatory parameters are repeated.")) - transaction_date = '2021-08-01' + transaction_date = nowdate() from_currency = 'USD' to_currency = 'INR' - req_params = { - "transaction_date": transaction_date, - "from_currency": from_currency, - "to_currency": to_currency - } params = {} for row in self.req_params: - try: - params[row.key] = req_params[row.value] - req_params.pop(row.value) - except: - frappe.throw(_("Make sure no mandatory parameters are repeated.")) - for eparam in self.extra_params: - params[eparam.key] = eparam.value.format( + params[row.key] = row.value.format( transaction_date=transaction_date, to_currency=to_currency, from_currency=from_currency @@ -54,4 +42,4 @@ class CurrencyExchangeSettings(Document): if not isinstance(value, (int, float)): frappe.throw(_("Returned exchange rate is neither integer not float.")) self.url = response.url - frappe.msgprint("Exchange rate of USD to INR on 01-08-2021 is " + str(value)) + frappe.msgprint("Exchange rate of USD to INR is " + str(value)) diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json index dbb886fe60..886d38529e 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json +++ b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json @@ -19,17 +19,16 @@ }, { "fieldname": "value", - "fieldtype": "Select", + "fieldtype": "Data", "in_list_view": 1, "label": "Value", - "options": "\ntransaction_date\nfrom_currency\nto_currency", "reqd": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-03 18:50:47.145457", + "modified": "2021-09-04 11:24:21.944002", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings Details", diff --git a/erpnext/setup/doctype/currency_exchange_settings_extra_details/__init__.py b/erpnext/setup/doctype/currency_exchange_settings_extra_details/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json deleted file mode 100644 index f21f9cef0b..0000000000 --- a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "actions": [], - "creation": "2021-09-02 15:18:17.888667", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "key", - "value" - ], - "fields": [ - { - "fieldname": "key", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Key", - "reqd": 1, - "unique": 1 - }, - { - "fieldname": "value", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Value", - "reqd": 1 - } - ], - "index_web_pages_for_search": 1, - "istable": 1, - "links": [], - "modified": "2021-09-03 18:50:28.482851", - "modified_by": "Administrator", - "module": "Setup", - "name": "Currency Exchange Settings Extra Details", - "owner": "Administrator", - "permissions": [], - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1 -} \ No newline at end of file diff --git a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py b/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py deleted file mode 100644 index ee51533091..0000000000 --- a/erpnext/setup/doctype/currency_exchange_settings_extra_details/currency_exchange_settings_extra_details.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - -# import frappe -from frappe.model.document import Document - -class CurrencyExchangeSettingsExtraDetails(Document): - pass diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index ad4d90003d..55be9ee32a 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -59,15 +59,18 @@ def set_single_defaults(): pass except frappe.ValidationError: pass - ces = frappe.get_single('Currency Exchange Settings') - ces.api_endpoint = "https://api.exchangerate.host/convert" - ces.append('result_key', {'key': 'result'}) - ces.append('req_params', {'key': 'date', 'value': 'transaction_date'}) - ces.append('req_params', {'key': 'from', 'value': 'from_currency'}) - ces.append('req_params', {'key': 'to', 'value': 'to_currency'}) - ces.save() - frappe.db.set_default("date_format", "dd-mm-yyyy") + frappe.db.set_default("date_format", "dd-mm-yyyy") + ces = frappe.get_single('Currency Exchange Settings') + try: + ces.api_endpoint = "https://api.exchangerate.host/convert" + ces.append('result_key', {'key': 'result'}) + ces.append('req_params', {'key': 'date', 'value': '{transaction_date}'}) + ces.append('req_params', {'key': 'from', 'value': '{from_currency}'}) + ces.append('req_params', {'key': 'to', 'value': '{to_currency}'}) + ces.save() + except frappe.ValidationError: + pass def create_compact_item_print_custom_field(): create_custom_field('Print Settings', { diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 9146566f65..4fcd7d5936 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -108,9 +108,7 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No } params = {} for row in settings.req_params: - params[row.key] = req_params[row.value] - for eparam in settings.extra_params: - params[eparam.key] = format_ces_api(eparam.value, req_params) + params[row.key] = format_ces_api(row.value, req_params) response = requests.get(format_ces_api(settings.api_endpoint, req_params), params=params) # expire in 6 hours response.raise_for_status() From 06340ad08ae286cf7c9b63c637d7c47be7eca76b Mon Sep 17 00:00:00 2001 From: rtdany10 Date: Sat, 4 Sep 2021 17:53:51 +0530 Subject: [PATCH 06/50] feat: button to restore default settings --- .../currency_exchange_settings.js | 25 ++++++++++++++++--- .../currency_exchange_settings.py | 2 +- .../currency_exchange_settings_details.json | 5 ++-- .../currency_exchange_settings_result.json | 5 ++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js index 6b0ccb7713..c48bca8b8f 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -2,7 +2,26 @@ // For license information, please see license.txt frappe.ui.form.on('Currency Exchange Settings', { - // refresh: function(frm) { - - // } + refresh: function(frm) { + frm.add_custom_button(__('Restore Defaults'), function(){ + frm.doc.api_endpoint = "https://api.exchangerate.host/convert"; + frm.clear_table("req_params") + frm.clear_table("result_key") + let params = { + date: '{transaction_date}', + from: '{from_currency}', + to: '{to_currency}' + } + var row; + $.each(params, function(key, value){ + row = frm.add_child("req_params"); + row.key = key; + row.value = value; + }) + row = frm.add_child("result_key"); + row.key = 'result'; + frm.refresh_fields(); + frm.save(); + }); + } }); diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py index badd14f159..fa5286a4bb 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -37,7 +37,7 @@ class CurrencyExchangeSettings(Document): to_currency=to_currency, from_currency=from_currency )] - except KeyError: + except Exception: frappe.throw("Invalid result key. Response: " + response.text) if not isinstance(value, (int, float)): frappe.throw(_("Returned exchange rate is neither integer not float.")) diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json index 886d38529e..c9b27e1961 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json +++ b/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json @@ -14,8 +14,7 @@ "fieldtype": "Data", "in_list_view": 1, "label": "Key", - "reqd": 1, - "unique": 1 + "reqd": 1 }, { "fieldname": "value", @@ -28,7 +27,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-04 11:24:21.944002", + "modified": "2021-09-04 17:49:17.383982", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings Details", diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json index 1b2c623867..387e245a2f 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json +++ b/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json @@ -13,14 +13,13 @@ "fieldtype": "Data", "in_list_view": 1, "label": "Key", - "reqd": 1, - "unique": 1 + "reqd": 1 } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-03 15:41:09.997576", + "modified": "2021-09-04 17:49:33.858070", "modified_by": "Administrator", "module": "Setup", "name": "Currency Exchange Settings Result", From 7291d9f236a809595add2d90b7f2bfc03bfa2b82 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Wed, 3 Nov 2021 14:13:22 +0000 Subject: [PATCH 07/50] feat: option for preconfigured selectable service providers --- .../currency_exchange_settings/__init__.py | 0 .../currency_exchange_settings.js | 49 +++++++++++++++++ .../currency_exchange_settings.json | 52 +++++++++++-------- .../currency_exchange_settings.py | 0 .../test_currency_exchange_settings.py | 8 +++ .../__init__.py | 0 .../currency_exchange_settings_details.json | 4 +- .../currency_exchange_settings_details.py | 0 .../__init__.py | 0 .../currency_exchange_settings_result.json | 4 +- .../currency_exchange_settings_result.py | 2 +- .../currency_exchange_settings.js | 27 ---------- .../test_currency_exchange_settings.py | 8 --- 13 files changed, 92 insertions(+), 62 deletions(-) rename erpnext/{setup => accounts}/doctype/currency_exchange_settings/__init__.py (100%) create mode 100644 erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js rename erpnext/{setup => accounts}/doctype/currency_exchange_settings/currency_exchange_settings.json (88%) rename erpnext/{setup => accounts}/doctype/currency_exchange_settings/currency_exchange_settings.py (100%) create mode 100644 erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py rename erpnext/{setup => accounts}/doctype/currency_exchange_settings_details/__init__.py (100%) rename erpnext/{setup => accounts}/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json (91%) rename erpnext/{setup => accounts}/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py (100%) rename erpnext/{setup => accounts}/doctype/currency_exchange_settings_result/__init__.py (100%) rename erpnext/{setup => accounts}/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json (89%) rename erpnext/{setup => accounts}/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py (69%) delete mode 100644 erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js delete mode 100644 erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py diff --git a/erpnext/setup/doctype/currency_exchange_settings/__init__.py b/erpnext/accounts/doctype/currency_exchange_settings/__init__.py similarity index 100% rename from erpnext/setup/doctype/currency_exchange_settings/__init__.py rename to erpnext/accounts/doctype/currency_exchange_settings/__init__.py diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js new file mode 100644 index 0000000000..f29183a316 --- /dev/null +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -0,0 +1,49 @@ +// Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Currency Exchange Settings', { + service_provider: function(frm) { + if (frm.doc.service_provider == "Exchangerate.host"){ + frm.doc.api_endpoint = "https://api.exchangerate.host/convert"; + frm.clear_table("req_params") + frm.clear_table("result_key") + let params = { + date: '{transaction_date}', + from: '{from_currency}', + to: '{to_currency}' + } + var row; + $.each(params, function(key, value){ + row = frm.add_child("req_params"); + row.key = key; + row.value = value; + }) + row = frm.add_child("result_key"); + row.key = 'result'; + frm.refresh_fields(); + frm.save(); + } + else if (frm.doc.service_provider == "Frankfurter.app"){ + frm.doc.api_endpoint = "https://frankfurter.app/{transaction_date}"; + frm.clear_table("req_params") + frm.clear_table("result_key") + var row; + let result = ['rates', '{to_currency}'] + let params = { + base: '{from_currency}', + symbols: '{to_currency}' + } + $.each(params, function(key, value){ + row = frm.add_child("req_params"); + row.key = key; + row.value = value; + }) + $.each(result, function(key, value){ + row = frm.add_child("result_key"); + row.key = value; + }) + frm.refresh_fields(); + frm.save(); + } + } +}); diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json similarity index 88% rename from erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json rename to erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json index d3d23043c4..a0530c19a3 100644 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.json +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -6,6 +6,7 @@ "engine": "InnoDB", "field_order": [ "api_details_section", + "service_provider", "api_endpoint", "url", "column_break_3", @@ -16,6 +17,11 @@ "result_key" ], "fields": [ + { + "fieldname": "api_details_section", + "fieldtype": "Section Break", + "label": "API Details" + }, { "fieldname": "api_endpoint", "fieldtype": "Data", @@ -23,15 +29,27 @@ "label": "API Endpoint", "reqd": 1 }, + { + "fieldname": "url", + "fieldtype": "Data", + "label": "Example URL", + "read_only": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "help", + "fieldtype": "HTML", + "label": "Help", + "options": "

Currency Exchange Settings Help

\n

There are 3 variables that could be used within the endpoint, result key and in values of the parameter.

\n

Exchange rate between {from_currency} and {to_currency} on {transaction_date} is fetched by the API.

\n

Example: If your endpoint is exchange.com/2021-08-01, then, you will have to input exchange.com/{transaction_date}

" + }, { "fieldname": "section_break_2", "fieldtype": "Section Break", "label": "Request Parameters" }, - { - "fieldname": "column_break_4", - "fieldtype": "Column Break" - }, { "fieldname": "req_params", "fieldtype": "Table", @@ -40,12 +58,7 @@ "reqd": 1 }, { - "fieldname": "api_details_section", - "fieldtype": "Section Break", - "label": "API Details" - }, - { - "fieldname": "column_break_3", + "fieldname": "column_break_4", "fieldtype": "Column Break" }, { @@ -56,24 +69,19 @@ "reqd": 1 }, { - "fieldname": "url", - "fieldtype": "Data", - "label": "Example URL", - "read_only": 1 - }, - { - "fieldname": "help", - "fieldtype": "HTML", - "label": "Help", - "options": "

Currency Exchange Settings Help

\n

There are 3 variables that could be used within the endpoint, result key and in values of the parameter.

\n

Exchange rate between {from_currency} and {to_currency} on {transaction_date} is fetched by the API.

\n

Example: If your endpoint is exchange.com/2021-08-01, then, you will have to input exchange.com/{transaction_date}

" + "fieldname": "service_provider", + "fieldtype": "Select", + "label": "Service Provider", + "options": "Exchangerate.host\nFrankfurter.app\nCustom", + "reqd": 1 } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-09-04 11:41:34.375637", + "modified": "2021-11-03 19:27:27.922353", "modified_by": "Administrator", - "module": "Setup", + "module": "Accounts", "name": "Currency Exchange Settings", "owner": "Administrator", "permissions": [ diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py similarity index 100% rename from erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.py rename to erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py diff --git a/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py new file mode 100644 index 0000000000..59c579978f --- /dev/null +++ b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py @@ -0,0 +1,8 @@ +# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +import unittest + +class TestCurrencyExchangeSettings(unittest.TestCase): + pass diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/__init__.py b/erpnext/accounts/doctype/currency_exchange_settings_details/__init__.py similarity index 100% rename from erpnext/setup/doctype/currency_exchange_settings_details/__init__.py rename to erpnext/accounts/doctype/currency_exchange_settings_details/__init__.py diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json b/erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json similarity index 91% rename from erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json rename to erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json index c9b27e1961..30935871c6 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json +++ b/erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.json @@ -27,9 +27,9 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-04 17:49:17.383982", + "modified": "2021-11-03 19:14:55.889037", "modified_by": "Administrator", - "module": "Setup", + "module": "Accounts", "name": "Currency Exchange Settings Details", "owner": "Administrator", "permissions": [], diff --git a/erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py b/erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py similarity index 100% rename from erpnext/setup/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py rename to erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/__init__.py b/erpnext/accounts/doctype/currency_exchange_settings_result/__init__.py similarity index 100% rename from erpnext/setup/doctype/currency_exchange_settings_result/__init__.py rename to erpnext/accounts/doctype/currency_exchange_settings_result/__init__.py diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json b/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json similarity index 89% rename from erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json rename to erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json index 387e245a2f..fff5337616 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json +++ b/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.json @@ -19,9 +19,9 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-04 17:49:33.858070", + "modified": "2021-11-03 19:14:40.054245", "modified_by": "Administrator", - "module": "Setup", + "module": "Accounts", "name": "Currency Exchange Settings Result", "owner": "Administrator", "permissions": [], diff --git a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py b/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py similarity index 69% rename from erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py rename to erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py index 2c4fb61ab9..49da97bd5e 100644 --- a/erpnext/setup/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py +++ b/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py @@ -1,4 +1,4 @@ -# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors # For license information, please see license.txt # import frappe diff --git a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js deleted file mode 100644 index c48bca8b8f..0000000000 --- a/erpnext/setup/doctype/currency_exchange_settings/currency_exchange_settings.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Currency Exchange Settings', { - refresh: function(frm) { - frm.add_custom_button(__('Restore Defaults'), function(){ - frm.doc.api_endpoint = "https://api.exchangerate.host/convert"; - frm.clear_table("req_params") - frm.clear_table("result_key") - let params = { - date: '{transaction_date}', - from: '{from_currency}', - to: '{to_currency}' - } - var row; - $.each(params, function(key, value){ - row = frm.add_child("req_params"); - row.key = key; - row.value = value; - }) - row = frm.add_child("result_key"); - row.key = 'result'; - frm.refresh_fields(); - frm.save(); - }); - } -}); diff --git a/erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py b/erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py deleted file mode 100644 index 80a9a1768d..0000000000 --- a/erpnext/setup/doctype/currency_exchange_settings/test_currency_exchange_settings.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -# import frappe -import unittest - -class TestCurrencyExchangeSettings(unittest.TestCase): - pass From 08b2735a7928610650a8f7e880cb63f726cdb218 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 4 Nov 2021 05:01:37 +0000 Subject: [PATCH 08/50] fix: make fields editable only when service provider is custom --- .../currency_exchange_settings.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json index a0530c19a3..091102ce47 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -27,6 +27,7 @@ "fieldtype": "Data", "in_list_view": 1, "label": "API Endpoint", + "read_only_depends_on": "eval: doc.service_provider != \"Custom\"", "reqd": 1 }, { @@ -55,6 +56,7 @@ "fieldtype": "Table", "label": "Parameters", "options": "Currency Exchange Settings Details", + "read_only_depends_on": "eval: doc.service_provider != \"Custom\"", "reqd": 1 }, { @@ -66,6 +68,7 @@ "fieldtype": "Table", "label": "Result Key", "options": "Currency Exchange Settings Result", + "read_only_depends_on": "eval: doc.service_provider != \"Custom\"", "reqd": 1 }, { @@ -79,7 +82,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-11-03 19:27:27.922353", + "modified": "2021-11-04 10:27:09.332768", "modified_by": "Administrator", "module": "Accounts", "name": "Currency Exchange Settings", From e65a76b21425918e6b0b0bdcadef6cf431faa503 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 4 Nov 2021 05:04:10 +0000 Subject: [PATCH 09/50] chore: clean up --- .../currency_exchange_settings.js | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js index f29183a316..58a2b8c7a4 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -4,46 +4,44 @@ frappe.ui.form.on('Currency Exchange Settings', { service_provider: function(frm) { if (frm.doc.service_provider == "Exchangerate.host"){ - frm.doc.api_endpoint = "https://api.exchangerate.host/convert"; - frm.clear_table("req_params") - frm.clear_table("result_key") + let result = ['result'] let params = { date: '{transaction_date}', from: '{from_currency}', to: '{to_currency}' } - var row; - $.each(params, function(key, value){ - row = frm.add_child("req_params"); - row.key = key; - row.value = value; - }) - row = frm.add_child("result_key"); - row.key = 'result'; - frm.refresh_fields(); - frm.save(); + add_param(frm, "https://api.exchangerate.host/convert", params, result) } else if (frm.doc.service_provider == "Frankfurter.app"){ - frm.doc.api_endpoint = "https://frankfurter.app/{transaction_date}"; - frm.clear_table("req_params") - frm.clear_table("result_key") - var row; let result = ['rates', '{to_currency}'] let params = { base: '{from_currency}', symbols: '{to_currency}' } - $.each(params, function(key, value){ - row = frm.add_child("req_params"); - row.key = key; - row.value = value; - }) - $.each(result, function(key, value){ - row = frm.add_child("result_key"); - row.key = value; - }) - frm.refresh_fields(); - frm.save(); + add_param(frm, "https://frankfurter.app/{transaction_date}", params, result) } } }); + + +function add_param(frm, api, params, result){ + var row; + frm.clear_table("req_params") + frm.clear_table("result_key") + + frm.doc.api_endpoint = api; + + $.each(params, function(key, value){ + row = frm.add_child("req_params"); + row.key = key; + row.value = value; + }); + + $.each(result, function(key, value){ + row = frm.add_child("result_key"); + row.key = value; + }); + + frm.refresh_fields(); + frm.save(); +} From 1f8be8498570d8de0299f0cea5da6a566c39283b Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 4 Nov 2021 05:12:09 +0000 Subject: [PATCH 10/50] fix : remove mutable data structures from argument defaults --- erpnext/setup/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index 4fcd7d5936..c8b4374bac 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -122,11 +122,11 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}. Please create a Currency Exchange record manually").format(from_currency, to_currency, transaction_date)) return 0.0 -def format_ces_api(data="", param={}): +def format_ces_api(data, param): return data.format( - transaction_date=param["transaction_date"], - to_currency=param["to_currency"], - from_currency=param["from_currency"] + transaction_date=param.get("transaction_date"), + to_currency=param.get("to_currency"), + from_currency=param.get("from_currency") ) def enable_all_roles_and_domains(): From 4a0f2175ad22c2e16f5b5e81e151aca69bfb4c3d Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 4 Nov 2021 05:25:48 +0000 Subject: [PATCH 11/50] fix: pre-commit issues --- .../currency_exchange_settings/currency_exchange_settings.py | 3 ++- .../test_currency_exchange_settings.py | 1 + .../currency_exchange_settings_details.py | 1 + .../currency_exchange_settings_result.py | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py index fa5286a4bb..e515542f1d 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -3,8 +3,9 @@ import frappe from frappe import _ -from frappe.utils import nowdate from frappe.model.document import Document +from frappe.utils import nowdate + class CurrencyExchangeSettings(Document): def validate(self): diff --git a/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py index 59c579978f..2778729f58 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/test_currency_exchange_settings.py @@ -4,5 +4,6 @@ # import frappe import unittest + class TestCurrencyExchangeSettings(unittest.TestCase): pass diff --git a/erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py b/erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py index f870b11c5a..a6ad7634a5 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py +++ b/erpnext/accounts/doctype/currency_exchange_settings_details/currency_exchange_settings_details.py @@ -4,5 +4,6 @@ # import frappe from frappe.model.document import Document + class CurrencyExchangeSettingsDetails(Document): pass diff --git a/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py b/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py index 49da97bd5e..177412860a 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py +++ b/erpnext/accounts/doctype/currency_exchange_settings_result/currency_exchange_settings_result.py @@ -4,5 +4,6 @@ # import frappe from frappe.model.document import Document + class CurrencyExchangeSettingsResult(Document): pass From 4716523c7768cb62672c06a39ab041f89256f609 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 4 Nov 2021 05:38:00 +0000 Subject: [PATCH 12/50] fix: sider issues --- .../currency_exchange_settings.js | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js index 58a2b8c7a4..22cfc906fb 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -3,41 +3,41 @@ frappe.ui.form.on('Currency Exchange Settings', { service_provider: function(frm) { - if (frm.doc.service_provider == "Exchangerate.host"){ - let result = ['result'] - let params = { - date: '{transaction_date}', - from: '{from_currency}', - to: '{to_currency}' - } - add_param(frm, "https://api.exchangerate.host/convert", params, result) - } - else if (frm.doc.service_provider == "Frankfurter.app"){ - let result = ['rates', '{to_currency}'] - let params = { - base: '{from_currency}', - symbols: '{to_currency}' - } - add_param(frm, "https://frankfurter.app/{transaction_date}", params, result) - } + if (frm.doc.service_provider == "Exchangerate.host") { + let result = ['result']; + let params = { + date: '{transaction_date}', + from: '{from_currency}', + to: '{to_currency}' + }; + add_param(frm, "https://api.exchangerate.host/convert", params, result); + } + else if (frm.doc.service_provider == "Frankfurter.app") { + let result = ['rates', '{to_currency}']; + let params = { + base: '{from_currency}', + symbols: '{to_currency}' + }; + add_param(frm, "https://frankfurter.app/{transaction_date}", params, result); + } } }); -function add_param(frm, api, params, result){ +function add_param(frm, api, params, result) { var row; - frm.clear_table("req_params") - frm.clear_table("result_key") + frm.clear_table("req_params"); + frm.clear_table("result_key"); frm.doc.api_endpoint = api; - $.each(params, function(key, value){ + $.each(params, function(key, value) { row = frm.add_child("req_params"); row.key = key; row.value = value; }); - $.each(result, function(key, value){ + $.each(result, function(key, value) { row = frm.add_child("result_key"); row.key = value; }); From e50893e99116b7bf5796ea91ca9459962e5dedb5 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Sat, 13 Nov 2021 13:12:38 +0530 Subject: [PATCH 13/50] fix: eslint brace style issue --- .../currency_exchange_settings/currency_exchange_settings.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js index 22cfc906fb..a3a6561d35 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -11,8 +11,7 @@ frappe.ui.form.on('Currency Exchange Settings', { to: '{to_currency}' }; add_param(frm, "https://api.exchangerate.host/convert", params, result); - } - else if (frm.doc.service_provider == "Frankfurter.app") { + } else if (frm.doc.service_provider == "Frankfurter.app") { let result = ['rates', '{to_currency}']; let params = { base: '{from_currency}', From fe4d7f86ee7384e794c54b32e5b5f4415654f02a Mon Sep 17 00:00:00 2001 From: ruthra Date: Fri, 7 Jan 2022 16:30:56 +0530 Subject: [PATCH 14/50] fix: deferred report division by zero exception --- .../deferred_revenue_and_expense.py | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py b/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py index a4842c1844..3a51db8a97 100644 --- a/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py +++ b/erpnext/accounts/report/deferred_revenue_and_expense/deferred_revenue_and_expense.py @@ -121,20 +121,21 @@ class Deferred_Item(object): """ simulate future posting by creating dummy gl entries. starts from the last posting date. """ - if add_days(self.last_entry_date, 1) < self.period_list[-1].to_date: - self.estimate_for_period_list = get_period_list( - self.filters.from_fiscal_year, - self.filters.to_fiscal_year, - add_days(self.last_entry_date, 1), - self.period_list[-1].to_date, - "Date Range", - "Monthly", - company=self.filters.company, - ) - for period in self.estimate_for_period_list: - amount = self.calculate_amount(period.from_date, period.to_date) - gle = self.make_dummy_gle(period.key, period.to_date, amount) - self.gle_entries.append(gle) + if self.service_start_date != self.service_end_date: + if add_days(self.last_entry_date, 1) < self.period_list[-1].to_date: + self.estimate_for_period_list = get_period_list( + self.filters.from_fiscal_year, + self.filters.to_fiscal_year, + add_days(self.last_entry_date, 1), + self.period_list[-1].to_date, + "Date Range", + "Monthly", + company=self.filters.company, + ) + for period in self.estimate_for_period_list: + amount = self.calculate_amount(period.from_date, period.to_date) + gle = self.make_dummy_gle(period.key, period.to_date, amount) + self.gle_entries.append(gle) def calculate_item_revenue_expense_for_period(self): """ From 2fe919e746cd7b1294f305da83aef34672656e08 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 9 Jan 2022 20:04:21 +0530 Subject: [PATCH 15/50] chore: update CODEOWNERS --- CODEOWNERS | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index a4a14de1b8..bfc2601088 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -23,13 +23,13 @@ erpnext/stock/ @marination @rohitwaghchaure @ankush erpnext/crm/ @ruchamahabal @pateljannat erpnext/education/ @ruchamahabal @pateljannat -erpnext/healthcare/ @ruchamahabal @pateljannat @chillaranand erpnext/hr/ @ruchamahabal @pateljannat -erpnext/non_profit/ @ruchamahabal erpnext/payroll @ruchamahabal @pateljannat erpnext/projects/ @ruchamahabal @pateljannat -erpnext/controllers @deepeshgarg007 @nextchamp-saqib @rohitwaghchaure @marination +erpnext/controllers/ @deepeshgarg007 @nextchamp-saqib @rohitwaghchaure @marination @ankush +erpnext/patches/ @deepeshgarg007 @nextchamp-saqib @marination @ankush +erpnext/public/ @nextchamp-saqib @marination -.github/ @surajshetty3416 @ankush +.github/ @ankush requirements.txt @gavindsouza From 23b0a3f54643c77be52d81b9d1cd0760550849f2 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 9 Jan 2022 20:04:35 +0530 Subject: [PATCH 16/50] ci: add auto labeller workflow --- .github/labeler.yml | 55 ++++++++++++++++++++++++++++++++++ .github/workflows/labeller.yml | 12 ++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/labeler.yml create mode 100644 .github/workflows/labeller.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000000..19d08aeb8b --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,55 @@ +accounts: +- 'erpnext/accounts/*' +- 'erpnext/controllers/accounts_controller.py' +- 'erpnext/controllers/taxes_and_totals.py' + +stock: +- 'erpnext/stock/*' +- 'erpnext/controllers/stock_controller.py' +- 'erpnext/controllers/item_variant.py' + +assets: +- 'erpnext/assets/*' + +regional: +- 'erpnext/regional/*' + +selling: +- 'erpnext/selling/*' +- 'erpnext/controllers/selling_controller.py' + +buying: +- 'erpnext/buying/*' +- 'erpnext/controllers/buying_controller.py' + +support: +- 'erpnext/support/*' + +POS: +- 'pos*' + +ecommerce: +- 'erpnext/e_commerce/*' + +maintenance: +- 'erpnext/maintenance/*' + +manufacturing: +- 'erpnext/manufacturing/*' + +crm: +- 'erpnext/crm/*' + +HR: +- 'erpnext/hr/*' + +payroll: +- 'erpnext/payroll*' + +projects: +- 'erpnext/projects/*' + +# Any python files modifed but no test files modified +needs-tests: +- any: ['**/*.py'] +- all: ['!**/test*.py'] diff --git a/.github/workflows/labeller.yml b/.github/workflows/labeller.yml new file mode 100644 index 0000000000..0e112f97ac --- /dev/null +++ b/.github/workflows/labeller.yml @@ -0,0 +1,12 @@ +name: "Pull Request Labeler" +on: +- pull_request_target + +jobs: + triage: + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v3 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + sync-labels: true From 55d00a3cf6d9cb0239176bb7ca9c4cc890dd61f2 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 9 Jan 2022 20:18:42 +0530 Subject: [PATCH 17/50] ci: fix auto label behaviour --- .github/labeler.yml | 4 ++-- .github/workflows/labeller.yml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index 19d08aeb8b..fc3f06da92 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -51,5 +51,5 @@ projects: # Any python files modifed but no test files modified needs-tests: -- any: ['**/*.py'] -- all: ['!**/test*.py'] +- any: ['erpnext/**/*.py'] + all: ['!erpnext/**/test*.py'] diff --git a/.github/workflows/labeller.yml b/.github/workflows/labeller.yml index 0e112f97ac..331ddc9b80 100644 --- a/.github/workflows/labeller.yml +++ b/.github/workflows/labeller.yml @@ -9,4 +9,3 @@ jobs: - uses: actions/labeler@v3 with: repo-token: "${{ secrets.GITHUB_TOKEN }}" - sync-labels: true From 5b67dbf8d026a95b5a049d5bc97e11bd2c31ff66 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 9 Jan 2022 20:27:18 +0530 Subject: [PATCH 18/50] ci: only run label action once --- .github/workflows/labeller.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/labeller.yml b/.github/workflows/labeller.yml index 331ddc9b80..a774400611 100644 --- a/.github/workflows/labeller.yml +++ b/.github/workflows/labeller.yml @@ -1,6 +1,7 @@ name: "Pull Request Labeler" on: -- pull_request_target + pull_request_target: + types: [opened, reopened] jobs: triage: From 31123436fbe223b0116922097108fa444e5092d3 Mon Sep 17 00:00:00 2001 From: Conn Campbell Date: Sun, 9 Jan 2022 21:58:10 -0700 Subject: [PATCH 19/50] fix: Task Depends on not removed from Gantt chart (#28309) Co-authored-by: conncampbell --- erpnext/projects/doctype/task/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 9b1ea043be..8fa0538f36 100755 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -102,7 +102,7 @@ class Task(NestedSet): frappe.throw(_("Completed On cannot be greater than Today")) def update_depends_on(self): - depends_on_tasks = self.depends_on_tasks or "" + depends_on_tasks = "" for d in self.depends_on: if d.task and d.task not in depends_on_tasks: depends_on_tasks += d.task + "," From 0faa116f9799f6d921ce8868a8f8eac1756ae008 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 4 Jan 2022 16:36:08 +0530 Subject: [PATCH 20/50] fix(patch): serial no whitespace trimming old data can contain trailing/leading whitespace which doesn't work well with code to find last SLE for serial no. --- erpnext/patches.txt | 1 + .../v13_0/trim_whitespace_from_serial_nos.py | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 99741eb078..c5e4f7e8a9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -279,6 +279,7 @@ erpnext.patches.v13_0.add_custom_field_for_south_africa #2 erpnext.patches.v13_0.update_recipient_email_digest erpnext.patches.v13_0.shopify_deprecation_warning erpnext.patches.v13_0.remove_bad_selling_defaults +erpnext.patches.v13_0.trim_whitespace_from_serial_nos erpnext.patches.v13_0.migrate_stripe_api erpnext.patches.v13_0.reset_clearance_date_for_intracompany_payment_entries erpnext.patches.v13_0.einvoicing_deprecation_warning diff --git a/erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py b/erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py new file mode 100644 index 0000000000..4f112550c5 --- /dev/null +++ b/erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py @@ -0,0 +1,61 @@ +import frappe + +from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos + + +def execute(): + broken_sles = frappe.db.sql(""" + select name, serial_no + from `tabStock Ledger Entry` + where + is_cancelled = 0 + and (serial_no like %s or serial_no like %s or serial_no like %s or serial_no like %s) + """, + ( + " %", # leading whitespace + "% ", # trailing whitespace + "%\n %", # leading whitespace on newline + "% \n%", # trailing whitespace on newline + ), + as_dict=True, + ) + + frappe.db.MAX_WRITES_PER_TRANSACTION += len(broken_sles) + + if not broken_sles: + return + + broken_serial_nos = set() + + for sle in broken_sles: + serial_no_list = get_serial_nos(sle.serial_no) + correct_sr_no = "\n".join(serial_no_list) + + if correct_sr_no == sle.serial_no: + continue + + frappe.db.set_value("Stock Ledger Entry", sle.name, "serial_no", correct_sr_no, update_modified=False) + broken_serial_nos.update(serial_no_list) + + if not broken_serial_nos: + return + + broken_sr_no_records = [sr[0] for sr in frappe.db.sql(""" + select name + from `tabSerial No` + where status='Active' + and coalesce(purchase_document_type, '') = '' + and name in %s """, (list(broken_serial_nos),) + )] + + frappe.db.MAX_WRITES_PER_TRANSACTION += len(broken_sr_no_records) + + patch_savepoint = "serial_no_patch" + for serial_no in broken_sr_no_records: + try: + frappe.db.savepoint(patch_savepoint) + sn = frappe.get_doc("Serial No", serial_no) + sn.update_serial_no_reference() + sn.db_update() + except Exception: + frappe.db.rollback(save_point=patch_savepoint) From cbaa8fdade4aad306887b23cef9bfeaa17ff07c0 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 10 Jan 2022 16:09:43 +0530 Subject: [PATCH 21/50] refactor: convert query to ORM --- .../v13_0/trim_whitespace_from_serial_nos.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py b/erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py index 4f112550c5..8a9633d896 100644 --- a/erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py +++ b/erpnext/patches/v13_0/trim_whitespace_from_serial_nos.py @@ -27,6 +27,7 @@ def execute(): broken_serial_nos = set() + # patch SLEs for sle in broken_sles: serial_no_list = get_serial_nos(sle.serial_no) correct_sr_no = "\n".join(serial_no_list) @@ -40,13 +41,16 @@ def execute(): if not broken_serial_nos: return - broken_sr_no_records = [sr[0] for sr in frappe.db.sql(""" - select name - from `tabSerial No` - where status='Active' - and coalesce(purchase_document_type, '') = '' - and name in %s """, (list(broken_serial_nos),) - )] + # Patch serial No documents if they don't have purchase info + # Purchase info is used for fetching incoming rate + broken_sr_no_records = frappe.get_list("Serial No", + filters={ + "status":"Active", + "name": ("in", broken_serial_nos), + "purchase_document_type": ("is", "not set") + }, + pluck="name", + ) frappe.db.MAX_WRITES_PER_TRANSACTION += len(broken_sr_no_records) From e2dab6f421c55f1a8aea1439a83c1fadedae8369 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 10 Jan 2022 17:31:38 +0530 Subject: [PATCH 22/50] fix: Cleanup and fixes --- .../currency_exchange_settings.js | 7 +-- .../currency_exchange_settings.json | 27 ++++++++- .../currency_exchange_settings.py | 59 ++++++++++++++----- erpnext/patches.txt | 3 +- .../v13_0/update_exchange_rate_settings.py | 5 ++ erpnext/setup/install.py | 17 ++++-- erpnext/setup/utils.py | 2 +- 7 files changed, 92 insertions(+), 28 deletions(-) create mode 100644 erpnext/patches/v13_0/update_exchange_rate_settings.py diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js index a3a6561d35..6c40f2bec0 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.js @@ -1,9 +1,9 @@ -// Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt frappe.ui.form.on('Currency Exchange Settings', { service_provider: function(frm) { - if (frm.doc.service_provider == "Exchangerate.host") { + if (frm.doc.service_provider == "exchangerate.host") { let result = ['result']; let params = { date: '{transaction_date}', @@ -11,7 +11,7 @@ frappe.ui.form.on('Currency Exchange Settings', { to: '{to_currency}' }; add_param(frm, "https://api.exchangerate.host/convert", params, result); - } else if (frm.doc.service_provider == "Frankfurter.app") { + } else if (frm.doc.service_provider == "frankfurter.app") { let result = ['rates', '{to_currency}']; let params = { base: '{from_currency}', @@ -42,5 +42,4 @@ function add_param(frm, api, params, result) { }); frm.refresh_fields(); - frm.save(); } diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json index 091102ce47..7921fcc2b9 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.json @@ -1,6 +1,6 @@ { "actions": [], - "creation": "2021-09-02 14:53:50.923529", + "creation": "2022-01-10 13:03:26.237081", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", @@ -75,14 +75,14 @@ "fieldname": "service_provider", "fieldtype": "Select", "label": "Service Provider", - "options": "Exchangerate.host\nFrankfurter.app\nCustom", + "options": "frankfurter.app\nexchangerate.host\nCustom", "reqd": 1 } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-11-04 10:27:09.332768", + "modified": "2022-01-10 15:51:14.521174", "modified_by": "Administrator", "module": "Accounts", "name": "Currency Exchange Settings", @@ -97,9 +97,30 @@ "role": "System Manager", "share": 1, "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "Accounts Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "Accounts User", + "share": 1, + "write": 1 } ], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py index e515542f1d..c55e28b06c 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -1,7 +1,8 @@ -# Copyright (c) 2021, Wahni Green Technologies Pvt. Ltd. and contributors +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt import frappe +import requests from frappe import _ from frappe.model.document import Document from frappe.utils import nowdate @@ -9,38 +10,68 @@ from frappe.utils import nowdate class CurrencyExchangeSettings(Document): def validate(self): - transaction_date = nowdate() - from_currency = 'USD' - to_currency = 'INR' + self.set_parameters_and_result() + response, value = self.validate_parameters() + self.validate_result(response, value) + + def set_parameters_and_result(self): + if self.service_provider == 'exchangerate.host': + self.set('result_key', []) + self.set('req_params', []) + + self.api_endpoint = "https://api.exchangerate.host/convert" + self.append('result_key', {'key': 'result'}) + self.append('req_params', {'key': 'date', 'value': '{transaction_date}'}) + self.append('req_params', {'key': 'from', 'value': '{from_currency}'}) + self.append('req_params', {'key': 'to', 'value': '{to_currency}'}) + elif self.service_provider == 'frankfurter.app': + self.set('result_key', []) + self.set('req_params', []) + + self.api_endpoint = "https://frankfurter.app/{transaction_date}" + self.append('result_key', {'key': 'rates'}) + self.append('result_key', {'key': '{to_currency}'}) + self.append('req_params', {'key': 'base', 'value': '{from_currency}'}) + self.append('req_params', {'key': 'symbols', 'value': '{to_currency}'}) + + def validate_parameters(self): params = {} + for row in self.req_params: params[row.key] = row.value.format( - transaction_date=transaction_date, - to_currency=to_currency, - from_currency=from_currency + transaction_date=nowdate(), + to_currency='INR', + from_currency='USD' ) - import requests + api_url = self.api_endpoint.format( - transaction_date=transaction_date, - to_currency=to_currency, - from_currency=from_currency + transaction_date=nowdate(), + to_currency='INR', + from_currency='USD' ) + try: response = requests.get(api_url, params=params) except requests.exceptions.RequestException as e: frappe.throw("Error: " + str(e)) + response.raise_for_status() value = response.json() + + return response, value + + def validate_result(self, response, value): try: for key in self.result_key: value = value[str(key.key).format( - transaction_date=transaction_date, - to_currency=to_currency, - from_currency=from_currency + transaction_date=nowdate(), + to_currency='INR', + from_currency='USD' )] except Exception: frappe.throw("Invalid result key. Response: " + response.text) if not isinstance(value, (int, float)): frappe.throw(_("Returned exchange rate is neither integer not float.")) + self.url = response.url frappe.msgprint("Exchange rate of USD to INR is " + str(value)) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d9cedab52a..7f24273a6c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -317,4 +317,5 @@ erpnext.patches.v14_0.rename_ongoing_status_in_sla_documents erpnext.patches.v14_0.migrate_crm_settings erpnext.patches.v13_0.rename_ksa_qr_field erpnext.patches.v13_0.disable_ksa_print_format_for_others # 16-12-2021 -erpnext.patches.v14_0.add_default_exit_questionnaire_notification_template \ No newline at end of file +erpnext.patches.v14_0.add_default_exit_questionnaire_notification_template +erpnext.patches.v13_0.update_exchange_rate_settings \ No newline at end of file diff --git a/erpnext/patches/v13_0/update_exchange_rate_settings.py b/erpnext/patches/v13_0/update_exchange_rate_settings.py new file mode 100644 index 0000000000..6af93dcba1 --- /dev/null +++ b/erpnext/patches/v13_0/update_exchange_rate_settings.py @@ -0,0 +1,5 @@ +from erpnext.setup.install import setup_currency_exchange + + +def execute(): + setup_currency_exchange() \ No newline at end of file diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index da39776333..bafaab814b 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -59,13 +59,20 @@ def set_single_defaults(): pass frappe.db.set_default("date_format", "dd-mm-yyyy") + + setup_currency_exchange() + +def setup_currency_exchange(): ces = frappe.get_single('Currency Exchange Settings') try: - ces.api_endpoint = "https://api.exchangerate.host/convert" - ces.append('result_key', {'key': 'result'}) - ces.append('req_params', {'key': 'date', 'value': '{transaction_date}'}) - ces.append('req_params', {'key': 'from', 'value': '{from_currency}'}) - ces.append('req_params', {'key': 'to', 'value': '{to_currency}'}) + ces.set('result_key', []) + ces.set('req_params', []) + + ces.api_endpoint = "https://frankfurter.app/{transaction_date}" + ces.append('result_key', {'key': 'rates'}) + ces.append('result_key', {'key': '{to_currency}'}) + ces.append('req_params', {'key': 'base', 'value': '{from_currency}'}) + ces.append('req_params', {'key': 'symbols', 'value': '{to_currency}'}) ces.save() except frappe.ValidationError: pass diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py index bfa26f29d9..4441bb9562 100644 --- a/erpnext/setup/utils.py +++ b/erpnext/setup/utils.py @@ -100,7 +100,7 @@ def get_exchange_rate(from_currency, to_currency, transaction_date=None, args=No if not value: import requests - settings = frappe.get_single('Currency Exchange Settings') + settings = frappe.get_cached_doc('Currency Exchange Settings') req_params = { "transaction_date": transaction_date, "from_currency": from_currency, From e5b649b588edaf177f7b4ca280e65137a4d45172 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Mon, 10 Jan 2022 18:24:08 +0530 Subject: [PATCH 23/50] fix: pos invoices consolidation case with permlevel (#29011) --- erpnext/accounts/doctype/sales_invoice/sales_invoice.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 545abf77e6..5062c1c807 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -651,7 +651,7 @@ "hide_seconds": 1, "label": "Ignore Pricing Rule", "no_copy": 1, - "permlevel": 1, + "permlevel": 0, "print_hide": 1 }, { @@ -2038,7 +2038,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2021-10-21 20:19:38.667508", + "modified": "2021-12-23 20:19:38.667508", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", From 2854f63cafe87bdb87f3d85c2f032ee8fdec0983 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 10 Jan 2022 13:51:06 +0530 Subject: [PATCH 24/50] fix!: drop python 3.7 support --- .github/workflows/docs-checker.yml | 2 +- .github/workflows/patch.yml | 2 +- .github/workflows/server-tests-mariadb.yml | 2 +- .github/workflows/server-tests-postgres.yml | 2 +- .github/workflows/ui-tests.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docs-checker.yml b/.github/workflows/docs-checker.yml index db46c5621b..b644568d5e 100644 --- a/.github/workflows/docs-checker.yml +++ b/.github/workflows/docs-checker.yml @@ -12,7 +12,7 @@ jobs: - name: 'Setup Environment' uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: 3.8 - name: 'Clone repo' uses: actions/checkout@v2 diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml index 33a28ac9bb..d05bbbec50 100644 --- a/.github/workflows/patch.yml +++ b/.github/workflows/patch.yml @@ -34,7 +34,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.8 - name: Setup Node uses: actions/setup-node@v2 diff --git a/.github/workflows/server-tests-mariadb.yml b/.github/workflows/server-tests-mariadb.yml index 186f95e6ec..7347a5856a 100644 --- a/.github/workflows/server-tests-mariadb.yml +++ b/.github/workflows/server-tests-mariadb.yml @@ -46,7 +46,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.8 - name: Setup Node uses: actions/setup-node@v2 diff --git a/.github/workflows/server-tests-postgres.yml b/.github/workflows/server-tests-postgres.yml index 3bbf6a91f5..77d3c1ae61 100644 --- a/.github/workflows/server-tests-postgres.yml +++ b/.github/workflows/server-tests-postgres.yml @@ -46,7 +46,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.8 - name: Setup Node uses: actions/setup-node@v2 diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index d765f0482c..ab6a53b5d9 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -36,7 +36,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: 3.8 - uses: actions/setup-node@v2 with: From fab7a580569496ed88d74218acaf54d4fcd5e966 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 10 Jan 2022 14:19:29 +0530 Subject: [PATCH 25/50] chore: remove misleading comment --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index faefb77a9c..f447fac736 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ # frappe # https://github.com/frappe/frappe is installed during bench-init gocardless-pro~=1.22.0 -googlemaps # used in ERPNext, but dependency is defined in Frappe +googlemaps pandas~=1.1.5 plaid-python~=7.2.1 pycountry~=20.7.3 From 2d76c05175bf324da4ea24e1542a7dcb7d52c178 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 9 Jan 2022 18:41:33 +0530 Subject: [PATCH 26/50] refactor: unnecessary joining of lists --- erpnext/accounts/report/general_ledger/general_ledger.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index 385c8b2b6e..7303bf5ef8 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -547,10 +547,7 @@ def get_columns(filters): "fieldname": "balance", "fieldtype": "Float", "width": 130 - } - ] - - columns.extend([ + }, { "label": _("Voucher Type"), "fieldname": "voucher_type", @@ -584,7 +581,7 @@ def get_columns(filters): "fieldname": "project", "width": 100 } - ]) + ] if filters.get("include_dimensions"): for dim in get_accounting_dimensions(as_list = False): From f195f803ff3226450cd1c0b739e4ef34114a6ffb Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sun, 9 Jan 2022 19:23:27 +0530 Subject: [PATCH 27/50] test: account reports --- erpnext/accounts/test/test_reports.py | 48 +++++++++++++++++++++++++++ erpnext/tests/utils.py | 14 +++++--- 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 erpnext/accounts/test/test_reports.py diff --git a/erpnext/accounts/test/test_reports.py b/erpnext/accounts/test/test_reports.py new file mode 100644 index 0000000000..78c109ab94 --- /dev/null +++ b/erpnext/accounts/test/test_reports.py @@ -0,0 +1,48 @@ +import unittest +from typing import List, Tuple + +from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report + +DEFAULT_FILTERS = { + "company": "_Test Company", + "from_date": "2010-01-01", + "to_date": "2030-01-01", + "period_start_date": "2010-01-01", + "period_end_date": "2030-01-01" +} + + +REPORT_FILTER_TEST_CASES: List[Tuple[ReportName, ReportFilters]] = [ + ("General Ledger", {"group_by": "Group by Voucher (Consolidated)"} ), + ("General Ledger", {"group_by": "Group by Voucher (Consolidated)", "include_dimensions": 1} ), + ("Accounts Payable", {"range1": 30, "range2": 60, "range3": 90, "range4": 120}), + ("Accounts Receivable", {"range1": 30, "range2": 60, "range3": 90, "range4": 120}), + ("Consolidated Financial Statement", {"report": "Balance Sheet"} ), + ("Consolidated Financial Statement", {"report": "Profit and Loss Statement"} ), + ("Consolidated Financial Statement", {"report": "Cash Flow"} ), + ("Gross Profit", {"group_by": "Invoice"}), + ("Gross Profit", {"group_by": "Item Code"}), + ("Gross Profit", {"group_by": "Item Group"}), + ("Gross Profit", {"group_by": "Customer"}), + ("Gross Profit", {"group_by": "Customer Group"}), + ("Item-wise Sales Register", {}), + ("Item-wise Purchase Register", {}), + ("Sales Register", {}), + ("Purchase Register", {}), + ("Tax Detail", {"mode": "run", "report_name": "Tax Detail"},), +] + +OPTIONAL_FILTERS = {} + + +class TestReports(unittest.TestCase): + def test_execute_all_accounts_reports(self): + """Test that all script report in stock modules are executable with supported filters""" + for report, filter in REPORT_FILTER_TEST_CASES: + execute_script_report( + report_name=report, + module="Accounts", + filters=filter, + default_filters=DEFAULT_FILTERS, + optional_filters=OPTIONAL_FILTERS if filter.get("_optional") else None, + ) diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index fbf25948a7..bc9f04e089 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -125,17 +125,23 @@ def execute_script_report( if default_filters is None: default_filters = {} + test_filters = [] report_execute_fn = frappe.get_attr(get_report_module_dotted_path(module, report_name) + ".execute") report_filters = frappe._dict(default_filters).copy().update(filters) - report_data = report_execute_fn(report_filters) + test_filters.append(report_filters) if optional_filters: for key, value in optional_filters.items(): - filter_with_optional_param = report_filters.copy().update({key: value}) - report_execute_fn(filter_with_optional_param) + test_filters.append(report_filters.copy().update({key: value})) + + for test_filter in test_filters: + try: + report_execute_fn(test_filter) + except Exception: + print(f"Report failed to execute with filters: {test_filter}") + raise - return report_data def timeout(seconds=30, error_message="Test timed out."): From ca5ea5f55faec323f3d0612de6fe25fe98965921 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 10 Jan 2022 21:28:29 +0530 Subject: [PATCH 28/50] fix: test cases --- .../currency_exchange_settings.py | 7 +++- .../v13_0/update_exchange_rate_settings.py | 5 +++ .../test_currency_exchange.py | 42 ++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py index c55e28b06c..e16ff3aa7e 100644 --- a/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py +++ b/erpnext/accounts/doctype/currency_exchange_settings/currency_exchange_settings.py @@ -35,8 +35,10 @@ class CurrencyExchangeSettings(Document): self.append('req_params', {'key': 'symbols', 'value': '{to_currency}'}) def validate_parameters(self): - params = {} + if frappe.flags.in_test: + return None, None + params = {} for row in self.req_params: params[row.key] = row.value.format( transaction_date=nowdate(), @@ -61,6 +63,9 @@ class CurrencyExchangeSettings(Document): return response, value def validate_result(self, response, value): + if frappe.flags.in_test: + return + try: for key in self.result_key: value = value[str(key.key).format( diff --git a/erpnext/patches/v13_0/update_exchange_rate_settings.py b/erpnext/patches/v13_0/update_exchange_rate_settings.py index 6af93dcba1..b7ec232bba 100644 --- a/erpnext/patches/v13_0/update_exchange_rate_settings.py +++ b/erpnext/patches/v13_0/update_exchange_rate_settings.py @@ -1,5 +1,10 @@ +import frappe + from erpnext.setup.install import setup_currency_exchange def execute(): + frappe.reload_doc("accounts", "doctype", "currency_exchange_settings") + frappe.reload_doc("accounts", "doctype", "currency_exchange_settings_result") + frappe.reload_doc("accounts", "doctype", "currency_exchange_settings_details") setup_currency_exchange() \ No newline at end of file diff --git a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py index 2b007e9efd..06a79b4102 100644 --- a/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py +++ b/erpnext/setup/doctype/currency_exchange/test_currency_exchange.py @@ -62,8 +62,13 @@ def patched_requests_get(*args, **kwargs): if kwargs['params'].get('date') and kwargs['params'].get('from') and kwargs['params'].get('to'): if test_exchange_values.get(kwargs['params']['date']): return PatchResponse({'result': test_exchange_values[kwargs['params']['date']]}, 200) + elif args[0].startswith("https://frankfurter.app") and kwargs.get('params'): + if kwargs['params'].get('base') and kwargs['params'].get('symbols'): + date = args[0].replace("https://frankfurter.app/", "") + if test_exchange_values.get(date): + return PatchResponse({'rates': {kwargs['params'].get('symbols'): test_exchange_values.get(date)}}, 200) - return PatchResponse({'result': None}, 404) + return PatchResponse({'rates': None}, 404) @mock.patch('requests.get', side_effect=patched_requests_get) class TestCurrencyExchange(unittest.TestCase): @@ -102,6 +107,41 @@ class TestCurrencyExchange(unittest.TestCase): self.assertFalse(exchange_rate == 60) self.assertEqual(flt(exchange_rate, 3), 65.1) + def test_exchange_rate_via_exchangerate_host(self, mock_get): + save_new_records(test_records) + + # Update Currency Exchange Rate + settings = frappe.get_single("Currency Exchange Settings") + settings.service_provider = 'exchangerate.host' + settings.save() + + # Update exchange + frappe.db.set_value("Accounts Settings", None, "allow_stale", 1) + + # Start with allow_stale is True + exchange_rate = get_exchange_rate("USD", "INR", "2016-01-01", "for_buying") + self.assertEqual(flt(exchange_rate, 3), 60.0) + + exchange_rate = get_exchange_rate("USD", "INR", "2016-01-15", "for_buying") + self.assertEqual(exchange_rate, 65.1) + + exchange_rate = get_exchange_rate("USD", "INR", "2016-01-30", "for_selling") + self.assertEqual(exchange_rate, 62.9) + + # Exchange rate as on 15th Dec, 2015 + self.clear_cache() + exchange_rate = get_exchange_rate("USD", "INR", "2015-12-15", "for_selling") + self.assertFalse(exchange_rate == 60) + self.assertEqual(flt(exchange_rate, 3), 66.999) + + exchange_rate = get_exchange_rate("USD", "INR", "2016-01-20", "for_buying") + self.assertFalse(exchange_rate == 60) + self.assertEqual(flt(exchange_rate, 3), 65.1) + + settings = frappe.get_single("Currency Exchange Settings") + settings.service_provider = 'frankfurter.app' + settings.save() + def test_exchange_rate_strict(self, mock_get): # strict currency settings frappe.db.set_value("Accounts Settings", None, "allow_stale", 0) From c62083653b528fa5d3b93fbbe35d4a6a2c475bec Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Tue, 11 Jan 2022 12:45:40 +0530 Subject: [PATCH 29/50] fix(gl-report): group by cost center only if include_dimensions is checked (#28883) --- .../report/general_ledger/general_ledger.js | 2 +- .../report/general_ledger/general_ledger.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js index b2968761c6..010284c2ea 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.js +++ b/erpnext/accounts/report/general_ledger/general_ledger.js @@ -167,7 +167,7 @@ frappe.query_reports["General Ledger"] = { "fieldname": "include_dimensions", "label": __("Consider Accounting Dimensions"), "fieldtype": "Check", - "default": 0 + "default": 1 }, { "fieldname": "show_opening_entries", diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index 7303bf5ef8..7f27920547 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -448,9 +448,11 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map): elif group_by_voucher_consolidated: keylist = [gle.get("voucher_type"), gle.get("voucher_no"), gle.get("account")] - for dim in accounting_dimensions: - keylist.append(gle.get(dim)) - keylist.append(gle.get("cost_center")) + if filters.get("include_dimensions"): + for dim in accounting_dimensions: + keylist.append(gle.get(dim)) + keylist.append(gle.get("cost_center")) + key = tuple(keylist) if key not in consolidated_gle: consolidated_gle.setdefault(key, gle) @@ -591,14 +593,14 @@ def get_columns(filters): "fieldname": dim.fieldname, "width": 100 }) - - columns.extend([ - { + columns.append({ "label": _("Cost Center"), "options": "Cost Center", "fieldname": "cost_center", "width": 100 - }, + }) + + columns.extend([ { "label": _("Against Voucher Type"), "fieldname": "against_voucher_type", From 75c8b2556e2282f15bf0bc44f9bec3afad146215 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Tue, 11 Jan 2022 13:25:42 +0530 Subject: [PATCH 30/50] fix(pos): cannot ignore pricing rule for one particular invoice (#29222) --- .../doctype/pos_invoice/pos_invoice.py | 1 - .../doctype/pos_invoice/test_pos_invoice.py | 31 +++++++++++++++++++ .../doctype/pricing_rule/test_pricing_rule.py | 4 ++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 11d59bcf70..134bccf3d1 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -353,7 +353,6 @@ class POSInvoice(SalesInvoice): if not for_validate and not self.customer: self.customer = profile.customer - self.ignore_pricing_rule = profile.ignore_pricing_rule self.account_for_change_amount = profile.get('account_for_change_amount') or self.account_for_change_amount self.set_warehouse = profile.get('warehouse') or self.set_warehouse diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index 7d31e0aa19..56479a0b77 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -556,6 +556,37 @@ class TestPOSInvoice(unittest.TestCase): batch.cancel() batch.delete() + def test_ignore_pricing_rule(self): + from erpnext.accounts.doctype.pricing_rule.test_pricing_rule import make_pricing_rule + + item_price = frappe.get_doc({ + 'doctype': 'Item Price', + 'item_code': '_Test Item', + 'price_list': '_Test Price List', + 'price_list_rate': '450', + }) + item_price.insert() + pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10) + pr.save() + pos_inv = create_pos_invoice(qty=1, do_not_submit=1) + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEquals(pos_inv.items[0].discount_percentage, 10) + # rate shouldn't change + self.assertEquals(pos_inv.items[0].rate, 405) + + pos_inv.ignore_pricing_rule = 1 + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEquals(pos_inv.ignore_pricing_rule, 1) + # rate should change since pricing rules are ignored + self.assertEquals(pos_inv.items[0].rate, 300) + + item_price.delete() + pos_inv.delete() + pr.delete() + + def create_pos_invoice(**args): args = frappe._dict(args) pos_profile = None diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 314c89424b..5746a840f3 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -650,7 +650,7 @@ def make_pricing_rule(**args): "rate": args.rate or 0.0, "margin_rate_or_amount": args.margin_rate_or_amount or 0.0, "condition": args.condition or '', - "priority": 1, + "priority": args.priority or 1, "discount_amount": args.discount_amount or 0.0, "apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0 }) @@ -676,6 +676,8 @@ def make_pricing_rule(**args): if args.get(applicable_for): doc.db_set(applicable_for, args.get(applicable_for)) + return doc + def setup_pricing_rule_data(): if not frappe.db.exists('Campaign', '_Test Campaign'): frappe.get_doc({ From 754596dfc139a9890b1e446a4d2b2abfeab68449 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 11 Jan 2022 14:20:44 +0530 Subject: [PATCH 31/50] fix: "update cost" should ignore overridden routing times #29154 fix: "update cost" should ignore overridden routing times --- erpnext/manufacturing/doctype/bom/bom.py | 10 ---------- erpnext/manufacturing/doctype/routing/test_routing.py | 5 +++-- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index f82d9a0d55..5a60fb751d 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -530,16 +530,6 @@ class BOM(WebsiteGenerator): row.hour_rate = (hour_rate / flt(self.conversion_rate) if self.conversion_rate and hour_rate else hour_rate) - if self.routing: - time_in_mins = flt(frappe.db.get_value("BOM Operation", { - "workstation": row.workstation, - "operation": row.operation, - "parent": self.routing - }, ["time_in_mins"])) - - if time_in_mins: - row.time_in_mins = time_in_mins - if row.hour_rate and row.time_in_mins: row.base_hour_rate = flt(row.hour_rate) * flt(self.conversion_rate) row.operating_cost = flt(row.hour_rate) * flt(row.time_in_mins) / 60.0 diff --git a/erpnext/manufacturing/doctype/routing/test_routing.py b/erpnext/manufacturing/doctype/routing/test_routing.py index e90b0a7d6d..8bd60ea4ac 100644 --- a/erpnext/manufacturing/doctype/routing/test_routing.py +++ b/erpnext/manufacturing/doctype/routing/test_routing.py @@ -46,6 +46,7 @@ class TestRouting(ERPNextTestCase): wo_doc.delete() def test_update_bom_operation_time(self): + """Update cost shouldn't update routing times.""" operations = [ { "operation": "Test Operation A", @@ -85,8 +86,8 @@ class TestRouting(ERPNextTestCase): routing_doc.save() bom_doc.update_cost() bom_doc.reload() - self.assertEqual(bom_doc.operations[0].time_in_mins, 90) - self.assertEqual(bom_doc.operations[1].time_in_mins, 42.2) + self.assertEqual(bom_doc.operations[0].time_in_mins, 30) + self.assertEqual(bom_doc.operations[1].time_in_mins, 20) def setup_operations(rows): From 2b33e63d2ca0f9872215453419c349493946c64d Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 11 Jan 2022 14:40:08 +0530 Subject: [PATCH 32/50] fix: use `get_all` instead of `get_list` while fetching SLA doctypes (#29216) Co-authored-by: Ankush Menat --- .../doctype/service_level_agreement/service_level_agreement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/support/doctype/service_level_agreement/service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/service_level_agreement.py index b3348f1e1e..ea617fd1eb 100644 --- a/erpnext/support/doctype/service_level_agreement/service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/service_level_agreement.py @@ -853,7 +853,7 @@ def get_user_time(user, to_string=False): @frappe.whitelist() def get_sla_doctypes(): doctypes = [] - data = frappe.get_list('Service Level Agreement', + data = frappe.get_all('Service Level Agreement', {'enabled': 1}, ['document_type'], distinct=1 From c45042c00edcfe385810d22b1564a6c0b971121c Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Tue, 11 Jan 2022 15:03:07 +0530 Subject: [PATCH 33/50] feat: early payment discount on sales & purchase orders (#29101) --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index c1b056b9c7..0e07abd725 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1708,7 +1708,10 @@ def set_paid_amount_and_received_amount(dt, party_account_currency, bank, outsta def apply_early_payment_discount(paid_amount, received_amount, doc): total_discount = 0 - if doc.doctype in ['Sales Invoice', 'Purchase Invoice'] and doc.payment_schedule: + eligible_for_payments = ['Sales Order', 'Sales Invoice', 'Purchase Order', 'Purchase Invoice'] + has_payment_schedule = hasattr(doc, 'payment_schedule') and doc.payment_schedule + + if doc.doctype in eligible_for_payments and has_payment_schedule: for term in doc.payment_schedule: if not term.discounted_amount and term.discount and getdate(nowdate()) <= term.discount_date: if term.discount_type == 'Percentage': From 33aad4b950045d90eb4505274fd8d504776608a8 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 11 Jan 2022 17:06:31 +0530 Subject: [PATCH 34/50] fix: UOM autocomplete broken All new recent sites seem to have all UOMs as disabled by default. The desired behaviour is exact opposite of this. --- erpnext/controllers/tests/test_queries.py | 5 +++++ erpnext/setup/setup_wizard/operations/install_fixtures.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/tests/test_queries.py b/erpnext/controllers/tests/test_queries.py index 05541d1688..908d78c15b 100644 --- a/erpnext/controllers/tests/test_queries.py +++ b/erpnext/controllers/tests/test_queries.py @@ -1,6 +1,8 @@ import unittest from functools import partial +import frappe + from erpnext.controllers import queries @@ -85,3 +87,6 @@ class TestQueries(unittest.TestCase): wh = query(filters=[["Bin", "item_code", "=", "_Test Item"]]) self.assertGreaterEqual(len(wh), 1) + + def test_default_uoms(self): + self.assertGreaterEqual(frappe.db.count("UOM", {"enabled": 1}), 10) diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index 336b51c0ab..9dbf49eae7 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -353,7 +353,8 @@ def add_uom_data(): "doctype": "UOM", "uom_name": _(d.get("uom_name")), "name": _(d.get("uom_name")), - "must_be_whole_number": d.get("must_be_whole_number") + "must_be_whole_number": d.get("must_be_whole_number"), + "enabled": 1, }).db_insert() # bootstrap uom conversion factors From f8119563ca51f46917cc521429d61a374b6cbc8a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 11 Jan 2022 17:22:40 +0530 Subject: [PATCH 35/50] fix(patch): enable all uoms on recently created sites --- erpnext/patches.txt | 1 + erpnext/patches/v13_0/enable_uoms.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 erpnext/patches/v13_0/enable_uoms.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 821a49329e..5190f9f8c6 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -305,6 +305,7 @@ erpnext.patches.v13_0.add_default_interview_notification_templates erpnext.patches.v13_0.enable_scheduler_job_for_item_reposting erpnext.patches.v13_0.requeue_failed_reposts erpnext.patches.v13_0.update_job_card_status +erpnext.patches.v13_0.enable_uoms erpnext.patches.v12_0.update_production_plan_status erpnext.patches.v13_0.healthcare_deprecation_warning erpnext.patches.v13_0.item_naming_series_not_mandatory diff --git a/erpnext/patches/v13_0/enable_uoms.py b/erpnext/patches/v13_0/enable_uoms.py new file mode 100644 index 0000000000..4d3f637630 --- /dev/null +++ b/erpnext/patches/v13_0/enable_uoms.py @@ -0,0 +1,13 @@ +import frappe + + +def execute(): + frappe.reload_doc('setup', 'doctype', 'uom') + + uom = frappe.qb.DocType("UOM") + + (frappe.qb + .update(uom) + .set(uom.enabled, 1) + .where(uom.creation >= "2021-10-18") # date when this field was released + ).run() From 8f0d10a1b791fb6c9471fe8aec785e5bd6ac5321 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 11 Jan 2022 18:45:53 +0530 Subject: [PATCH 36/50] chore: add crm module in issue template [skip ci] --- .github/ISSUE_TEMPLATE/bug_report.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 8f938112a7..4d61f1fb94 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -40,6 +40,7 @@ body: - HR - projects - support + - CRM - assets - integrations - quality @@ -48,6 +49,7 @@ body: - agriculture - education - non-profit + - other validations: required: true From 8f0b2fa90ed395a0fcbefb5e099ef60fc79bf6aa Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 6 Jan 2022 22:12:31 +0530 Subject: [PATCH 37/50] fix: incorrect scrap item qty --- .../doctype/work_order/test_work_order.py | 38 +++++++++++++++++- .../stock/doctype/stock_entry/stock_entry.py | 39 ++++++++++++------- 2 files changed, 61 insertions(+), 16 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index 9926b15894..e7eb9c6149 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -2,7 +2,7 @@ # License: GNU General Public License v3. See license.txt import frappe -from frappe.utils import add_months, cint, flt, now, today +from frappe.utils import add_days, add_months, cint, flt, now, today from erpnext.manufacturing.doctype.job_card.job_card import JobCardCancelError from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom @@ -12,6 +12,7 @@ from erpnext.manufacturing.doctype.work_order.work_order import ( OverProductionError, StockOverProductionError, close_work_order, + make_job_card, make_stock_entry, stop_unstop, ) @@ -804,6 +805,34 @@ class TestWorkOrder(ERPNextTestCase): if row.is_scrap_item: self.assertEqual(row.qty, 1) + # Partial Job Card 1 with qty 10 + wo_order = make_wo_order_test_record(item=item, company=company, planned_start_date=add_days(now(), 60), qty=20, skip_transfer=1) + job_card = frappe.db.get_value('Job Card', {'work_order': wo_order.name}, 'name') + update_job_card(job_card, 10) + + stock_entry = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 10)) + for row in stock_entry.items: + if row.is_scrap_item: + self.assertEqual(row.qty, 2) + + # Partial Job Card 2 with qty 10 + operations = [] + wo_order.load_from_db() + for row in wo_order.operations: + n_dict = row.as_dict() + n_dict['qty'] = 10 + n_dict['pending_qty'] = 10 + operations.append(n_dict) + + make_job_card(wo_order.name, operations) + job_card = frappe.db.get_value('Job Card', {'work_order': wo_order.name, 'docstatus': 0}, 'name') + update_job_card(job_card, 10) + + stock_entry = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 10)) + for row in stock_entry.items: + if row.is_scrap_item: + self.assertEqual(row.qty, 2) + def test_close_work_order(self): items = ['Test FG Item for Closed WO', 'Test RM Item 1 for Closed WO', 'Test RM Item 2 for Closed WO'] @@ -883,7 +912,8 @@ class TestWorkOrder(ERPNextTestCase): self.assertEqual(wo1.operations[0].time_in_mins, wo2.operations[0].time_in_mins) -def update_job_card(job_card): +def update_job_card(job_card, jc_qty=None): + employee = frappe.db.get_value('Employee', {'status': 'Active'}, 'name') job_card_doc = frappe.get_doc('Job Card', job_card) job_card_doc.set('scrap_items', [ { @@ -896,8 +926,12 @@ def update_job_card(job_card): }, ]) + if jc_qty: + job_card_doc.for_quantity = jc_qty + job_card_doc.append('time_logs', { 'from_time': now(), + 'employee': employee, 'time_in_mins': 60, 'completed_qty': job_card_doc.for_quantity }) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 93e303c9a7..8dcf48aa24 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -8,6 +8,7 @@ from collections import defaultdict import frappe from frappe import _ from frappe.model.mapper import get_mapped_doc +from frappe.query_builder.functions import Sum from frappe.utils import cint, comma_or, cstr, flt, format_time, formatdate, getdate, nowdate import erpnext @@ -1275,22 +1276,29 @@ class StockEntry(StockController): if not self.pro_doc: self.set_work_order_details() - scrap_items = frappe.db.sql(''' - SELECT - JCSI.item_code, JCSI.item_name, SUM(JCSI.stock_qty) as stock_qty, JCSI.stock_uom, JCSI.description - FROM - `tabJob Card` JC, `tabJob Card Scrap Item` JCSI - WHERE - JCSI.parent = JC.name AND JC.docstatus = 1 - AND JCSI.item_code IS NOT NULL AND JC.work_order = %s - GROUP BY - JCSI.item_code - ''', self.work_order, as_dict=1) - - pending_qty = flt(self.pro_doc.qty) - flt(self.pro_doc.produced_qty) - if pending_qty <=0: + if not self.pro_doc.operations: return [] + job_card = frappe.qb.DocType('Job Card') + job_card_scrap_item = frappe.qb.DocType('Job Card Scrap Item') + + scrap_items = ( + frappe.qb.from_(job_card) + .select( + Sum(job_card_scrap_item.stock_qty).as_('stock_qty'), + job_card_scrap_item.item_code, job_card_scrap_item.item_name, + job_card_scrap_item.description, job_card_scrap_item.stock_uom) + .join(job_card_scrap_item) + .on(job_card_scrap_item.parent == job_card.name) + .where( + (job_card_scrap_item.item_code.isnotnull()) + & (job_card.work_order == self.work_order) + & (job_card.docstatus == 1)) + .groupby(job_card_scrap_item.item_code) + ).run(as_dict=1) + + pending_qty = flt(self.get_completed_job_card_qty()) - flt(self.pro_doc.produced_qty) + used_scrap_items = self.get_used_scrap_items() for row in scrap_items: row.stock_qty -= flt(used_scrap_items.get(row.item_code)) @@ -1304,6 +1312,9 @@ class StockEntry(StockController): return scrap_items + def get_completed_job_card_qty(self): + return flt(min([d.completed_qty for d in self.pro_doc.operations])) + def get_used_scrap_items(self): used_scrap_items = defaultdict(float) data = frappe.get_all( From aef432ee2f8f5e043a226c3c5ab1b2c9d267b67a Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Wed, 12 Jan 2022 13:11:21 +0530 Subject: [PATCH 38/50] fix: description not fetched in sales order analytics report (#29230) --- .../report/sales_order_analysis/sales_order_analysis.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py index 0c0acc76e3..b2bf5464b5 100644 --- a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py +++ b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py @@ -68,7 +68,8 @@ def get_data(conditions, filters): (soi.billed_amt * IFNULL(so.conversion_rate, 1)) as billed_amount, (soi.base_amount - (soi.billed_amt * IFNULL(so.conversion_rate, 1))) as pending_amount, soi.warehouse as warehouse, - so.company, soi.name + so.company, soi.name, + soi.description as description FROM `tabSales Order` so, (`tabSales Order Item` soi @@ -184,6 +185,12 @@ def get_columns(filters): "options": "Item", "width": 100 }) + columns.append({ + "label":_("Description"), + "fieldname": "description", + "fieldtype": "Small Text", + "width": 100 + }) columns.extend([ { From 11fae15becc67a266065be2372c2cd3bc717acdd Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Wed, 12 Jan 2022 13:23:18 +0530 Subject: [PATCH 39/50] fix(asset): check if fixed asset account is set against company (#29189) --- erpnext/assets/doctype/asset/asset.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index a18b03a888..ee3ec8e63a 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -608,7 +608,17 @@ class Asset(AccountsController): return purchase_document def get_fixed_asset_account(self): - return get_asset_category_account('fixed_asset_account', None, self.name, None, self.asset_category, self.company) + fixed_asset_account = get_asset_category_account('fixed_asset_account', None, self.name, None, self.asset_category, self.company) + if not fixed_asset_account: + frappe.throw( + _("Set {0} in asset category {1} for company {2}").format( + frappe.bold("Fixed Asset Account"), + frappe.bold(self.asset_category), + frappe.bold(self.company), + ), + title=_("Account not Found"), + ) + return fixed_asset_account def get_cwip_account(self, cwip_enabled=False): cwip_account = None From efcfb825d7a72a403f06f62e322cedd7fbbffd29 Mon Sep 17 00:00:00 2001 From: Marica Date: Wed, 12 Jan 2022 16:44:33 +0530 Subject: [PATCH 40/50] Merge pull request #29257 from marination/fix-reset-wh-defaults fix: Avoid resetting Default wh fields for Manufacture Entry --- .../tests/test_transaction_base.py | 79 ++++++++++++++++--- .../stock/doctype/stock_entry/stock_entry.py | 8 +- erpnext/utilities/transaction_base.py | 2 - 3 files changed, 72 insertions(+), 17 deletions(-) diff --git a/erpnext/controllers/tests/test_transaction_base.py b/erpnext/controllers/tests/test_transaction_base.py index 13aa697610..f4d3f97ef0 100644 --- a/erpnext/controllers/tests/test_transaction_base.py +++ b/erpnext/controllers/tests/test_transaction_base.py @@ -4,19 +4,72 @@ import frappe class TestUtils(unittest.TestCase): - def test_reset_default_field_value(self): - doc = frappe.get_doc({ - "doctype": "Purchase Receipt", - "set_warehouse": "Warehouse 1", - }) + def test_reset_default_field_value(self): + doc = frappe.get_doc({ + "doctype": "Purchase Receipt", + "set_warehouse": "Warehouse 1", + }) - # Same values - doc.items = [{"warehouse": "Warehouse 1"}, {"warehouse": "Warehouse 1"}, {"warehouse": "Warehouse 1"}] - doc.reset_default_field_value("set_warehouse", "items", "warehouse") - self.assertEqual(doc.set_warehouse, "Warehouse 1") + # Same values + doc.items = [{"warehouse": "Warehouse 1"}, {"warehouse": "Warehouse 1"}, {"warehouse": "Warehouse 1"}] + doc.reset_default_field_value("set_warehouse", "items", "warehouse") + self.assertEqual(doc.set_warehouse, "Warehouse 1") - # Mixed values - doc.items = [{"warehouse": "Warehouse 1"}, {"warehouse": "Warehouse 2"}, {"warehouse": "Warehouse 1"}] - doc.reset_default_field_value("set_warehouse", "items", "warehouse") - self.assertEqual(doc.set_warehouse, None) + # Mixed values + doc.items = [{"warehouse": "Warehouse 1"}, {"warehouse": "Warehouse 2"}, {"warehouse": "Warehouse 1"}] + doc.reset_default_field_value("set_warehouse", "items", "warehouse") + self.assertEqual(doc.set_warehouse, None) + def test_reset_default_field_value_in_mfg_stock_entry(self): + # manufacture stock entry with rows having blank source/target wh + se = frappe.get_doc( + doctype="Stock Entry", + purpose="Manufacture", + stock_entry_type="Manufacture", + company="_Test Company", + from_warehouse="_Test Warehouse - _TC", + to_warehouse="_Test Warehouse 1 - _TC", + items=[ + frappe._dict(item_code="_Test Item", qty=1, basic_rate=200, s_warehouse="_Test Warehouse - _TC"), + frappe._dict(item_code="_Test FG Item", qty=4, t_warehouse="_Test Warehouse 1 - _TC", is_finished_item=1) + ] + ) + se.save() + + # default fields must be untouched + self.assertEqual(se.from_warehouse, "_Test Warehouse - _TC") + self.assertEqual(se.to_warehouse, "_Test Warehouse 1 - _TC") + + se.delete() + + def test_reset_default_field_value_in_transfer_stock_entry(self): + doc = frappe.get_doc({ + "doctype": "Stock Entry", + "purpose": "Material Receipt", + "from_warehouse": "Warehouse 1", + "to_warehouse": "Warehouse 2", + }) + + # Same values + doc.items = [ + {"s_warehouse": "Warehouse 1", "t_warehouse": "Warehouse 2"}, + {"s_warehouse": "Warehouse 1", "t_warehouse": "Warehouse 2"}, + {"s_warehouse": "Warehouse 1", "t_warehouse": "Warehouse 2"} + ] + + doc.reset_default_field_value("from_warehouse", "items", "s_warehouse") + doc.reset_default_field_value("to_warehouse", "items", "t_warehouse") + self.assertEqual(doc.from_warehouse, "Warehouse 1") + self.assertEqual(doc.to_warehouse, "Warehouse 2") + + # Mixed values in source wh + doc.items = [ + {"s_warehouse": "Warehouse 1", "t_warehouse": "Warehouse 2"}, + {"s_warehouse": "Warehouse 3", "t_warehouse": "Warehouse 2"}, + {"s_warehouse": "Warehouse 1", "t_warehouse": "Warehouse 2"} + ] + + doc.reset_default_field_value("from_warehouse", "items", "s_warehouse") + doc.reset_default_field_value("to_warehouse", "items", "t_warehouse") + self.assertEqual(doc.from_warehouse, None) + self.assertEqual(doc.to_warehouse, "Warehouse 2") \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 8dcf48aa24..d1149ea6a2 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -110,8 +110,12 @@ class StockEntry(StockController): self.set_actual_qty() self.calculate_rate_and_amount() self.validate_putaway_capacity() - self.reset_default_field_value("from_warehouse", "items", "s_warehouse") - self.reset_default_field_value("to_warehouse", "items", "t_warehouse") + + if not self.get("purpose") == "Manufacture": + # ignore scrap item wh difference and empty source/target wh + # in Manufacture Entry + self.reset_default_field_value("from_warehouse", "items", "s_warehouse") + self.reset_default_field_value("to_warehouse", "items", "t_warehouse") def on_submit(self): self.update_stock_ledger() diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py index 1d8b3a8db6..feea2284b7 100644 --- a/erpnext/utilities/transaction_base.py +++ b/erpnext/utilities/transaction_base.py @@ -181,8 +181,6 @@ class TransactionBase(StatusUpdater): if len(child_table_values) > 1: self.set(default_field, None) - else: - self.set(default_field, list(child_table_values)[0]) def delete_events(ref_type, ref_name): events = frappe.db.sql_list(""" SELECT From 8b5827ed6db1041526b6440ca8e4fde19c646e1e Mon Sep 17 00:00:00 2001 From: Mohammed Yusuf Shaikh <49878143+mohammedyusufshaikh@users.noreply.github.com> Date: Wed, 12 Jan 2022 18:49:33 +0530 Subject: [PATCH 41/50] fix: from time and to time not updated in drag and drop action #29114 fix: from time and to time not updated in drag and drop action --- erpnext/education/api.py | 4 ++-- .../doctype/course_schedule/course_schedule.py | 12 +++++++++++- .../course_schedule/course_schedule_calendar.js | 7 +++---- .../doctype/course_schedule/test_course_schedule.py | 6 ++++++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/erpnext/education/api.py b/erpnext/education/api.py index d9013b0816..636b948a1c 100644 --- a/erpnext/education/api.py +++ b/erpnext/education/api.py @@ -201,8 +201,8 @@ def get_course_schedule_events(start, end, filters=None): conditions = get_event_conditions("Course Schedule", filters) data = frappe.db.sql("""select name, course, color, - timestamp(schedule_date, from_time) as from_datetime, - timestamp(schedule_date, to_time) as to_datetime, + timestamp(schedule_date, from_time) as from_time, + timestamp(schedule_date, to_time) as to_time, room, student_group, 0 as 'allDay' from `tabCourse Schedule` where ( schedule_date between %(start)s and %(end)s ) diff --git a/erpnext/education/doctype/course_schedule/course_schedule.py b/erpnext/education/doctype/course_schedule/course_schedule.py index ffd323d3d2..615d2c4709 100644 --- a/erpnext/education/doctype/course_schedule/course_schedule.py +++ b/erpnext/education/doctype/course_schedule/course_schedule.py @@ -3,6 +3,8 @@ # For license information, please see license.txt +from datetime import datetime + import frappe from frappe import _ from frappe.model.document import Document @@ -30,6 +32,14 @@ class CourseSchedule(Document): if self.from_time > self.to_time: frappe.throw(_("From Time cannot be greater than To Time.")) + """Handles specicfic case to update schedule date in calendar """ + if isinstance(self.from_time, str): + try: + datetime_obj = datetime.strptime(self.from_time, '%Y-%m-%d %H:%M:%S') + self.schedule_date = datetime_obj + except ValueError: + pass + def validate_overlap(self): """Validates overlap for Student Group, Instructor, Room""" @@ -47,4 +57,4 @@ class CourseSchedule(Document): validate_overlap_for(self, "Assessment Plan", "student_group") validate_overlap_for(self, "Assessment Plan", "room") - validate_overlap_for(self, "Assessment Plan", "supervisor", self.instructor) + validate_overlap_for(self, "Assessment Plan", "supervisor", self.instructor) \ No newline at end of file diff --git a/erpnext/education/doctype/course_schedule/course_schedule_calendar.js b/erpnext/education/doctype/course_schedule/course_schedule_calendar.js index 803527e548..cacd539b22 100644 --- a/erpnext/education/doctype/course_schedule/course_schedule_calendar.js +++ b/erpnext/education/doctype/course_schedule/course_schedule_calendar.js @@ -1,11 +1,10 @@ frappe.views.calendar["Course Schedule"] = { field_map: { - // from_datetime and to_datetime don't exist as docfields but are used in onload - "start": "from_datetime", - "end": "to_datetime", + "start": "from_time", + "end": "to_time", "id": "name", "title": "course", - "allDay": "allDay" + "allDay": "allDay", }, gantt: false, order_by: "schedule_date", diff --git a/erpnext/education/doctype/course_schedule/test_course_schedule.py b/erpnext/education/doctype/course_schedule/test_course_schedule.py index a732419555..56149affce 100644 --- a/erpnext/education/doctype/course_schedule/test_course_schedule.py +++ b/erpnext/education/doctype/course_schedule/test_course_schedule.py @@ -6,6 +6,7 @@ import unittest import frappe from frappe.utils import to_timedelta, today +from frappe.utils.data import add_to_date from erpnext.education.utils import OverlapError @@ -39,6 +40,11 @@ class TestCourseSchedule(unittest.TestCase): make_course_schedule_test_record(from_time= cs1.from_time, to_time= cs1.to_time, student_group="Course-TC102-2014-2015 (_Test Academic Term)", instructor="_Test Instructor 2", room=frappe.get_all("Room")[1].name) + def test_update_schedule_date(self): + doc = make_course_schedule_test_record(schedule_date= add_to_date(today(), days=1)) + doc.schedule_date = add_to_date(doc.schedule_date, days=1) + doc.save() + def make_course_schedule_test_record(**args): args = frappe._dict(args) From 5cda4ea39f85456e6d68df0c6a6498f98a052734 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 12 Jan 2022 19:03:36 +0530 Subject: [PATCH 42/50] fix: autoname generated for Job Applicant is too long (#29260) * fix: autoname generated for Job Applicant is too long - autoname based on email and append number if exists instead of concatenating name, email, title - add more search fields for context during selection * test: Job applicant naming and fix related tests --- .../test_employee_onboarding.py | 8 +++---- .../doctype/job_applicant/job_applicant.json | 6 ++++-- .../hr/doctype/job_applicant/job_applicant.py | 10 +++++---- .../job_applicant/test_job_applicant.py | 21 ++++++++++++++++++- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py b/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py index cb1b56048b..2d129c8acf 100644 --- a/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py +++ b/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py @@ -19,7 +19,7 @@ class TestEmployeeOnboarding(unittest.TestCase): if frappe.db.exists('Employee Onboarding', {'employee_name': 'Test Researcher'}): frappe.delete_doc('Employee Onboarding', {'employee_name': 'Test Researcher'}) - project = "Employee Onboarding : Test Researcher - test@researcher.com" + project = "Employee Onboarding : test@researcher.com" frappe.db.sql("delete from tabProject where name=%s", project) frappe.db.sql("delete from tabTask where project=%s", project) @@ -27,7 +27,7 @@ class TestEmployeeOnboarding(unittest.TestCase): onboarding = create_employee_onboarding() project_name = frappe.db.get_value('Project', onboarding.project, 'project_name') - self.assertEqual(project_name, 'Employee Onboarding : Test Researcher - test@researcher.com') + self.assertEqual(project_name, 'Employee Onboarding : test@researcher.com') # don't allow making employee if onboarding is not complete self.assertRaises(IncompleteTaskError, make_employee, onboarding.name) @@ -64,8 +64,8 @@ class TestEmployeeOnboarding(unittest.TestCase): def get_job_applicant(): - if frappe.db.exists('Job Applicant', 'Test Researcher - test@researcher.com'): - return frappe.get_doc('Job Applicant', 'Test Researcher - test@researcher.com') + if frappe.db.exists('Job Applicant', 'test@researcher.com'): + return frappe.get_doc('Job Applicant', 'test@researcher.com') applicant = frappe.new_doc('Job Applicant') applicant.applicant_name = 'Test Researcher' applicant.email_id = 'test@researcher.com' diff --git a/erpnext/hr/doctype/job_applicant/job_applicant.json b/erpnext/hr/doctype/job_applicant/job_applicant.json index 200f675221..66b609cf99 100644 --- a/erpnext/hr/doctype/job_applicant/job_applicant.json +++ b/erpnext/hr/doctype/job_applicant/job_applicant.json @@ -192,10 +192,11 @@ "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2021-09-29 23:06:10.904260", + "modified": "2022-01-12 16:28:53.196881", "modified_by": "Administrator", "module": "HR", "name": "Job Applicant", + "naming_rule": "Expression (old style)", "owner": "Administrator", "permissions": [ { @@ -210,10 +211,11 @@ "write": 1 } ], - "search_fields": "applicant_name", + "search_fields": "applicant_name, email_id, job_title, phone_number", "sender_field": "email_id", "sort_field": "modified", "sort_order": "ASC", + "states": [], "subject_field": "notes", "title_field": "applicant_name" } \ No newline at end of file diff --git a/erpnext/hr/doctype/job_applicant/job_applicant.py b/erpnext/hr/doctype/job_applicant/job_applicant.py index abaa50c84c..5b3d9bfb4f 100644 --- a/erpnext/hr/doctype/job_applicant/job_applicant.py +++ b/erpnext/hr/doctype/job_applicant/job_applicant.py @@ -7,6 +7,7 @@ import frappe from frappe import _ from frappe.model.document import Document +from frappe.model.naming import append_number_if_name_exists from frappe.utils import validate_email_address from erpnext.hr.doctype.interview.interview import get_interviewers @@ -21,10 +22,11 @@ class JobApplicant(Document): self.get("__onload").job_offer = job_offer[0].name def autoname(self): - keys = filter(None, (self.applicant_name, self.email_id, self.job_title)) - if not keys: - frappe.throw(_("Name or Email is mandatory"), frappe.NameError) - self.name = " - ".join(keys) + self.name = self.email_id + + # applicant can apply more than once for a different job title or reapply + if frappe.db.exists("Job Applicant", self.name): + self.name = append_number_if_name_exists("Job Applicant", self.name) def validate(self): if self.email_id: diff --git a/erpnext/hr/doctype/job_applicant/test_job_applicant.py b/erpnext/hr/doctype/job_applicant/test_job_applicant.py index 36dcf6b074..bf1622028d 100644 --- a/erpnext/hr/doctype/job_applicant/test_job_applicant.py +++ b/erpnext/hr/doctype/job_applicant/test_job_applicant.py @@ -9,7 +9,26 @@ from erpnext.hr.doctype.designation.test_designation import create_designation class TestJobApplicant(unittest.TestCase): - pass + def test_job_applicant_naming(self): + applicant = frappe.get_doc({ + "doctype": "Job Applicant", + "status": "Open", + "applicant_name": "_Test Applicant", + "email_id": "job_applicant_naming@example.com" + }).insert() + self.assertEqual(applicant.name, 'job_applicant_naming@example.com') + + applicant = frappe.get_doc({ + "doctype": "Job Applicant", + "status": "Open", + "applicant_name": "_Test Applicant", + "email_id": "job_applicant_naming@example.com" + }).insert() + self.assertEqual(applicant.name, 'job_applicant_naming@example.com-1') + + def tearDown(self): + frappe.db.rollback() + def create_job_applicant(**args): args = frappe._dict(args) From eb8d08b411b66797d9f3892e079c49828335d34a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 12 Jan 2022 19:23:22 +0530 Subject: [PATCH 43/50] fix: remove all stock UOM conversion when changing stock UOM --- erpnext/stock/doctype/item/item.py | 22 ++++++++++++---------- erpnext/stock/doctype/item/test_item.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index decf522d2f..281e881875 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -492,18 +492,20 @@ class Item(WebsiteGenerator): context.shopping_cart = get_product_info_for_website(self.name, skip_quotation_creation=True) def add_default_uom_in_conversion_factor_table(self): - uom_conv_list = [d.uom for d in self.get("uoms")] - if self.stock_uom not in uom_conv_list: - ch = self.append('uoms', {}) - ch.uom = self.stock_uom - ch.conversion_factor = 1 + if not self.is_new() and self.has_value_changed("stock_uom"): + self.uoms = [] + frappe.msgprint( + _("Successfully changed Stock UOM, please redefine conversion factors for new UOM."), + alert=True, + ) - to_remove = [] - for d in self.get("uoms"): - if d.conversion_factor == 1 and d.uom != self.stock_uom: - to_remove.append(d) + uoms_list = [d.uom for d in self.get("uoms")] - [self.remove(d) for d in to_remove] + if self.stock_uom not in uoms_list: + self.append("uoms", { + "uom": self.stock_uom, + "conversion_factor": 1 + }) def update_show_in_website(self): if self.disabled: diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 4028d93334..0957ce0615 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -584,6 +584,16 @@ class TestItem(ERPNextTestCase): except frappe.ValidationError as e: self.fail(f"UoM change not allowed even though no SLE / BIN with positive qty exists: {e}") + def test_erasure_of_old_conversions(self): + item = create_item("_item change uom") + item.stock_uom = "Gram" + item.append("uoms", frappe._dict(uom="Box", conversion_factor=2)) + item.save() + item.reload() + item.stock_uom = "Nos" + item.save() + self.assertEqual(len(item.uoms), 1) + def test_validate_stock_item(self): self.assertRaises(frappe.ValidationError, validate_is_stock_item, "_Test Non Stock Item") From 82b2d22627635f0076a98bbff066b15520566775 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 13 Jan 2022 11:09:36 +0530 Subject: [PATCH 44/50] fix(Payroll): Cannot submit salary slips from amended payroll entry. (backport #29228) (#29268) * fix: salary slip transaction state after payroll entry cancel * fix: use db_set in on_cancel method Co-authored-by: Rucha Mahabal Co-authored-by: Rucha Mahabal (cherry picked from commit 81f1b7dfeb68c5a70f4aa9bc0e24f7aedcd79669) Co-authored-by: Devin Slauenwhite --- erpnext/payroll/doctype/payroll_entry/payroll_entry.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index ed3fa5befc..db88c0643c 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -61,6 +61,8 @@ class PayrollEntry(Document): def on_cancel(self): frappe.delete_doc("Salary Slip", frappe.db.sql_list("""select name from `tabSalary Slip` where payroll_entry=%s """, (self.name))) + self.db_set("salary_slips_created", 0) + self.db_set("salary_slips_submitted", 0) def get_emp_list(self): """ From dabe5981bbb54a5b2dff704481c4eb3e1676c3fb Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 13 Jan 2022 12:51:34 +0530 Subject: [PATCH 45/50] fix: accounts are coming from different company in the dropdown --- erpnext/setup/doctype/company/company.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 45e8dccc31..dd185fc663 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -213,6 +213,9 @@ erpnext.company.setup_queries = function(frm) { ["default_payroll_payable_account", {"root_type": "Liability"}], ["round_off_account", {"root_type": "Expense"}], ["write_off_account", {"root_type": "Expense"}], + ["default_deferred_expense_account", {}], + ["default_deferred_revenue_account", {}], + ["default_expense_claim_payable_account", {}], ["default_discount_account", {}], ["discount_allowed_account", {"root_type": "Expense"}], ["discount_received_account", {"root_type": "Income"}], From eac7b5d5aaed83217b0a2843d13e75cb94dbb9a0 Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 13 Jan 2022 12:15:40 +0530 Subject: [PATCH 46/50] fix: Allow multiple fg in repack entry --- .../stock/doctype/stock_entry/stock_entry.py | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index d1149ea6a2..486c4c4280 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -738,9 +738,9 @@ class StockEntry(StockController): def validate_finished_goods(self): """ - 1. Check if FG exists - 2. Check if Multiple FG Items are present - 3. Check FG Item and Qty against WO if present + 1. Check if FG exists (mfg, repack) + 2. Check if Multiple FG Items are present (mfg) + 3. Check FG Item and Qty against WO if present (mfg) """ production_item, wo_qty, finished_items = None, 0, [] @@ -753,8 +753,9 @@ class StockEntry(StockController): for d in self.get('items'): if d.is_finished_item: if not self.work_order: + # Independent MFG Entry/ Repack Entry, no WO to match against finished_items.append(d.item_code) - continue # Independent Manufacture Entry, no WO to match against + continue if d.item_code != production_item: frappe.throw(_("Finished Item {0} does not match with Work Order {1}") @@ -767,19 +768,17 @@ class StockEntry(StockController): finished_items.append(d.item_code) - if len(set(finished_items)) > 1: + if not finished_items: frappe.throw( - msg=_("Multiple items cannot be marked as finished item"), - title=_("Note"), - exc=FinishedGoodError + msg=_("There must be atleast 1 Finished Good in this Stock Entry").format(self.name), + title=_("Missing Finished Good"), exc=FinishedGoodError ) if self.purpose == "Manufacture": - if not finished_items: + if len(set(finished_items)) > 1: frappe.throw( - msg=_("There must be atleast 1 Finished Good in this Stock Entry").format(self.name), - title=_("Missing Finished Good"), - exc=FinishedGoodError + msg=_("Multiple items cannot be marked as finished item"), + title=_("Note"), exc=FinishedGoodError ) allowance_percentage = flt( From 3a18e62a9b9cfa0c84add308f60933d83e74e6bb Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 13 Jan 2022 14:08:11 +0530 Subject: [PATCH 47/50] fix: filter for leave period in Bulk Leave Policy Assignment (#29272) * fix: filter for leave period in Bulk Leave Policy Assignment * fix: set title for Leave Policy Assignment --- .../hr/doctype/leave_period/leave_period.json | 230 ++---------------- .../leave_policy_assignment.json | 5 +- .../leave_policy_assignment_list.js | 11 +- 3 files changed, 36 insertions(+), 210 deletions(-) diff --git a/erpnext/hr/doctype/leave_period/leave_period.json b/erpnext/hr/doctype/leave_period/leave_period.json index 9e895c34fb..84ce1147e9 100644 --- a/erpnext/hr/doctype/leave_period/leave_period.json +++ b/erpnext/hr/doctype/leave_period/leave_period.json @@ -1,294 +1,108 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, + "actions": [], "allow_import": 1, "allow_rename": 1, "autoname": "HR-LPR-.YYYY.-.#####", - "beta": 0, "creation": "2018-04-13 15:20:52.864288", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", "editable_grid": 1, "engine": "InnoDB", + "field_order": [ + "from_date", + "to_date", + "is_active", + "column_break_3", + "company", + "optional_holiday_list" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "from_date", "fieldtype": "Date", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "From 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 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "to_date", "fieldtype": "Date", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "To 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 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, + "default": "0", "fieldname": "is_active", "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 Active", - "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 + "label": "Is Active" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "column_break_3", - "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 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "company", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Company", - "length": 0, - "no_copy": 0, "options": "Company", - "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 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "optional_holiday_list", "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": "Holiday List for Optional Leave", - "length": 0, - "no_copy": 0, - "options": "Holiday List", - "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 + "options": "Holiday List" } ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2019-05-30 16:15:43.305502", + "links": [], + "modified": "2022-01-13 13:28:12.951025", "modified_by": "Administrator", "module": "HR", "name": "Leave Period", - "name_case": "", + "naming_rule": "Expression (old style)", "owner": "Administrator", "permissions": [ { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "System Manager", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 }, { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "HR Manager", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 }, { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "HR User", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 } ], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, + "search_fields": "from_date, to_date, company", "sort_field": "modified", "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + "states": [], + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json index 3373350e73..27f0540b24 100644 --- a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json +++ b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json @@ -113,10 +113,11 @@ ], "is_submittable": 1, "links": [], - "modified": "2021-03-01 17:54:01.014509", + "modified": "2022-01-13 13:37:11.218882", "modified_by": "Administrator", "module": "HR", "name": "Leave Policy Assignment", + "naming_rule": "Expression (old style)", "owner": "Administrator", "permissions": [ { @@ -164,5 +165,7 @@ ], "sort_field": "modified", "sort_order": "DESC", + "states": [], + "title_field": "employee_name", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment_list.js b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment_list.js index 8b954c46a1..6b75817cba 100644 --- a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment_list.js +++ b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment_list.js @@ -48,7 +48,16 @@ frappe.listview_settings['Leave Policy Assignment'] = { if (cur_dialog.fields_dict.leave_period.value) { me.set_effective_date(); } - } + }, + get_query() { + let filters = {"is_active": 1}; + if (cur_dialog.fields_dict.company.value) + filters["company"] = cur_dialog.fields_dict.company.value; + + return { + filters: filters + }; + }, }, { fieldtype: "Column Break" From 3922a39591ad79a44438f3edf28841348a64d74c Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 13 Jan 2022 14:36:21 +0530 Subject: [PATCH 48/50] test: Basic test one item repacked into two - Also run fg validation and fg marking after checking purpose, avoid unnecessary calls --- .../stock/doctype/stock_entry/stock_entry.py | 38 ++++++++++--------- .../doctype/stock_entry/test_stock_entry.py | 35 ++++++++++++++++- 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 486c4c4280..a61b3199c0 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -86,8 +86,11 @@ class StockEntry(StockController): self.validate_warehouse() self.validate_work_order() self.validate_bom() - self.mark_finished_and_scrap_items() - self.validate_finished_goods() + + if self.purpose in ("Manufacture", "Repack"): + self.mark_finished_and_scrap_items() + self.validate_finished_goods() + self.validate_with_material_request() self.validate_batch() self.validate_inspection() @@ -706,26 +709,25 @@ class StockEntry(StockController): validate_bom_no(item_code, d.bom_no) def mark_finished_and_scrap_items(self): - if self.purpose in ("Repack", "Manufacture"): - if any([d.item_code for d in self.items if (d.is_finished_item and d.t_warehouse)]): - return + if any([d.item_code for d in self.items if (d.is_finished_item and d.t_warehouse)]): + return - finished_item = self.get_finished_item() + finished_item = self.get_finished_item() - if not finished_item and self.purpose == "Manufacture": - # In case of independent Manufacture entry, don't auto set - # user must decide and set - return + if not finished_item and self.purpose == "Manufacture": + # In case of independent Manufacture entry, don't auto set + # user must decide and set + return - for d in self.items: - if d.t_warehouse and not d.s_warehouse: - if self.purpose=="Repack" or d.item_code == finished_item: - d.is_finished_item = 1 - else: - d.is_scrap_item = 1 + for d in self.items: + if d.t_warehouse and not d.s_warehouse: + if self.purpose=="Repack" or d.item_code == finished_item: + d.is_finished_item = 1 else: - d.is_finished_item = 0 - d.is_scrap_item = 0 + d.is_scrap_item = 1 + else: + d.is_finished_item = 0 + d.is_scrap_item = 0 def get_finished_item(self): finished_item = None diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index b874874adf..c292461824 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -226,9 +226,40 @@ class TestStockEntry(ERPNextTestCase): mtn.cancel() - def test_repack_no_change_in_valuation(self): - company = frappe.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') + def test_repack_multiple_fg(self): + "Test `is_finsihed_item` for one item repacked into two items." + make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=100, basic_rate=100) + repack = frappe.copy_doc(test_records[3]) + repack.posting_date = nowdate() + repack.posting_time = nowtime() + + repack.items[0].qty = 100.0 + repack.items[0].transfer_qty = 100.0 + repack.items[1].qty = 50.0 + repack.items[1].basic_rate = 200 + + repack.append("items", { + "conversion_factor": 1.0, + "cost_center": "_Test Cost Center - _TC", + "doctype": "Stock Entry Detail", + "expense_account": "Stock Adjustment - _TC", + "basic_rate": 150, + "item_code": "_Test Item 2", + "parentfield": "items", + "qty": 50.0, + "stock_uom": "_Test UOM", + "t_warehouse": "_Test Warehouse - _TC", + "transfer_qty": 50.0, + "uom": "_Test UOM" + }) + repack.set_stock_entry_type() + repack.insert() + + self.assertEqual(repack.items[1].is_finished_item, 1) + self.assertEqual(repack.items[2].is_finished_item, 1) + + def test_repack_no_change_in_valuation(self): make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, basic_rate=100) make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse - _TC", qty=50, basic_rate=100) From c49dff385a4798e329f0a8390563afee945c7656 Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 13 Jan 2022 15:02:59 +0530 Subject: [PATCH 49/50] test: Check for FinishedGoodError if 0 FG in repack entry --- erpnext/stock/doctype/stock_entry/test_stock_entry.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index c292461824..8f5d442d19 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -227,7 +227,7 @@ class TestStockEntry(ERPNextTestCase): mtn.cancel() def test_repack_multiple_fg(self): - "Test `is_finsihed_item` for one item repacked into two items." + "Test `is_finished_item` for one item repacked into two items." make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=100, basic_rate=100) repack = frappe.copy_doc(test_records[3]) @@ -237,7 +237,6 @@ class TestStockEntry(ERPNextTestCase): repack.items[0].qty = 100.0 repack.items[0].transfer_qty = 100.0 repack.items[1].qty = 50.0 - repack.items[1].basic_rate = 200 repack.append("items", { "conversion_factor": 1.0, @@ -259,6 +258,14 @@ class TestStockEntry(ERPNextTestCase): self.assertEqual(repack.items[1].is_finished_item, 1) self.assertEqual(repack.items[2].is_finished_item, 1) + repack.items[1].is_finished_item = 0 + repack.items[2].is_finished_item = 0 + + # must raise error if 0 fg in repack entry + self.assertRaises(FinishedGoodError, repack.validate_finished_goods) + + repack.delete() # teardown + def test_repack_no_change_in_valuation(self): make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, basic_rate=100) make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse - _TC", From be0a4412d310eba7cf8f6968bcf7458c924d5bcf Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 13 Jan 2022 17:19:59 +0530 Subject: [PATCH 50/50] chore: update label rules --- .github/labeler.yml | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index fc3f06da92..3aaba71b12 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -1,53 +1,53 @@ accounts: -- 'erpnext/accounts/*' -- 'erpnext/controllers/accounts_controller.py' -- 'erpnext/controllers/taxes_and_totals.py' +- erpnext/accounts/* +- erpnext/controllers/accounts_controller.py +- erpnext/controllers/taxes_and_totals.py stock: -- 'erpnext/stock/*' -- 'erpnext/controllers/stock_controller.py' -- 'erpnext/controllers/item_variant.py' +- erpnext/stock/* +- erpnext/controllers/stock_controller.py +- erpnext/controllers/item_variant.py assets: -- 'erpnext/assets/*' +- erpnext/assets/* regional: -- 'erpnext/regional/*' +- erpnext/regional/* selling: -- 'erpnext/selling/*' -- 'erpnext/controllers/selling_controller.py' +- erpnext/selling/* +- erpnext/controllers/selling_controller.py buying: -- 'erpnext/buying/*' -- 'erpnext/controllers/buying_controller.py' +- erpnext/buying/* +- erpnext/controllers/buying_controller.py support: -- 'erpnext/support/*' +- erpnext/support/* POS: -- 'pos*' +- pos* ecommerce: -- 'erpnext/e_commerce/*' +- erpnext/e_commerce/* maintenance: -- 'erpnext/maintenance/*' +- erpnext/maintenance/* manufacturing: -- 'erpnext/manufacturing/*' +- erpnext/manufacturing/* crm: -- 'erpnext/crm/*' +- erpnext/crm/* HR: -- 'erpnext/hr/*' +- erpnext/hr/* payroll: -- 'erpnext/payroll*' +- erpnext/payroll* projects: -- 'erpnext/projects/*' +- erpnext/projects/* # Any python files modifed but no test files modified needs-tests: