diff --git a/.github/helper/.flake8_strict b/.github/helper/.flake8_strict index 4c7f5f82cfb..a79137d7c32 100644 --- a/.github/helper/.flake8_strict +++ b/.github/helper/.flake8_strict @@ -1,6 +1,8 @@ [flake8] ignore = B007, + B009, + B010, B950, E101, E111, diff --git a/.github/helper/semgrep_rules/frappe_correctness.yml b/.github/helper/semgrep_rules/frappe_correctness.yml index d9603e89aa4..166e98a8a29 100644 --- a/.github/helper/semgrep_rules/frappe_correctness.yml +++ b/.github/helper/semgrep_rules/frappe_correctness.yml @@ -131,3 +131,21 @@ rules: key `$X` is uselessly assigned twice. This could be a potential bug. languages: [python] severity: ERROR + + +- id: frappe-manual-commit + patterns: + - pattern: frappe.db.commit() + - pattern-not-inside: | + try: + ... + except ...: + ... + message: | + Manually commiting a transaction is highly discouraged. Read about the transaction model implemented by Frappe Framework before adding manual commits: https://frappeframework.com/docs/user/en/api/database#database-transaction-model If you think manual commit is required then add a comment explaining why and `// nosemgrep` on the same line. + paths: + exclude: + - "**/patches/**" + - "**/demo/**" + languages: [python] + severity: ERROR diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index cc3c5ceb7d1..90b5f28e9b7 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -99,6 +99,8 @@ jobs: - name: Build Assets run: cd ~/frappe-bench/ && bench build + env: + CI: Yes - name: UI Tests run: cd ~/frappe-bench/ && bench --site test_site run-ui-tests erpnext --headless diff --git a/.mergify.yml b/.mergify.yml new file mode 100644 index 00000000000..f3d04096cfc --- /dev/null +++ b/.mergify.yml @@ -0,0 +1,58 @@ +pull_request_rules: + - name: Auto-close PRs on stable branch + conditions: + - and: + - and: + - author!=surajshetty3416 + - author!=gavindsouza + - author!=rohitwaghchaure + - author!=nabinhait + - or: + - base=version-13 + - base=version-12 + actions: + close: + comment: + message: | + @{{author}}, thanks for the contribution, but we do not accept pull requests on a stable branch. Please raise PR on an appropriate hotfix branch. + https://github.com/frappe/erpnext/wiki/Pull-Request-Checklist#which-branch + + - name: backport to version-13-hotfix + conditions: + - label="backport version-13-hotfix" + actions: + backport: + branches: + - version-13-hotfix + assignees: + - "{{ author }}" + + - name: backport to version-13-pre-release + conditions: + - label="backport version-13-pre-release" + actions: + backport: + branches: + - version-13-pre-release + assignees: + - "{{ author }}" + + - name: backport to version-12-hotfix + conditions: + - label="backport version-12-hotfix" + actions: + backport: + branches: + - version-12-hotfix + assignees: + - "{{ author }}" + + - name: backport to version-12-pre-release + conditions: + - label="backport version-12-pre-release" + actions: + backport: + branches: + - version-12-pre-release + assignees: + - "{{ author }}" \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2b3a471f774..b74d9a640da 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,9 @@ repos: rev: 3.9.2 hooks: - id: flake8 + additional_dependencies: [ + 'flake8-bugbear', + ] args: ['--config', '.github/helper/.flake8_strict'] exclude: ".*setup.py$" diff --git a/cypress/integration/test_organizational_chart_desktop.js b/cypress/integration/test_organizational_chart_desktop.js index 79e08b3bbad..464cce48d03 100644 --- a/cypress/integration/test_organizational_chart_desktop.js +++ b/cypress/integration/test_organizational_chart_desktop.js @@ -24,7 +24,7 @@ context('Organizational Chart', () => { cy.get('.frappe-control[data-fieldname=company] input').focus().as('input'); cy.get('@input') .clear({ force: true }) - .type('Test Org Chart{enter}', { force: true }) + .type('Test Org Chart{downarrow}{enter}', { force: true }) .blur({ force: true }); }); }); diff --git a/cypress/integration/test_organizational_chart_mobile.js b/cypress/integration/test_organizational_chart_mobile.js index 161fae098a2..971ac6d3ef3 100644 --- a/cypress/integration/test_organizational_chart_mobile.js +++ b/cypress/integration/test_organizational_chart_mobile.js @@ -25,7 +25,7 @@ context('Organizational Chart Mobile', () => { cy.get('.frappe-control[data-fieldname=company] input').focus().as('input'); cy.get('@input') .clear({ force: true }) - .type('Test Org Chart{enter}', { force: true }) + .type('Test Org Chart{downarrow}{enter}', { force: true }) .blur({ force: true }); }); }); diff --git a/erpnext/__init__.py b/erpnext/__init__.py index e4ba67017e6..89d12e005c8 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -7,7 +7,7 @@ import frappe from erpnext.hooks import regional_overrides -__version__ = '13.12.1' +__version__ = '13.13.0' def get_default_company(user=None): '''Get default company for user''' diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index f6198eb23ba..605262f7b3e 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -8,6 +8,8 @@ from frappe import _, throw from frappe.utils import cint, cstr from frappe.utils.nestedset import NestedSet, get_ancestors_of, get_descendants_of +import erpnext + class RootNotEditable(frappe.ValidationError): pass class BalanceMismatchError(frappe.ValidationError): pass @@ -196,7 +198,7 @@ class Account(NestedSet): "company": company, # parent account's currency should be passed down to child account's curreny # if it is None, it picks it up from default company currency, which might be unintended - "account_currency": self.account_currency, + "account_currency": erpnext.get_company_currency(company), "parent_account": parent_acc_name_map[company] }) @@ -207,8 +209,7 @@ class Account(NestedSet): # update the parent company's value in child companies doc = frappe.get_doc("Account", child_account) parent_value_changed = False - for field in ['account_type', 'account_currency', - 'freeze_account', 'balance_must_be']: + for field in ['account_type', 'freeze_account', 'balance_must_be']: if doc.get(field) != self.get(field): parent_value_changed = True doc.set(field, self.get(field)) diff --git a/erpnext/accounts/doctype/account/account_tree.js b/erpnext/accounts/doctype/account/account_tree.js index 7516134baf5..a4b6e0b45ae 100644 --- a/erpnext/accounts/doctype/account/account_tree.js +++ b/erpnext/accounts/doctype/account/account_tree.js @@ -45,6 +45,49 @@ frappe.treeview_settings["Account"] = { ], root_label: "Accounts", get_tree_nodes: 'erpnext.accounts.utils.get_children', + on_get_node: function(nodes, deep=false) { + if (frappe.boot.user.can_read.indexOf("GL Entry") == -1) return; + + let accounts = []; + if (deep) { + // in case of `get_all_nodes` + accounts = nodes.reduce((acc, node) => [...acc, ...node.data], []); + } else { + accounts = nodes; + } + + const get_balances = frappe.call({ + method: 'erpnext.accounts.utils.get_account_balances', + args: { + accounts: accounts, + company: cur_tree.args.company + }, + }); + + get_balances.then(r => { + if (!r.message || r.message.length == 0) return; + + for (let account of r.message) { + + const node = cur_tree.nodes && cur_tree.nodes[account.value]; + if (!node || node.is_root) continue; + + // show Dr if positive since balance is calculated as debit - credit else show Cr + const balance = account.balance_in_account_currency || account.balance; + const dr_or_cr = balance > 0 ? "Dr": "Cr"; + const format = (value, currency) => format_currency(Math.abs(value), currency); + + if (account.balance!==undefined) { + $('' + + (account.balance_in_account_currency ? + (format(account.balance_in_account_currency, account.account_currency) + " / ") : "") + + format(account.balance, account.company_currency) + + " " + dr_or_cr + + '').insertBefore(node.$ul); + } + } + }); + }, add_tree_node: 'erpnext.accounts.utils.add_ac', menu_items:[ { @@ -122,24 +165,6 @@ frappe.treeview_settings["Account"] = { } }, "add"); }, - onrender: function(node) { - if (frappe.boot.user.can_read.indexOf("GL Entry") !== -1) { - - // show Dr if positive since balance is calculated as debit - credit else show Cr - let balance = node.data.balance_in_account_currency || node.data.balance; - let dr_or_cr = balance > 0 ? "Dr": "Cr"; - - if (node.data && node.data.balance!==undefined) { - $('' - + (node.data.balance_in_account_currency ? - (format_currency(Math.abs(node.data.balance_in_account_currency), - node.data.account_currency) + " / ") : "") - + format_currency(Math.abs(node.data.balance), node.data.company_currency) - + " " + dr_or_cr - + '').insertBefore(node.$ul); - } - } - }, toolbar: [ { label:__("Add Child"), diff --git a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py index d6ccd169362..05caafe1c47 100644 --- a/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py +++ b/erpnext/accounts/doctype/account/chart_of_accounts/chart_of_accounts.py @@ -12,7 +12,7 @@ from six import iteritems from unidecode import unidecode -def create_charts(company, chart_template=None, existing_company=None, custom_chart=None): +def create_charts(company, chart_template=None, existing_company=None, custom_chart=None, from_coa_importer=None): chart = custom_chart or get_chart(chart_template, existing_company) if chart: accounts = [] @@ -22,7 +22,7 @@ def create_charts(company, chart_template=None, existing_company=None, custom_ch if root_account: root_type = child.get("root_type") - if account_name not in ["account_number", "account_type", + if account_name not in ["account_name", "account_number", "account_type", "root_type", "is_group", "tax_rate"]: account_number = cstr(child.get("account_number")).strip() @@ -35,7 +35,7 @@ def create_charts(company, chart_template=None, existing_company=None, custom_ch account = frappe.get_doc({ "doctype": "Account", - "account_name": account_name, + "account_name": child.get('account_name') if from_coa_importer else account_name, "company": company, "parent_account": parent, "is_group": is_group, @@ -213,7 +213,7 @@ def validate_bank_account(coa, bank_account): return (bank_account in accounts) @frappe.whitelist() -def build_tree_from_json(chart_template, chart_data=None): +def build_tree_from_json(chart_template, chart_data=None, from_coa_importer=False): ''' get chart template from its folder and parse the json to be rendered as tree ''' chart = chart_data or get_chart(chart_template) @@ -226,9 +226,12 @@ def build_tree_from_json(chart_template, chart_data=None): ''' recursively called to form a parent-child based list of dict from chart template ''' for account_name, child in iteritems(children): account = {} - if account_name in ["account_number", "account_type",\ + if account_name in ["account_name", "account_number", "account_type",\ "root_type", "is_group", "tax_rate"]: continue + if from_coa_importer: + account_name = child['account_name'] + account['parent_account'] = parent account['expandable'] = True if identify_is_group(child) else False account['value'] = (cstr(child.get('account_number')).strip() + ' - ' + account_name) \ diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 935e29a9d33..baab628b210 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -175,7 +175,7 @@ "default": "0", "fieldname": "automatically_fetch_payment_terms", "fieldtype": "Check", - "label": "Automatically Fetch Payment Terms" + "label": "Automatically Fetch Payment Terms from Order" }, { "description": "The percentage you are allowed to bill more against the amount ordered. For example, if the order value is $100 for an item and tolerance is set as 10%, then you are allowed to bill up to $110 ", @@ -283,7 +283,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-08-19 11:17:38.788054", + "modified": "2021-10-11 17:42:36.427699", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", diff --git a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py index 5e596f8677d..eabe408d640 100644 --- a/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py +++ b/erpnext/accounts/doctype/chart_of_accounts_importer/chart_of_accounts_importer.py @@ -69,7 +69,7 @@ def import_coa(file_name, company): frappe.local.flags.ignore_root_company_validation = True forest = build_forest(data) - create_charts(company, custom_chart=forest) + create_charts(company, custom_chart=forest, from_coa_importer=True) # trigger on_update for company to reset default accounts set_default_accounts(company) @@ -148,7 +148,7 @@ def get_coa(doctype, parent, is_root=False, file_name=None, for_validate=0): if not for_validate: forest = build_forest(data) - accounts = build_tree_from_json("", chart_data=forest) # returns a list of dict in a tree render-able form + accounts = build_tree_from_json("", chart_data=forest, from_coa_importer=True) # returns a list of dict in a tree render-able form # filter out to show data for the selected node only accounts = [d for d in accounts if d['parent_account']==parent] @@ -212,11 +212,14 @@ def build_forest(data): if not account_name: error_messages.append("Row {0}: Please enter Account Name".format(line_no)) + name = account_name if account_number: account_number = cstr(account_number).strip() account_name = "{} - {}".format(account_number, account_name) charts_map[account_name] = {} + charts_map[account_name]['account_name'] = name + if account_number: charts_map[account_name]["account_number"] = account_number if cint(is_group) == 1: charts_map[account_name]["is_group"] = is_group if account_type: charts_map[account_name]["account_type"] = account_type if root_type: charts_map[account_name]["root_type"] = root_type diff --git a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py index 0813926f5f2..003389e0b51 100644 --- a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py +++ b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py @@ -16,7 +16,7 @@ class LoyaltyPointEntry(Document): def get_loyalty_point_entries(customer, loyalty_program, company, expiry_date=None): if not expiry_date: - date = today() + expiry_date = today() return frappe.db.sql(''' select name, loyalty_points, expiry_date, loyalty_program_tier, invoice_type, invoice diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 607f85c87bd..9b4a91d4e96 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -390,6 +390,9 @@ class PaymentEntry(AccountsController): invoice_paid_amount_map[invoice_key]['discounted_amt'] = ref.total_amount * (term.discount / 100) for key, allocated_amount in iteritems(invoice_payment_amount_map): + if not invoice_paid_amount_map.get(key): + frappe.throw(_('Payment term {0} not used in {1}').format(key[0], key[1])) + outstanding = flt(invoice_paid_amount_map.get(key, {}).get('outstanding')) discounted_amt = flt(invoice_paid_amount_map.get(key, {}).get('discounted_amt')) @@ -502,12 +505,13 @@ class PaymentEntry(AccountsController): def validate_received_amount(self): if self.paid_from_account_currency == self.paid_to_account_currency: - if self.paid_amount != self.received_amount: - frappe.throw(_("Received Amount should be same as Paid Amount")) + if self.paid_amount < self.received_amount: + frappe.throw(_("Received Amount cannot be greater than Paid Amount")) def set_received_amount(self): self.base_received_amount = self.base_paid_amount - if self.paid_from_account_currency == self.paid_to_account_currency: + if self.paid_from_account_currency == self.paid_to_account_currency \ + and not self.payment_type == 'Internal Transfer': self.received_amount = self.paid_amount def set_amounts_after_tax(self): @@ -709,10 +713,14 @@ class PaymentEntry(AccountsController): dr_or_cr = "credit" if erpnext.get_party_account_type(self.party_type) == 'Receivable' else "debit" for d in self.get("references"): + cost_center = self.cost_center + if d.reference_doctype == "Sales Invoice" and not cost_center: + cost_center = frappe.db.get_value(d.reference_doctype, d.reference_name, "cost_center") gle = party_gl_dict.copy() gle.update({ "against_voucher_type": d.reference_doctype, - "against_voucher": d.reference_name + "against_voucher": d.reference_name, + "cost_center": cost_center }) allocated_amount_in_company_currency = flt(flt(d.allocated_amount) * flt(d.exchange_rate), diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js index bcba13eb288..74531879e95 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js @@ -52,21 +52,35 @@ erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.ext refresh: function() { this.frm.disable_save(); + this.frm.set_df_property('invoices', 'cannot_delete_rows', true); + this.frm.set_df_property('payments', 'cannot_delete_rows', true); + this.frm.set_df_property('allocation', 'cannot_delete_rows', true); + + this.frm.set_df_property('invoices', 'cannot_add_rows', true); + this.frm.set_df_property('payments', 'cannot_add_rows', true); + this.frm.set_df_property('allocation', 'cannot_add_rows', true); + if (this.frm.doc.receivable_payable_account) { this.frm.add_custom_button(__('Get Unreconciled Entries'), () => this.frm.trigger("get_unreconciled_entries") ); + this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'primary'); } if (this.frm.doc.invoices.length && this.frm.doc.payments.length) { this.frm.add_custom_button(__('Allocate'), () => this.frm.trigger("allocate") ); + this.frm.change_custom_button_type('Allocate', null, 'primary'); + this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'default'); } if (this.frm.doc.allocation.length) { this.frm.add_custom_button(__('Reconcile'), () => this.frm.trigger("reconcile") ); + this.frm.change_custom_button_type('Reconcile', null, 'primary'); + this.frm.change_custom_button_type('Get Unreconciled Entries', null, 'default'); + this.frm.change_custom_button_type('Allocate', null, 'default'); } }, diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json index 9023b3646f2..eb0c20f92d9 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.json @@ -12,15 +12,16 @@ "receivable_payable_account", "col_break1", "from_invoice_date", - "to_invoice_date", - "minimum_invoice_amount", - "maximum_invoice_amount", - "invoice_limit", - "column_break_13", "from_payment_date", - "to_payment_date", + "minimum_invoice_amount", "minimum_payment_amount", + "column_break_11", + "to_invoice_date", + "to_payment_date", + "maximum_invoice_amount", "maximum_payment_amount", + "column_break_13", + "invoice_limit", "payment_limit", "bank_cash_account", "sec_break1", @@ -79,6 +80,7 @@ }, { "depends_on": "eval:(doc.payments).length || (doc.invoices).length", + "description": "If you need to reconcile particular transactions against each other, then please select accordingly. If not, all the transactions will be allocated in FIFO order.", "fieldname": "sec_break1", "fieldtype": "Section Break", "label": "Unreconciled Entries" @@ -163,6 +165,7 @@ "label": "Maximum Payment Amount" }, { + "description": "System will fetch all the entries if limit value is zero.", "fieldname": "payment_limit", "fieldtype": "Int", "label": "Payment Limit" @@ -171,13 +174,17 @@ "fieldname": "maximum_invoice_amount", "fieldtype": "Currency", "label": "Maximum Invoice Amount" + }, + { + "fieldname": "column_break_11", + "fieldtype": "Column Break" } ], "hide_toolbar": 1, "icon": "icon-resize-horizontal", "issingle": 1, "links": [], - "modified": "2021-08-30 13:05:51.977861", + "modified": "2021-10-04 20:27:11.114194", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Reconciliation", diff --git a/erpnext/accounts/doctype/payment_reconciliation_allocation/payment_reconciliation_allocation.json b/erpnext/accounts/doctype/payment_reconciliation_allocation/payment_reconciliation_allocation.json index b8c65eea847..6a21692c6ac 100644 --- a/erpnext/accounts/doctype/payment_reconciliation_allocation/payment_reconciliation_allocation.json +++ b/erpnext/accounts/doctype/payment_reconciliation_allocation/payment_reconciliation_allocation.json @@ -14,8 +14,8 @@ "section_break_6", "allocated_amount", "unreconciled_amount", - "amount", "column_break_8", + "amount", "is_advance", "section_break_5", "difference_amount", @@ -127,12 +127,13 @@ "fieldname": "reference_row", "fieldtype": "Data", "hidden": 1, - "label": "Reference Row" + "label": "Reference Row", + "read_only": 1 } ], "istable": 1, "links": [], - "modified": "2021-09-20 17:23:09.455803", + "modified": "2021-10-06 11:48:59.616562", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Reconciliation Allocation", diff --git a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py index 83ecfb47bb5..7c53f4a0b07 100644 --- a/erpnext/accounts/doctype/pos_profile/test_pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/test_pos_profile.py @@ -33,7 +33,9 @@ class TestPOSProfile(unittest.TestCase): frappe.db.sql("delete from `tabPOS Profile`") -def get_customers_list(pos_profile={}): +def get_customers_list(pos_profile=None): + if pos_profile is None: + pos_profile = {} cond = "1=1" customer_groups = [] if pos_profile.get('customer_groups'): diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 12b486e45eb..0637fdaef02 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -398,7 +398,9 @@ def get_qty_and_rate_for_other_item(doc, pr_doc, pricing_rules): pricing_rules[0].apply_rule_on_other_items = items return pricing_rules -def get_qty_amount_data_for_cumulative(pr_doc, doc, items=[]): +def get_qty_amount_data_for_cumulative(pr_doc, doc, items=None): + if items is None: + items = [] sum_qty, sum_amt = [0, 0] doctype = doc.get('parenttype') or doc.doctype diff --git a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py index d09f7dc2da2..f5391ca4cc9 100644 --- a/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py +++ b/erpnext/accounts/doctype/promotional_scheme/promotional_scheme.py @@ -69,7 +69,9 @@ class PromotionalScheme(Document): {'promotional_scheme': self.name}): frappe.delete_doc('Pricing Rule', rule.name) -def get_pricing_rules(doc, rules = {}): +def get_pricing_rules(doc, rules=None): + if rules is None: + rules = {} new_doc = [] for child_doc, fields in {'price_discount_slabs': price_discount_fields, 'product_discount_slabs': product_discount_fields}.items(): @@ -78,7 +80,9 @@ def get_pricing_rules(doc, rules = {}): return new_doc -def _get_pricing_rules(doc, child_doc, discount_fields, rules = {}): +def _get_pricing_rules(doc, child_doc, discount_fields, rules=None): + if rules is None: + rules = {} new_doc = [] args = get_args_for_pricing_rule(doc) applicable_for = frappe.scrub(doc.get('applicable_for')) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json index 55e288eeef9..03cbc4acbc4 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json @@ -149,16 +149,18 @@ "cb_17", "hold_comment", "more_info", + "status", + "inter_company_invoice_reference", + "represents_company", + "column_break_147", + "is_internal_supplier", + "accounting_details_section", "credit_to", "party_account_currency", "is_opening", "against_expense_account", "column_break_63", "unrealized_profit_loss_account", - "status", - "inter_company_invoice_reference", - "is_internal_supplier", - "represents_company", "remarks", "subscription_section", "from_date", @@ -1171,6 +1173,15 @@ "options": "fa fa-file-text", "print_hide": 1 }, + { + "default": "0", + "fetch_from": "supplier.is_internal_supplier", + "fieldname": "is_internal_supplier", + "fieldtype": "Check", + "ignore_user_permissions": 1, + "label": "Is Internal Supplier", + "read_only": 1 + }, { "fieldname": "credit_to", "fieldtype": "Link", @@ -1196,7 +1207,7 @@ "default": "No", "fieldname": "is_opening", "fieldtype": "Select", - "label": "Is Opening", + "label": "Is Opening Entry", "oldfieldname": "is_opening", "oldfieldtype": "Select", "options": "No\nYes", @@ -1298,15 +1309,6 @@ "fieldname": "dimension_col_break", "fieldtype": "Column Break" }, - { - "default": "0", - "fetch_from": "supplier.is_internal_supplier", - "fieldname": "is_internal_supplier", - "fieldtype": "Check", - "ignore_user_permissions": 1, - "label": "Is Internal Supplier", - "read_only": 1 - }, { "fieldname": "tax_withholding_category", "fieldtype": "Link", @@ -1395,13 +1397,24 @@ "hidden": 1, "label": "Ignore Default Payment Terms Template", "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "accounting_details_section", + "fieldtype": "Section Break", + "label": "Accounting Details", + "print_hide": 1 + }, + { + "fieldname": "column_break_147", + "fieldtype": "Column Break" } ], "icon": "fa fa-file-text", "idx": 204, "is_submittable": 1, "links": [], - "modified": "2021-09-28 13:10:28.351810", + "modified": "2021-10-12 20:55:16.145651", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice", diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 16f06bd9176..be0dd92f340 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -15,6 +15,7 @@ from erpnext.accounts.deferred_revenue import validate_service_stop_date from erpnext.accounts.doctype.gl_entry.gl_entry import update_outstanding_amt from erpnext.accounts.doctype.sales_invoice.sales_invoice import ( check_if_return_invoice_linked_with_payment_entry, + get_total_in_party_account_currency, is_overdue, unlink_inter_company_doc, update_linked_doc, @@ -1147,6 +1148,7 @@ class PurchaseInvoice(BuyingController): return outstanding_amount = flt(self.outstanding_amount, self.precision("outstanding_amount")) + total = get_total_in_party_account_currency(self) if not status: if self.docstatus == 2: @@ -1154,9 +1156,9 @@ class PurchaseInvoice(BuyingController): elif self.docstatus == 1: if self.is_internal_transfer(): self.status = 'Internal Transfer' - elif is_overdue(self): + elif is_overdue(self, total): self.status = "Overdue" - elif 0 < outstanding_amount < flt(self.grand_total, self.precision("grand_total")): + elif 0 < outstanding_amount < total: self.status = "Partly Paid" elif outstanding_amount > 0 and getdate(self.due_date) >= getdate(): self.status = "Unpaid" diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index f59f5748f35..24928186b6b 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -446,12 +446,15 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte }, currency() { + var me = this; this._super(); - $.each(cur_frm.doc.timesheets, function(i, d) { - let row = frappe.get_doc(d.doctype, d.name) - set_timesheet_detail_rate(row.doctype, row.name, cur_frm.doc.currency, row.timesheet_detail) - }); - calculate_total_billing_amount(cur_frm) + if (this.frm.doc.timesheets) { + this.frm.doc.timesheets.forEach((d) => { + let row = frappe.get_doc(d.doctype, d.name) + set_timesheet_detail_rate(row.doctype, row.name, me.frm.doc.currency, row.timesheet_detail) + }); + frm.trigger("calculate_timesheet_totals"); + } } }); @@ -999,7 +1002,7 @@ frappe.ui.form.on('Sales Invoice', { frappe.ui.form.on("Sales Invoice Timesheet", { - timesheets_remove(frm, cdt, cdn) { + timesheets_remove(frm) { frm.trigger("calculate_timesheet_totals"); } }); diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index a24164487e6..93e32f1a18c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -124,6 +124,13 @@ "total_advance", "outstanding_amount", "disable_rounded_total", + "column_break4", + "write_off_amount", + "base_write_off_amount", + "write_off_outstanding_amount_automatically", + "column_break_74", + "write_off_account", + "write_off_cost_center", "advances_section", "allocate_advances_automatically", "get_advances", @@ -144,13 +151,6 @@ "column_break_90", "change_amount", "account_for_change_amount", - "column_break4", - "write_off_amount", - "base_write_off_amount", - "write_off_outstanding_amount_automatically", - "column_break_74", - "write_off_account", - "write_off_cost_center", "terms_section_break", "tc_name", "terms", @@ -161,14 +161,14 @@ "column_break_84", "language", "more_information", + "status", "inter_company_invoice_reference", - "is_internal_customer", "represents_company", "customer_group", "campaign", - "is_discounted", "col_break23", - "status", + "is_internal_customer", + "is_discounted", "source", "more_info", "debit_to", @@ -1990,16 +1990,6 @@ "label": "Additional Discount Account", "options": "Account" }, - { - "default": "0", - "fieldname": "ignore_default_payment_terms_template", - "fieldtype": "Check", - "hidden": 1, - "label": "Ignore Default Payment Terms Template", - "read_only": 1, - "show_days": 1, - "show_seconds": 1 - }, { "allow_on_submit": 1, "fieldname": "dispatch_address_name", @@ -2015,6 +2005,14 @@ "label": "Dispatch Address", "read_only": 1 }, + { + "default": "0", + "fieldname": "ignore_default_payment_terms_template", + "fieldtype": "Check", + "hidden": 1, + "label": "Ignore Default Payment Terms Template", + "read_only": 1 + }, { "fieldname": "total_billing_hours", "fieldtype": "Float", @@ -2033,7 +2031,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2021-09-28 13:09:34.391799", + "modified": "2021-10-11 20:19:38.667508", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", @@ -2088,4 +2086,4 @@ "title_field": "title", "track_changes": 1, "track_seen": 1 -} +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 65d7f46dea8..902fceeac75 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1296,12 +1296,20 @@ class SalesInvoice(SellingController): serial_nos = item.serial_no or "" si_serial_nos = set(get_serial_nos(serial_nos)) + serial_no_diff = si_serial_nos - dn_serial_nos - if si_serial_nos - dn_serial_nos: - frappe.throw(_("Serial Numbers in row {0} does not match with Delivery Note").format(item.idx)) + if serial_no_diff: + dn_link = frappe.utils.get_link_to_form("Delivery Note", item.delivery_note) + serial_no_msg = ", ".join(frappe.bold(d) for d in serial_no_diff) + + msg = _("Row #{0}: The following Serial Nos are not present in Delivery Note {1}:").format( + item.idx, dn_link) + msg += " " + serial_no_msg + + frappe.throw(msg=msg, title=_("Serial Nos Mismatch")) if item.serial_no and cint(item.qty) != len(si_serial_nos): - frappe.throw(_("Row {0}: {1} Serial numbers required for Item {2}. You have provided {3}.").format( + frappe.throw(_("Row #{0}: {1} Serial numbers required for Item {2}. You have provided {3}.").format( item.idx, item.qty, item.item_code, len(si_serial_nos))) def update_project(self): @@ -1470,6 +1478,7 @@ class SalesInvoice(SellingController): return outstanding_amount = flt(self.outstanding_amount, self.precision("outstanding_amount")) + total = get_total_in_party_account_currency(self) if not status: if self.docstatus == 2: @@ -1477,9 +1486,9 @@ class SalesInvoice(SellingController): elif self.docstatus == 1: if self.is_internal_transfer(): self.status = 'Internal Transfer' - elif is_overdue(self): + elif is_overdue(self, total): self.status = "Overdue" - elif 0 < outstanding_amount < flt(self.grand_total, self.precision("grand_total")): + elif 0 < outstanding_amount < total: self.status = "Partly Paid" elif outstanding_amount > 0 and getdate(self.due_date) >= getdate(): self.status = "Unpaid" @@ -1506,27 +1515,42 @@ class SalesInvoice(SellingController): if update: self.db_set('status', self.status, update_modified = update_modified) -def is_overdue(doc): - outstanding_amount = flt(doc.outstanding_amount, doc.precision("outstanding_amount")) +def get_total_in_party_account_currency(doc): + total_fieldname = ( + "grand_total" + if doc.disable_rounded_total + else "rounded_total" + ) + if doc.party_account_currency != doc.currency: + total_fieldname = "base_" + total_fieldname + + return flt(doc.get(total_fieldname), doc.precision(total_fieldname)) + +def is_overdue(doc, total): + outstanding_amount = flt(doc.outstanding_amount, doc.precision("outstanding_amount")) if outstanding_amount <= 0: return - grand_total = flt(doc.grand_total, doc.precision("grand_total")) - nowdate = getdate() - if doc.payment_schedule: - # calculate payable amount till date - payable_amount = sum( - payment.payment_amount - for payment in doc.payment_schedule - if getdate(payment.due_date) < nowdate - ) + today = getdate() + if doc.get('is_pos') or not doc.get('payment_schedule'): + return getdate(doc.due_date) < today - if (grand_total - outstanding_amount) < payable_amount: - return True + # calculate payable amount till date + payment_amount_field = ( + "base_payment_amount" + if doc.party_account_currency != doc.currency + else "payment_amount" + ) + + payable_amount = sum( + payment.get(payment_amount_field) + for payment in doc.payment_schedule + if getdate(payment.due_date) < today + ) + + return (total - outstanding_amount) < payable_amount - elif getdate(doc.due_date) < nowdate: - return True def get_discounting_status(sales_invoice): status = None diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 67465c51acd..b457a58b812 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1085,8 +1085,6 @@ class TestSalesInvoice(unittest.TestCase): actual_qty_1 = get_qty_after_transaction(item_code = "_Test Item", warehouse = "Stores - TCP1") - frappe.db.commit() - self.assertEqual(actual_qty_0 - 5, actual_qty_1) # outgoing_rate @@ -2341,6 +2339,18 @@ class TestSalesInvoice(unittest.TestCase): si.reload() self.assertEqual(si.status, "Paid") + def test_sales_invoice_submission_post_account_freezing_date(self): + frappe.db.set_value('Accounts Settings', None, 'acc_frozen_upto', add_days(getdate(), 1)) + si = create_sales_invoice(do_not_save=True) + si.posting_date = add_days(getdate(), 1) + si.save() + + self.assertRaises(frappe.ValidationError, si.submit) + si.posting_date = getdate() + si.submit() + + frappe.db.set_value('Accounts Settings', None, 'acc_frozen_upto', None) + def get_sales_invoice_for_e_invoice(): si = make_sales_invoice_for_ewaybill() si.naming_series = 'INV-2020-.#####' diff --git a/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json b/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json index 2cddbbfceee..69b7c129f09 100644 --- a/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json +++ b/erpnext/accounts/doctype/sales_invoice_timesheet/sales_invoice_timesheet.json @@ -16,9 +16,9 @@ "column_break_9", "billing_amount", "section_break_11", - "timesheet_detail", - "column_break_5", "time_sheet", + "timesheet_detail", + "column_break_13", "project_name" ], "fields": [ @@ -91,7 +91,6 @@ "fieldtype": "Column Break" }, { - "fieldname": "section_break_7", "fieldtype": "Section Break", "label": "Totals" @@ -110,11 +109,15 @@ "fieldtype": "Data", "label": "Project Name", "read_only": 1 + }, + { + "fieldname": "column_break_13", + "fieldtype": "Column Break" } ], "istable": 1, "links": [], - "modified": "2021-08-15 18:37:08.084930", + "modified": "2021-10-02 03:48:44.979777", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Timesheet", diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index a41a548752c..ab5c46d2f85 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -33,7 +33,7 @@ class Subscription(Document): # update start just before the subscription doc is created self.update_subscription_period(self.start_date) - def update_subscription_period(self, date=None): + def update_subscription_period(self, date=None, return_date=False): """ Subscription period is the period to be billed. This method updates the beginning of the billing period and end of the billing period. @@ -41,28 +41,41 @@ class Subscription(Document): The beginning of the billing period is represented in the doctype as `current_invoice_start` and the end of the billing period is represented as `current_invoice_end`. - """ - self.set_current_invoice_start(date) - self.set_current_invoice_end() - def set_current_invoice_start(self, date=None): + If return_date is True, it wont update the start and end dates. + This is implemented to get the dates to check if is_current_invoice_generated """ - This sets the date of the beginning of the current billing period. + _current_invoice_start = self.get_current_invoice_start(date) + _current_invoice_end = self.get_current_invoice_end(_current_invoice_start) + + if return_date: + return _current_invoice_start, _current_invoice_end + + self.current_invoice_start = _current_invoice_start + self.current_invoice_end = _current_invoice_end + + def get_current_invoice_start(self, date=None): + """ + This returns the date of the beginning of the current billing period. If the `date` parameter is not given , it will be automatically set as today's date. """ - if self.is_new_subscription() and self.trial_period_end and getdate(self.trial_period_end) > getdate(self.start_date): - self.current_invoice_start = add_days(self.trial_period_end, 1) - elif self.trial_period_start and self.is_trialling(): - self.current_invoice_start = self.trial_period_start - elif date: - self.current_invoice_start = date - else: - self.current_invoice_start = nowdate() + _current_invoice_start = None - def set_current_invoice_end(self): + if self.is_new_subscription() and self.trial_period_end and getdate(self.trial_period_end) > getdate(self.start_date): + _current_invoice_start = add_days(self.trial_period_end, 1) + elif self.trial_period_start and self.is_trialling(): + _current_invoice_start = self.trial_period_start + elif date: + _current_invoice_start = date + else: + _current_invoice_start = nowdate() + + return _current_invoice_start + + def get_current_invoice_end(self, date=None): """ - This sets the date of the end of the current billing period. + This returns the date of the end of the current billing period. If the subscription is in trial period, it will be set as the end of the trial period. @@ -71,44 +84,47 @@ class Subscription(Document): current billing period where `x` is the billing interval from the `Subscription Plan` in the `Subscription`. """ - if self.is_trialling() and getdate(self.current_invoice_start) < getdate(self.trial_period_end): - self.current_invoice_end = self.trial_period_end + _current_invoice_end = None + + if self.is_trialling() and getdate(date) < getdate(self.trial_period_end): + _current_invoice_end = self.trial_period_end else: billing_cycle_info = self.get_billing_cycle_data() if billing_cycle_info: - if self.is_new_subscription() and getdate(self.start_date) < getdate(self.current_invoice_start): - self.current_invoice_end = add_to_date(self.start_date, **billing_cycle_info) + if self.is_new_subscription() and getdate(self.start_date) < getdate(date): + _current_invoice_end = add_to_date(self.start_date, **billing_cycle_info) # For cases where trial period is for an entire billing interval - if getdate(self.current_invoice_end) < getdate(self.current_invoice_start): - self.current_invoice_end = add_to_date(self.current_invoice_start, **billing_cycle_info) + if getdate(self.current_invoice_end) < getdate(date): + _current_invoice_end = add_to_date(date, **billing_cycle_info) else: - self.current_invoice_end = add_to_date(self.current_invoice_start, **billing_cycle_info) + _current_invoice_end = add_to_date(date, **billing_cycle_info) else: - self.current_invoice_end = get_last_day(self.current_invoice_start) + _current_invoice_end = get_last_day(date) if self.follow_calendar_months: billing_info = self.get_billing_cycle_and_interval() billing_interval_count = billing_info[0]['billing_interval_count'] calendar_months = get_calendar_months(billing_interval_count) calendar_month = 0 - current_invoice_end_month = getdate(self.current_invoice_end).month - current_invoice_end_year = getdate(self.current_invoice_end).year + current_invoice_end_month = getdate(_current_invoice_end).month + current_invoice_end_year = getdate(_current_invoice_end).year for month in calendar_months: if month <= current_invoice_end_month: calendar_month = month if cint(calendar_month - billing_interval_count) <= 0 and \ - getdate(self.current_invoice_start).month != 1: + getdate(date).month != 1: calendar_month = 12 current_invoice_end_year -= 1 - self.current_invoice_end = get_last_day(cstr(current_invoice_end_year) + '-' \ - + cstr(calendar_month) + '-01') + _current_invoice_end = get_last_day(cstr(current_invoice_end_year) + '-' + cstr(calendar_month) + '-01') - if self.end_date and getdate(self.current_invoice_end) > getdate(self.end_date): - self.current_invoice_end = self.end_date + if self.end_date and getdate(_current_invoice_end) > getdate(self.end_date): + _current_invoice_end = self.end_date + + return _current_invoice_end @staticmethod def validate_plans_billing_cycle(billing_cycle_data): @@ -484,8 +500,9 @@ class Subscription(Document): def is_current_invoice_generated(self): invoice = self.get_current_invoice() + _current_start_date, _current_end_date = self.update_subscription_period(date=add_days(self.current_invoice_end, 1), return_date=True) - if invoice and getdate(self.current_invoice_start) <= getdate(invoice.posting_date) <= getdate(self.current_invoice_end): + if invoice and getdate(_current_start_date) <= getdate(invoice.posting_date) <= getdate(_current_end_date): return True return False @@ -538,15 +555,15 @@ class Subscription(Document): else: self.set_status_grace_period() - if getdate() > getdate(self.current_invoice_end): - self.update_subscription_period(add_days(self.current_invoice_end, 1)) - # Generate invoices periodically even if current invoice are unpaid if self.generate_new_invoices_past_due_date and not self.is_current_invoice_generated() and (self.is_postpaid_to_invoice() or self.is_prepaid_to_invoice()): prorate = frappe.db.get_single_value('Subscription Settings', 'prorate') self.generate_invoice(prorate) + if getdate() > getdate(self.current_invoice_end): + self.update_subscription_period(add_days(self.current_invoice_end, 1)) + @staticmethod def is_paid(invoice): """ diff --git a/erpnext/accounts/doctype/subscription/test_subscription.py b/erpnext/accounts/doctype/subscription/test_subscription.py index e2cf4d5a442..0f7a0a86a4d 100644 --- a/erpnext/accounts/doctype/subscription/test_subscription.py +++ b/erpnext/accounts/doctype/subscription/test_subscription.py @@ -18,6 +18,7 @@ from frappe.utils.data import ( from erpnext.accounts.doctype.subscription.subscription import get_prorata_factor +test_dependencies = ("UOM", "Item Group", "Item") def create_plan(): if not frappe.db.exists('Subscription Plan', '_Test Plan Name'): @@ -68,7 +69,6 @@ def create_plan(): supplier.insert() class TestSubscription(unittest.TestCase): - def setUp(self): create_plan() diff --git a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py index 16ef5fc9745..c3cb8396d0d 100644 --- a/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py +++ b/erpnext/accounts/doctype/tax_withholding_category/tax_withholding_category.py @@ -203,6 +203,9 @@ def get_tax_amount(party_type, parties, inv, tax_details, posting_date, pan_no=N # then chargeable value is "prev invoices + advances" value which cross the threshold tax_amount = get_tcs_amount(parties, inv, tax_details, vouchers, advance_vouchers) + if cint(tax_details.round_off_tax_amount): + tax_amount = round(tax_amount) + return tax_amount, tax_deducted def get_invoice_vouchers(parties, tax_details, company, party_type='Supplier'): @@ -322,9 +325,6 @@ def get_tds_amount(ldc, parties, inv, tax_details, tax_deducted, vouchers): else: tds_amount = supp_credit_amt * tax_details.rate / 100 if supp_credit_amt > 0 else 0 - if cint(tax_details.round_off_tax_amount): - tds_amount = round(tds_amount) - return tds_amount def get_tcs_amount(parties, inv, tax_details, vouchers, adv_vouchers): diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 0cee6f5b3aa..0cae16bc51a 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -293,7 +293,7 @@ def check_freezing_date(posting_date, adv_adj=False): if acc_frozen_upto: frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier') if getdate(posting_date) <= getdate(acc_frozen_upto) \ - and not frozen_accounts_modifier in frappe.get_roles() or frappe.session.user == 'Administrator': + and (frozen_accounts_modifier not in frappe.get_roles() or frappe.session.user == 'Administrator'): frappe.throw(_("You are not authorized to add or update entries before {0}").format(formatdate(acc_frozen_upto))) def set_as_cancel(voucher_type, voucher_no): diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py index d5271885b7e..bb8138bfc2e 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.py +++ b/erpnext/accounts/report/cash_flow/cash_flow.py @@ -139,9 +139,9 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_ data["total"] = total return data -def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters={}): +def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters=None): cond = "" - filters = frappe._dict(filters) + filters = frappe._dict(filters or {}) if filters.include_default_book_entries: company_fb = frappe.db.get_value("Company", company, 'default_finance_book') diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js index 6a8301a6f91..e24a5f99184 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.js @@ -103,8 +103,11 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() { column.is_tree = true; } - value = default_formatter(value, row, column, data); + if (data && data.account && column.apply_currency_formatter) { + data.currency = erpnext.get_currency(column.company_name); + } + value = default_formatter(value, row, column, data); if (!data.parent_account) { value = $(`${value}`); diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py index b0cfbac9cb1..a600ead9e54 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -3,12 +3,14 @@ from __future__ import unicode_literals +from collections import defaultdict + import frappe from frappe import _ from frappe.utils import cint, flt, getdate +import erpnext from erpnext.accounts.report.balance_sheet.balance_sheet import ( - check_opening_balance, get_chart_data, get_provisional_profit_loss, ) @@ -31,7 +33,7 @@ from erpnext.accounts.report.profit_and_loss_statement.profit_and_loss_statement from erpnext.accounts.report.profit_and_loss_statement.profit_and_loss_statement import ( get_report_summary as get_pl_summary, ) -from erpnext.accounts.report.utils import convert_to_presentation_currency +from erpnext.accounts.report.utils import convert, convert_to_presentation_currency def execute(filters=None): @@ -42,7 +44,7 @@ def execute(filters=None): fiscal_year = get_fiscal_year_data(filters.get('from_fiscal_year'), filters.get('to_fiscal_year')) companies_column, companies = get_companies(filters) - columns = get_columns(companies_column) + columns = get_columns(companies_column, filters) if filters.get('report') == "Balance Sheet": data, message, chart, report_summary = get_balance_sheet_data(fiscal_year, companies, columns, filters) @@ -73,21 +75,24 @@ def get_balance_sheet_data(fiscal_year, companies, columns, filters): provisional_profit_loss, total_credit = get_provisional_profit_loss(asset, liability, equity, companies, filters.get('company'), company_currency, True) - message, opening_balance = check_opening_balance(asset, liability, equity) + message, opening_balance = prepare_companywise_opening_balance(asset, liability, equity, companies) - if opening_balance and round(opening_balance,2) !=0: - unclosed ={ + if opening_balance: + unclosed = { "account_name": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'", "account": "'" + _("Unclosed Fiscal Years Profit / Loss (Credit)") + "'", "warn_if_negative": True, "currency": company_currency } - for company in companies: - unclosed[company] = opening_balance - if provisional_profit_loss: - provisional_profit_loss[company] = provisional_profit_loss[company] - opening_balance - unclosed["total"]=opening_balance + for company in companies: + unclosed[company] = opening_balance.get(company) + if provisional_profit_loss and provisional_profit_loss.get(company): + provisional_profit_loss[company] = ( + flt(provisional_profit_loss[company]) - flt(opening_balance.get(company)) + ) + + unclosed["total"] = opening_balance.get(company) data.append(unclosed) if provisional_profit_loss: @@ -102,6 +107,37 @@ def get_balance_sheet_data(fiscal_year, companies, columns, filters): return data, message, chart, report_summary +def prepare_companywise_opening_balance(asset_data, liability_data, equity_data, companies): + opening_balance = {} + for company in companies: + opening_value = 0 + + # opening_value = Aseet - liability - equity + for data in [asset_data, liability_data, equity_data]: + account_name = get_root_account_name(data[0].root_type, company) + opening_value += get_opening_balance(account_name, data, company) + + opening_balance[company] = opening_value + + if opening_balance: + return _("Previous Financial Year is not closed"), opening_balance + + return '', {} + +def get_opening_balance(account_name, data, company): + for row in data: + if row.get('account_name') == account_name: + return row.get('company_wise_opening_bal', {}).get(company, 0.0) + +def get_root_account_name(root_type, company): + return frappe.get_all( + 'Account', + fields=['account_name'], + filters = {'root_type': root_type, 'is_group': 1, + 'company': company, 'parent_account': ('is', 'not set')}, + as_list=1 + )[0][0] + def get_profit_loss_data(fiscal_year, companies, columns, filters): income, expense, net_profit_loss = get_income_expense_data(companies, fiscal_year, filters) company_currency = get_company_currency(filters) @@ -193,30 +229,37 @@ def get_account_type_based_data(account_type, companies, fiscal_year, filters): data["total"] = total return data -def get_columns(companies): - columns = [{ - "fieldname": "account", - "label": _("Account"), - "fieldtype": "Link", - "options": "Account", - "width": 300 - }] - - columns.append({ - "fieldname": "currency", - "label": _("Currency"), - "fieldtype": "Link", - "options": "Currency", - "hidden": 1 - }) +def get_columns(companies, filters): + columns = [ + { + "fieldname": "account", + "label": _("Account"), + "fieldtype": "Link", + "options": "Account", + "width": 300 + }, { + "fieldname": "currency", + "label": _("Currency"), + "fieldtype": "Link", + "options": "Currency", + "hidden": 1 + } + ] for company in companies: + apply_currency_formatter = 1 if not filters.presentation_currency else 0 + currency = filters.presentation_currency + if not currency: + currency = erpnext.get_company_currency(company) + columns.append({ "fieldname": company, - "label": company, + "label": f'{company} ({currency})', "fieldtype": "Currency", "options": "currency", - "width": 150 + "width": 150, + "apply_currency_formatter": apply_currency_formatter, + "company_name": company }) return columns @@ -236,6 +279,8 @@ def get_data(companies, root_type, balance_must_be, fiscal_year, filters=None, i start_date = filters.period_start_date if filters.report != 'Balance Sheet' else None end_date = filters.period_end_date + filters.end_date = end_date + gl_entries_by_account = {} for root in frappe.db.sql("""select lft, rgt from tabAccount where root_type=%s and ifnull(parent_account, '') = ''""", root_type, as_dict=1): @@ -244,9 +289,10 @@ def get_data(companies, root_type, balance_must_be, fiscal_year, filters=None, i end_date, root.lft, root.rgt, filters, gl_entries_by_account, accounts_by_name, accounts, ignore_closing_entries=False) - calculate_values(accounts_by_name, gl_entries_by_account, companies, start_date, filters) + calculate_values(accounts_by_name, gl_entries_by_account, companies, filters, fiscal_year) accumulate_values_into_parents(accounts, accounts_by_name, companies) - out = prepare_data(accounts, start_date, end_date, balance_must_be, companies, company_currency) + + out = prepare_data(accounts, start_date, end_date, balance_must_be, companies, company_currency, filters) if out: add_total_row(out, root_type, balance_must_be, companies, company_currency) @@ -257,7 +303,10 @@ def get_company_currency(filters=None): return (filters.get('presentation_currency') or frappe.get_cached_value('Company', filters.company, "default_currency")) -def calculate_values(accounts_by_name, gl_entries_by_account, companies, start_date, filters): +def calculate_values(accounts_by_name, gl_entries_by_account, companies, filters, fiscal_year): + start_date = (fiscal_year.year_start_date + if filters.filter_based_on == 'Fiscal Year' else filters.period_start_date) + for entries in gl_entries_by_account.values(): for entry in entries: if entry.account_number: @@ -266,15 +315,32 @@ def calculate_values(accounts_by_name, gl_entries_by_account, companies, start_d account_name = entry.account_name d = accounts_by_name.get(account_name) + if d: + debit, credit = 0, 0 for company in companies: # check if posting date is within the period if (entry.company == company or (filters.get('accumulated_in_group_company')) and entry.company in companies.get(company)): - d[company] = d.get(company, 0.0) + flt(entry.debit) - flt(entry.credit) + parent_company_currency = erpnext.get_company_currency(d.company) + child_company_currency = erpnext.get_company_currency(entry.company) + + debit, credit = flt(entry.debit), flt(entry.credit) + + if (not filters.get('presentation_currency') + and entry.company != company + and parent_company_currency != child_company_currency + and filters.get('accumulated_in_group_company')): + debit = convert(debit, parent_company_currency, child_company_currency, filters.end_date) + credit = convert(credit, parent_company_currency, child_company_currency, filters.end_date) + + d[company] = d.get(company, 0.0) + flt(debit) - flt(credit) + + if entry.posting_date < getdate(start_date): + d['company_wise_opening_bal'][company] += (flt(debit) - flt(credit)) if entry.posting_date < getdate(start_date): - d["opening_balance"] = d.get("opening_balance", 0.0) + flt(entry.debit) - flt(entry.credit) + d["opening_balance"] = d.get("opening_balance", 0.0) + flt(debit) - flt(credit) def accumulate_values_into_parents(accounts, accounts_by_name, companies): """accumulate children's values in parent accounts""" @@ -282,17 +348,18 @@ def accumulate_values_into_parents(accounts, accounts_by_name, companies): if d.parent_account: account = d.parent_account_name - if not accounts_by_name.get(account): - continue + # if not accounts_by_name.get(account): + # continue for company in companies: accounts_by_name[account][company] = \ accounts_by_name[account].get(company, 0.0) + d.get(company, 0.0) + accounts_by_name[account]['company_wise_opening_bal'][company] += d.get('company_wise_opening_bal', {}).get(company, 0.0) + accounts_by_name[account]["opening_balance"] = \ accounts_by_name[account].get("opening_balance", 0.0) + d.get("opening_balance", 0.0) - def get_account_heads(root_type, companies, filters): accounts = get_accounts(root_type, filters) @@ -353,7 +420,7 @@ def get_accounts(root_type, filters): `tabAccount` where company = %s and root_type = %s """ , (filters.get('company'), root_type), as_dict=1) -def prepare_data(accounts, start_date, end_date, balance_must_be, companies, company_currency): +def prepare_data(accounts, start_date, end_date, balance_must_be, companies, company_currency, filters): data = [] for d in accounts: @@ -367,10 +434,13 @@ def prepare_data(accounts, start_date, end_date, balance_must_be, companies, com "parent_account": _(d.parent_account), "indent": flt(d.indent), "year_start_date": start_date, + "root_type": d.root_type, "year_end_date": end_date, - "currency": company_currency, + "currency": filters.presentation_currency, + "company_wise_opening_bal": d.company_wise_opening_bal, "opening_balance": d.get("opening_balance", 0.0) * (1 if balance_must_be == "Debit" else -1) }) + for company in companies: if d.get(company) and balance_must_be == "Credit": # change sign based on Debit or Credit, since calculation is done using (debit - credit) @@ -385,6 +455,7 @@ def prepare_data(accounts, start_date, end_date, balance_must_be, companies, com row["has_value"] = has_value row["total"] = total + data.append(row) return data @@ -447,6 +518,7 @@ def get_account_details(account): 'is_group', 'account_name', 'account_number', 'parent_account', 'lft', 'rgt'], as_dict=1) def validate_entries(key, entry, accounts_by_name, accounts): + # If an account present in the child company and not in the parent company if key not in accounts_by_name: args = get_account_details(entry.account) @@ -456,12 +528,23 @@ def validate_entries(key, entry, accounts_by_name, accounts): args.update({ 'lft': parent_args.lft + 1, 'rgt': parent_args.rgt - 1, + 'indent': 3, 'root_type': parent_args.root_type, - 'report_type': parent_args.report_type + 'report_type': parent_args.report_type, + 'parent_account_name': parent_args.account_name, + 'company_wise_opening_bal': defaultdict(float) }) accounts_by_name.setdefault(key, args) - accounts.append(args) + + idx = len(accounts) + # To identify parent account index + for index, row in enumerate(accounts): + if row.parent_account_name == args.parent_account_name: + idx = index + break + + accounts.insert(idx+1, args) def get_additional_conditions(from_date, ignore_closing_entries, filters): additional_conditions = [] @@ -491,7 +574,6 @@ def add_total_row(out, root_type, balance_must_be, companies, company_currency): for company in companies: total_row.setdefault(company, 0.0) total_row[company] += row.get(company, 0.0) - row[company] = 0.0 total_row.setdefault("total", 0.0) total_row["total"] += flt(row["total"]) @@ -511,6 +593,7 @@ def filter_accounts(accounts, depth=10): account_name = d.account_number + ' - ' + d.account_name else: account_name = d.account_name + d['company_wise_opening_bal'] = defaultdict(float) accounts_by_name[account_name] = d parent_children_map.setdefault(d.parent_account or None, []).append(d) diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index 5bd6e583dbb..0094bc2eebe 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -421,8 +421,6 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map): update_value_in_dict(totals, 'closing', gle) elif gle.posting_date <= to_date: - update_value_in_dict(gle_map[gle.get(group_by)].totals, 'total', gle) - update_value_in_dict(totals, 'total', gle) if filters.get("group_by") != 'Group by Voucher (Consolidated)': gle_map[gle.get(group_by)].entries.append(gle) elif filters.get("group_by") == 'Group by Voucher (Consolidated)': @@ -436,10 +434,11 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map): else: update_value_in_dict(consolidated_gle, key, gle) - update_value_in_dict(gle_map[gle.get(group_by)].totals, 'closing', gle) - update_value_in_dict(totals, 'closing', gle) - for key, value in consolidated_gle.items(): + update_value_in_dict(gle_map[value.get(group_by)].totals, 'total', value) + update_value_in_dict(totals, 'total', value) + update_value_in_dict(gle_map[value.get(group_by)].totals, 'closing', value) + update_value_in_dict(totals, 'closing', value) entries.append(value) return totals, entries diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 848a3a36b12..b425062dc6f 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -4,11 +4,14 @@ from __future__ import unicode_literals +from json import loads + import frappe import frappe.defaults from frappe import _, throw from frappe.model.meta import get_field_precision from frappe.utils import cint, cstr, flt, formatdate, get_number_format_info, getdate, now, nowdate +from six import string_types import erpnext @@ -787,16 +790,28 @@ def get_children(doctype, parent, company, is_root=False): if doctype == 'Account': sort_accounts(acc, is_root, key="value") - company_currency = frappe.get_cached_value('Company', company, "default_currency") - for each in acc: - each["company_currency"] = company_currency - each["balance"] = flt(get_balance_on(each.get("value"), in_account_currency=False, company=company)) - - if each.account_currency != company_currency: - each["balance_in_account_currency"] = flt(get_balance_on(each.get("value"), company=company)) return acc +@frappe.whitelist() +def get_account_balances(accounts, company): + + if isinstance(accounts, string_types): + accounts = loads(accounts) + + if not accounts: + return [] + + company_currency = frappe.get_cached_value("Company", company, "default_currency") + + for account in accounts: + account["company_currency"] = company_currency + account["balance"] = flt(get_balance_on(account["value"], in_account_currency=False, company=company)) + if account["account_currency"] and account["account_currency"] != company_currency: + account["balance_in_account_currency"] = flt(get_balance_on(account["value"], company=company)) + + return accounts + def create_payment_gateway_account(gateway, payment_channel="Email"): from erpnext.setup.setup_wizard.operations.install_fixtures import create_bank_account diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 7e135be30b7..99a6cc35dbb 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -194,7 +194,7 @@ class Asset(AccountsController): start = self.clear_depreciation_schedule() # value_after_depreciation - current Asset value - if d.value_after_depreciation: + if self.docstatus == 1 and d.value_after_depreciation: value_after_depreciation = (flt(d.value_after_depreciation) - flt(self.opening_accumulated_depreciation)) else: diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 7183ee7e369..cf4581b4a16 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -682,6 +682,27 @@ class TestAsset(unittest.TestCase): # reset indian company frappe.flags.company = company_flag + def test_expected_value_change(self): + """ + tests if changing `expected_value_after_useful_life` + affects `value_after_depreciation` + """ + + asset = create_asset(calculate_depreciation=1) + asset.opening_accumulated_depreciation = 2000 + asset.number_of_depreciations_booked = 1 + + asset.finance_books[0].expected_value_after_useful_life = 100 + asset.save() + asset.reload() + self.assertEquals(asset.finance_books[0].value_after_depreciation, 98000.0) + + # changing expected_value_after_useful_life shouldn't affect value_after_depreciation + asset.finance_books[0].expected_value_after_useful_life = 200 + asset.save() + asset.reload() + self.assertEquals(asset.finance_books[0].value_after_depreciation, 98000.0) + def create_asset_data(): if not frappe.db.exists("Asset Category", "Computers"): create_asset_category() diff --git a/erpnext/assets/doctype/asset_repair/test_asset_repair.py b/erpnext/assets/doctype/asset_repair/test_asset_repair.py index 9945a328cfc..30e3a5296e0 100644 --- a/erpnext/assets/doctype/asset_repair/test_asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/test_asset_repair.py @@ -22,7 +22,7 @@ class TestAssetRepair(unittest.TestCase): frappe.db.sql("delete from `tabTax Rule`") def test_update_status(self): - asset = create_asset() + asset = create_asset(submit=1) initial_status = asset.status asset_repair = create_asset_repair(asset = asset) @@ -76,7 +76,7 @@ class TestAssetRepair(unittest.TestCase): self.assertEqual(stock_entry.items[0].qty, asset_repair.stock_items[0].consumed_quantity) def test_increase_in_asset_value_due_to_stock_consumption(self): - asset = create_asset(calculate_depreciation = 1) + asset = create_asset(calculate_depreciation = 1, submit=1) initial_asset_value = get_asset_value(asset) asset_repair = create_asset_repair(asset= asset, stock_consumption = 1, submit = 1) asset.reload() @@ -85,7 +85,7 @@ class TestAssetRepair(unittest.TestCase): self.assertEqual(asset_repair.stock_items[0].total_value, increase_in_asset_value) def test_increase_in_asset_value_due_to_repair_cost_capitalisation(self): - asset = create_asset(calculate_depreciation = 1) + asset = create_asset(calculate_depreciation = 1, submit=1) initial_asset_value = get_asset_value(asset) asset_repair = create_asset_repair(asset= asset, capitalize_repair_cost = 1, submit = 1) asset.reload() @@ -103,7 +103,7 @@ class TestAssetRepair(unittest.TestCase): self.assertEqual(asset_repair.name, gl_entry.voucher_no) def test_increase_in_asset_life(self): - asset = create_asset(calculate_depreciation = 1) + asset = create_asset(calculate_depreciation = 1, submit=1) initial_num_of_depreciations = num_of_depreciations(asset) create_asset_repair(asset= asset, capitalize_repair_cost = 1, submit = 1) asset.reload() @@ -126,7 +126,7 @@ def create_asset_repair(**args): if args.asset: asset = args.asset else: - asset = create_asset(is_existing_asset = 1) + asset = create_asset(is_existing_asset = 1, submit=1) asset_repair = frappe.new_doc("Asset Repair") asset_repair.update({ "asset": asset.name, diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.js b/erpnext/buying/doctype/buying_settings/buying_settings.js index 944bb61cfeb..32431fc3910 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.js +++ b/erpnext/buying/doctype/buying_settings/buying_settings.js @@ -11,7 +11,7 @@ frappe.tour['Buying Settings'] = [ { fieldname: "supp_master_name", title: "Supplier Naming By", - description: __("By default, the Supplier Name is set as per the Supplier Name entered. If you want Suppliers to be named by a ") + "Naming Series" + __(" choose the 'Naming Series' option."), + description: __("By default, the Supplier Name is set as per the Supplier Name entered. If you want Suppliers to be named by a Naming Series choose the 'Naming Series' option."), }, { fieldname: "buying_price_list", diff --git a/erpnext/buying/form_tour/buying_settings/buying_settings.json b/erpnext/buying/form_tour/buying_settings/buying_settings.json new file mode 100644 index 00000000000..fa8c80d6cdf --- /dev/null +++ b/erpnext/buying/form_tour/buying_settings/buying_settings.json @@ -0,0 +1,77 @@ +{ + "creation": "2021-07-28 11:51:42.319984", + "docstatus": 0, + "doctype": "Form Tour", + "idx": 0, + "is_standard": 1, + "modified": "2021-10-05 13:06:56.414584", + "modified_by": "Administrator", + "module": "Buying", + "name": "Buying Settings", + "owner": "Administrator", + "reference_doctype": "Buying Settings", + "save_on_complete": 0, + "steps": [ + { + "description": "When a Supplier is saved, system generates a unique identity or name for that Supplier which can be used to refer the Supplier in various Buying transactions.", + "field": "", + "fieldname": "supp_master_name", + "fieldtype": "Select", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Supplier Naming By", + "parent_field": "", + "position": "Bottom", + "title": "Supplier Naming By" + }, + { + "description": "Configure what should be the default value of Supplier Group when creating a new Supplier.", + "field": "", + "fieldname": "supplier_group", + "fieldtype": "Link", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Default Supplier Group", + "parent_field": "", + "position": "Right", + "title": "Default Supplier Group" + }, + { + "description": "Item prices will be fetched from this Price List.", + "field": "", + "fieldname": "buying_price_list", + "fieldtype": "Link", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Default Buying Price List", + "parent_field": "", + "position": "Bottom", + "title": "Default Buying Price List" + }, + { + "description": "If this option is configured \"Yes\", ERPNext will prevent you from creating a Purchase Invoice or a Purchase Receipt directly without creating a Purchase Order first.", + "field": "", + "fieldname": "po_required", + "fieldtype": "Select", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Is Purchase Order Required for Purchase Invoice & Receipt Creation?", + "parent_field": "", + "position": "Bottom", + "title": "Purchase Order Required" + }, + { + "description": "If this option is configured \"Yes\", ERPNext will prevent you from creating a Purchase Invoice without creating a Purchase Receipt first.", + "field": "", + "fieldname": "pr_required", + "fieldtype": "Select", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Is Purchase Receipt Required for Purchase Invoice Creation?", + "parent_field": "", + "position": "Bottom", + "title": "Purchase Receipt Required" + } + ], + "title": "Buying Settings" +} \ No newline at end of file diff --git a/erpnext/buying/form_tour/purchase_order/purchase_order.json b/erpnext/buying/form_tour/purchase_order/purchase_order.json new file mode 100644 index 00000000000..3cc88fbf4fe --- /dev/null +++ b/erpnext/buying/form_tour/purchase_order/purchase_order.json @@ -0,0 +1,82 @@ +{ + "creation": "2021-07-29 14:11:58.271113", + "docstatus": 0, + "doctype": "Form Tour", + "idx": 0, + "is_standard": 1, + "modified": "2021-10-05 13:11:31.436135", + "modified_by": "Administrator", + "module": "Buying", + "name": "Purchase Order", + "owner": "Administrator", + "reference_doctype": "Purchase Order", + "save_on_complete": 1, + "steps": [ + { + "description": "Select a Supplier", + "field": "", + "fieldname": "supplier", + "fieldtype": "Link", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Supplier", + "parent_field": "", + "position": "Right", + "title": "Supplier" + }, + { + "description": "Set the \"Required By\" date for the materials. This sets the \"Required By\" date for all the items.", + "field": "", + "fieldname": "schedule_date", + "fieldtype": "Date", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Required By", + "parent_field": "", + "position": "Left", + "title": "Required By" + }, + { + "description": "Items to be purchased can be added here.", + "field": "", + "fieldname": "items", + "fieldtype": "Table", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Items", + "parent_field": "", + "position": "Bottom", + "title": "Items Table" + }, + { + "child_doctype": "Purchase Order Item", + "description": "Enter the Item Code.", + "field": "", + "fieldname": "item_code", + "fieldtype": "Link", + "has_next_condition": 1, + "is_table_field": 1, + "label": "Item Code", + "next_step_condition": "eval: doc.item_code", + "parent_field": "", + "parent_fieldname": "items", + "position": "Right", + "title": "Item Code" + }, + { + "child_doctype": "Purchase Order Item", + "description": "Enter the required quantity for the material.", + "field": "", + "fieldname": "qty", + "fieldtype": "Float", + "has_next_condition": 0, + "is_table_field": 1, + "label": "Quantity", + "parent_field": "", + "parent_fieldname": "items", + "position": "Bottom", + "title": "Quantity" + } + ], + "title": "Purchase Order" +} \ No newline at end of file diff --git a/erpnext/buying/module_onboarding/buying/buying.json b/erpnext/buying/module_onboarding/buying/buying.json index 887f85b82d1..84e97a2d4d2 100644 --- a/erpnext/buying/module_onboarding/buying/buying.json +++ b/erpnext/buying/module_onboarding/buying/buying.json @@ -19,7 +19,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/buying", "idx": 0, "is_complete": 0, - "modified": "2020-07-08 14:05:28.273641", + "modified": "2021-08-24 18:13:42.463776", "modified_by": "Administrator", "module": "Buying", "name": "Buying", @@ -28,23 +28,11 @@ { "step": "Introduction to Buying" }, - { - "step": "Create a Supplier" - }, - { - "step": "Setup your Warehouse" - }, - { - "step": "Create a Product" - }, { "step": "Create a Material Request" }, { "step": "Create your first Purchase Order" - }, - { - "step": "Buying Settings" } ], "subtitle": "Products, Purchases, Analysis, and more.", diff --git a/erpnext/buying/onboarding_step/create_a_material_request/create_a_material_request.json b/erpnext/buying/onboarding_step/create_a_material_request/create_a_material_request.json index 9dc493dd499..28e86ab0641 100644 --- a/erpnext/buying/onboarding_step/create_a_material_request/create_a_material_request.json +++ b/erpnext/buying/onboarding_step/create_a_material_request/create_a_material_request.json @@ -1,19 +1,21 @@ { - "action": "Create Entry", + "action": "Show Form Tour", + "action_label": "Let\u2019s create your first Material Request", "creation": "2020-05-15 14:39:09.818764", + "description": "# Track Material Request\n\n\nAlso known as Purchase Request or an Indent, is a document identifying a requirement of a set of items (products or services) for various purposes like procurement, transfer, issue, or manufacturing. Once the Material Request is validated, a purchase manager can take the next actions for purchasing items like requesting RFQ from a supplier or directly placing an order with an identified Supplier.\n\n", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-15 14:39:09.818764", + "modified": "2021-08-24 18:08:08.347501", "modified_by": "Administrator", "name": "Create a Material Request", "owner": "Administrator", "reference_document": "Material Request", + "show_form_tour": 1, "show_full_form": 1, - "title": "Create a Material Request", + "title": "Track Material Request", "validate_action": 1 } \ No newline at end of file diff --git a/erpnext/buying/onboarding_step/create_your_first_purchase_order/create_your_first_purchase_order.json b/erpnext/buying/onboarding_step/create_your_first_purchase_order/create_your_first_purchase_order.json index 9dbed239789..18a39315861 100644 --- a/erpnext/buying/onboarding_step/create_your_first_purchase_order/create_your_first_purchase_order.json +++ b/erpnext/buying/onboarding_step/create_your_first_purchase_order/create_your_first_purchase_order.json @@ -1,19 +1,21 @@ { - "action": "Create Entry", + "action": "Show Form Tour", + "action_label": "Let\u2019s create your first Purchase Order", "creation": "2020-05-12 18:17:49.976035", + "description": "# Create first Purchase Order\n\nPurchase Order is at the heart of your buying transactions. In ERPNext, Purchase Order can can be created against a Purchase Material Request (indent) and Supplier Quotation as well. Purchase Orders is also linked to Purchase Receipt and Purchase Invoices, allowing you to keep a birds-eye view on your purchase deals.\n\n", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-12 18:31:56.856112", + "modified": "2021-08-24 18:08:08.936484", "modified_by": "Administrator", "name": "Create your first Purchase Order", "owner": "Administrator", "reference_document": "Purchase Order", + "show_form_tour": 0, "show_full_form": 0, - "title": "Create your first Purchase Order", + "title": "Create first Purchase Order", "validate_action": 1 } \ No newline at end of file diff --git a/erpnext/buying/onboarding_step/introduction_to_buying/introduction_to_buying.json b/erpnext/buying/onboarding_step/introduction_to_buying/introduction_to_buying.json index fd98fddafae..01ac8b81760 100644 --- a/erpnext/buying/onboarding_step/introduction_to_buying/introduction_to_buying.json +++ b/erpnext/buying/onboarding_step/introduction_to_buying/introduction_to_buying.json @@ -1,19 +1,22 @@ { - "action": "Watch Video", + "action": "Show Form Tour", + "action_label": "Let\u2019s walk-through few Buying Settings", "creation": "2020-05-06 15:37:09.477765", + "description": "# Buying Settings\n\n\nBuying module\u2019s features are highly configurable as per your business needs. Buying Settings is the place where you can set your preferences for:\n\n- Supplier naming and default values\n- Billing and shipping preference in buying transactions\n\n\n", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, - "is_single": 0, + "is_single": 1, "is_skipped": 0, - "modified": "2020-05-12 18:25:08.509900", + "modified": "2021-08-24 18:08:08.345735", "modified_by": "Administrator", "name": "Introduction to Buying", "owner": "Administrator", - "show_full_form": 0, - "title": "Introduction to Buying", + "reference_document": "Buying Settings", + "show_form_tour": 1, + "show_full_form": 1, + "title": "Buying Settings", "validate_action": 1, "video_url": "https://youtu.be/efFajTTQBa8" } \ No newline at end of file diff --git a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py index a5b09473a05..fd23795287f 100644 --- a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py +++ b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py @@ -45,7 +45,6 @@ class TestProcurementTracker(unittest.TestCase): pr = make_purchase_receipt(po.name) pr.get("items")[0].cost_center = "Main - _TPC" pr.submit() - frappe.db.commit() date_obj = datetime.date(datetime.now()) po.load_from_db() diff --git a/erpnext/change_log/v13/v13_13_0.md b/erpnext/change_log/v13/v13_13_0.md new file mode 100644 index 00000000000..3da2d721744 --- /dev/null +++ b/erpnext/change_log/v13/v13_13_0.md @@ -0,0 +1,29 @@ +# Version 13.13.0 Release Notes + +### Features & Enhancements + +- HR Module onboarding ([#25741](https://github.com/frappe/erpnext/pull/25741)) +- Tracking multiple rounds for the interview ([#25482](https://github.com/frappe/erpnext/pull/25482)) +- HSN based tax breakup table check in GST Settings (India Localization) ([#27907](https://github.com/frappe/erpnext/pull/27907)) + +### Fixes + +- To improve stock transactions added indexes in stock queries and speed up bin updation ([#27758](https://github.com/frappe/erpnext/pull/27758)) +- Interstate internal transfer invoices not visible in GSTR-1 ([#27970](https://github.com/frappe/erpnext/pull/27970)) +- Account number and name incorrectly imported using COA importer ([#27967](https://github.com/frappe/erpnext/pull/27967)) +- Multiple fixes to timesheets ([#27775](https://github.com/frappe/erpnext/pull/27742)) +- Totals row incorrect value in GL Entry ([#27867](https://github.com/frappe/erpnext/pull/27867)) +- Sales Order delivery Date not getting set via data import ([#27862](https://github.com/frappe/erpnext/pull/27862)) +- Add cost center in gl entry for advance payment entry ([#27840](https://github.com/frappe/erpnext/pull/27840)) +- Item Variant selection empty popup on website ([#27924](https://github.com/frappe/erpnext/pull/27924)) +- Improve performance of fetching account balance in chart of accounts ([#27661](https://github.com/frappe/erpnext/pull/27661)) +- Chart Of Accounts import button not visible ([#27748](https://github.com/frappe/erpnext/pull/27748)) +- Website Items with same Item name unhandled, thumbnails missing ([#27720](https://github.com/frappe/erpnext/pull/27720)) +- Delete linked Transaction Deletion Record docs on deleting company ([#27785](https://github.com/frappe/erpnext/pull/27785)) +- Display appropriate message for Payment Term discrepancies in Payment Entry ([#27749](https://github.com/frappe/erpnext/pull/27749)) +- Updated buying onboarding tours. ([#27800](https://github.com/frappe/erpnext/pull/27800)) +- Fixed variant qty in BOM while making work order ([#27686](https://github.com/frappe/erpnext/pull/27686)) +- Availability slots display, disabled Practitioner Schedule ([#27812](https://github.com/frappe/erpnext/pull/27812)) +- Consolidated report not consider company currency ([#27863](https://github.com/frappe/erpnext/pull/27863)) +- Batch Number not copied from Purchase Receipt to Stock Entry ([#27794](https://github.com/frappe/erpnext/pull/27794)) +- Employee Leave Balance report should only consider ledgers of transaction type Leave Allocation ([#27728](https://github.com/frappe/erpnext/pull/27728)) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 835a16f77f6..829da8953bf 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1691,17 +1691,58 @@ def get_advance_payment_entries(party_type, party, party_account, order_doctype, def update_invoice_status(): """Updates status as Overdue for applicable invoices. Runs daily.""" + today = getdate() for doctype in ("Sales Invoice", "Purchase Invoice"): frappe.db.sql(""" - update `tab{}` as dt set dt.status = 'Overdue' - where dt.docstatus = 1 - and dt.status != 'Overdue' - and dt.outstanding_amount > 0 - and (dt.grand_total - dt.outstanding_amount) < - (select sum(payment_amount) from `tabPayment Schedule` as ps - where ps.parent = dt.name and ps.due_date < %s) - """.format(doctype), getdate()) + UPDATE `tab{doctype}` invoice SET invoice.status = 'Overdue' + WHERE invoice.docstatus = 1 + AND invoice.status REGEXP '^Unpaid|^Partly Paid' + AND invoice.outstanding_amount > 0 + AND ( + {or_condition} + ( + ( + CASE + WHEN invoice.party_account_currency = invoice.currency + THEN ( + CASE + WHEN invoice.disable_rounded_total + THEN invoice.grand_total + ELSE invoice.rounded_total + END + ) + ELSE ( + CASE + WHEN invoice.disable_rounded_total + THEN invoice.base_grand_total + ELSE invoice.base_rounded_total + END + ) + END + ) - invoice.outstanding_amount + ) < ( + SELECT SUM( + CASE + WHEN invoice.party_account_currency = invoice.currency + THEN ps.payment_amount + ELSE ps.base_payment_amount + END + ) + FROM `tabPayment Schedule` ps + WHERE ps.parent = invoice.name + AND ps.due_date < %(today)s + ) + ) + """.format( + doctype=doctype, + or_condition=( + "invoice.is_pos AND invoice.due_date < %(today)s OR" + if doctype == "Sales Invoice" + else "" + ) + ), {"today": today} + ) @frappe.whitelist() def get_payment_terms(terms_template, posting_date=None, grand_total=None, base_grand_total=None, bill_date=None): diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 78a6e52e4d7..08d422d3bcd 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -79,8 +79,15 @@ class StockController(AccountsController): def clean_serial_nos(self): for row in self.get("items"): if hasattr(row, "serial_no") and row.serial_no: - # replace commas by linefeed and remove all spaces in string - row.serial_no = row.serial_no.replace(",", "\n").replace(" ", "") + # replace commas by linefeed + row.serial_no = row.serial_no.replace(",", "\n") + + # strip preceeding and succeeding spaces for each SN + # (SN could have valid spaces in between e.g. SN - 123 - 2021) + serial_no_list = row.serial_no.split("\n") + serial_no_list = [sn.strip() for sn in serial_no_list] + + row.serial_no = "\n".join(serial_no_list) def get_gl_entries(self, warehouse_account=None, default_expense_account=None, default_cost_center=None): @@ -591,7 +598,7 @@ def future_sle_exists(args, sl_entries=None): data = frappe.db.sql(""" select item_code, warehouse, count(name) as total_row - from `tabStock Ledger Entry` + from `tabStock Ledger Entry` force index (item_warehouse) where ({}) and timestamp(posting_date, posting_time) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 0b3f50897ab..8027cbc69cc 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -34,6 +34,7 @@ class Opportunity(TransactionBase): self.validate_item_details() self.validate_uom_is_integer("uom", "qty") self.validate_cust_name() + self.map_fields() if not self.title: self.title = self.customer_name @@ -41,6 +42,15 @@ class Opportunity(TransactionBase): if not self.with_items: self.items = [] + def map_fields(self): + for field in self.meta.fields: + if not self.get(field.fieldname): + try: + value = frappe.db.get_value(self.opportunity_from, self.party_name, field.fieldname) + frappe.db.set(self, field.fieldname, value) + except Exception: + continue + def make_new_lead_if_required(self): """Set lead against new opportunity""" if (not self.get("party_name")) and self.contact_email: diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/test_e_commerce_settings.py b/erpnext/e_commerce/doctype/e_commerce_settings/test_e_commerce_settings.py index e3a1e1a16a4..7020548838c 100644 --- a/erpnext/e_commerce/doctype/e_commerce_settings/test_e_commerce_settings.py +++ b/erpnext/e_commerce/doctype/e_commerce_settings/test_e_commerce_settings.py @@ -41,7 +41,6 @@ class TestECommerceSettings(unittest.TestCase): def test_tax_rule_validation(self): frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 0") - frappe.db.commit() cart_settings = self.get_cart_settings() cart_settings.enabled = 1 diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py index c7c68cf09cf..03b9834c1d1 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.py +++ b/erpnext/e_commerce/doctype/website_item/website_item.py @@ -147,7 +147,7 @@ class WebsiteItem(WebsiteGenerator): def make_thumbnail(self): """Make a thumbnail of `website_image`""" - if frappe.flags.in_import: + if frappe.flags.in_import or frappe.flags.in_migrate: return import requests.exceptions diff --git a/erpnext/education/doctype/student/student.py b/erpnext/education/doctype/student/student.py index ae498ba57db..be4ee560a51 100644 --- a/erpnext/education/doctype/student/student.py +++ b/erpnext/education/doctype/student/student.py @@ -138,7 +138,9 @@ class Student(Document): enrollment.submit() return enrollment - def enroll_in_course(self, course_name, program_enrollment, enrollment_date=frappe.utils.datetime.datetime.now()): + def enroll_in_course(self, course_name, program_enrollment, enrollment_date=None): + if enrollment_date is None: + enrollment_date = frappe.utils.datetime.datetime.now() try: enrollment = frappe.get_doc({ "doctype": "Course Enrollment", diff --git a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py index 9cede8a2f69..d40e4109120 100644 --- a/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py +++ b/erpnext/healthcare/doctype/inpatient_record/inpatient_record.py @@ -62,7 +62,9 @@ class InpatientRecord(Document): admit_patient(self, service_unit, check_in, expected_discharge) @frappe.whitelist() - def discharge(self, check_out=now_datetime()): + def discharge(self, check_out=None): + if not check_out: + check_out = now_datetime() if (getdate(check_out) < getdate(self.admitted_datetime)): frappe.throw(_('Discharge date cannot be less than Admission date')) discharge_patient(self, check_out) diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js index 49847d5bc8a..bba001c9c0e 100644 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.js @@ -433,11 +433,12 @@ let check_and_set_availability = function(frm) { slot_html += `
${__('Maximum Capacity:')} ${slot_info.service_unit_capacity} `; } - slot_html += '

'; + slot_html += '
'; slot_html += slot_info.avail_slot.map(slot => { appointment_count = 0; disabled = false; + count_class = tool_tip = ''; start_str = slot.from_time; slot_start_time = moment(slot.from_time, 'HH:mm:ss'); slot_end_time = moment(slot.to_time, 'HH:mm:ss'); @@ -486,10 +487,11 @@ let check_and_set_availability = function(frm) { data-duration=${interval} data-service-unit="${slot_info.service_unit || ''}" style="margin: 0 10px 10px 0; width: auto;" ${disabled ? 'disabled="disabled"' : ""} - data-toggle="tooltip" title="${tool_tip}"> - ${start_str.substring(0, start_str.length - 3)}
- ${count} + data-toggle="tooltip" title="${tool_tip || ''}"> + ${start_str.substring(0, start_str.length - 3)} + ${slot_info.service_unit_capacity ? `
${count} ` : ''} `; + }).join(""); if (slot_info.service_unit_capacity) { diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index dcbcda09d81..6d4cf4a5add 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -354,7 +354,7 @@ def get_available_slots(practitioner_doc, date): validate_practitioner_schedules(schedule_entry, practitioner) practitioner_schedule = frappe.get_doc('Practitioner Schedule', schedule_entry.schedule) - if practitioner_schedule: + if practitioner_schedule and not practitioner_schedule.disabled: available_slots = [] for time_slot in practitioner_schedule.time_slots: if weekday == time_slot.day: diff --git a/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py b/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py index be8d4021144..2cc918af9e5 100644 --- a/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py +++ b/erpnext/healthcare/doctype/patient_medical_record/test_patient_medical_record.py @@ -21,6 +21,7 @@ class TestPatientMedicalRecord(unittest.TestCase): def setUp(self): frappe.db.set_value('Healthcare Settings', None, 'enable_free_follow_ups', 0) frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1) + frappe.db.sql('delete from `tabPatient Appointment`') make_pos_profile() def test_medical_record(self): diff --git a/erpnext/healthcare/doctype/therapy_plan/test_therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/test_therapy_plan.py index 4f96f6a7066..021ba9bb1c3 100644 --- a/erpnext/healthcare/doctype/therapy_plan/test_therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/test_therapy_plan.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import unittest import frappe -from frappe.utils import flt, getdate, nowdate +from frappe.utils import add_days, flt, getdate, nowdate from erpnext.healthcare.doctype.patient_appointment.test_patient_appointment import ( create_appointment, @@ -33,10 +33,12 @@ class TestTherapyPlan(unittest.TestCase): self.assertEqual(plan.status, 'Not Started') session = make_therapy_session(plan.name, plan.patient, 'Basic Rehab', '_Test Company') + session.start_date = getdate() frappe.get_doc(session).submit() self.assertEqual(frappe.db.get_value('Therapy Plan', plan.name, 'status'), 'In Progress') session = make_therapy_session(plan.name, plan.patient, 'Basic Rehab', '_Test Company') + session.start_date = add_days(getdate(), 1) frappe.get_doc(session).submit() self.assertEqual(frappe.db.get_value('Therapy Plan', plan.name, 'status'), 'Completed') @@ -44,6 +46,7 @@ class TestTherapyPlan(unittest.TestCase): appointment = create_appointment(patient, practitioner, nowdate()) session = make_therapy_session(plan.name, plan.patient, 'Basic Rehab', '_Test Company', appointment.name) + session.start_date = add_days(getdate(), 2) session = frappe.get_doc(session) session.submit() self.assertEqual(frappe.db.get_value('Patient Appointment', appointment.name, 'status'), 'Closed') diff --git a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py index 6d63f391895..b31a9527a8c 100644 --- a/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py +++ b/erpnext/healthcare/doctype/therapy_plan/therapy_plan.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document -from frappe.utils import flt, today +from frappe.utils import flt class TherapyPlan(Document): @@ -63,8 +63,6 @@ def make_therapy_session(therapy_plan, patient, therapy_type, company, appointme therapy_session.exercises = therapy_type.exercises therapy_session.appointment = appointment - if frappe.flags.in_test: - therapy_session.start_date = today() return therapy_session.as_dict() diff --git a/erpnext/healthcare/utils.py b/erpnext/healthcare/utils.py index 0d2d89d6e0e..2b60231bdb7 100644 --- a/erpnext/healthcare/utils.py +++ b/erpnext/healthcare/utils.py @@ -611,7 +611,7 @@ def render_docs_as_html(docs): @frappe.whitelist() -def render_doc_as_html(doctype, docname, exclude_fields = []): +def render_doc_as_html(doctype, docname, exclude_fields = None): """ Render document as HTML """ @@ -622,6 +622,9 @@ def render_doc_as_html(doctype, docname, exclude_fields = []): sec_on = has_data = False col_on = 0 + if exclude_fields is None: + exclude_fields = [] + for df in meta.fields: # on section break append previous section and html to doc html if df.fieldtype == "Section Break": diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 396e1c48041..3094deaafa7 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -338,6 +338,7 @@ scheduler_events = { "all": [ "erpnext.projects.doctype.project.project.project_status_update_reminder", "erpnext.healthcare.doctype.patient_appointment.patient_appointment.send_appointment_reminder", + "erpnext.hr.doctype.interview.interview.send_interview_reminder", "erpnext.crm.doctype.social_media_post.social_media_post.process_scheduled_social_media_posts" ], "hourly": [ @@ -383,6 +384,7 @@ scheduler_events = { "erpnext.buying.doctype.supplier_quotation.supplier_quotation.set_expired_status", "erpnext.accounts.doctype.process_statement_of_accounts.process_statement_of_accounts.send_auto_email", "erpnext.non_profit.doctype.membership.membership.set_expired_status" + "erpnext.hr.doctype.interview.interview.send_daily_feedback_reminder" ], "daily_long": [ "erpnext.setup.doctype.email_digest.email_digest.send", diff --git a/erpnext/hr/doctype/attendance/attendance_list.js b/erpnext/hr/doctype/attendance/attendance_list.js index 9a3bac0eb23..6b3c29a76b4 100644 --- a/erpnext/hr/doctype/attendance/attendance_list.js +++ b/erpnext/hr/doctype/attendance/attendance_list.js @@ -9,83 +9,86 @@ frappe.listview_settings['Attendance'] = { return [__(doc.status), "orange", "status,=," + doc.status]; } }, + onload: function(list_view) { let me = this; - const months = moment.months() - list_view.page.add_inner_button( __("Mark Attendance"), function() { + const months = moment.months(); + list_view.page.add_inner_button(__("Mark Attendance"), function() { let dialog = new frappe.ui.Dialog({ title: __("Mark Attendance"), - fields: [ - { - fieldname: 'employee', - label: __('For Employee'), - fieldtype: 'Link', - options: 'Employee', - get_query: () => { - return {query: "erpnext.controllers.queries.employee_query"} - }, - reqd: 1, - onchange: function() { - dialog.set_df_property("unmarked_days", "hidden", 1); - dialog.set_df_property("status", "hidden", 1); - dialog.set_df_property("month", "value", ''); + fields: [{ + fieldname: 'employee', + label: __('For Employee'), + fieldtype: 'Link', + options: 'Employee', + get_query: () => { + return {query: "erpnext.controllers.queries.employee_query"}; + }, + reqd: 1, + onchange: function() { + dialog.set_df_property("unmarked_days", "hidden", 1); + dialog.set_df_property("status", "hidden", 1); + dialog.set_df_property("month", "value", ''); + dialog.set_df_property("unmarked_days", "options", []); + dialog.no_unmarked_days_left = false; + } + }, + { + label: __("For Month"), + fieldtype: "Select", + fieldname: "month", + options: months, + reqd: 1, + onchange: function() { + if (dialog.fields_dict.employee.value && dialog.fields_dict.month.value) { + dialog.set_df_property("status", "hidden", 0); dialog.set_df_property("unmarked_days", "options", []); dialog.no_unmarked_days_left = false; + me.get_multi_select_options(dialog.fields_dict.employee.value, dialog.fields_dict.month.value).then(options => { + if (options.length > 0) { + dialog.set_df_property("unmarked_days", "hidden", 0); + dialog.set_df_property("unmarked_days", "options", options); + } else { + dialog.no_unmarked_days_left = true; + } + }); } - }, - { - label: __("For Month"), - fieldtype: "Select", - fieldname: "month", - options: months, - reqd: 1, - onchange: function() { - if(dialog.fields_dict.employee.value && dialog.fields_dict.month.value) { - dialog.set_df_property("status", "hidden", 0); - dialog.set_df_property("unmarked_days", "options", []); - dialog.no_unmarked_days_left = false; - me.get_multi_select_options(dialog.fields_dict.employee.value, dialog.fields_dict.month.value).then(options =>{ - if (options.length > 0) { - dialog.set_df_property("unmarked_days", "hidden", 0); - dialog.set_df_property("unmarked_days", "options", options); - } else { - dialog.no_unmarked_days_left = true; - } - }); - } - } - }, - { - label: __("Status"), - fieldtype: "Select", - fieldname: "status", - options: ["Present", "Absent", "Half Day", "Work From Home"], - hidden:1, - reqd: 1, + } + }, + { + label: __("Status"), + fieldtype: "Select", + fieldname: "status", + options: ["Present", "Absent", "Half Day", "Work From Home"], + hidden: 1, + reqd: 1, - }, - { - label: __("Unmarked Attendance for days"), - fieldname: "unmarked_days", - fieldtype: "MultiCheck", - options: [], - columns: 2, - hidden: 1 - }, - ], - primary_action(data) { + }, + { + label: __("Unmarked Attendance for days"), + fieldname: "unmarked_days", + fieldtype: "MultiCheck", + options: [], + columns: 2, + hidden: 1 + }], + primary_action(data) { if (cur_dialog.no_unmarked_days_left) { - frappe.msgprint(__("Attendance for the month of {0} , has already been marked for the Employee {1}",[dialog.fields_dict.month.value, dialog.fields_dict.employee.value])); + frappe.msgprint(__("Attendance for the month of {0} , has already been marked for the Employee {1}", + [dialog.fields_dict.month.value, dialog.fields_dict.employee.value])); } else { - frappe.confirm(__('Mark attendance as {0} for {1} on selected dates?', [data.status,data.month]), () => { + frappe.confirm(__('Mark attendance as {0} for {1} on selected dates?', [data.status, data.month]), () => { frappe.call({ method: "erpnext.hr.doctype.attendance.attendance.mark_bulk_attendance", args: { data: data }, - callback: function(r) { + callback: function (r) { if (r.message === 1) { - frappe.show_alert({message: __("Attendance Marked"), indicator: 'blue'}); + frappe.show_alert({ + message: __("Attendance Marked"), + indicator: 'blue' + }); cur_dialog.hide(); } } @@ -101,21 +104,26 @@ frappe.listview_settings['Attendance'] = { dialog.show(); }); }, - get_multi_select_options: function(employee, month){ + + get_multi_select_options: function(employee, month) { return new Promise(resolve => { frappe.call({ method: 'erpnext.hr.doctype.attendance.attendance.get_unmarked_days', async: false, - args:{ + args: { employee: employee, month: month, } }).then(r => { var options = []; - for(var d in r.message){ + for (var d in r.message) { var momentObj = moment(r.message[d], 'YYYY-MM-DD'); var date = momentObj.format('DD-MM-YYYY'); - options.push({ "label":date, "value": r.message[d] , "checked": 1}); + options.push({ + "label": date, + "value": r.message[d], + "checked": 1 + }); } resolve(options); }); diff --git a/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py b/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py index bed12e31eaa..8a23682ad47 100644 --- a/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py +++ b/erpnext/hr/doctype/daily_work_summary/test_daily_work_summary.py @@ -74,7 +74,6 @@ class TestDailyWorkSummary(unittest.TestCase): from `tabEmail Queue` as q, `tabEmail Queue Recipient` as r \ where q.name = r.parent""", as_dict=1) - frappe.db.commit() def setup_groups(self, hour=None): # setup email to trigger at this hour diff --git a/erpnext/hr/doctype/employee/employee.js b/erpnext/hr/doctype/employee/employee.js index c21d4b893cc..1ac40c6186d 100755 --- a/erpnext/hr/doctype/employee/employee.js +++ b/erpnext/hr/doctype/employee/employee.js @@ -4,40 +4,46 @@ frappe.provide("erpnext.hr"); erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({ setup: function() { - this.frm.fields_dict.user_id.get_query = function(doc, cdt, cdn) { + this.frm.fields_dict.user_id.get_query = function() { return { query: "frappe.core.doctype.user.user.user_query", - filters: {ignore_user_type: 1} - } - } - this.frm.fields_dict.reports_to.get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.employee_query"} } + filters: { + ignore_user_type: 1 + } + }; + }; + this.frm.fields_dict.reports_to.get_query = function() { + return { + query: "erpnext.controllers.queries.employee_query" + }; + }; }, refresh: function() { - var me = this; erpnext.toggle_naming_series(); }, date_of_birth: function() { return cur_frm.call({ method: "get_retirement_date", - args: {date_of_birth: this.frm.doc.date_of_birth} + args: { + date_of_birth: this.frm.doc.date_of_birth + } }); }, salutation: function() { - if(this.frm.doc.salutation) { + if (this.frm.doc.salutation) { this.frm.set_value("gender", { "Mr": "Male", "Ms": "Female" - }[this.frm.doc.salutation]); + } [this.frm.doc.salutation]); } }, }); -frappe.ui.form.on('Employee',{ - setup: function(frm) { +frappe.ui.form.on('Employee', { + setup: function (frm) { frm.set_query("leave_policy", function() { return { "filters": { @@ -46,7 +52,7 @@ frappe.ui.form.on('Employee',{ }; }); }, - onload:function(frm) { + onload: function (frm) { frm.set_query("department", function() { return { "filters": { @@ -55,23 +61,28 @@ frappe.ui.form.on('Employee',{ }; }); }, - prefered_contact_email:function(frm){ - frm.events.update_contact(frm) + prefered_contact_email: function(frm) { + frm.events.update_contact(frm); }, - personal_email:function(frm){ - frm.events.update_contact(frm) + + personal_email: function(frm) { + frm.events.update_contact(frm); }, - company_email:function(frm){ - frm.events.update_contact(frm) + + company_email: function(frm) { + frm.events.update_contact(frm); }, - user_id:function(frm){ - frm.events.update_contact(frm) + + user_id: function(frm) { + frm.events.update_contact(frm); }, - update_contact:function(frm){ + + update_contact: function(frm) { var prefered_email_fieldname = frappe.model.scrub(frm.doc.prefered_contact_email) || 'user_id'; frm.set_value("prefered_email", - frm.fields_dict[prefered_email_fieldname].value) + frm.fields_dict[prefered_email_fieldname].value); }, + status: function(frm) { return frm.call({ method: "deactivate_sales_person", @@ -81,19 +92,63 @@ frappe.ui.form.on('Employee',{ } }); }, + create_user: function(frm) { - if (!frm.doc.prefered_email) - { - frappe.throw(__("Please enter Preferred Contact Email")) + if (!frm.doc.prefered_email) { + frappe.throw(__("Please enter Preferred Contact Email")); } frappe.call({ method: "erpnext.hr.doctype.employee.employee.create_user", - args: { employee: frm.doc.name, email: frm.doc.prefered_email }, - callback: function(r) - { - frm.set_value("user_id", r.message) + args: { + employee: frm.doc.name, + email: frm.doc.prefered_email + }, + callback: function (r) { + frm.set_value("user_id", r.message); } }); } }); -cur_frm.cscript = new erpnext.hr.EmployeeController({frm: cur_frm}); + +cur_frm.cscript = new erpnext.hr.EmployeeController({ + frm: cur_frm +}); + + +frappe.tour['Employee'] = [ + { + fieldname: "first_name", + title: "First Name", + description: __("Enter First and Last name of Employee, based on Which Full Name will be updated. IN transactions, it will be Full Name which will be fetched.") + }, + { + fieldname: "company", + title: "Company", + description: __("Select a Company this Employee belongs to. Other HR features like Payroll. Expense Claims and Leaves for this Employee will be created for a given company only.") + }, + { + fieldname: "date_of_birth", + title: "Date of Birth", + description: __("Select Date of Birth. This will validate Employees age and prevent hiring of under-age staff.") + }, + { + fieldname: "date_of_joining", + title: "Date of Joining", + description: __("Select Date of joining. It will have impact on the first salary calculation, Leave allocation on pro-rata bases.") + }, + { + fieldname: "holiday_list", + title: "Holiday List", + description: __("Select a default Holiday List for this Employee. The days listed in Holiday List will not be counted in Leave Application.") + }, + { + fieldname: "reports_to", + title: "Reports To", + description: __("Here, you can select a senior of this Employee. Based on this, Organization Chart will be populated.") + }, + { + fieldname: "leave_approver", + title: "Leave Approver", + description: __("Select Leave Approver for an employee. The user one who will look after his/her Leave application") + }, +]; diff --git a/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py b/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py index 33cad7b7e9b..bc369bc5b46 100644 --- a/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py +++ b/erpnext/hr/doctype/employee_onboarding/test_employee_onboarding.py @@ -72,6 +72,7 @@ def get_job_applicant(): applicant = frappe.new_doc('Job Applicant') applicant.applicant_name = 'Test Researcher' applicant.email_id = 'test@researcher.com' + applicant.designation = 'Researcher' applicant.status = 'Open' applicant.cover_letter = 'I am a great Researcher.' applicant.insert() diff --git a/erpnext/hr/doctype/employee_referral/employee_referral.py b/erpnext/hr/doctype/employee_referral/employee_referral.py index 5cb5bb5fd3a..db356bf91f1 100644 --- a/erpnext/hr/doctype/employee_referral/employee_referral.py +++ b/erpnext/hr/doctype/employee_referral/employee_referral.py @@ -38,8 +38,10 @@ def create_job_applicant(source_name, target_doc=None): status = "Open" job_applicant = frappe.new_doc("Job Applicant") + job_applicant.source = "Employee Referral" job_applicant.employee_referral = emp_ref.name job_applicant.status = status + job_applicant.designation = emp_ref.for_designation job_applicant.applicant_name = emp_ref.full_name job_applicant.email_id = emp_ref.email job_applicant.phone_number = emp_ref.contact_no diff --git a/erpnext/hr/doctype/employee_referral/test_employee_referral.py b/erpnext/hr/doctype/employee_referral/test_employee_referral.py index d0ee2fcdea7..1340f62bbf4 100644 --- a/erpnext/hr/doctype/employee_referral/test_employee_referral.py +++ b/erpnext/hr/doctype/employee_referral/test_employee_referral.py @@ -17,6 +17,11 @@ from erpnext.hr.doctype.employee_referral.employee_referral import ( class TestEmployeeReferral(unittest.TestCase): + + def setUp(self): + frappe.db.sql("DELETE FROM `tabJob Applicant`") + frappe.db.sql("DELETE FROM `tabEmployee Referral`") + def test_workflow_and_status_sync(self): emp_ref = create_employee_referral() @@ -50,6 +55,10 @@ class TestEmployeeReferral(unittest.TestCase): add_sal = create_additional_salary(emp_ref) self.assertTrue(add_sal.ref_docname, emp_ref.name) + def tearDown(self): + frappe.db.sql("DELETE FROM `tabJob Applicant`") + frappe.db.sql("DELETE FROM `tabEmployee Referral`") + def create_employee_referral(): emp_ref = frappe.new_doc("Employee Referral") diff --git a/erpnext/hr/doctype/expected_skill_set/__init__.py b/erpnext/hr/doctype/expected_skill_set/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/expected_skill_set/expected_skill_set.json b/erpnext/hr/doctype/expected_skill_set/expected_skill_set.json new file mode 100644 index 00000000000..899f5bd0ff4 --- /dev/null +++ b/erpnext/hr/doctype/expected_skill_set/expected_skill_set.json @@ -0,0 +1,40 @@ +{ + "actions": [], + "creation": "2021-04-12 13:05:06.741330", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "skill", + "description" + ], + "fields": [ + { + "fieldname": "skill", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Skill", + "options": "Skill", + "reqd": 1 + }, + { + "fetch_from": "skill.description", + "fieldname": "description", + "fieldtype": "Small Text", + "in_list_view": 1, + "label": "Description" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-04-12 14:26:33.062549", + "modified_by": "Administrator", + "module": "HR", + "name": "Expected Skill Set", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/expected_skill_set/expected_skill_set.py b/erpnext/hr/doctype/expected_skill_set/expected_skill_set.py new file mode 100644 index 00000000000..27120c1fb37 --- /dev/null +++ b/erpnext/hr/doctype/expected_skill_set/expected_skill_set.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +# import frappe +from frappe.model.document import Document + + +class ExpectedSkillSet(Document): + pass diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index 3c4c672816c..218e97d7fc2 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -10,6 +10,26 @@ frappe.ui.form.on('Expense Claim', { }, company: function(frm) { erpnext.accounts.dimensions.update_dimension(frm, frm.doctype); + var expenses = frm.doc.expenses; + for (var i = 0; i < expenses.length; i++) { + var expense = expenses[i]; + if (!expense.expense_type) { + continue; + } + frappe.call({ + method: "erpnext.hr.doctype.expense_claim.expense_claim.get_expense_claim_account_and_cost_center", + args: { + "expense_claim_type": expense.expense_type, + "company": frm.doc.company + }, + callback: function(r) { + if (r.message) { + expense.default_account = r.message.account; + expense.cost_center = r.message.cost_center; + } + } + }); + } }, }); diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py index e54c1457244..86a8b877e4b 100644 --- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py @@ -176,7 +176,7 @@ def generate_taxes(): account = create_account(company=company_name, account_name="Output Tax CGST", account_type="Tax", parent_account=parent_account) return {'taxes':[{ "account_head": account, - "rate": 0, + "rate": 9, "description": "CGST", "tax_amount": 10, "total": 210 diff --git a/erpnext/hr/doctype/expense_taxes_and_charges/expense_taxes_and_charges.json b/erpnext/hr/doctype/expense_taxes_and_charges/expense_taxes_and_charges.json index 020457d4ec6..4a1064b66b7 100644 --- a/erpnext/hr/doctype/expense_taxes_and_charges/expense_taxes_and_charges.json +++ b/erpnext/hr/doctype/expense_taxes_and_charges/expense_taxes_and_charges.json @@ -56,8 +56,6 @@ }, { "columns": 2, - "fetch_from": "account_head.tax_rate", - "fetch_if_empty": 1, "fieldname": "rate", "fieldtype": "Float", "in_list_view": 1, @@ -111,4 +109,4 @@ "sort_field": "modified", "sort_order": "ASC", "track_changes": 1 -} \ No newline at end of file +} diff --git a/erpnext/hr/doctype/holiday_list/holiday_list.js b/erpnext/hr/doctype/holiday_list/holiday_list.js index 462bd8bb671..ea033c7ed92 100644 --- a/erpnext/hr/doctype/holiday_list/holiday_list.js +++ b/erpnext/hr/doctype/holiday_list/holiday_list.js @@ -1,10 +1,10 @@ // Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors // For license information, please see license.txt -frappe.ui.form.on('Holiday List', { +frappe.ui.form.on("Holiday List", { refresh: function(frm) { if (frm.doc.holidays) { - frm.set_value('total_holidays', frm.doc.holidays.length); + frm.set_value("total_holidays", frm.doc.holidays.length); } }, from_date: function(frm) { @@ -14,3 +14,36 @@ frappe.ui.form.on('Holiday List', { } } }); + +frappe.tour["Holiday List"] = [ + { + fieldname: "holiday_list_name", + title: "Holiday List Name", + description: __("Enter a name for this Holiday List."), + }, + { + fieldname: "from_date", + title: "From Date", + description: __("Based on your HR Policy, select your leave allocation period's start date"), + }, + { + fieldname: "to_date", + title: "To Date", + description: __("Based on your HR Policy, select your leave allocation period's end date"), + }, + { + fieldname: "weekly_off", + title: "Weekly Off", + description: __("Select your weekly off day"), + }, + { + fieldname: "get_weekly_off_dates", + title: "Add Holidays", + description: __("Click on Add to Holidays. This will populate the holidays table with all the dates that fall on the selected weekly off. Repeat the process for populating the dates for all your weekly holidays"), + }, + { + fieldname: "holidays", + title: "Holidays", + description: __("Here, your weekly offs are pre-populated based on the previous selections. You can add more rows to also add public and national holidays individually.") + }, +]; diff --git a/erpnext/hr/doctype/holiday_list/holiday_list.py b/erpnext/hr/doctype/holiday_list/holiday_list.py index 8d91ac2ddd7..89a8784a755 100644 --- a/erpnext/hr/doctype/holiday_list/holiday_list.py +++ b/erpnext/hr/doctype/holiday_list/holiday_list.py @@ -1,4 +1,3 @@ - # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt @@ -94,9 +93,11 @@ def get_events(start, end, filters=None): update={"allDay": 1}) -def is_holiday(holiday_list, date=today()): +def is_holiday(holiday_list, date=None): """Returns true if the given date is a holiday in the given holiday list """ + if date is None: + date = today() if holiday_list: return bool(frappe.get_all('Holiday List', dict(name=holiday_list, holiday_date=date))) diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.js b/erpnext/hr/doctype/hr_settings/hr_settings.js index ec99472d9bc..6e26a1fa71d 100644 --- a/erpnext/hr/doctype/hr_settings/hr_settings.js +++ b/erpnext/hr/doctype/hr_settings/hr_settings.js @@ -2,7 +2,22 @@ // For license information, please see license.txt frappe.ui.form.on('HR Settings', { - restrict_backdated_leave_application: function(frm) { - frm.toggle_reqd("role_allowed_to_create_backdated_leave_application", frm.doc.restrict_backdated_leave_application); - } }); + +frappe.tour['HR Settings'] = [ + { + fieldname: 'emp_created_by', + title: 'Employee Naming By', + description: __('Employee can be named by Employee ID if you assign one, or via Naming Series. Select your preference here.'), + }, + { + fieldname: 'standard_working_hours', + title: 'Standard Working Hours', + description: __('Enter the Standard Working Hours for a normal work day. These hours will be used in calculations of reports such as Employee Hours Utilization and Project Profitability analysis.'), + }, + { + fieldname: 'leave_and_expense_claim_settings', + title: 'Leave and Expense Clain Settings', + description: __('Review various other settings related to Employee Leaves and Expense Claim') + } +]; diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.json b/erpnext/hr/doctype/hr_settings/hr_settings.json index 8aa3c0ca9f1..5148435c130 100644 --- a/erpnext/hr/doctype/hr_settings/hr_settings.json +++ b/erpnext/hr/doctype/hr_settings/hr_settings.json @@ -7,30 +7,36 @@ "engine": "InnoDB", "field_order": [ "employee_settings", - "retirement_age", "emp_created_by", - "column_break_4", "standard_working_hours", - "expense_approver_mandatory_in_expense_claim", + "column_break_9", + "retirement_age", "reminders_section", "send_birthday_reminders", - "column_break_9", - "send_work_anniversary_reminders", "column_break_11", + "send_work_anniversary_reminders", + "column_break_18", "send_holiday_reminders", "frequency", - "leave_settings", + "leave_and_expense_claim_settings", "send_leave_notification", "leave_approval_notification_template", "leave_status_notification_template", - "role_allowed_to_create_backdated_leave_application", - "column_break_18", "leave_approver_mandatory_in_leave_application", + "restrict_backdated_leave_application", + "role_allowed_to_create_backdated_leave_application", + "column_break_29", + "expense_approver_mandatory_in_expense_claim", "show_leaves_of_all_department_members_in_calendar", "auto_leave_encashment", - "restrict_backdated_leave_application", - "hiring_settings", - "check_vacancies" + "hiring_settings_section", + "check_vacancies", + "send_interview_reminder", + "interview_reminder_template", + "remind_before", + "column_break_4", + "send_interview_feedback_reminder", + "feedback_reminder_notification_template" ], "fields": [ { @@ -39,17 +45,16 @@ "label": "Employee Settings" }, { - "description": "Enter retirement age in years", "fieldname": "retirement_age", "fieldtype": "Data", - "label": "Retirement Age" + "label": "Retirement Age (In Years)" }, { "default": "Naming Series", - "description": "Employee records are created using the selected field", + "description": "Employee records are created using the selected option", "fieldname": "emp_created_by", "fieldtype": "Select", - "label": "Employee Records to be created by", + "label": "Employee Naming By", "options": "Naming Series\nEmployee Number\nFull Name" }, { @@ -62,28 +67,6 @@ "fieldtype": "Check", "label": "Expense Approver Mandatory In Expense Claim" }, - { - "collapsible": 1, - "fieldname": "leave_settings", - "fieldtype": "Section Break", - "label": "Leave Settings" - }, - { - "depends_on": "eval: doc.send_leave_notification == 1", - "fieldname": "leave_approval_notification_template", - "fieldtype": "Link", - "label": "Leave Approval Notification Template", - "mandatory_depends_on": "eval: doc.send_leave_notification == 1", - "options": "Email Template" - }, - { - "depends_on": "eval: doc.send_leave_notification == 1", - "fieldname": "leave_status_notification_template", - "fieldtype": "Link", - "label": "Leave Status Notification Template", - "mandatory_depends_on": "eval: doc.send_leave_notification == 1", - "options": "Email Template" - }, { "fieldname": "column_break_18", "fieldtype": "Column Break" @@ -100,35 +83,18 @@ "fieldtype": "Check", "label": "Show Leaves Of All Department Members In Calendar" }, - { - "collapsible": 1, - "fieldname": "hiring_settings", - "fieldtype": "Section Break", - "label": "Hiring Settings" - }, - { - "default": "0", - "fieldname": "check_vacancies", - "fieldtype": "Check", - "label": "Check Vacancies On Job Offer Creation" - }, { "default": "0", "fieldname": "auto_leave_encashment", "fieldtype": "Check", "label": "Auto Leave Encashment" }, - { - "default": "0", - "fieldname": "restrict_backdated_leave_application", - "fieldtype": "Check", - "label": "Restrict Backdated Leave Application" - }, { "depends_on": "eval:doc.restrict_backdated_leave_application == 1", "fieldname": "role_allowed_to_create_backdated_leave_application", "fieldtype": "Link", "label": "Role Allowed to Create Backdated Leave Application", + "mandatory_depends_on": "eval:doc.restrict_backdated_leave_application == 1", "options": "Role" }, { @@ -137,11 +103,40 @@ "fieldtype": "Check", "label": "Send Leave Notification" }, + { + "depends_on": "eval: doc.send_leave_notification == 1", + "fieldname": "leave_approval_notification_template", + "fieldtype": "Link", + "label": "Leave Approval Notification Template", + "mandatory_depends_on": "eval: doc.send_leave_notification == 1", + "options": "Email Template" + }, + { + "depends_on": "eval: doc.send_leave_notification == 1", + "fieldname": "leave_status_notification_template", + "fieldtype": "Link", + "label": "Leave Status Notification Template", + "mandatory_depends_on": "eval: doc.send_leave_notification == 1", + "options": "Email Template" + }, { "fieldname": "standard_working_hours", "fieldtype": "Int", "label": "Standard Working Hours" }, + { + "collapsible": 1, + "fieldname": "leave_and_expense_claim_settings", + "fieldtype": "Section Break", + "label": "Leave and Expense Claim Settings" + }, + { + "default": "00:15:00", + "depends_on": "send_interview_reminder", + "fieldname": "remind_before", + "fieldtype": "Time", + "label": "Remind Before" + }, { "collapsible": 1, "fieldname": "reminders_section", @@ -166,6 +161,7 @@ "fieldname": "frequency", "fieldtype": "Select", "label": "Set the frequency for holiday reminders", + "mandatory_depends_on": "send_holiday_reminders", "options": "Weekly\nMonthly" }, { @@ -181,13 +177,62 @@ { "fieldname": "column_break_11", "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "send_interview_reminder", + "fieldtype": "Check", + "label": "Send Interview Reminder" + }, + { + "default": "0", + "fieldname": "send_interview_feedback_reminder", + "fieldtype": "Check", + "label": "Send Interview Feedback Reminder" + }, + { + "fieldname": "column_break_29", + "fieldtype": "Column Break" + }, + { + "depends_on": "send_interview_feedback_reminder", + "fieldname": "feedback_reminder_notification_template", + "fieldtype": "Link", + "label": "Feedback Reminder Notification Template", + "mandatory_depends_on": "send_interview_feedback_reminder", + "options": "Email Template" + }, + { + "depends_on": "send_interview_reminder", + "fieldname": "interview_reminder_template", + "fieldtype": "Link", + "label": "Interview Reminder Notification Template", + "mandatory_depends_on": "send_interview_reminder", + "options": "Email Template" + }, + { + "default": "0", + "fieldname": "restrict_backdated_leave_application", + "fieldtype": "Check", + "label": "Restrict Backdated Leave Application" + }, + { + "fieldname": "hiring_settings_section", + "fieldtype": "Section Break", + "label": "Hiring Settings" + }, + { + "default": "0", + "fieldname": "check_vacancies", + "fieldtype": "Check", + "label": "Check Vacancies On Job Offer Creation" } ], "icon": "fa fa-cog", "idx": 1, "issingle": 1, "links": [], - "modified": "2021-08-24 14:54:12.834162", + "modified": "2021-10-01 23:46:11.098236", "modified_by": "Administrator", "module": "HR", "name": "HR Settings", diff --git a/erpnext/hr/doctype/interview/__init__.py b/erpnext/hr/doctype/interview/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/interview/interview.js b/erpnext/hr/doctype/interview/interview.js new file mode 100644 index 00000000000..6341e3a62b4 --- /dev/null +++ b/erpnext/hr/doctype/interview/interview.js @@ -0,0 +1,237 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Interview', { + onload: function (frm) { + frm.events.set_job_applicant_query(frm); + + frm.set_query('interviewer', 'interview_details', function () { + return { + query: 'erpnext.hr.doctype.interview.interview.get_interviewer_list' + }; + }); + }, + + refresh: function (frm) { + if (frm.doc.docstatus != 2 && !frm.doc.__islocal) { + if (frm.doc.status === 'Pending') { + frm.add_custom_button(__('Reschedule Interview'), function() { + frm.events.show_reschedule_dialog(frm); + frm.refresh(); + }); + } + + let allowed_interviewers = []; + frm.doc.interview_details.forEach(values => { + allowed_interviewers.push(values.interviewer); + }); + + if ((allowed_interviewers.includes(frappe.session.user))) { + frappe.db.get_value('Interview Feedback', {'interviewer': frappe.session.user, 'interview': frm.doc.name, 'docstatus': 1}, 'name', (r) => { + if (Object.keys(r).length === 0) { + frm.add_custom_button(__('Submit Feedback'), function () { + frappe.call({ + method: 'erpnext.hr.doctype.interview.interview.get_expected_skill_set', + args: { + interview_round: frm.doc.interview_round + }, + callback: function (r) { + frm.events.show_feedback_dialog(frm, r.message); + frm.refresh(); + } + }); + }).addClass('btn-primary'); + } + }); + } + } + }, + + show_reschedule_dialog: function (frm) { + let d = new frappe.ui.Dialog({ + title: 'Reschedule Interview', + fields: [ + { + label: 'Schedule On', + fieldname: 'scheduled_on', + fieldtype: 'Date', + reqd: 1 + }, + { + label: 'From Time', + fieldname: 'from_time', + fieldtype: 'Time', + reqd: 1 + }, + { + label: 'To Time', + fieldname: 'to_time', + fieldtype: 'Time', + reqd: 1 + } + ], + primary_action_label: 'Reschedule', + primary_action(values) { + frm.call({ + method: 'reschedule_interview', + doc: frm.doc, + args: { + scheduled_on: values.scheduled_on, + from_time: values.from_time, + to_time: values.to_time + } + }).then(() => { + frm.refresh(); + d.hide(); + }); + } + }); + d.show(); + }, + + show_feedback_dialog: function (frm, data) { + let fields = frm.events.get_fields_for_feedback(); + + let d = new frappe.ui.Dialog({ + title: __('Submit Feedback'), + fields: [ + { + fieldname: 'skill_set', + fieldtype: 'Table', + label: __('Skill Assessment'), + cannot_add_rows: false, + in_editable_grid: true, + reqd: 1, + fields: fields, + data: data + }, + { + fieldname: 'result', + fieldtype: 'Select', + options: ['', 'Cleared', 'Rejected'], + label: __('Result') + }, + { + fieldname: 'feedback', + fieldtype: 'Small Text', + label: __('Feedback') + } + ], + size: 'large', + minimizable: true, + primary_action: function(values) { + frappe.call({ + method: 'erpnext.hr.doctype.interview.interview.create_interview_feedback', + args: { + data: values, + interview_name: frm.doc.name, + interviewer: frappe.session.user, + job_applicant: frm.doc.job_applicant + } + }).then(() => { + frm.refresh(); + }); + d.hide(); + } + }); + d.show(); + }, + + get_fields_for_feedback: function () { + return [{ + fieldtype: 'Link', + fieldname: 'skill', + options: 'Skill', + in_list_view: 1, + label: __('Skill') + }, { + fieldtype: 'Rating', + fieldname: 'rating', + label: __('Rating'), + in_list_view: 1, + reqd: 1, + }]; + }, + + set_job_applicant_query: function (frm) { + frm.set_query('job_applicant', function () { + let job_applicant_filters = { + status: ['!=', 'Rejected'] + }; + if (frm.doc.designation) { + job_applicant_filters.designation = frm.doc.designation; + } + return { + filters: job_applicant_filters + }; + }); + }, + + interview_round: async function (frm) { + frm.events.reset_values(frm); + frm.set_value('job_applicant', ''); + + let round_data = (await frappe.db.get_value('Interview Round', frm.doc.interview_round, 'designation')).message; + frm.set_value('designation', round_data.designation); + frm.events.set_job_applicant_query(frm); + + if (frm.doc.interview_round) { + frm.events.set_interview_details(frm); + } else { + frm.set_value('interview_details', []); + } + }, + + set_interview_details: function (frm) { + frappe.call({ + method: 'erpnext.hr.doctype.interview.interview.get_interviewers', + args: { + interview_round: frm.doc.interview_round + }, + callback: function (data) { + let interview_details = data.message; + frm.set_value('interview_details', []); + if (data.message.length) { + frm.set_value('interview_details', interview_details); + } + } + }); + }, + + job_applicant: function (frm) { + if (!frm.doc.interview_round) { + frm.doc.job_applicant = ''; + frm.refresh(); + frappe.throw(__('Select Interview Round First')); + } + + if (frm.doc.job_applicant) { + frm.events.set_designation_and_job_opening(frm); + } else { + frm.events.reset_values(frm); + } + }, + + set_designation_and_job_opening: async function (frm) { + let round_data = (await frappe.db.get_value('Interview Round', frm.doc.interview_round, 'designation')).message; + frm.set_value('designation', round_data.designation); + frm.events.set_job_applicant_query(frm); + + let job_applicant_data = (await frappe.db.get_value( + 'Job Applicant', frm.doc.job_applicant, ['designation', 'job_title', 'resume_link'], + )).message; + + if (!round_data.designation) { + frm.set_value('designation', job_applicant_data.designation); + } + + frm.set_value('job_opening', job_applicant_data.job_title); + frm.set_value('resume_link', job_applicant_data.resume_link); + }, + + reset_values: function (frm) { + frm.set_value('designation', ''); + frm.set_value('job_opening', ''); + frm.set_value('resume_link', ''); + } +}); diff --git a/erpnext/hr/doctype/interview/interview.json b/erpnext/hr/doctype/interview/interview.json new file mode 100644 index 00000000000..0d393e7556f --- /dev/null +++ b/erpnext/hr/doctype/interview/interview.json @@ -0,0 +1,254 @@ +{ + "actions": [], + "autoname": "HR-INT-.YYYY.-.####", + "creation": "2021-04-12 15:03:11.524090", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "interview_details_section", + "interview_round", + "job_applicant", + "job_opening", + "designation", + "resume_link", + "column_break_4", + "status", + "scheduled_on", + "from_time", + "to_time", + "interview_feedback_section", + "interview_details", + "ratings_section", + "expected_average_rating", + "column_break_12", + "average_rating", + "section_break_13", + "interview_summary", + "reminded", + "amended_from" + ], + "fields": [ + { + "fieldname": "job_applicant", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Job Applicant", + "options": "Job Applicant", + "reqd": 1 + }, + { + "fieldname": "job_opening", + "fieldtype": "Link", + "label": "Job Opening", + "options": "Job Opening", + "read_only": 1 + }, + { + "fieldname": "interview_round", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Interview Round", + "options": "Interview Round", + "reqd": 1 + }, + { + "default": "Pending", + "fieldname": "status", + "fieldtype": "Select", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Status", + "options": "Pending\nUnder Review\nCleared\nRejected", + "reqd": 1 + }, + { + "fieldname": "ratings_section", + "fieldtype": "Section Break", + "label": "Ratings" + }, + { + "allow_on_submit": 1, + "fieldname": "average_rating", + "fieldtype": "Rating", + "in_list_view": 1, + "label": "Obtained Average Rating", + "read_only": 1 + }, + { + "allow_on_submit": 1, + "fieldname": "interview_summary", + "fieldtype": "Text" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "resume_link", + "fieldtype": "Data", + "label": "Resume link" + }, + { + "fieldname": "interview_details_section", + "fieldtype": "Section Break", + "label": "Details" + }, + { + "fetch_from": "interview_round.expected_average_rating", + "fieldname": "expected_average_rating", + "fieldtype": "Rating", + "label": "Expected Average Rating", + "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "section_break_13", + "fieldtype": "Section Break", + "label": "Interview Summary" + }, + { + "fieldname": "column_break_12", + "fieldtype": "Column Break" + }, + { + "fetch_from": "interview_round.designation", + "fieldname": "designation", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Designation", + "options": "Designation", + "read_only": 1 + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Interview", + "print_hide": 1, + "read_only": 1 + }, + { + "fieldname": "scheduled_on", + "fieldtype": "Date", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Scheduled On", + "reqd": 1, + "set_only_once": 1 + }, + { + "default": "0", + "fieldname": "reminded", + "fieldtype": "Check", + "hidden": 1, + "label": "Reminded" + }, + { + "allow_on_submit": 1, + "fieldname": "interview_details", + "fieldtype": "Table", + "options": "Interview Detail" + }, + { + "fieldname": "interview_feedback_section", + "fieldtype": "Section Break", + "label": "Feedback" + }, + { + "fieldname": "from_time", + "fieldtype": "Time", + "in_list_view": 1, + "label": "From Time", + "reqd": 1, + "set_only_once": 1 + }, + { + "fieldname": "to_time", + "fieldtype": "Time", + "in_list_view": 1, + "label": "To Time", + "reqd": 1, + "set_only_once": 1 + } + ], + "index_web_pages_for_search": 1, + "is_submittable": 1, + "links": [ + { + "link_doctype": "Interview Feedback", + "link_fieldname": "interview" + } + ], + "modified": "2021-09-30 13:30:05.421035", + "modified_by": "Administrator", + "module": "HR", + "name": "Interview", + "owner": "Administrator", + "permissions": [ + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR Manager", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Interviewer", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR User", + "share": 1, + "submit": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "title_field": "job_applicant", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/interview/interview.py b/erpnext/hr/doctype/interview/interview.py new file mode 100644 index 00000000000..955acca631d --- /dev/null +++ b/erpnext/hr/doctype/interview/interview.py @@ -0,0 +1,293 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +import datetime + +import frappe +from frappe import _ +from frappe.model.document import Document +from frappe.utils import cstr, get_datetime, get_link_to_form + + +class DuplicateInterviewRoundError(frappe.ValidationError): + pass + +class Interview(Document): + def validate(self): + self.validate_duplicate_interview() + self.validate_designation() + self.validate_overlap() + + def on_submit(self): + if self.status not in ['Cleared', 'Rejected']: + frappe.throw(_('Only Interviews with Cleared or Rejected status can be submitted.'), title=_('Not Allowed')) + + def validate_duplicate_interview(self): + duplicate_interview = frappe.db.exists('Interview', { + 'job_applicant': self.job_applicant, + 'interview_round': self.interview_round, + 'docstatus': 1 + } + ) + + if duplicate_interview: + frappe.throw(_('Job Applicants are not allowed to appear twice for the same Interview round. Interview {0} already scheduled for Job Applicant {1}').format( + frappe.bold(get_link_to_form('Interview', duplicate_interview)), + frappe.bold(self.job_applicant) + )) + + def validate_designation(self): + applicant_designation = frappe.db.get_value('Job Applicant', self.job_applicant, 'designation') + if self.designation : + if self.designation != applicant_designation: + frappe.throw(_('Interview Round {0} is only for Designation {1}. Job Applicant has applied for the role {2}').format( + self.interview_round, frappe.bold(self.designation), applicant_designation), + exc=DuplicateInterviewRoundError) + else: + self.designation = applicant_designation + + def validate_overlap(self): + interviewers = [entry.interviewer for entry in self.interview_details] or [''] + + overlaps = frappe.db.sql(""" + SELECT interview.name + FROM `tabInterview` as interview + INNER JOIN `tabInterview Detail` as detail + WHERE + interview.scheduled_on = %s and interview.name != %s and interview.docstatus != 2 + and (interview.job_applicant = %s or detail.interviewer IN %s) and + ((from_time < %s and to_time > %s) or + (from_time > %s and to_time < %s) or + (from_time = %s)) + """, (self.scheduled_on, self.name, self.job_applicant, interviewers, + self.from_time, self.to_time, self.from_time, self.to_time, self.from_time)) + + if overlaps: + overlapping_details = _('Interview overlaps with {0}').format(get_link_to_form('Interview', overlaps[0][0])) + frappe.throw(overlapping_details, title=_('Overlap')) + + + @frappe.whitelist() + def reschedule_interview(self, scheduled_on, from_time, to_time): + original_date = self.scheduled_on + from_time = self.from_time + to_time = self.to_time + + self.db_set({ + 'scheduled_on': scheduled_on, + 'from_time': from_time, + 'to_time': to_time + }) + self.notify_update() + + recipients = get_recipients(self.name) + + try: + frappe.sendmail( + recipients= recipients, + subject=_('Interview: {0} Rescheduled').format(self.name), + message=_('Your Interview session is rescheduled from {0} {1} - {2} to {3} {4} - {5}').format( + original_date, from_time, to_time, self.scheduled_on, self.from_time, self.to_time), + reference_doctype=self.doctype, + reference_name=self.name + ) + except Exception: + frappe.msgprint(_('Failed to send the Interview Reschedule notification. Please configure your email account.')) + + frappe.msgprint(_('Interview Rescheduled successfully'), indicator='green') + + +def get_recipients(name, for_feedback=0): + interview = frappe.get_doc('Interview', name) + + if for_feedback: + recipients = [d.interviewer for d in interview.interview_details if not d.interview_feedback] + else: + recipients = [d.interviewer for d in interview.interview_details] + recipients.append(frappe.db.get_value('Job Applicant', interview.job_applicant, 'email_id')) + + return recipients + + +@frappe.whitelist() +def get_interviewers(interview_round): + return frappe.get_all('Interviewer', filters={'parent': interview_round}, fields=['user as interviewer']) + + +def send_interview_reminder(): + reminder_settings = frappe.db.get_value('HR Settings', 'HR Settings', + ['send_interview_reminder', 'interview_reminder_template'], as_dict=True) + + if not reminder_settings.send_interview_reminder: + return + + remind_before = cstr(frappe.db.get_single_value('HR Settings', 'remind_before')) or '01:00:00' + remind_before = datetime.datetime.strptime(remind_before, '%H:%M:%S') + reminder_date_time = datetime.datetime.now() + datetime.timedelta( + hours=remind_before.hour, minutes=remind_before.minute, seconds=remind_before.second) + + interviews = frappe.get_all('Interview', filters={ + 'scheduled_on': ['between', (datetime.datetime.now(), reminder_date_time)], + 'status': 'Pending', + 'reminded': 0, + 'docstatus': ['!=', 2] + }) + + interview_template = frappe.get_doc('Email Template', reminder_settings.interview_reminder_template) + + for d in interviews: + doc = frappe.get_doc('Interview', d.name) + context = doc.as_dict() + message = frappe.render_template(interview_template.response, context) + recipients = get_recipients(doc.name) + + frappe.sendmail( + recipients= recipients, + subject=interview_template.subject, + message=message, + reference_doctype=doc.doctype, + reference_name=doc.name + ) + + doc.db_set('reminded', 1) + + +def send_daily_feedback_reminder(): + reminder_settings = frappe.db.get_value('HR Settings', 'HR Settings', + ['send_interview_feedback_reminder', 'feedback_reminder_notification_template'], as_dict=True) + + if not reminder_settings.send_interview_feedback_reminder: + return + + interview_feedback_template = frappe.get_doc('Email Template', reminder_settings.feedback_reminder_notification_template) + interviews = frappe.get_all('Interview', filters={'status': ['in', ['Under Review', 'Pending']], 'docstatus': ['!=', 2]}) + + for entry in interviews: + recipients = get_recipients(entry.name, for_feedback=1) + + doc = frappe.get_doc('Interview', entry.name) + context = doc.as_dict() + + message = frappe.render_template(interview_feedback_template.response, context) + + if len(recipients): + frappe.sendmail( + recipients= recipients, + subject=interview_feedback_template.subject, + message=message, + reference_doctype='Interview', + reference_name=entry.name + ) + + +@frappe.whitelist() +def get_expected_skill_set(interview_round): + return frappe.get_all('Expected Skill Set', filters ={'parent': interview_round}, fields=['skill']) + + +@frappe.whitelist() +def create_interview_feedback(data, interview_name, interviewer, job_applicant): + import json + + from six import string_types + + if isinstance(data, string_types): + data = frappe._dict(json.loads(data)) + + if frappe.session.user != interviewer: + frappe.throw(_('Only Interviewer Are allowed to submit Interview Feedback')) + + interview_feedback = frappe.new_doc('Interview Feedback') + interview_feedback.interview = interview_name + interview_feedback.interviewer = interviewer + interview_feedback.job_applicant = job_applicant + + for d in data.skill_set: + d = frappe._dict(d) + interview_feedback.append('skill_assessment', {'skill': d.skill, 'rating': d.rating}) + + interview_feedback.feedback = data.feedback + interview_feedback.result = data.result + + interview_feedback.save() + interview_feedback.submit() + + frappe.msgprint(_('Interview Feedback {0} submitted successfully').format( + get_link_to_form('Interview Feedback', interview_feedback.name))) + + +@frappe.whitelist() +@frappe.validate_and_sanitize_search_inputs +def get_interviewer_list(doctype, txt, searchfield, start, page_len, filters): + filters = [ + ['Has Role', 'parent', 'like', '%{}%'.format(txt)], + ['Has Role', 'role', '=', 'interviewer'], + ['Has Role', 'parenttype', '=', 'User'] + ] + + if filters and isinstance(filters, list): + filters.extend(filters) + + return frappe.get_all('Has Role', limit_start=start, limit_page_length=page_len, + filters=filters, fields = ['parent'], as_list=1) + + +@frappe.whitelist() +def get_events(start, end, filters=None): + """Returns events for Gantt / Calendar view rendering. + + :param start: Start date-time. + :param end: End date-time. + :param filters: Filters (JSON). + """ + from frappe.desk.calendar import get_event_conditions + + events = [] + + event_color = { + "Pending": "#fff4f0", + "Under Review": "#d3e8fc", + "Cleared": "#eaf5ed", + "Rejected": "#fce7e7" + } + + conditions = get_event_conditions('Interview', filters) + + interviews = frappe.db.sql(""" + SELECT DISTINCT + `tabInterview`.name, `tabInterview`.job_applicant, `tabInterview`.interview_round, + `tabInterview`.scheduled_on, `tabInterview`.status, `tabInterview`.from_time as from_time, + `tabInterview`.to_time as to_time + from + `tabInterview` + where + (`tabInterview`.scheduled_on between %(start)s and %(end)s) + and docstatus != 2 + {conditions} + """.format(conditions=conditions), { + "start": start, + "end": end + }, as_dict=True, update={"allDay": 0}) + + for d in interviews: + subject_data = [] + for field in ["name", "job_applicant", "interview_round"]: + if not d.get(field): + continue + subject_data.append(d.get(field)) + + color = event_color.get(d.status) + interview_data = { + 'from': get_datetime('%s %s' % (d.scheduled_on, d.from_time or '00:00:00')), + 'to': get_datetime('%s %s' % (d.scheduled_on, d.to_time or '00:00:00')), + 'name': d.name, + 'subject': '\n'.join(subject_data), + 'color': color if color else "#89bcde" + } + + events.append(interview_data) + + return events \ No newline at end of file diff --git a/erpnext/hr/doctype/interview/interview_calendar.js b/erpnext/hr/doctype/interview/interview_calendar.js new file mode 100644 index 00000000000..b46b72ecb21 --- /dev/null +++ b/erpnext/hr/doctype/interview/interview_calendar.js @@ -0,0 +1,14 @@ + +frappe.views.calendar['Interview'] = { + field_map: { + 'start': 'from', + 'end': 'to', + 'id': 'name', + 'title': 'subject', + 'allDay': 'allDay', + 'color': 'color' + }, + order_by: 'scheduled_on', + gantt: true, + get_events_method: 'erpnext.hr.doctype.interview.interview.get_events' +}; diff --git a/erpnext/hr/doctype/interview/interview_feedback_reminder_template.html b/erpnext/hr/doctype/interview/interview_feedback_reminder_template.html new file mode 100644 index 00000000000..8d39fb54ef7 --- /dev/null +++ b/erpnext/hr/doctype/interview/interview_feedback_reminder_template.html @@ -0,0 +1,5 @@ +

Interview Feedback Reminder

+ +

+ Interview Feedback for Interview {{ name }} is not submitted yet. Please submit your feedback. Thank you, good day! +

diff --git a/erpnext/hr/doctype/interview/interview_list.js b/erpnext/hr/doctype/interview/interview_list.js new file mode 100644 index 00000000000..b1f072f0d4b --- /dev/null +++ b/erpnext/hr/doctype/interview/interview_list.js @@ -0,0 +1,12 @@ +frappe.listview_settings['Interview'] = { + has_indicator_for_draft: 1, + get_indicator: function(doc) { + let status_color = { + 'Pending': 'orange', + 'Under Review': 'blue', + 'Cleared': 'green', + 'Rejected': 'red', + }; + return [__(doc.status), status_color[doc.status], 'status,=,'+doc.status]; + } +}; diff --git a/erpnext/hr/doctype/interview/interview_reminder_notification_template.html b/erpnext/hr/doctype/interview/interview_reminder_notification_template.html new file mode 100644 index 00000000000..76de46e28db --- /dev/null +++ b/erpnext/hr/doctype/interview/interview_reminder_notification_template.html @@ -0,0 +1,5 @@ +

Interview Reminder

+ +

+ Interview: {{name}} is scheduled on {{scheduled_on}} from {{from_time}} to {{to_time}} +

diff --git a/erpnext/hr/doctype/interview/test_interview.py b/erpnext/hr/doctype/interview/test_interview.py new file mode 100644 index 00000000000..4612e17db03 --- /dev/null +++ b/erpnext/hr/doctype/interview/test_interview.py @@ -0,0 +1,174 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import datetime +import os +import unittest + +import frappe +from frappe import _ +from frappe.core.doctype.user_permission.test_user_permission import create_user +from frappe.utils import add_days, getdate, nowtime + +from erpnext.hr.doctype.designation.test_designation import create_designation +from erpnext.hr.doctype.interview.interview import DuplicateInterviewRoundError +from erpnext.hr.doctype.job_applicant.test_job_applicant import create_job_applicant + + +class TestInterview(unittest.TestCase): + def test_validations_for_designation(self): + job_applicant = create_job_applicant() + interview = create_interview_and_dependencies(job_applicant.name, designation='_Test_Sales_manager', save=0) + self.assertRaises(DuplicateInterviewRoundError, interview.save) + + def test_notification_on_rescheduling(self): + job_applicant = create_job_applicant() + interview = create_interview_and_dependencies(job_applicant.name, scheduled_on=add_days(getdate(), -4)) + + previous_scheduled_date = interview.scheduled_on + frappe.db.sql("DELETE FROM `tabEmail Queue`") + + interview.reschedule_interview(add_days(getdate(previous_scheduled_date), 2), + from_time=nowtime(), to_time=nowtime()) + interview.reload() + + self.assertEqual(interview.scheduled_on, add_days(getdate(previous_scheduled_date), 2)) + + notification = frappe.get_all("Email Queue", filters={"message": ("like", "%Your Interview session is rescheduled from%")}) + self.assertIsNotNone(notification) + + def test_notification_for_scheduling(self): + from erpnext.hr.doctype.interview.interview import send_interview_reminder + + setup_reminder_settings() + + job_applicant = create_job_applicant() + scheduled_on = datetime.datetime.now() + datetime.timedelta(minutes=10) + + interview = create_interview_and_dependencies(job_applicant.name, scheduled_on=scheduled_on) + + frappe.db.sql("DELETE FROM `tabEmail Queue`") + send_interview_reminder() + + interview.reload() + + email_queue = frappe.db.sql("""select * from `tabEmail Queue`""", as_dict=True) + self.assertTrue("Subject: Interview Reminder" in email_queue[0].message) + + def test_notification_for_feedback_submission(self): + from erpnext.hr.doctype.interview.interview import send_daily_feedback_reminder + + setup_reminder_settings() + + job_applicant = create_job_applicant() + scheduled_on = add_days(getdate(), -4) + create_interview_and_dependencies(job_applicant.name, scheduled_on=scheduled_on) + + frappe.db.sql("DELETE FROM `tabEmail Queue`") + send_daily_feedback_reminder() + + email_queue = frappe.db.sql("""select * from `tabEmail Queue`""", as_dict=True) + self.assertTrue("Subject: Interview Feedback Reminder" in email_queue[0].message) + + def tearDown(self): + frappe.db.rollback() + + +def create_interview_and_dependencies(job_applicant, scheduled_on=None, from_time=None, to_time=None, designation=None, save=1): + if designation: + designation=create_designation(designation_name = "_Test_Sales_manager").name + + interviewer_1 = create_user("test_interviewer1@example.com", "Interviewer") + interviewer_2 = create_user("test_interviewer2@example.com", "Interviewer") + + interview_round = create_interview_round( + "Technical Round", ["Python", "JS"], + designation=designation, save=True + ) + + interview = frappe.new_doc("Interview") + interview.interview_round = interview_round.name + interview.job_applicant = job_applicant + interview.scheduled_on = scheduled_on or getdate() + interview.from_time = from_time or nowtime() + interview.to_time = to_time or nowtime() + + interview.append("interview_details", {"interviewer": interviewer_1.name}) + interview.append("interview_details", {"interviewer": interviewer_2.name}) + + if save: + interview.save() + + return interview + +def create_interview_round(name, skill_set, interviewers=[], designation=None, save=True): + create_skill_set(skill_set) + interview_round = frappe.new_doc("Interview Round") + interview_round.round_name = name + interview_round.interview_type = create_interview_type() + interview_round.expected_average_rating = 4 + if designation: + interview_round.designation = designation + + for skill in skill_set: + interview_round.append("expected_skill_set", {"skill": skill}) + + for interviewer in interviewers: + interview_round.append("interviewer", { + "user": interviewer + }) + + if save: + interview_round.save() + + return interview_round + +def create_skill_set(skill_set): + for skill in skill_set: + if not frappe.db.exists("Skill", skill): + doc = frappe.new_doc("Skill") + doc.skill_name = skill + doc.save() + +def create_interview_type(name="test_interview_type"): + if frappe.db.exists("Interview Type", name): + return frappe.get_doc("Interview Type", name).name + else: + doc = frappe.new_doc("Interview Type") + doc.name = name + doc.description = "_Test_Description" + doc.save() + + return doc.name + +def setup_reminder_settings(): + if not frappe.db.exists('Email Template', _('Interview Reminder')): + base_path = frappe.get_app_path('erpnext', 'hr', 'doctype') + response = frappe.read_file(os.path.join(base_path, 'interview/interview_reminder_notification_template.html')) + + frappe.get_doc({ + 'doctype': 'Email Template', + 'name': _('Interview Reminder'), + 'response': response, + 'subject': _('Interview Reminder'), + 'owner': frappe.session.user, + }).insert(ignore_permissions=True) + + if not frappe.db.exists('Email Template', _('Interview Feedback Reminder')): + base_path = frappe.get_app_path('erpnext', 'hr', 'doctype') + response = frappe.read_file(os.path.join(base_path, 'interview/interview_feedback_reminder_template.html')) + + frappe.get_doc({ + 'doctype': 'Email Template', + 'name': _('Interview Feedback Reminder'), + 'response': response, + 'subject': _('Interview Feedback Reminder'), + 'owner': frappe.session.user, + }).insert(ignore_permissions=True) + + hr_settings = frappe.get_doc('HR Settings') + hr_settings.interview_reminder_template = _('Interview Reminder') + hr_settings.feedback_reminder_notification_template = _('Interview Feedback Reminder') + hr_settings.save() diff --git a/erpnext/hr/doctype/interview_detail/__init__.py b/erpnext/hr/doctype/interview_detail/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/interview_detail/interview_detail.js b/erpnext/hr/doctype/interview_detail/interview_detail.js new file mode 100644 index 00000000000..88518ca4cc1 --- /dev/null +++ b/erpnext/hr/doctype/interview_detail/interview_detail.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Interview Detail', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/hr/doctype/interview_detail/interview_detail.json b/erpnext/hr/doctype/interview_detail/interview_detail.json new file mode 100644 index 00000000000..b5b49c0993a --- /dev/null +++ b/erpnext/hr/doctype/interview_detail/interview_detail.json @@ -0,0 +1,74 @@ +{ + "actions": [], + "creation": "2021-04-12 16:24:10.382863", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "interviewer", + "interview_feedback", + "average_rating", + "result", + "column_break_4", + "comments" + ], + "fields": [ + { + "fieldname": "interviewer", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Interviewer", + "options": "User" + }, + { + "allow_on_submit": 1, + "fieldname": "interview_feedback", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Interview Feedback", + "options": "Interview Feedback", + "read_only": 1 + }, + { + "allow_on_submit": 1, + "fieldname": "average_rating", + "fieldtype": "Rating", + "in_list_view": 1, + "label": "Average Rating", + "read_only": 1 + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "allow_on_submit": 1, + "fetch_from": "interview_feedback.feedback", + "fieldname": "comments", + "fieldtype": "Text", + "label": "Comments", + "read_only": 1 + }, + { + "allow_on_submit": 1, + "fieldname": "result", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Result", + "options": "\nCleared\nRejected", + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-09-29 13:13:25.865063", + "modified_by": "Administrator", + "module": "HR", + "name": "Interview Detail", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/interview_detail/interview_detail.py b/erpnext/hr/doctype/interview_detail/interview_detail.py new file mode 100644 index 00000000000..8be3d34fad3 --- /dev/null +++ b/erpnext/hr/doctype/interview_detail/interview_detail.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +# import frappe +from frappe.model.document import Document + + +class InterviewDetail(Document): + pass diff --git a/erpnext/hr/doctype/interview_detail/test_interview_detail.py b/erpnext/hr/doctype/interview_detail/test_interview_detail.py new file mode 100644 index 00000000000..a29dffff779 --- /dev/null +++ b/erpnext/hr/doctype/interview_detail/test_interview_detail.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + + +class TestInterviewDetail(unittest.TestCase): + pass diff --git a/erpnext/hr/doctype/interview_feedback/__init__.py b/erpnext/hr/doctype/interview_feedback/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/interview_feedback/interview_feedback.js b/erpnext/hr/doctype/interview_feedback/interview_feedback.js new file mode 100644 index 00000000000..dec559fceae --- /dev/null +++ b/erpnext/hr/doctype/interview_feedback/interview_feedback.js @@ -0,0 +1,54 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Interview Feedback', { + onload: function(frm) { + frm.ignore_doctypes_on_cancel_all = ['Interview']; + + frm.set_query('interview', function() { + return { + filters: { + docstatus: ['!=', 2] + } + }; + }); + }, + + interview_round: function(frm) { + frappe.call({ + method: 'erpnext.hr.doctype.interview.interview.get_expected_skill_set', + args: { + interview_round: frm.doc.interview_round + }, + callback: function(r) { + frm.set_value('skill_assessment', r.message); + } + }); + }, + + interview: function(frm) { + frappe.call({ + method: 'erpnext.hr.doctype.interview_feedback.interview_feedback.get_applicable_interviewers', + args: { + interview: frm.doc.interview || '' + }, + callback: function(r) { + frm.set_query('interviewer', function() { + return { + filters: { + name: ['in', r.message] + } + }; + }); + } + }); + + }, + + interviewer: function(frm) { + if (!frm.doc.interview) { + frappe.throw(__('Select Interview first')); + frm.set_value('interviewer', ''); + } + } +}); diff --git a/erpnext/hr/doctype/interview_feedback/interview_feedback.json b/erpnext/hr/doctype/interview_feedback/interview_feedback.json new file mode 100644 index 00000000000..6a2f7e86969 --- /dev/null +++ b/erpnext/hr/doctype/interview_feedback/interview_feedback.json @@ -0,0 +1,171 @@ +{ + "actions": [], + "autoname": "HR-INT-FEED-.####", + "creation": "2021-04-12 17:03:13.833285", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "details_section", + "interview", + "interview_round", + "job_applicant", + "column_break_3", + "interviewer", + "result", + "section_break_4", + "skill_assessment", + "average_rating", + "section_break_7", + "feedback", + "amended_from" + ], + "fields": [ + { + "allow_in_quick_entry": 1, + "fieldname": "interview", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Interview", + "options": "Interview", + "reqd": 1 + }, + { + "allow_in_quick_entry": 1, + "fetch_from": "interview.interview_round", + "fieldname": "interview_round", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Interview Round", + "options": "Interview Round", + "read_only": 1, + "reqd": 1 + }, + { + "allow_in_quick_entry": 1, + "fieldname": "interviewer", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Interviewer", + "options": "User", + "reqd": 1 + }, + { + "fieldname": "section_break_4", + "fieldtype": "Section Break", + "label": "Skill Assessment" + }, + { + "allow_in_quick_entry": 1, + "fieldname": "skill_assessment", + "fieldtype": "Table", + "options": "Skill Assessment", + "reqd": 1 + }, + { + "allow_in_quick_entry": 1, + "fieldname": "average_rating", + "fieldtype": "Rating", + "in_list_view": 1, + "label": "Average Rating", + "read_only": 1 + }, + { + "fieldname": "section_break_7", + "fieldtype": "Section Break", + "label": "Feedback" + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Interview Feedback", + "print_hide": 1, + "read_only": 1 + }, + { + "allow_in_quick_entry": 1, + "fieldname": "feedback", + "fieldtype": "Text" + }, + { + "fieldname": "result", + "fieldtype": "Select", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Result", + "options": "\nCleared\nRejected", + "reqd": 1 + }, + { + "fieldname": "details_section", + "fieldtype": "Section Break", + "label": "Details" + }, + { + "fetch_from": "interview.job_applicant", + "fieldname": "job_applicant", + "fieldtype": "Link", + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Job Applicant", + "options": "Job Applicant", + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "is_submittable": 1, + "links": [], + "modified": "2021-09-30 13:30:49.955352", + "modified_by": "Administrator", + "module": "HR", + "name": "Interview Feedback", + "owner": "Administrator", + "permissions": [ + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR Manager", + "share": 1 + }, + { + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Interviewer", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR User", + "share": 1 + } + ], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "title_field": "interviewer", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/interview_feedback/interview_feedback.py b/erpnext/hr/doctype/interview_feedback/interview_feedback.py new file mode 100644 index 00000000000..1c5a4948f24 --- /dev/null +++ b/erpnext/hr/doctype/interview_feedback/interview_feedback.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +import frappe +from frappe import _ +from frappe.model.document import Document +from frappe.utils import flt, get_link_to_form, getdate + + +class InterviewFeedback(Document): + def validate(self): + self.validate_interviewer() + self.validate_interview_date() + self.validate_duplicate() + self.calculate_average_rating() + + def on_submit(self): + self.update_interview_details() + + def on_cancel(self): + self.update_interview_details() + + def validate_interviewer(self): + applicable_interviewers = get_applicable_interviewers(self.interview) + if self.interviewer not in applicable_interviewers: + frappe.throw(_('{0} is not allowed to submit Interview Feedback for the Interview: {1}').format( + frappe.bold(self.interviewer), frappe.bold(self.interview))) + + def validate_interview_date(self): + scheduled_date = frappe.db.get_value('Interview', self.interview, 'scheduled_on') + + if getdate() < getdate(scheduled_date) and self.docstatus == 1: + frappe.throw(_('{0} submission before {1} is not allowed').format( + frappe.bold('Interview Feedback'), + frappe.bold('Interview Scheduled Date') + )) + + def validate_duplicate(self): + duplicate_feedback = frappe.db.exists('Interview Feedback', { + 'interviewer': self.interviewer, + 'interview': self.interview, + 'docstatus': 1 + }) + + if duplicate_feedback: + frappe.throw(_('Feedback already submitted for the Interview {0}. Please cancel the previous Interview Feedback {1} to continue.').format( + self.interview, get_link_to_form('Interview Feedback', duplicate_feedback))) + + def calculate_average_rating(self): + total_rating = 0 + for d in self.skill_assessment: + if d.rating: + total_rating += d.rating + + self.average_rating = flt(total_rating / len(self.skill_assessment) if len(self.skill_assessment) else 0) + + def update_interview_details(self): + doc = frappe.get_doc('Interview', self.interview) + total_rating = 0 + + if self.docstatus == 2: + for entry in doc.interview_details: + if entry.interview_feedback == self.name: + entry.average_rating = entry.interview_feedback = entry.comments = entry.result = None + break + else: + for entry in doc.interview_details: + if entry.interviewer == self.interviewer: + entry.average_rating = self.average_rating + entry.interview_feedback = self.name + entry.comments = self.feedback + entry.result = self.result + + if entry.average_rating: + total_rating += entry.average_rating + + doc.average_rating = flt(total_rating / len(doc.interview_details) if len(doc.interview_details) else 0) + doc.save() + doc.notify_update() + + +@frappe.whitelist() +def get_applicable_interviewers(interview): + data = frappe.get_all('Interview Detail', filters={'parent': interview}, fields=['interviewer']) + return [d.interviewer for d in data] diff --git a/erpnext/hr/doctype/interview_feedback/test_interview_feedback.py b/erpnext/hr/doctype/interview_feedback/test_interview_feedback.py new file mode 100644 index 00000000000..c4b7981833b --- /dev/null +++ b/erpnext/hr/doctype/interview_feedback/test_interview_feedback.py @@ -0,0 +1,103 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import unittest + +import frappe +from frappe.utils import add_days, flt, getdate + +from erpnext.hr.doctype.interview.test_interview import ( + create_interview_and_dependencies, + create_skill_set, +) +from erpnext.hr.doctype.job_applicant.test_job_applicant import create_job_applicant + + +class TestInterviewFeedback(unittest.TestCase): + def test_validation_for_skill_set(self): + frappe.set_user("Administrator") + job_applicant = create_job_applicant() + interview = create_interview_and_dependencies(job_applicant.name, scheduled_on=add_days(getdate(), -1)) + skill_ratings = get_skills_rating(interview.interview_round) + + interviewer = interview.interview_details[0].interviewer + create_skill_set(['Leadership']) + + interview_feedback = create_interview_feedback(interview.name, interviewer, skill_ratings) + interview_feedback.append("skill_assessment", {"skill": 'Leadership', 'rating': 4}) + frappe.set_user(interviewer) + + self.assertRaises(frappe.ValidationError, interview_feedback.save) + + frappe.set_user("Administrator") + + def test_average_ratings_on_feedback_submission_and_cancellation(self): + job_applicant = create_job_applicant() + interview = create_interview_and_dependencies(job_applicant.name, scheduled_on=add_days(getdate(), -1)) + skill_ratings = get_skills_rating(interview.interview_round) + + # For First Interviewer Feedback + interviewer = interview.interview_details[0].interviewer + frappe.set_user(interviewer) + + # calculating Average + feedback_1 = create_interview_feedback(interview.name, interviewer, skill_ratings) + + total_rating = 0 + for d in feedback_1.skill_assessment: + if d.rating: + total_rating += d.rating + + avg_rating = flt(total_rating / len(feedback_1.skill_assessment) if len(feedback_1.skill_assessment) else 0) + + self.assertEqual(flt(avg_rating, 3), feedback_1.average_rating) + + avg_on_interview_detail = frappe.db.get_value('Interview Detail', { + 'parent': feedback_1.interview, + 'interviewer': feedback_1.interviewer, + 'interview_feedback': feedback_1.name + }, 'average_rating') + + # 1. average should be reflected in Interview Detail. + self.assertEqual(avg_on_interview_detail, round(feedback_1.average_rating)) + + '''For Second Interviewer Feedback''' + interviewer = interview.interview_details[1].interviewer + frappe.set_user(interviewer) + + feedback_2 = create_interview_feedback(interview.name, interviewer, skill_ratings) + interview.reload() + + feedback_2.cancel() + interview.reload() + + frappe.set_user("Administrator") + + def tearDown(self): + frappe.db.rollback() + + +def create_interview_feedback(interview, interviewer, skills_ratings): + interview_feedback = frappe.new_doc("Interview Feedback") + interview_feedback.interview = interview + interview_feedback.interviewer = interviewer + interview_feedback.result = "Cleared" + + for rating in skills_ratings: + interview_feedback.append("skill_assessment", rating) + + interview_feedback.save() + interview_feedback.submit() + + return interview_feedback + + +def get_skills_rating(interview_round): + import random + + skills = frappe.get_all("Expected Skill Set", filters={"parent": interview_round}, fields = ["skill"]) + for d in skills: + d["rating"] = random.randint(1, 5) + return skills diff --git a/erpnext/hr/doctype/interview_round/__init__.py b/erpnext/hr/doctype/interview_round/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/interview_round/interview_round.js b/erpnext/hr/doctype/interview_round/interview_round.js new file mode 100644 index 00000000000..6a608b03d25 --- /dev/null +++ b/erpnext/hr/doctype/interview_round/interview_round.js @@ -0,0 +1,24 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on("Interview Round", { + refresh: function(frm) { + if (!frm.doc.__islocal) { + frm.add_custom_button(__("Create Interview"), function() { + frm.events.create_interview(frm); + }); + } + }, + create_interview: function(frm) { + frappe.call({ + method: "erpnext.hr.doctype.interview_round.interview_round.create_interview", + args: { + doc: frm.doc + }, + callback: function (r) { + var doclist = frappe.model.sync(r.message); + frappe.set_route("Form", doclist[0].doctype, doclist[0].name); + } + }); + } +}); diff --git a/erpnext/hr/doctype/interview_round/interview_round.json b/erpnext/hr/doctype/interview_round/interview_round.json new file mode 100644 index 00000000000..9c95185e9ce --- /dev/null +++ b/erpnext/hr/doctype/interview_round/interview_round.json @@ -0,0 +1,118 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "field:round_name", + "creation": "2021-04-12 12:57:19.902866", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "round_name", + "interview_type", + "interviewers", + "column_break_3", + "designation", + "expected_average_rating", + "expected_skills_section", + "expected_skill_set" + ], + "fields": [ + { + "fieldname": "round_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Round Name", + "reqd": 1, + "unique": 1 + }, + { + "fieldname": "designation", + "fieldtype": "Link", + "label": "Designation", + "options": "Designation" + }, + { + "fieldname": "expected_skills_section", + "fieldtype": "Section Break", + "label": "Expected Skillset" + }, + { + "fieldname": "expected_skill_set", + "fieldtype": "Table", + "options": "Expected Skill Set", + "reqd": 1 + }, + { + "fieldname": "expected_average_rating", + "fieldtype": "Rating", + "label": "Expected Average Rating", + "reqd": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fieldname": "interview_type", + "fieldtype": "Link", + "label": "Interview Type", + "options": "Interview Type", + "reqd": 1 + }, + { + "fieldname": "interviewers", + "fieldtype": "Table MultiSelect", + "label": "Interviewers", + "options": "Interviewer" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-09-30 13:01:25.666660", + "modified_by": "Administrator", + "module": "HR", + "name": "Interview Round", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR User", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Interviewer", + "select": 1, + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/interview_round/interview_round.py b/erpnext/hr/doctype/interview_round/interview_round.py new file mode 100644 index 00000000000..8230c785852 --- /dev/null +++ b/erpnext/hr/doctype/interview_round/interview_round.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +import json + +import frappe +from frappe.model.document import Document + + +class InterviewRound(Document): + pass + +@frappe.whitelist() +def create_interview(doc): + if isinstance(doc, str): + doc = json.loads(doc) + doc = frappe.get_doc(doc) + + interview = frappe.new_doc("Interview") + interview.interview_round = doc.name + interview.designation = doc.designation + + if doc.interviewers: + interview.interview_details = [] + for data in doc.interviewers: + interview.append("interview_details", { + "interviewer": data.user + }) + return interview + + + diff --git a/erpnext/hr/doctype/interview_round/test_interview_round.py b/erpnext/hr/doctype/interview_round/test_interview_round.py new file mode 100644 index 00000000000..932d3defc2c --- /dev/null +++ b/erpnext/hr/doctype/interview_round/test_interview_round.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +import unittest + +# import frappe + + +class TestInterviewRound(unittest.TestCase): + pass + diff --git a/erpnext/hr/doctype/interview_type/__init__.py b/erpnext/hr/doctype/interview_type/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/interview_type/interview_type.js b/erpnext/hr/doctype/interview_type/interview_type.js new file mode 100644 index 00000000000..af77b527d4d --- /dev/null +++ b/erpnext/hr/doctype/interview_type/interview_type.js @@ -0,0 +1,8 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Interview Type', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/hr/doctype/interview_type/interview_type.json b/erpnext/hr/doctype/interview_type/interview_type.json new file mode 100644 index 00000000000..14636a18cb3 --- /dev/null +++ b/erpnext/hr/doctype/interview_type/interview_type.json @@ -0,0 +1,73 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "Prompt", + "creation": "2021-04-12 14:44:40.664034", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "description" + ], + "fields": [ + { + "fieldname": "description", + "fieldtype": "Text", + "in_list_view": 1, + "label": "Description" + } + ], + "index_web_pages_for_search": 1, + "links": [ + { + "link_doctype": "Interview Round", + "link_fieldname": "interview_type" + } + ], + "modified": "2021-09-30 13:00:16.471518", + "modified_by": "Administrator", + "module": "HR", + "name": "Interview Type", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "HR User", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/interview_type/interview_type.py b/erpnext/hr/doctype/interview_type/interview_type.py new file mode 100644 index 00000000000..ee5be54c755 --- /dev/null +++ b/erpnext/hr/doctype/interview_type/interview_type.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +# import frappe +from frappe.model.document import Document + + +class InterviewType(Document): + pass diff --git a/erpnext/hr/doctype/interview_type/test_interview_type.py b/erpnext/hr/doctype/interview_type/test_interview_type.py new file mode 100644 index 00000000000..a5d3cf99229 --- /dev/null +++ b/erpnext/hr/doctype/interview_type/test_interview_type.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + + +class TestInterviewType(unittest.TestCase): + pass diff --git a/erpnext/hr/doctype/interviewer/__init__.py b/erpnext/hr/doctype/interviewer/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/interviewer/interviewer.json b/erpnext/hr/doctype/interviewer/interviewer.json new file mode 100644 index 00000000000..a37b8b0e4e5 --- /dev/null +++ b/erpnext/hr/doctype/interviewer/interviewer.json @@ -0,0 +1,31 @@ +{ + "actions": [], + "creation": "2021-04-12 17:38:19.354734", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "user" + ], + "fields": [ + { + "fieldname": "user", + "fieldtype": "Link", + "in_list_view": 1, + "label": "User", + "options": "User" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-04-13 13:41:35.817568", + "modified_by": "Administrator", + "module": "HR", + "name": "Interviewer", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/interviewer/interviewer.py b/erpnext/hr/doctype/interviewer/interviewer.py new file mode 100644 index 00000000000..1c8dbbed591 --- /dev/null +++ b/erpnext/hr/doctype/interviewer/interviewer.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +# import frappe +from frappe.model.document import Document + + +class Interviewer(Document): + pass diff --git a/erpnext/hr/doctype/job_applicant/job_applicant.js b/erpnext/hr/doctype/job_applicant/job_applicant.js index 7658bc93539..d7b1c6c9df3 100644 --- a/erpnext/hr/doctype/job_applicant/job_applicant.js +++ b/erpnext/hr/doctype/job_applicant/job_applicant.js @@ -8,6 +8,24 @@ cur_frm.email_field = "email_id"; frappe.ui.form.on("Job Applicant", { refresh: function(frm) { + frm.set_query("job_title", function() { + return { + filters: { + 'status': 'Open' + } + }; + }); + frm.events.create_custom_buttons(frm); + frm.events.make_dashboard(frm); + }, + + create_custom_buttons: function(frm) { + if (!frm.doc.__islocal && frm.doc.status !== "Rejected" && frm.doc.status !== "Accepted") { + frm.add_custom_button(__("Create Interview"), function() { + frm.events.create_dialog(frm); + }); + } + if (!frm.doc.__islocal) { if (frm.doc.__onload && frm.doc.__onload.job_offer) { $('[data-doctype="Employee Onboarding"]').find("button").show(); @@ -28,14 +46,57 @@ frappe.ui.form.on("Job Applicant", { }); } } + }, - frm.set_query("job_title", function() { - return { - filters: { - 'status': 'Open' - } - }; + make_dashboard: function(frm) { + frappe.call({ + method: "erpnext.hr.doctype.job_applicant.job_applicant.get_interview_details", + args: { + job_applicant: frm.doc.name + }, + callback: function(r) { + $("div").remove(".form-dashboard-section.custom"); + frm.dashboard.add_section( + frappe.render_template('job_applicant_dashboard', { + data: r.message + }), + __("Interview Summary") + ); + } }); + }, + create_dialog: function(frm) { + let d = new frappe.ui.Dialog({ + title: 'Enter Interview Round', + fields: [ + { + label: 'Interview Round', + fieldname: 'interview_round', + fieldtype: 'Link', + options: 'Interview Round' + }, + ], + primary_action_label: 'Create Interview', + primary_action(values) { + frm.events.create_interview(frm, values); + d.hide(); + } + }); + d.show(); + }, + + create_interview: function (frm, values) { + frappe.call({ + method: "erpnext.hr.doctype.job_applicant.job_applicant.create_interview", + args: { + doc: frm.doc, + interview_round: values.interview_round + }, + callback: function (r) { + var doclist = frappe.model.sync(r.message); + frappe.set_route("Form", doclist[0].doctype, doclist[0].name); + } + }); } }); diff --git a/erpnext/hr/doctype/job_applicant/job_applicant.json b/erpnext/hr/doctype/job_applicant/job_applicant.json index bcea5f50d93..200f675221b 100644 --- a/erpnext/hr/doctype/job_applicant/job_applicant.json +++ b/erpnext/hr/doctype/job_applicant/job_applicant.json @@ -9,16 +9,20 @@ "email_append_to": 1, "engine": "InnoDB", "field_order": [ + "details_section", "applicant_name", "email_id", "phone_number", "country", - "status", "column_break_3", "job_title", + "designation", + "status", + "source_and_rating_section", "source", "source_name", "employee_referral", + "column_break_13", "applicant_rating", "section_break_6", "notes", @@ -84,7 +88,8 @@ }, { "fieldname": "section_break_6", - "fieldtype": "Section Break" + "fieldtype": "Section Break", + "label": "Resume" }, { "fieldname": "cover_letter", @@ -160,13 +165,34 @@ "label": "Employee Referral", "options": "Employee Referral", "read_only": 1 + }, + { + "fieldname": "details_section", + "fieldtype": "Section Break", + "label": "Details" + }, + { + "fieldname": "source_and_rating_section", + "fieldtype": "Section Break", + "label": "Source and Rating" + }, + { + "fieldname": "column_break_13", + "fieldtype": "Column Break" + }, + { + "fetch_from": "job_opening.designation", + "fieldname": "designation", + "fieldtype": "Link", + "label": "Designation", + "options": "Designation" } ], "icon": "fa fa-user", "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2021-03-24 15:51:11.117517", + "modified": "2021-09-29 23:06:10.904260", "modified_by": "Administrator", "module": "HR", "name": "Job Applicant", diff --git a/erpnext/hr/doctype/job_applicant/job_applicant.py b/erpnext/hr/doctype/job_applicant/job_applicant.py index 6971e5b4fef..151f49248fd 100644 --- a/erpnext/hr/doctype/job_applicant/job_applicant.py +++ b/erpnext/hr/doctype/job_applicant/job_applicant.py @@ -8,7 +8,9 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import comma_and, validate_email_address +from frappe.utils import validate_email_address + +from erpnext.hr.doctype.interview.interview import get_interviewers class DuplicationError(frappe.ValidationError): pass @@ -26,7 +28,6 @@ class JobApplicant(Document): self.name = " - ".join(keys) def validate(self): - self.check_email_id_is_unique() if self.email_id: validate_email_address(self.email_id, True) @@ -44,11 +45,44 @@ class JobApplicant(Document): elif self.status in ["Accepted", "Rejected"]: emp_ref.db_set("status", self.status) +@frappe.whitelist() +def create_interview(doc, interview_round): + import json - def check_email_id_is_unique(self): - if self.email_id: - names = frappe.db.sql_list("""select name from `tabJob Applicant` - where email_id=%s and name!=%s and job_title=%s""", (self.email_id, self.name, self.job_title)) + from six import string_types - if names: - frappe.throw(_("Email Address must be unique, already exists for {0}").format(comma_and(names)), frappe.DuplicateEntryError) + if isinstance(doc, string_types): + doc = json.loads(doc) + doc = frappe.get_doc(doc) + + round_designation = frappe.db.get_value("Interview Round", interview_round, "designation") + + if round_designation and doc.designation and round_designation != doc.designation: + frappe.throw(_("Interview Round {0} is only applicable for the Designation {1}").format(interview_round, round_designation)) + + interview = frappe.new_doc("Interview") + interview.interview_round = interview_round + interview.job_applicant = doc.name + interview.designation = doc.designation + interview.resume_link = doc.resume_link + interview.job_opening = doc.job_title + interviewer_detail = get_interviewers(interview_round) + + for d in interviewer_detail: + interview.append("interview_details", { + "interviewer": d.interviewer + }) + return interview + +@frappe.whitelist() +def get_interview_details(job_applicant): + interview_details = frappe.db.get_all("Interview", + filters={"job_applicant":job_applicant, "docstatus": ["!=", 2]}, + fields=["name", "interview_round", "expected_average_rating", "average_rating", "status"] + ) + interview_detail_map = {} + + for detail in interview_details: + interview_detail_map[detail.name] = detail + + return interview_detail_map diff --git a/erpnext/hr/doctype/job_applicant/job_applicant_dashboard.html b/erpnext/hr/doctype/job_applicant/job_applicant_dashboard.html new file mode 100644 index 00000000000..c286787a556 --- /dev/null +++ b/erpnext/hr/doctype/job_applicant/job_applicant_dashboard.html @@ -0,0 +1,44 @@ + +{% if not jQuery.isEmptyObject(data) %} + + + + + + + + + + + + + {% for(const [key, value] of Object.entries(data)) { %} + + + + + + + + {% } %} + +
{{ __("Interview") }}{{ __("Interview Round") }}{{ __("Status") }}{{ __("Expected Rating") }}{{ __("Rating") }}
{%= key %} {%= value["interview_round"] %} {%= value["status"] %} + {% for (i = 0; i < value["expected_average_rating"]; i++) { %} + + {% } %} + {% for (i = 0; i < (5-value["expected_average_rating"]); i++) { %} + + {% } %} + + {% if(value["average_rating"]){ %} + {% for (i = 0; i < value["average_rating"]; i++) { %} + + {% } %} + {% for (i = 0; i < (5-value["average_rating"]); i++) { %} + + {% } %} + {% } %} +
+{% else %} +

No Interview has been scheduled.

+{% endif %} diff --git a/erpnext/hr/doctype/job_applicant/job_applicant_dashboard.py b/erpnext/hr/doctype/job_applicant/job_applicant_dashboard.py index c0059431cfc..2f7795fc089 100644 --- a/erpnext/hr/doctype/job_applicant/job_applicant_dashboard.py +++ b/erpnext/hr/doctype/job_applicant/job_applicant_dashboard.py @@ -2,14 +2,17 @@ from __future__ import unicode_literals def get_data(): - return { - 'fieldname': 'job_applicant', - 'transactions': [ - { - 'items': ['Employee', 'Employee Onboarding'] - }, - { - 'items': ['Job Offer'] - }, - ], - } + return { + 'fieldname': 'job_applicant', + 'transactions': [ + { + 'items': ['Employee', 'Employee Onboarding'] + }, + { + 'items': ['Job Offer', 'Appointment Letter'] + }, + { + 'items': ['Interview'] + } + ], + } diff --git a/erpnext/hr/doctype/job_applicant/test_job_applicant.py b/erpnext/hr/doctype/job_applicant/test_job_applicant.py index e583e25eae0..8fc12907421 100644 --- a/erpnext/hr/doctype/job_applicant/test_job_applicant.py +++ b/erpnext/hr/doctype/job_applicant/test_job_applicant.py @@ -7,7 +7,8 @@ import unittest import frappe -# test_records = frappe.get_test_records('Job Applicant') +from erpnext.hr.doctype.designation.test_designation import create_designation + class TestJobApplicant(unittest.TestCase): pass @@ -25,7 +26,8 @@ def create_job_applicant(**args): job_applicant = frappe.get_doc({ "doctype": "Job Applicant", - "status": args.status or "Open" + "status": args.status or "Open", + "designation": create_designation().name }) job_applicant.update(filters) diff --git a/erpnext/hr/doctype/job_offer/test_job_offer.py b/erpnext/hr/doctype/job_offer/test_job_offer.py index 3f3eca17e62..162b245d13c 100644 --- a/erpnext/hr/doctype/job_offer/test_job_offer.py +++ b/erpnext/hr/doctype/job_offer/test_job_offer.py @@ -32,6 +32,7 @@ class TestJobOffer(unittest.TestCase): self.assertTrue(frappe.db.exists("Job Offer", job_offer.name)) def test_job_applicant_update(self): + frappe.db.set_value("HR Settings", None, "check_vacancies", 0) create_staffing_plan() job_applicant = create_job_applicant(email_id="test_job_applicants@example.com") job_offer = create_job_offer(job_applicant=job_applicant.name) @@ -43,7 +44,11 @@ class TestJobOffer(unittest.TestCase): job_offer.status = "Rejected" job_offer.submit() job_applicant.reload() - self.assertEqual(job_applicant.status, "Rejected") + self.assertEquals(job_applicant.status, "Rejected") + frappe.db.set_value("HR Settings", None, "check_vacancies", 1) + + def tearDown(self): + frappe.db.sql("DELETE FROM `tabJob Offer` WHERE 1") def create_job_offer(**args): args = frappe._dict(args) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.js b/erpnext/hr/doctype/leave_allocation/leave_allocation.js index d94764104d0..9742387c16a 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.js +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.js @@ -1,14 +1,14 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -cur_frm.add_fetch('employee','employee_name','employee_name'); +cur_frm.add_fetch('employee', 'employee_name', 'employee_name'); frappe.ui.form.on("Leave Allocation", { onload: function(frm) { // Ignore cancellation of doctype on cancel all. frm.ignore_doctypes_on_cancel_all = ["Leave Ledger Entry"]; - if(!frm.doc.from_date) frm.set_value("from_date", frappe.datetime.get_today()); + if (!frm.doc.from_date) frm.set_value("from_date", frappe.datetime.get_today()); frm.set_query("employee", function() { return { @@ -25,9 +25,9 @@ frappe.ui.form.on("Leave Allocation", { }, refresh: function(frm) { - if(frm.doc.docstatus === 1 && frm.doc.expired) { + if (frm.doc.docstatus === 1 && frm.doc.expired) { var valid_expiry = moment(frappe.datetime.get_today()).isBetween(frm.doc.from_date, frm.doc.to_date); - if(valid_expiry) { + if (valid_expiry) { // expire current allocation frm.add_custom_button(__('Expire Allocation'), function() { frm.trigger("expire_allocation"); @@ -44,8 +44,8 @@ frappe.ui.form.on("Leave Allocation", { 'expiry_date': frappe.datetime.get_today() }, freeze: true, - callback: function(r){ - if(!r.exc){ + callback: function(r) { + if (!r.exc) { frappe.msgprint(__("Allocation Expired!")); } frm.refresh(); @@ -77,8 +77,8 @@ frappe.ui.form.on("Leave Allocation", { }, leave_policy: function(frm) { - if(frm.doc.leave_policy && frm.doc.leave_type) { - frappe.db.get_value("Leave Policy Detail",{ + if (frm.doc.leave_policy && frm.doc.leave_type) { + frappe.db.get_value("Leave Policy Detail", { 'parent': frm.doc.leave_policy, 'leave_type': frm.doc.leave_type }, 'annual_allocation', (r) => { @@ -91,13 +91,41 @@ frappe.ui.form.on("Leave Allocation", { return frappe.call({ method: "set_total_leaves_allocated", doc: frm.doc, - callback: function(r) { + callback: function() { frm.refresh_fields(); } - }) + }); } else if (cint(frm.doc.carry_forward) == 0) { frm.set_value("unused_leaves", 0); frm.set_value("total_leaves_allocated", flt(frm.doc.new_leaves_allocated)); } } }); + +frappe.tour["Leave Allocation"] = [ + { + fieldname: "employee", + title: "Employee", + description: __("Select the Employee for which you want to allocate leaves.") + }, + { + fieldname: "leave_type", + title: "Leave Type", + description: __("Select the Leave Type like Sick leave, Privilege Leave, Casual Leave, etc.") + }, + { + fieldname: "from_date", + title: "From Date", + description: __("Select the date from which this Leave Allocation will be valid.") + }, + { + fieldname: "to_date", + title: "To Date", + description: __("Select the date after which this Leave Allocation will expire.") + }, + { + fieldname: "new_leaves_allocated", + title: "New Leaves Allocated", + description: __("Enter the number of leaves you want to allocate for the period.") + } +]; diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json index 3a6539ece9e..52ee463db02 100644 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json @@ -219,7 +219,8 @@ "fieldname": "leave_policy_assignment", "fieldtype": "Link", "label": "Leave Policy Assignment", - "options": "Leave Policy Assignment" + "options": "Leave Policy Assignment", + "read_only": 1 }, { "fetch_from": "employee.company", @@ -236,7 +237,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-06-03 15:28:26.335104", + "modified": "2021-10-01 15:28:26.335104", "modified_by": "Administrator", "module": "HR", "name": "Leave Allocation", diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js index 9ccb915908f..9e8cb5516f3 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.js +++ b/erpnext/hr/doctype/leave_application/leave_application.js @@ -1,8 +1,8 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -cur_frm.add_fetch('employee','employee_name','employee_name'); -cur_frm.add_fetch('employee','company','company'); +cur_frm.add_fetch('employee', 'employee_name', 'employee_name'); +cur_frm.add_fetch('employee', 'company', 'company'); frappe.ui.form.on("Leave Application", { setup: function(frm) { @@ -19,7 +19,6 @@ frappe.ui.form.on("Leave Application", { frm.set_query("employee", erpnext.queries.employee); }, onload: function(frm) { - // Ignore cancellation of doctype on cancel all. frm.ignore_doctypes_on_cancel_all = ["Leave Ledger Entry"]; @@ -42,9 +41,9 @@ frappe.ui.form.on("Leave Application", { }, validate: function(frm) { - if (frm.doc.from_date == frm.doc.to_date && frm.doc.half_day == 1){ + if (frm.doc.from_date == frm.doc.to_date && frm.doc.half_day == 1) { frm.doc.half_day_date = frm.doc.from_date; - }else if (frm.doc.half_day == 0){ + } else if (frm.doc.half_day == 0) { frm.doc.half_day_date = ""; } frm.toggle_reqd("half_day_date", frm.doc.half_day == 1); @@ -79,14 +78,14 @@ frappe.ui.form.on("Leave Application", { __("Allocated Leaves") ); frm.dashboard.show(); - let allowed_leave_types = Object.keys(leave_details); + let allowed_leave_types = Object.keys(leave_details); // lwps should be allowed, lwps don't have any allocation allowed_leave_types = allowed_leave_types.concat(lwps); - frm.set_query('leave_type', function(){ + frm.set_query('leave_type', function() { return { - filters : [ + filters: [ ['leave_type_name', 'in', allowed_leave_types] ] }; @@ -99,7 +98,7 @@ frappe.ui.form.on("Leave Application", { frm.trigger("calculate_total_days"); } cur_frm.set_intro(""); - if(frm.doc.__islocal && !in_list(frappe.user_roles, "Employee")) { + if (frm.doc.__islocal && !in_list(frappe.user_roles, "Employee")) { frm.set_intro(__("Fill the form and save it")); } @@ -118,7 +117,7 @@ frappe.ui.form.on("Leave Application", { }, leave_approver: function(frm) { - if(frm.doc.leave_approver){ + if (frm.doc.leave_approver) { frm.set_value("leave_approver_name", frappe.user.full_name(frm.doc.leave_approver)); } }, @@ -131,12 +130,10 @@ frappe.ui.form.on("Leave Application", { if (frm.doc.half_day) { if (frm.doc.from_date == frm.doc.to_date) { frm.set_value("half_day_date", frm.doc.from_date); - } - else { + } else { frm.trigger("half_day_datepicker"); } - } - else { + } else { frm.set_value("half_day_date", ""); } frm.trigger("calculate_total_days"); @@ -163,11 +160,11 @@ frappe.ui.form.on("Leave Application", { half_day_datepicker.update({ minDate: frappe.datetime.str_to_obj(frm.doc.from_date), maxDate: frappe.datetime.str_to_obj(frm.doc.to_date) - }) + }); }, get_leave_balance: function(frm) { - if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.from_date && frm.doc.to_date) { + if (frm.doc.docstatus === 0 && frm.doc.employee && frm.doc.leave_type && frm.doc.from_date && frm.doc.to_date) { return frappe.call({ method: "erpnext.hr.doctype.leave_application.leave_application.get_leave_balance_on", args: { @@ -177,11 +174,10 @@ frappe.ui.form.on("Leave Application", { leave_type: frm.doc.leave_type, consider_all_leaves_in_the_allocation_period: true }, - callback: function(r) { + callback: function (r) { if (!r.exc && r.message) { frm.set_value('leave_balance', r.message); - } - else { + } else { frm.set_value('leave_balance', "0"); } } @@ -190,12 +186,12 @@ frappe.ui.form.on("Leave Application", { }, calculate_total_days: function(frm) { - if(frm.doc.from_date && frm.doc.to_date && frm.doc.employee && frm.doc.leave_type) { + if (frm.doc.from_date && frm.doc.to_date && frm.doc.employee && frm.doc.leave_type) { var from_date = Date.parse(frm.doc.from_date); var to_date = Date.parse(frm.doc.to_date); - if(to_date < from_date){ + if (to_date < from_date) { frappe.msgprint(__("To Date cannot be less than From Date")); frm.set_value('to_date', ''); return; @@ -222,7 +218,7 @@ frappe.ui.form.on("Leave Application", { }, set_leave_approver: function(frm) { - if(frm.doc.employee) { + if (frm.doc.employee) { // server call is done to include holidays in leave days calculations return frappe.call({ method: 'erpnext.hr.doctype.leave_application.leave_application.get_leave_approver', @@ -238,3 +234,36 @@ frappe.ui.form.on("Leave Application", { } } }); + +frappe.tour["Leave Application"] = [ + { + fieldname: "employee", + title: "Employee", + description: __("Select the Employee.") + }, + { + fieldname: "leave_type", + title: "Leave Type", + description: __("Select type of leave the employee wants to apply for, like Sick Leave, Privilege Leave, Casual Leave, etc.") + }, + { + fieldname: "from_date", + title: "From Date", + description: __("Select the start date for your Leave Application.") + }, + { + fieldname: "to_date", + title: "To Date", + description: __("Select the end date for your Leave Application.") + }, + { + fieldname: "half_day", + title: "Half Day", + description: __("To apply for a Half Day check 'Half Day' and select the Half Day Date") + }, + { + fieldname: "leave_approver", + title: "Leave Approver", + description: __("Select your Leave Approver i.e. the person who approves or rejects your leaves.") + } +]; diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 9e6fc6d0f14..349ed7ad227 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -76,6 +76,7 @@ class LeaveApplication(Document): # notify leave applier about approval if frappe.db.get_single_value("HR Settings", "send_leave_notification"): self.notify_employee() + self.create_leave_ledger_entry() self.reload() @@ -108,7 +109,13 @@ class LeaveApplication(Document): if frappe.db.get_single_value("HR Settings", "restrict_backdated_leave_application"): if self.from_date and getdate(self.from_date) < getdate(): allowed_role = frappe.db.get_single_value("HR Settings", "role_allowed_to_create_backdated_leave_application") - if allowed_role not in frappe.get_roles(): + user = frappe.get_doc("User", frappe.session.user) + user_roles = [d.role for d in user.roles] + if not allowed_role: + frappe.throw(_("Backdated Leave Application is restricted. Please set the {} in {}").format( + frappe.bold("Role Allowed to Create Backdated Leave Application"), get_link_to_form("HR Settings", "HR Settings"))) + + if (allowed_role and allowed_role not in user_roles): frappe.throw(_("Only users with the {0} role can create backdated leave applications").format(allowed_role)) if self.from_date and self.to_date and (getdate(self.to_date) < getdate(self.from_date)): diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index b9c785a8a9c..629b20e768e 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -121,6 +121,7 @@ class TestLeaveApplication(unittest.TestCase): application = self.get_application(_test_records[0]) application.insert() + application.reload() application.status = "Approved" self.assertRaises(LeaveDayBlockedError, application.submit) diff --git a/erpnext/hr/doctype/leave_type/leave_type.js b/erpnext/hr/doctype/leave_type/leave_type.js index 8622309848a..b930dedaca8 100644 --- a/erpnext/hr/doctype/leave_type/leave_type.js +++ b/erpnext/hr/doctype/leave_type/leave_type.js @@ -2,3 +2,37 @@ frappe.ui.form.on("Leave Type", { refresh: function(frm) { } }); + + +frappe.tour["Leave Type"] = [ + { + fieldname: "max_leaves_allowed", + title: "Maximum Leave Allocation Allowed", + description: __("This field allows you to set the maximum number of leaves that can be allocated annually for this Leave Type while creating the Leave Policy") + }, + { + fieldname: "max_continuous_days_allowed", + title: "Maximum Consecutive Leaves Allowed", + description: __("This field allows you to set the maximum number of consecutive leaves an Employee can apply for.") + }, + { + fieldname: "is_optional_leave", + title: "Is Optional Leave", + description: __("Optional Leaves are holidays that Employees can choose to avail from a list of holidays published by the company.") + }, + { + fieldname: "is_compensatory", + title: "Is Compensatory Leave", + description: __("Leaves you can avail against a holiday you worked on. You can claim Compensatory Off Leave using Compensatory Leave request. Click") + " here " + __('to know more') + }, + { + fieldname: "allow_encashment", + title: "Allow Encashment", + description: __("From here, you can enable encashment for the balance leaves.") + }, + { + fieldname: "is_earned_leave", + title: "Is Earned Leaves", + description: __("Earned Leaves are leaves earned by an Employee after working with the company for a certain amount of time. Enabling this will allocate leaves on pro-rata basis by automatically updating Leave Allocation for leaves of this type at intervals set by 'Earned Leave Frequency.") + } +]; \ No newline at end of file diff --git a/erpnext/hr/doctype/leave_type/leave_type.json b/erpnext/hr/doctype/leave_type/leave_type.json index 8f2ae6eb15d..06ca4cdedbc 100644 --- a/erpnext/hr/doctype/leave_type/leave_type.json +++ b/erpnext/hr/doctype/leave_type/leave_type.json @@ -50,7 +50,7 @@ { "fieldname": "max_leaves_allowed", "fieldtype": "Int", - "label": "Max Leaves Allowed" + "label": "Maximum Leave Allocation Allowed" }, { "fieldname": "applicable_after", @@ -61,7 +61,7 @@ "fieldname": "max_continuous_days_allowed", "fieldtype": "Int", "in_list_view": 1, - "label": "Maximum Continuous Days Applicable", + "label": "Maximum Consecutive Leaves Allowed", "oldfieldname": "max_days_allowed", "oldfieldtype": "Data" }, @@ -87,6 +87,7 @@ }, { "default": "0", + "description": "These leaves are holidays permitted by the company however, availing it is optional for an Employee.", "fieldname": "is_optional_leave", "fieldtype": "Check", "label": "Is Optional Leave" @@ -205,6 +206,7 @@ }, { "depends_on": "eval:doc.is_ppl == 1", + "description": "For a day of leave taken, if you still pay (say) 50% of the daily salary, then enter 0.50 in this field.", "fieldname": "fraction_of_daily_salary_per_leave", "fieldtype": "Float", "label": "Fraction of Daily Salary per Leave", @@ -214,7 +216,7 @@ "icon": "fa fa-flag", "idx": 1, "links": [], - "modified": "2021-08-12 16:10:36.464690", + "modified": "2021-10-02 11:59:40.503359", "modified_by": "Administrator", "module": "HR", "name": "Leave Type", diff --git a/erpnext/hr/doctype/shift_assignment/shift_assignment.py b/erpnext/hr/doctype/shift_assignment/shift_assignment.py index 69af5c54c3b..05b74a0dde9 100644 --- a/erpnext/hr/doctype/shift_assignment/shift_assignment.py +++ b/erpnext/hr/doctype/shift_assignment/shift_assignment.py @@ -139,7 +139,7 @@ def get_shift_type_timing(shift_types): return shift_timing_map -def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=False, next_shift_direction=None): +def get_employee_shift(employee, for_date=None, consider_default_shift=False, next_shift_direction=None): """Returns a Shift Type for the given employee on the given date. (excluding the holidays) :param employee: Employee for which shift is required. @@ -147,6 +147,8 @@ def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=Fals :param consider_default_shift: If set to true, default shift is taken when no shift assignment is found. :param next_shift_direction: One of: None, 'forward', 'reverse'. Direction to look for next shift if shift not found on given date. """ + if for_date is None: + for_date = nowdate() default_shift = frappe.db.get_value('Employee', employee, 'default_shift') shift_type_name = None shift_assignment_details = frappe.db.get_value('Shift Assignment', {'employee':employee, 'start_date':('<=', for_date), 'docstatus': '1', 'status': "Active"}, ['shift_type', 'end_date']) @@ -200,9 +202,11 @@ def get_employee_shift(employee, for_date=nowdate(), consider_default_shift=Fals return get_shift_details(shift_type_name, for_date) -def get_employee_shift_timings(employee, for_timestamp=now_datetime(), consider_default_shift=False): +def get_employee_shift_timings(employee, for_timestamp=None, consider_default_shift=False): """Returns previous shift, current/upcoming shift, next_shift for the given timestamp and employee """ + if for_timestamp is None: + for_timestamp = now_datetime() # write and verify a test case for midnight shift. prev_shift = curr_shift = next_shift = None curr_shift = get_employee_shift(employee, for_timestamp.date(), consider_default_shift, 'forward') @@ -220,7 +224,7 @@ def get_employee_shift_timings(employee, for_timestamp=now_datetime(), consider_ return prev_shift, curr_shift, next_shift -def get_shift_details(shift_type_name, for_date=nowdate()): +def get_shift_details(shift_type_name, for_date=None): """Returns Shift Details which contain some additional information as described below. 'shift_details' contains the following keys: 'shift_type' - Object of DocType Shift Type, @@ -234,6 +238,8 @@ def get_shift_details(shift_type_name, for_date=nowdate()): """ if not shift_type_name: return None + if not for_date: + for_date = nowdate() shift_type = frappe.get_doc('Shift Type', shift_type_name) start_datetime = datetime.combine(for_date, datetime.min.time()) + shift_type.start_time for_date = for_date + timedelta(days=1) if shift_type.start_time > shift_type.end_time else for_date diff --git a/erpnext/hr/doctype/shift_type/shift_type.py b/erpnext/hr/doctype/shift_type/shift_type.py index e53373df279..7a35b28ac43 100644 --- a/erpnext/hr/doctype/shift_type/shift_type.py +++ b/erpnext/hr/doctype/shift_type/shift_type.py @@ -97,7 +97,7 @@ class ShiftType(Document): assigned_employees = [x[0] for x in assigned_employees] if consider_default_shift: - filters = {'default_shift': self.name} + filters = {'default_shift': self.name, 'status': ['!=', 'Inactive']} default_shift_employees = frappe.get_all('Employee', 'name', filters, as_list=True) default_shift_employees = [x[0] for x in default_shift_employees] return list(set(assigned_employees+default_shift_employees)) diff --git a/erpnext/hr/doctype/skill_assessment/__init__.py b/erpnext/hr/doctype/skill_assessment/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/doctype/skill_assessment/skill_assessment.json b/erpnext/hr/doctype/skill_assessment/skill_assessment.json new file mode 100644 index 00000000000..8b935c4073a --- /dev/null +++ b/erpnext/hr/doctype/skill_assessment/skill_assessment.json @@ -0,0 +1,41 @@ +{ + "actions": [], + "creation": "2021-04-12 17:07:39.656289", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "skill", + "rating" + ], + "fields": [ + { + "fieldname": "skill", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Skill", + "options": "Skill", + "read_only": 1, + "reqd": 1 + }, + { + "fieldname": "rating", + "fieldtype": "Rating", + "in_list_view": 1, + "label": "Rating", + "reqd": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-04-12 17:18:14.032298", + "modified_by": "Administrator", + "module": "HR", + "name": "Skill Assessment", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/hr/doctype/skill_assessment/skill_assessment.py b/erpnext/hr/doctype/skill_assessment/skill_assessment.py new file mode 100644 index 00000000000..3b74c4ed5f9 --- /dev/null +++ b/erpnext/hr/doctype/skill_assessment/skill_assessment.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals + +# import frappe +from frappe.model.document import Document + + +class SkillAssessment(Document): + pass diff --git a/erpnext/hr/doctype/staffing_plan/staffing_plan.py b/erpnext/hr/doctype/staffing_plan/staffing_plan.py index 57a92b05871..93cd4e1f629 100644 --- a/erpnext/hr/doctype/staffing_plan/staffing_plan.py +++ b/erpnext/hr/doctype/staffing_plan/staffing_plan.py @@ -155,7 +155,11 @@ def get_designation_counts(designation, company): return employee_counts @frappe.whitelist() -def get_active_staffing_plan_details(company, designation, from_date=getdate(nowdate()), to_date=getdate(nowdate())): +def get_active_staffing_plan_details(company, designation, from_date=None, to_date=None): + if from_date is None: + from_date = getdate(nowdate()) + if to_date is None: + to_date = getdate(nowdate()) if not company or not designation: frappe.throw(_("Please select Company and Designation")) diff --git a/erpnext/hr/module_onboarding/human_resource/human_resource.json b/erpnext/hr/module_onboarding/human_resource/human_resource.json index 518c002bcaa..cd11bd1102e 100644 --- a/erpnext/hr/module_onboarding/human_resource/human_resource.json +++ b/erpnext/hr/module_onboarding/human_resource/human_resource.json @@ -13,17 +13,14 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/human-resources", "idx": 0, "is_complete": 0, - "modified": "2020-07-08 14:05:47.018799", + "modified": "2021-05-19 05:32:01.794628", "modified_by": "Administrator", "module": "HR", "name": "Human Resource", "owner": "Administrator", "steps": [ { - "step": "Create Department" - }, - { - "step": "Create Designation" + "step": "HR Settings" }, { "step": "Create Holiday list" @@ -31,6 +28,9 @@ { "step": "Create Employee" }, + { + "step": "Data import" + }, { "step": "Create Leave Type" }, @@ -39,9 +39,6 @@ }, { "step": "Create Leave Application" - }, - { - "step": "HR Settings" } ], "subtitle": "Employee, Leaves, and more.", diff --git a/erpnext/hr/onboarding_step/create_employee/create_employee.json b/erpnext/hr/onboarding_step/create_employee/create_employee.json index 3aa33c6d862..47828186bf3 100644 --- a/erpnext/hr/onboarding_step/create_employee/create_employee.json +++ b/erpnext/hr/onboarding_step/create_employee/create_employee.json @@ -1,18 +1,20 @@ { - "action": "Create Entry", + "action": "Show Form Tour", + "action_label": "Show Tour", "creation": "2020-05-14 11:43:25.561152", + "description": "

Employee

\n\nAn individual who works and is recognized for his rights and duties in your company is your Employee. You can manage the Employee master. It captures the demographic, personal and professional details, joining and leave details, etc.", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 12:26:28.629074", + "modified": "2021-05-19 04:50:02.240321", "modified_by": "Administrator", "name": "Create Employee", "owner": "Administrator", "reference_document": "Employee", + "show_form_tour": 0, "show_full_form": 0, "title": "Create Employee", "validate_action": 0 diff --git a/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json b/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json index 32472b4b3fa..a08e85fff01 100644 --- a/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json +++ b/erpnext/hr/onboarding_step/create_holiday_list/create_holiday_list.json @@ -1,18 +1,20 @@ { - "action": "Create Entry", + "action": "Show Form Tour", + "action_label": "Show Tour", "creation": "2020-05-28 11:47:34.700174", + "description": "

Holiday List.

\n\nHoliday List is a list which contains the dates of holidays. Most organizations have a standard Holiday List for their employees. However, some of them may have different holiday lists based on different Locations or Departments. In ERPNext, you can configure multiple Holiday Lists.", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 12:25:38.068582", + "modified": "2021-05-19 04:19:52.305199", "modified_by": "Administrator", "name": "Create Holiday list", "owner": "Administrator", "reference_document": "Holiday List", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Holiday List", "validate_action": 0 diff --git a/erpnext/hr/onboarding_step/create_leave_allocation/create_leave_allocation.json b/erpnext/hr/onboarding_step/create_leave_allocation/create_leave_allocation.json index fa9941e6b97..0b0ce3fc8bb 100644 --- a/erpnext/hr/onboarding_step/create_leave_allocation/create_leave_allocation.json +++ b/erpnext/hr/onboarding_step/create_leave_allocation/create_leave_allocation.json @@ -1,18 +1,20 @@ { - "action": "Create Entry", + "action": "Show Form Tour", + "action_label": "Show Tour", "creation": "2020-05-14 11:48:56.123718", + "description": "

Leave Allocation

\n\nLeave Allocation enables you to allocate a specific number of leaves of a particular type to an Employee so that, an employee will be able to create a Leave Application only if Leaves are allocated. ", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 11:48:56.123718", + "modified": "2021-05-19 04:22:34.220238", "modified_by": "Administrator", "name": "Create Leave Allocation", "owner": "Administrator", "reference_document": "Leave Allocation", + "show_form_tour": 0, "show_full_form": 0, "title": "Create Leave Allocation", "validate_action": 0 diff --git a/erpnext/hr/onboarding_step/create_leave_application/create_leave_application.json b/erpnext/hr/onboarding_step/create_leave_application/create_leave_application.json index 1ed074e9a1d..af63aa59ed6 100644 --- a/erpnext/hr/onboarding_step/create_leave_application/create_leave_application.json +++ b/erpnext/hr/onboarding_step/create_leave_application/create_leave_application.json @@ -1,18 +1,20 @@ { - "action": "Create Entry", + "action": "Show Form Tour", + "action_label": "Show Tour", "creation": "2020-05-14 11:49:45.400764", + "description": "

Leave Application

\n\nLeave Application is a formal document created by an Employee to apply for Leaves for a particular time period based on there leave allocation and leave type according to there need.", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-14 11:49:45.400764", + "modified": "2021-05-19 04:39:09.893474", "modified_by": "Administrator", "name": "Create Leave Application", "owner": "Administrator", "reference_document": "Leave Application", + "show_form_tour": 0, "show_full_form": 0, "title": "Create Leave Application", "validate_action": 0 diff --git a/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json b/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json index 8cbfc5c81f9..397f5cde49c 100644 --- a/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json +++ b/erpnext/hr/onboarding_step/create_leave_type/create_leave_type.json @@ -1,18 +1,20 @@ { - "action": "Create Entry", + "action": "Show Form Tour", + "action_label": "Show Tour", "creation": "2020-05-27 11:17:31.119312", + "description": "

Leave Type

\n\nLeave type is defined based on many factors and features like encashment, earned leaves, partially paid, without pay and, a lot more. To check other options and to define your leave type click on Show Tour.", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 1, "is_single": 0, "is_skipped": 0, - "modified": "2020-05-20 11:17:31.119312", + "modified": "2021-05-19 04:32:48.135406", "modified_by": "Administrator", "name": "Create Leave Type", "owner": "Administrator", "reference_document": "Leave Type", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Leave Type", "validate_action": 0 diff --git a/erpnext/hr/onboarding_step/data_import/data_import.json b/erpnext/hr/onboarding_step/data_import/data_import.json new file mode 100644 index 00000000000..ac343c67759 --- /dev/null +++ b/erpnext/hr/onboarding_step/data_import/data_import.json @@ -0,0 +1,21 @@ +{ + "action": "Watch Video", + "action_label": "", + "creation": "2021-05-19 05:29:16.809610", + "description": "

Data Import

\n\nData import is the tool to migrate your existing data like Employee, Customer, Supplier, and a lot more to our ERPNext system.\nGo through the video for a detailed explanation of this tool.", + "docstatus": 0, + "doctype": "Onboarding Step", + "idx": 0, + "is_complete": 0, + "is_single": 0, + "is_skipped": 0, + "modified": "2021-05-19 05:29:16.809610", + "modified_by": "Administrator", + "name": "Data import", + "owner": "Administrator", + "show_form_tour": 0, + "show_full_form": 0, + "title": "Data Import", + "validate_action": 1, + "video_url": "https://www.youtube.com/watch?v=DQyqeurPI64" +} \ No newline at end of file diff --git a/erpnext/hr/onboarding_step/hr_settings/hr_settings.json b/erpnext/hr/onboarding_step/hr_settings/hr_settings.json index 0a1d0baf8aa..355664fbc59 100644 --- a/erpnext/hr/onboarding_step/hr_settings/hr_settings.json +++ b/erpnext/hr/onboarding_step/hr_settings/hr_settings.json @@ -1,18 +1,20 @@ { - "action": "Update Settings", + "action": "Show Form Tour", + "action_label": "Explore", "creation": "2020-05-28 13:13:52.427711", + "description": "

HR Settings

\n\nHr Settings consists of major settings related to Employee Lifecycle, Leave Management, etc. Click on Explore, to explore Hr Settings.", "docstatus": 0, "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 1, "is_skipped": 0, - "modified": "2020-05-20 11:16:42.430974", + "modified": "2021-05-18 07:02:05.747548", "modified_by": "Administrator", "name": "HR Settings", "owner": "Administrator", "reference_document": "HR Settings", + "show_form_tour": 0, "show_full_form": 0, "title": "HR Settings", "validate_action": 0 diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py index 6bca1368d3f..d463b9b62a8 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py @@ -182,10 +182,11 @@ def get_allocated_and_expired_leaves(from_date, to_date, employee, leave_type): records= frappe.db.sql(""" SELECT employee, leave_type, from_date, to_date, leaves, transaction_name, - is_carry_forward, is_expired + transaction_type, is_carry_forward, is_expired FROM `tabLeave Ledger Entry` WHERE employee=%(employee)s AND leave_type=%(leave_type)s AND docstatus=1 + AND transaction_type = 'Leave Allocation' AND (from_date between %(from_date)s AND %(to_date)s OR to_date between %(from_date)s AND %(to_date)s OR (from_date < %(from_date)s AND to_date > %(to_date)s)) diff --git a/erpnext/loan_management/doctype/loan/loan.json b/erpnext/loan_management/doctype/loan/loan.json index c9f23ca4df3..5979992bbe8 100644 --- a/erpnext/loan_management/doctype/loan/loan.json +++ b/erpnext/loan_management/doctype/loan/loan.json @@ -334,7 +334,6 @@ }, { "depends_on": "eval:doc.is_secured_loan", - "fetch_from": "loan_application.maximum_loan_amount", "fieldname": "maximum_loan_amount", "fieldtype": "Currency", "label": "Maximum Loan Amount", @@ -360,7 +359,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-04-19 18:10:32.360818", + "modified": "2021-10-12 18:10:32.360818", "modified_by": "Administrator", "module": "Loan Management", "name": "Loan", diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py index 7dbd42297e1..0f2c3cfdfc0 100644 --- a/erpnext/loan_management/doctype/loan/loan.py +++ b/erpnext/loan_management/doctype/loan/loan.py @@ -137,16 +137,23 @@ class Loan(AccountsController): frappe.throw(_("Loan amount is mandatory")) def link_loan_security_pledge(self): - if self.is_secured_loan: - loan_security_pledge = frappe.db.get_value('Loan Security Pledge', {'loan_application': self.loan_application}, - 'name') + if self.is_secured_loan and self.loan_application: + maximum_loan_value = frappe.db.get_value('Loan Security Pledge', + { + 'loan_application': self.loan_application, + 'status': 'Requested' + }, + 'sum(maximum_loan_value)' + ) - if loan_security_pledge: - frappe.db.set_value('Loan Security Pledge', loan_security_pledge, { - 'loan': self.name, - 'status': 'Pledged', - 'pledge_time': now_datetime() - }) + if maximum_loan_value: + frappe.db.sql(""" + UPDATE `tabLoan Security Pledge` + SET loan = %s, pledge_time = %s, status = 'Pledged' + WHERE status = 'Requested' and loan_application = %s + """, (self.name, now_datetime(), self.loan_application)) + + self.db_set('maximum_loan_amount', maximum_loan_value) def unlink_loan_security_pledge(self): pledges = frappe.get_all('Loan Security Pledge', fields=['name'], filters={'loan': self.name}) diff --git a/erpnext/loan_management/doctype/loan_application/loan_application.py b/erpnext/loan_management/doctype/loan_application/loan_application.py index e492920abb3..ede0467b0e7 100644 --- a/erpnext/loan_management/doctype/loan_application/loan_application.py +++ b/erpnext/loan_management/doctype/loan_application/loan_application.py @@ -130,10 +130,11 @@ class LoanApplication(Document): def create_loan(source_name, target_doc=None, submit=0): def update_accounts(source_doc, target_doc, source_parent): account_details = frappe.get_all("Loan Type", - fields=["mode_of_payment", "payment_account","loan_account", "interest_income_account", "penalty_income_account"], - filters = {'name': source_doc.loan_type} - )[0] + fields=["mode_of_payment", "payment_account","loan_account", "interest_income_account", "penalty_income_account"], + filters = {'name': source_doc.loan_type})[0] + if source_doc.is_secured_loan: + target_doc.maximum_loan_amount = 0 target_doc.mode_of_payment = account_details.mode_of_payment target_doc.payment_account = account_details.payment_account diff --git a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py index 6d9d4f490d3..99f0d259246 100644 --- a/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py +++ b/erpnext/loan_management/doctype/loan_disbursement/loan_disbursement.py @@ -198,7 +198,7 @@ def get_disbursal_amount(loan, on_current_security_price=0): security_value = get_total_pledged_security_value(loan) if loan_details.is_secured_loan and not on_current_security_price: - security_value = flt(loan_details.maximum_loan_amount) + security_value = get_maximum_amount_as_per_pledged_security(loan) if not security_value and not loan_details.is_secured_loan: security_value = flt(loan_details.loan_amount) @@ -209,3 +209,6 @@ def get_disbursal_amount(loan, on_current_security_price=0): disbursal_amount = loan_details.loan_amount - loan_details.disbursed_amount return disbursal_amount + +def get_maximum_amount_as_per_pledged_security(loan): + return flt(frappe.db.get_value('Loan Security Pledge', {'loan': loan}, 'sum(maximum_loan_value)')) diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index 13b73573274..40bb581165b 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -411,7 +411,7 @@ def get_amounts(amounts, against_loan, posting_date): if due_date and not final_due_date: final_due_date = add_days(due_date, loan_type_details.grace_period_in_days) - if against_loan_doc.status in ('Disbursed', 'Loan Closure Requested', 'Closed'): + if against_loan_doc.status in ('Disbursed', 'Closed') or against_loan_doc.disbursed_amount >= against_loan_doc.loan_amount: pending_principal_amount = against_loan_doc.total_payment - against_loan_doc.total_principal_paid \ - against_loan_doc.total_interest_payable - against_loan_doc.written_off_amount else: diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py index a1df9cfd0eb..adb57f9f397 100644 --- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py +++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.py @@ -199,12 +199,16 @@ class MaintenanceSchedule(TransactionBase): if chk: throw(_("Maintenance Schedule {0} exists against {1}").format(chk[0][0], d.sales_order)) + def validate_no_of_visits(self): + return len(self.schedules) != sum(d.no_of_visits for d in self.items) + def validate(self): self.validate_end_date_visits() self.validate_maintenance_detail() self.validate_dates_with_periodicity() self.validate_sales_order() - self.generate_schedule() + if not self.schedules or self.validate_no_of_visits(): + self.generate_schedule() def on_update(self): frappe.db.set(self, 'status', 'Draft') diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index ef074052620..23004ee41d7 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -215,7 +215,32 @@ frappe.ui.form.on("BOM", { label: __('Qty To Manufacture'), fieldname: 'qty', reqd: 1, - default: 1 + default: 1, + onchange: () => { + const { quantity, items: rm } = frm.doc; + const variant_items_map = rm.reduce((acc, item) => { + acc[item.item_code] = item.qty; + return acc; + }, {}); + const mf_qty = cur_dialog.fields_list.filter( + (f) => f.df.fieldname === "qty" + )[0]?.value; + const items = cur_dialog.fields.filter( + (f) => f.fieldname === "items" + )[0]?.data; + + if (!items) { + return; + } + + items.forEach((item) => { + item.qty = + (variant_items_map[item.item_code] * mf_qty) / + quantity; + }); + + cur_dialog.refresh(); + } }); } diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 651e6461494..3ea756eec97 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -1135,8 +1135,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): query_filters["has_variants"] = 0 if filters and filters.get("is_stock_item"): - or_cond_filters["is_stock_item"] = 1 - or_cond_filters["has_variants"] = 1 + query_filters["is_stock_item"] = 1 return frappe.get_list("Item", fields = fields, filters=query_filters, diff --git a/erpnext/manufacturing/doctype/bom/test_bom.py b/erpnext/manufacturing/doctype/bom/test_bom.py index 8338fa30ddc..6126c95cd45 100644 --- a/erpnext/manufacturing/doctype/bom/test_bom.py +++ b/erpnext/manufacturing/doctype/bom/test_bom.py @@ -4,12 +4,14 @@ import unittest from collections import deque +from functools import partial import frappe from frappe.test_runner import make_test_records from frappe.utils import cstr, flt from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order +from erpnext.manufacturing.doctype.bom.bom import item_query from erpnext.manufacturing.doctype.bom_update_tool.bom_update_tool import update_cost from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( @@ -344,6 +346,16 @@ class TestBOM(unittest.TestCase): for reqd_item, created_item in zip(reqd_order, created_order): self.assertEqual(reqd_item, created_item.item_code) + def test_bom_item_query(self): + query = partial(item_query, doctype="Item", txt="", searchfield="name", start=0, page_len=20, filters={"is_stock_item": 1}) + + test_items = query(txt="_Test") + filtered = query(txt="_Test Item 2") + + self.assertNotEqual(len(test_items), len(filtered), msg="Item filtering showing excessive results") + self.assertTrue(0 < len(filtered) <= 3, msg="Item filtering showing excessive results") + + def get_default_bom(item_code="_Test FG Item 2"): return frappe.db.get_value("BOM", {"item": item_code, "is_active": 1, "is_default": 1}) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 71d5335d518..fbe33dace83 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -262,7 +262,7 @@ erpnext.patches.v13_0.update_payment_terms_outstanding erpnext.patches.v12_0.add_state_code_for_ladakh erpnext.patches.v13_0.item_reposting_for_incorrect_sl_and_gl erpnext.patches.v13_0.delete_old_bank_reconciliation_doctypes -erpnext.patches.v12_0.update_vehicle_no_reqd_condition +erpnext.patches.v13_0.update_vehicle_no_reqd_condition erpnext.patches.v12_0.add_einvoice_status_field #2021-03-17 erpnext.patches.v12_0.add_einvoice_summary_report_permissions erpnext.patches.v13_0.setup_fields_for_80g_certificate_and_donation @@ -313,11 +313,17 @@ erpnext.patches.v13_0.create_website_items #30-09-2021 erpnext.patches.v13_0.populate_e_commerce_settings erpnext.patches.v13_0.make_homepage_products_website_items erpnext.patches.v13_0.update_dates_in_tax_withholding_category +erpnext.patches.v13_0.fix_invoice_statuses erpnext.patches.v13_0.replace_supplier_item_group_with_party_specific_item erpnext.patches.v13_0.gst_fields_for_pos_invoice erpnext.patches.v13_0.create_accounting_dimensions_in_pos_doctypes erpnext.patches.v13_0.create_custom_field_for_finance_book -erpnext.patches.v13_0.modify_invalid_gain_loss_gl_entries +erpnext.patches.v13_0.modify_invalid_gain_loss_gl_entries #2 erpnext.patches.v13_0.fix_additional_cost_in_mfg_stock_entry erpnext.patches.v13_0.shopping_cart_to_ecommerce erpnext.patches.v13_0.set_status_in_maintenance_schedule_table +erpnext.patches.v13_0.add_default_interview_notification_templates +erpnext.patches.v13_0.trim_sales_invoice_custom_field_length +erpnext.patches.v13_0.enable_scheduler_job_for_item_reposting +erpnext.patches.v13_0.requeue_failed_reposts +erpnext.patches.v13_0.fetch_thumbnail_in_website_items diff --git a/erpnext/patches/v13_0/add_default_interview_notification_templates.py b/erpnext/patches/v13_0/add_default_interview_notification_templates.py new file mode 100644 index 00000000000..5e8a27fa40a --- /dev/null +++ b/erpnext/patches/v13_0/add_default_interview_notification_templates.py @@ -0,0 +1,37 @@ +from __future__ import unicode_literals + +import os + +import frappe +from frappe import _ + + +def execute(): + if not frappe.db.exists('Email Template', _('Interview Reminder')): + base_path = frappe.get_app_path('erpnext', 'hr', 'doctype') + response = frappe.read_file(os.path.join(base_path, 'interview/interview_reminder_notification_template.html')) + + frappe.get_doc({ + 'doctype': 'Email Template', + 'name': _('Interview Reminder'), + 'response': response, + 'subject': _('Interview Reminder'), + 'owner': frappe.session.user, + }).insert(ignore_permissions=True) + + if not frappe.db.exists('Email Template', _('Interview Feedback Reminder')): + base_path = frappe.get_app_path('erpnext', 'hr', 'doctype') + response = frappe.read_file(os.path.join(base_path, 'interview/interview_feedback_reminder_template.html')) + + frappe.get_doc({ + 'doctype': 'Email Template', + 'name': _('Interview Feedback Reminder'), + 'response': response, + 'subject': _('Interview Feedback Reminder'), + 'owner': frappe.session.user, + }).insert(ignore_permissions=True) + + hr_settings = frappe.get_doc('HR Settings') + hr_settings.interview_reminder_template = _('Interview Reminder') + hr_settings.feedback_reminder_notification_template = _('Interview Feedback Reminder') + hr_settings.save() diff --git a/erpnext/patches/v13_0/create_website_items.py b/erpnext/patches/v13_0/create_website_items.py index 5c245ca29fc..3baa34b71c0 100644 --- a/erpnext/patches/v13_0/create_website_items.py +++ b/erpnext/patches/v13_0/create_website_items.py @@ -14,8 +14,9 @@ def execute(): item_fields = ["item_code", "item_name", "item_group", "stock_uom", "brand", "image", "has_variants", "variant_of", "description", "weightage"] web_fields_to_map = ["route", "slideshow", "website_image_alt", - "website_warehouse", "web_long_description", "website_content"] + "website_warehouse", "web_long_description", "website_content", "thumbnail"] + # get all valid columns (fields) from Item master DB schema item_table_fields = frappe.db.sql("desc `tabItem`", as_dict=1) item_table_fields = [d.get('Field') for d in item_table_fields] @@ -42,37 +43,30 @@ def execute(): fields=item_fields, or_filters=or_filters ) + total_count = len(items) - count = 0 - for item in items: + for count, item in enumerate(items, start=1): if frappe.db.exists("Website Item", {"item_code": item.item_code}): - # if website item already exists check for empty thumbnail - web_item_doc = frappe.get_doc("Website Item", {"item_code": item.item_code}) - if web_item_doc.website_image and not web_item_doc.thumbnail: - web_item_doc.make_thumbnail() - web_item_doc.save() - else: - # else make new website item from item (publish item) - website_item = make_website_item(item, save=False) - website_item.ranking = item.get("weightage") - for field in web_fields_to_map: - website_item.update({field: item.get(field)}) - website_item.save() + continue - # move Website Item Group & Website Specification table to Website Item - for doctype in ("Website Item Group", "Item Website Specification"): - web_item, item_code = website_item.name, item.item_code - frappe.db.sql(f""" - Update - `tab{doctype}` - set - parenttype = 'Website Item', - parent = '{web_item}' - where - parenttype = 'Item' - and parent = '{item_code}' - """) + # make new website item from item (publish item) + website_item = make_website_item(item, save=False) + website_item.ranking = item.get("weightage") + + for field in web_fields_to_map: + website_item.update({field: item.get(field)}) + + website_item.save() + + # move Website Item Group & Website Specification table to Website Item + for doctype in ("Website Item Group", "Item Website Specification"): + frappe.db.set_value( + doctype, + {"parenttype": "Item", "parent": item.item_code}, # filters + {"parenttype": "Website Item", "parent": website_item.name} # value dict + ) - count += 1 if count % 20 == 0: # commit after every 20 items - frappe.db.commit() \ No newline at end of file + frappe.db.commit() + + frappe.utils.update_progress_bar('Creating Website Items', count, total_count) \ No newline at end of file diff --git a/erpnext/patches/v13_0/enable_scheduler_job_for_item_reposting.py b/erpnext/patches/v13_0/enable_scheduler_job_for_item_reposting.py new file mode 100644 index 00000000000..7a51b432117 --- /dev/null +++ b/erpnext/patches/v13_0/enable_scheduler_job_for_item_reposting.py @@ -0,0 +1,8 @@ +import frappe + + +def execute(): + frappe.reload_doc('core', 'doctype', 'scheduled_job_type') + if frappe.db.exists('Scheduled Job Type', 'repost_item_valuation.repost_entries'): + frappe.db.set_value('Scheduled Job Type', + 'repost_item_valuation.repost_entries', 'stopped', 0) diff --git a/erpnext/patches/v13_0/fetch_thumbnail_in_website_items.py b/erpnext/patches/v13_0/fetch_thumbnail_in_website_items.py new file mode 100644 index 00000000000..32ad542cf88 --- /dev/null +++ b/erpnext/patches/v13_0/fetch_thumbnail_in_website_items.py @@ -0,0 +1,16 @@ +import frappe + + +def execute(): + if frappe.db.has_column("Item", "thumbnail"): + website_item = frappe.qb.DocType("Website Item").as_("wi") + item = frappe.qb.DocType("Item") + + frappe.qb.update(website_item).inner_join(item).on( + website_item.item_code == item.item_code + ).set( + website_item.thumbnail, item.thumbnail + ).where( + website_item.website_image.notnull() + & website_item.thumbnail.isnull() + ).run() diff --git a/erpnext/patches/v13_0/fix_invoice_statuses.py b/erpnext/patches/v13_0/fix_invoice_statuses.py new file mode 100644 index 00000000000..4395757159f --- /dev/null +++ b/erpnext/patches/v13_0/fix_invoice_statuses.py @@ -0,0 +1,113 @@ +import frappe +from frappe.utils import flt, getdate + +from erpnext.accounts.doctype.sales_invoice.sales_invoice import ( + get_total_in_party_account_currency, + is_overdue, +) + +TODAY = getdate() + +def execute(): + # This fix is not related to Party Specific Item, + # but it is needed for code introduced after Party Specific Item was + # If your DB doesn't have this doctype yet, you should be fine + if not frappe.db.exists("DocType", "Party Specific Item"): + return + + for doctype in ("Purchase Invoice", "Sales Invoice"): + fields = [ + "name", + "status", + "due_date", + "outstanding_amount", + "grand_total", + "base_grand_total", + "rounded_total", + "base_rounded_total", + "disable_rounded_total", + ] + if doctype == "Sales Invoice": + fields.append("is_pos") + + invoices_to_update = frappe.get_all( + doctype, + fields=fields, + filters={ + "docstatus": 1, + "status": ("in", ( + "Overdue", + "Overdue and Discounted", + "Partly Paid", + "Partly Paid and Discounted" + )), + "outstanding_amount": (">", 0), + "modified": (">", "2021-01-01") + # an assumption is being made that only invoices modified + # after 2021 got affected as incorrectly overdue. + # required for performance reasons. + } + ) + + invoices_to_update = { + invoice.name: invoice for invoice in invoices_to_update + } + + payment_schedule_items = frappe.get_all( + "Payment Schedule", + fields=( + "due_date", + "payment_amount", + "base_payment_amount", + "parent" + ), + filters={"parent": ("in", invoices_to_update)} + ) + + for item in payment_schedule_items: + invoices_to_update[item.parent].setdefault( + "payment_schedule", [] + ).append(item) + + status_map = {} + + for invoice in invoices_to_update.values(): + invoice.doctype = doctype + doc = frappe.get_doc(invoice) + correct_status = get_correct_status(doc) + if not correct_status or doc.status == correct_status: + continue + + status_map.setdefault(correct_status, []).append(doc.name) + + for status, docs in status_map.items(): + frappe.db.set_value( + doctype, {"name": ("in", docs)}, + "status", + status, + update_modified=False + ) + + + +def get_correct_status(doc): + outstanding_amount = flt( + doc.outstanding_amount, doc.precision("outstanding_amount") + ) + total = get_total_in_party_account_currency(doc) + + status = "" + if is_overdue(doc, total): + status = "Overdue" + elif 0 < outstanding_amount < total: + status = "Partly Paid" + elif outstanding_amount > 0 and getdate(doc.due_date) >= TODAY: + status = "Unpaid" + + if not status: + return + + if doc.status.endswith(" and Discounted"): + status += " and Discounted" + + return status diff --git a/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py b/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py index fa8a86437d0..3af7dac3422 100644 --- a/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py +++ b/erpnext/patches/v13_0/modify_invalid_gain_loss_gl_entries.py @@ -17,7 +17,7 @@ def execute(): where ref_exchange_rate = 1 and docstatus = 1 - and ifnull(exchange_gain_loss, '') != '' + and ifnull(exchange_gain_loss, 0) != 0 group by parent """, as_dict=1) @@ -30,7 +30,7 @@ def execute(): where ref_exchange_rate = 1 and docstatus = 1 - and ifnull(exchange_gain_loss, '') != '' + and ifnull(exchange_gain_loss, 0) != 0 group by parent """, as_dict=1) @@ -38,12 +38,24 @@ def execute(): if purchase_invoices + sales_invoices: frappe.log_error(json.dumps(purchase_invoices + sales_invoices, indent=2), title="Patch Log") + acc_frozen_upto = frappe.db.get_value('Accounts Settings', None, 'acc_frozen_upto') + if acc_frozen_upto: + frappe.db.set_value('Accounts Settings', None, 'acc_frozen_upto', None) + for invoice in purchase_invoices + sales_invoices: - doc = frappe.get_doc(invoice.type, invoice.name) - doc.docstatus = 2 - doc.make_gl_entries() - for advance in doc.advances: - if advance.ref_exchange_rate == 1: - advance.db_set('exchange_gain_loss', 0, False) - doc.docstatus = 1 - doc.make_gl_entries() \ No newline at end of file + try: + doc = frappe.get_doc(invoice.type, invoice.name) + doc.docstatus = 2 + doc.make_gl_entries() + for advance in doc.advances: + if advance.ref_exchange_rate == 1: + advance.db_set('exchange_gain_loss', 0, False) + doc.docstatus = 1 + doc.make_gl_entries() + frappe.db.commit() + except Exception: + frappe.db.rollback() + print(f'Failed to correct gl entries of {invoice.name}') + + if acc_frozen_upto: + frappe.db.set_value('Accounts Settings', None, 'acc_frozen_upto', acc_frozen_upto) \ No newline at end of file diff --git a/erpnext/patches/v13_0/requeue_failed_reposts.py b/erpnext/patches/v13_0/requeue_failed_reposts.py new file mode 100644 index 00000000000..213cb9e26e4 --- /dev/null +++ b/erpnext/patches/v13_0/requeue_failed_reposts.py @@ -0,0 +1,13 @@ +import frappe +from frappe.utils import cstr + + +def execute(): + + reposts = frappe.get_all("Repost Item Valuation", + {"status": "Failed", "modified": [">", "2021-10-05"] }, + ["name", "modified", "error_log"]) + + for repost in reposts: + if "check_freezing_date" in cstr(repost.error_log): + frappe.db.set_value("Repost Item Valuation", repost.name, "status", "Queued") diff --git a/erpnext/patches/v13_0/shopping_cart_to_ecommerce.py b/erpnext/patches/v13_0/shopping_cart_to_ecommerce.py index d336c929751..35710a9bb4a 100644 --- a/erpnext/patches/v13_0/shopping_cart_to_ecommerce.py +++ b/erpnext/patches/v13_0/shopping_cart_to_ecommerce.py @@ -26,4 +26,4 @@ def notify_users(): note.public = 1 note.notify_on_login = 1 note.content = """

You are seeing this message because Shopping Cart is enabled on your site.


Shopping Cart Settings and Products settings are now merged into "E Commerce Settings".


You can learn about new and improved E-Commerce features in the official documentation.

  1. https://docs.erpnext.com/docs/v13/user/manual/en/e_commerce/set_up_e_commerce


""" - note.save() + note.insert(ignore_mandatory=True) diff --git a/erpnext/patches/v13_0/trim_sales_invoice_custom_field_length.py b/erpnext/patches/v13_0/trim_sales_invoice_custom_field_length.py new file mode 100644 index 00000000000..fd48c0d902d --- /dev/null +++ b/erpnext/patches/v13_0/trim_sales_invoice_custom_field_length.py @@ -0,0 +1,18 @@ +# Copyright (c) 2020, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe + +from erpnext.regional.india.setup import create_custom_fields, get_custom_fields + + +def execute(): + company = frappe.get_all('Company', filters = {'country': 'India'}) + if not company: + return + + custom_fields = { + 'Sales Invoice': get_custom_fields().get('Sales Invoice') + } + + create_custom_fields(custom_fields, update=True) diff --git a/erpnext/patches/v12_0/update_vehicle_no_reqd_condition.py b/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py similarity index 81% rename from erpnext/patches/v12_0/update_vehicle_no_reqd_condition.py rename to erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py index 69bfaaa2cb1..902707b4b66 100644 --- a/erpnext/patches/v12_0/update_vehicle_no_reqd_condition.py +++ b/erpnext/patches/v13_0/update_vehicle_no_reqd_condition.py @@ -2,7 +2,7 @@ import frappe def execute(): - frappe.reload_doc('custom', 'doctype', 'custom_field') + frappe.reload_doc('custom', 'doctype', 'custom_field', force=True) company = frappe.get_all('Company', filters = {'country': 'India'}) if not company: return diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json index fbbf86c4a98..ad00d6d323f 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.json +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json @@ -329,7 +329,7 @@ { "fieldname": "earning_deduction", "fieldtype": "Section Break", - "label": "Earning & Deduction", + "label": "Earnings & Deductions", "oldfieldtype": "Section Break" }, { @@ -380,7 +380,7 @@ "depends_on": "total_loan_repayment", "fieldname": "loan_repayment", "fieldtype": "Section Break", - "label": "Loan repayment" + "label": "Loan Repayment" }, { "fieldname": "loans", @@ -425,7 +425,7 @@ { "fieldname": "net_pay_info", "fieldtype": "Section Break", - "label": "net pay info" + "label": "Net Pay Info" }, { "fieldname": "net_pay", @@ -647,7 +647,7 @@ "idx": 9, "is_submittable": 1, "links": [], - "modified": "2021-09-01 10:22:52.374549", + "modified": "2021-10-08 11:48:47.098248", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Slip", diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index 81582cecae3..91b109bb408 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -171,8 +171,6 @@ class TestSalarySlip(unittest.TestCase): days_in_month = no_of_days[0] no_of_holidays = no_of_days[1] - self.assertEqual(ss.payment_days, days_in_month - no_of_holidays - 1) - ss.reload() payment_days_based_comp_amount = 0 for component in ss.earnings: diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index a20c70a6dac..363c3b6a3ca 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -225,7 +225,6 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to query = f""" SELECT - tsd.name as name, tsd.parent as time_sheet, tsd.from_time as from_time, @@ -235,21 +234,16 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to tsd.activity_type as activity_type, tsd.description as description, ts.currency as currency, - tsd.project_name as project_name - + tsd.project_name as project_name FROM `tabTimesheet Detail` tsd - INNER JOIN `tabTimesheet` ts ON ts.name = tsd.parent - WHERE - tsd.parenttype = 'Timesheet' AND tsd.docstatus = 1 AND tsd.is_billable = 1 AND tsd.sales_invoice is NULL {condition} - ORDER BY tsd.from_time ASC """ diff --git a/erpnext/public/js/help_links.js b/erpnext/public/js/help_links.js index d0c935f4887..b643ccae947 100644 --- a/erpnext/public/js/help_links.js +++ b/erpnext/public/js/help_links.js @@ -5,7 +5,7 @@ const docsUrl = "https://erpnext.com/docs/"; frappe.help.help_links["Form/Rename Tool"] = [ { label: "Bulk Rename", - url: docsUrl + "user/manual/en/setting-up/data/bulk-rename", + url: docsUrl + "user/manual/en/using-erpnext/articles/bulk-rename", }, ]; @@ -59,10 +59,23 @@ frappe.help.help_links["Form/System Settings"] = [ }, ]; -frappe.help.help_links["data-import-tool"] = [ +frappe.help.help_links["Form/Data Import"] = [ { label: "Importing and Exporting Data", - url: docsUrl + "user/manual/en/setting-up/data/data-import-tool", + url: docsUrl + "user/manual/en/setting-up/data/data-import", + }, + { + label: "Overwriting Data from Data Import Tool", + url: + docsUrl + + "user/manual/en/setting-up/articles/overwriting-data-from-data-import-tool", + }, +]; + +frappe.help.help_links["List/Data Import"] = [ + { + label: "Importing and Exporting Data", + url: docsUrl + "user/manual/en/setting-up/data/data-import", }, { label: "Overwriting Data from Data Import Tool", @@ -101,14 +114,14 @@ frappe.help.help_links["Form/Global Defaults"] = [ }, ]; -frappe.help.help_links["Form/Email Digest"] = [ +frappe.help.help_links["List/Print Heading"] = [ { - label: "Email Digest", - url: docsUrl + "user/manual/en/setting-up/email/email-digest", + label: "Print Heading", + url: docsUrl + "user/manual/en/setting-up/print/print-headings", }, ]; -frappe.help.help_links["List/Print Heading"] = [ +frappe.help.help_links["Form/Print Heading"] = [ { label: "Print Heading", url: docsUrl + "user/manual/en/setting-up/print/print-headings", @@ -153,18 +166,25 @@ frappe.help.help_links["List/Email Account"] = [ frappe.help.help_links["List/Notification"] = [ { label: "Notification", - url: docsUrl + "user/manual/en/setting-up/email/notifications", + url: docsUrl + "user/manual/en/setting-up/notifications", }, ]; frappe.help.help_links["Form/Notification"] = [ { label: "Notification", - url: docsUrl + "user/manual/en/setting-up/email/notifications", + url: docsUrl + "user/manual/en/setting-up/notifications", }, ]; -frappe.help.help_links["List/Email Digest"] = [ +frappe.help.help_links["Form/Email Digest"] = [ + { + label: "Email Digest", + url: docsUrl + "user/manual/en/setting-up/email/email-digest", + }, +]; + +frappe.help.help_links["Form/Email Digest"] = [ { label: "Email Digest", url: docsUrl + "user/manual/en/setting-up/email/email-digest", @@ -174,7 +194,7 @@ frappe.help.help_links["List/Email Digest"] = [ frappe.help.help_links["List/Auto Email Report"] = [ { label: "Auto Email Reports", - url: docsUrl + "user/manual/en/setting-up/email/email-reports", + url: docsUrl + "user/manual/en/setting-up/email/auto-email-reports", }, ]; @@ -188,14 +208,7 @@ frappe.help.help_links["Form/Print Settings"] = [ frappe.help.help_links["print-format-builder"] = [ { label: "Print Format Builder", - url: docsUrl + "user/manual/en/setting-up/print/print-settings", - }, -]; - -frappe.help.help_links["List/Print Heading"] = [ - { - label: "Print Heading", - url: docsUrl + "user/manual/en/setting-up/print/print-headings", + url: docsUrl + "user/manual/en/setting-up/print/print-format-builder", }, ]; @@ -300,7 +313,7 @@ frappe.help.help_links["List/Sales Order"] = [ }, { label: "Recurring Sales Order", - url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + url: docsUrl + "user/manual/en/accounts/articles/recurring-orders-and-invoices", }, { label: "Applying Discount", @@ -315,7 +328,7 @@ frappe.help.help_links["Form/Sales Order"] = [ }, { label: "Recurring Sales Order", - url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + url: docsUrl + "user/manual/en/accounts/articles/recurring-orders-and-invoices", }, { label: "Applying Discount", @@ -344,14 +357,14 @@ frappe.help.help_links["Form/Sales Order"] = [ frappe.help.help_links["Form/Product Bundle"] = [ { label: "Product Bundle", - url: docsUrl + "user/manual/en/selling/setup/product-bundle", + url: docsUrl + "user/manual/en/selling/product-bundle", }, ]; frappe.help.help_links["Form/Selling Settings"] = [ { label: "Selling Settings", - url: docsUrl + "user/manual/en/selling/setup/selling-settings", + url: docsUrl + "user/manual/en/selling/selling-settings", }, ]; @@ -397,7 +410,7 @@ frappe.help.help_links["List/Purchase Order"] = [ }, { label: "Recurring Purchase Order", - url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + url: docsUrl + "user/manual/en/accounts/articles/recurring-orders-and-invoices", }, ]; @@ -420,7 +433,7 @@ frappe.help.help_links["Form/Purchase Order"] = [ }, { label: "Recurring Purchase Order", - url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + url: docsUrl + "user/manual/en/accounts/articles/recurring-orders-and-invoices", }, { label: "Subcontracting", @@ -435,24 +448,17 @@ frappe.help.help_links["List/Purchase Taxes and Charges Template"] = [ }, ]; -frappe.help.help_links["List/POS Profile"] = [ - { - label: "POS Profile", - url: docsUrl + "user/manual/en/setting-up/pos-setting", - }, -]; - frappe.help.help_links["List/Price List"] = [ { label: "Price List", - url: docsUrl + "user/manual/en/setting-up/price-lists", + url: docsUrl + "user/manual/en/stock/price-lists", }, ]; frappe.help.help_links["List/Authorization Rule"] = [ { label: "Authorization Rule", - url: docsUrl + "user/manual/en/setting-up/authorization-rule", + url: docsUrl + "user/manual/en/customize-erpnext/authorization-rule", }, ]; @@ -468,27 +474,14 @@ frappe.help.help_links["List/Stock Reconciliation"] = [ label: "Stock Reconciliation", url: docsUrl + - "user/manual/en/setting-up/stock-reconciliation-for-non-serialized-item", + "user/manual/en/stock/stock-reconciliation", }, ]; frappe.help.help_links["Tree/Territory"] = [ { label: "Territory", - url: docsUrl + "user/manual/en/setting-up/territory", - }, -]; - -frappe.help.help_links["Form/Dropbox Backup"] = [ - { - label: "Dropbox Backup", - url: docsUrl + "user/manual/en/setting-up/third-party-backups", - }, - { - label: "Setting Up Dropbox Backup", - url: - docsUrl + - "user/manual/en/setting-up/articles/setting-up-dropbox-backups", + url: docsUrl + "user/manual/en/selling/territory", }, ]; @@ -501,12 +494,6 @@ frappe.help.help_links["List/Company"] = [ label: "Company", url: docsUrl + "user/manual/en/setting-up/company-setup", }, - { - label: "Managing Multiple Companies", - url: - docsUrl + - "user/manual/en/setting-up/articles/managing-multiple-companies", - }, { label: "Delete All Related Transactions for a Company", url: @@ -517,21 +504,6 @@ frappe.help.help_links["List/Company"] = [ //Accounts -frappe.help.help_links["modules/Accounts"] = [ - { - label: "Introduction to Accounts", - url: docsUrl + "user/manual/en/accounts/", - }, - { - label: "Chart of Accounts", - url: docsUrl + "user/manual/en/accounts/chart-of-accounts.html", - }, - { - label: "Multi Currency Accounting", - url: docsUrl + "user/manual/en/accounts/multi-currency-accounting", - }, -]; - frappe.help.help_links["Tree/Account"] = [ { label: "Chart of Accounts", @@ -552,7 +524,7 @@ frappe.help.help_links["Form/Sales Invoice"] = [ }, { label: "Accounts Opening Balance", - url: docsUrl + "user/manual/en/accounts/opening-accounts", + url: docsUrl + "user/manual/en/accounts/opening-balance", }, { label: "Sales Return", @@ -560,7 +532,7 @@ frappe.help.help_links["Form/Sales Invoice"] = [ }, { label: "Recurring Sales Invoice", - url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + url: docsUrl + "user/manual/en/accounts/articles/recurring-orders-and-invoices", }, ]; @@ -571,7 +543,7 @@ frappe.help.help_links["List/Sales Invoice"] = [ }, { label: "Accounts Opening Balance", - url: docsUrl + "user/manual/en/accounts/opening-accounts", + url: docsUrl + "user/manual/en/accounts/opening-balances", }, { label: "Sales Return", @@ -579,21 +551,28 @@ frappe.help.help_links["List/Sales Invoice"] = [ }, { label: "Recurring Sales Invoice", - url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + url: docsUrl + "user/manual/en/accounts/articles/recurring-orders-and-invoices", }, ]; -frappe.help.help_links["pos"] = [ +frappe.help.help_links["point-of-sale"] = [ { label: "Point of Sale Invoice", - url: docsUrl + "user/manual/en/accounts/point-of-sale-pos-invoice", + url: docsUrl + "user/manual/en/accounts/point-of-sales", }, ]; frappe.help.help_links["List/POS Profile"] = [ { label: "Point of Sale Profile", - url: docsUrl + "user/manual/en/setting-up/pos-setting", + url: docsUrl + "user/manual/en/accounts/pos-profile", + }, +]; + +frappe.help.help_links["Form/POS Profile"] = [ + { + label: "POS Profile", + url: docsUrl + "user/manual/en/accounts/pos-profile", }, ]; @@ -604,11 +583,11 @@ frappe.help.help_links["List/Purchase Invoice"] = [ }, { label: "Accounts Opening Balance", - url: docsUrl + "user/manual/en/accounts/opening-accounts", + url: docsUrl + "user/manual/en/accounts/opening-balance", }, { label: "Recurring Purchase Invoice", - url: docsUrl + "user/manual/en/accounts/recurring-orders-and-invoices", + url: docsUrl + "user/manual/en/accounts/articles/recurring-orders-and-invoices", }, ]; @@ -623,7 +602,7 @@ frappe.help.help_links["List/Journal Entry"] = [ }, { label: "Accounts Opening Balance", - url: docsUrl + "user/manual/en/accounts/opening-accounts", + url: docsUrl + "user/manual/en/accounts/opening-balance", }, ]; @@ -644,7 +623,7 @@ frappe.help.help_links["List/Payment Request"] = [ frappe.help.help_links["List/Asset"] = [ { label: "Managing Fixed Assets", - url: docsUrl + "user/manual/en/accounts/opening-balance/fixed_assets", + url: docsUrl + "user/manual/en/asset", }, ]; @@ -659,6 +638,8 @@ frappe.help.help_links["Tree/Cost Center"] = [ { label: "Budgeting", url: docsUrl + "user/manual/en/accounts/budgeting" }, ]; +//Stock + frappe.help.help_links["List/Item"] = [ { label: "Item", url: docsUrl + "user/manual/en/stock/item" }, { @@ -676,7 +657,7 @@ frappe.help.help_links["List/Item"] = [ }, { label: "Managing Fixed Assets", - url: docsUrl + "user/manual/en/accounts/opening-balance/fixed_assets", + url: docsUrl + "user/manual/en/asset", }, { label: "Item Codification", @@ -711,7 +692,7 @@ frappe.help.help_links["Form/Item"] = [ }, { label: "Managing Fixed Assets", - url: docsUrl + "user/manual/en/accounts/opening-balance/fixed_assets", + url: docsUrl + "user/manual/en/asset", }, { label: "Item Codification", @@ -771,10 +752,6 @@ frappe.help.help_links["Form/Delivery Note"] = [ url: docsUrl + "user/manual/en/stock/articles/track-items-using-barcode", }, - { - label: "Subcontracting", - url: docsUrl + "user/manual/en/manufacturing/subcontracting", - }, ]; frappe.help.help_links["List/Installation Note"] = [ @@ -784,21 +761,10 @@ frappe.help.help_links["List/Installation Note"] = [ }, ]; -frappe.help.help_links["Tree"] = [ - { - label: "Managing Tree Structure Masters", - url: - docsUrl + - "user/manual/en/setting-up/articles/managing-tree-structure-masters", - }, -]; - frappe.help.help_links["List/Budget"] = [ { label: "Budgeting", url: docsUrl + "user/manual/en/accounts/budgeting" }, ]; -//Stock - frappe.help.help_links["List/Material Request"] = [ { label: "Material Request", @@ -861,6 +827,10 @@ frappe.help.help_links["Form/Serial No"] = [ { label: "Serial No", url: docsUrl + "user/manual/en/stock/serial-no" }, ]; +frappe.help.help_links["List/Batch"] = [ + { label: "Batch", url: docsUrl + "user/manual/en/stock/batch" }, +]; + frappe.help.help_links["Form/Batch"] = [ { label: "Batch", url: docsUrl + "user/manual/en/stock/batch" }, ]; @@ -868,35 +838,35 @@ frappe.help.help_links["Form/Batch"] = [ frappe.help.help_links["Form/Packing Slip"] = [ { label: "Packing Slip", - url: docsUrl + "user/manual/en/stock/tools/packing-slip", + url: docsUrl + "user/manual/en/stock/packing-slip", }, ]; frappe.help.help_links["Form/Quality Inspection"] = [ { label: "Quality Inspection", - url: docsUrl + "user/manual/en/stock/tools/quality-inspection", + url: docsUrl + "user/manual/en/stock/quality-inspection", }, ]; frappe.help.help_links["Form/Landed Cost Voucher"] = [ { label: "Landed Cost Voucher", - url: docsUrl + "user/manual/en/stock/tools/landed-cost-voucher", + url: docsUrl + "user/manual/en/stock/landed-cost-voucher", }, ]; frappe.help.help_links["Tree/Item Group"] = [ { label: "Item Group", - url: docsUrl + "user/manual/en/stock/setup/item-group", + url: docsUrl + "user/manual/en/stock/item-group", }, ]; frappe.help.help_links["Form/Item Attribute"] = [ { label: "Item Attribute", - url: docsUrl + "user/manual/en/stock/setup/item-attribute", + url: docsUrl + "user/manual/en/stock/item-attribute", }, ]; @@ -911,7 +881,7 @@ frappe.help.help_links["Form/UOM"] = [ frappe.help.help_links["Form/Stock Reconciliation"] = [ { label: "Opening Stock Entry", - url: docsUrl + "user/manual/en/stock/opening-stock", + url: docsUrl + "user/manual/en/stock/stock-reconciliation", }, ]; @@ -938,13 +908,13 @@ frappe.help.help_links["Form/Newsletter"] = [ ]; frappe.help.help_links["Form/Campaign"] = [ - { label: "Campaign", url: docsUrl + "user/manual/en/CRM/setup/campaign" }, + { label: "Campaign", url: docsUrl + "user/manual/en/CRM/campaign" }, ]; frappe.help.help_links["Tree/Sales Person"] = [ { label: "Sales Person", - url: docsUrl + "user/manual/en/CRM/setup/sales-person", + url: docsUrl + "user/manual/en/CRM/sales-person", }, ]; @@ -953,30 +923,13 @@ frappe.help.help_links["Form/Sales Person"] = [ label: "Sales Person Target", url: docsUrl + - "user/manual/en/selling/setup/sales-person-target-allocation", + "user/manual/en/selling/sales-person-target-allocation", }, -]; - -//Support - -frappe.help.help_links["List/Feedback Trigger"] = [ { - label: "Feedback Trigger", - url: docsUrl + "user/manual/en/setting-up/feedback/setting-up-feedback", - }, -]; - -frappe.help.help_links["List/Feedback Request"] = [ - { - label: "Feedback Request", - url: docsUrl + "user/manual/en/setting-up/feedback/submit-feedback", - }, -]; - -frappe.help.help_links["List/Feedback Request"] = [ - { - label: "Feedback Request", - url: docsUrl + "user/manual/en/setting-up/feedback/submit-feedback", + label: "Sales Person in Transactions", + url: + docsUrl + + "user/manual/en/selling/articles/sales-persons-in-the-sales-transactions", }, ]; @@ -1019,7 +972,7 @@ frappe.help.help_links["Form/Operation"] = [ frappe.help.help_links["Form/BOM Update Tool"] = [ { label: "BOM Update Tool", - url: docsUrl + "user/manual/en/manufacturing/tools/bom-update-tool", + url: docsUrl + "user/manual/en/manufacturing/bom-update-tool", }, ]; @@ -1036,7 +989,7 @@ frappe.help.help_links["Form/Customize Form"] = [ }, ]; -frappe.help.help_links["Form/Custom Field"] = [ +frappe.help.help_links["List/Custom Field"] = [ { label: "Custom Field", url: docsUrl + "user/manual/en/customize-erpnext/custom-field", diff --git a/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js b/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js index 7b358195c3e..831626aa915 100644 --- a/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js +++ b/erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js @@ -334,10 +334,12 @@ erpnext.HierarchyChart = class { if (child_nodes) { $.each(child_nodes, (_i, data) => { - this.add_node(node, data); - setTimeout(() => { - this.add_connector(node.id, data.id); - }, 250); + if (!$(`[id="${data.id}"]`).length) { + this.add_node(node, data); + setTimeout(() => { + this.add_connector(node.id, data.id); + }, 250); + } }); } } diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index e1cef614a22..c363d931cb1 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -712,6 +712,7 @@ erpnext.utils.map_current_doc = function(opts) { allow_child_item_selection: opts.allow_child_item_selection, child_fieldname: opts.child_fielname, child_columns: opts.child_columns, + size: opts.size, action: function(selections, args) { let values = selections; if (values.length === 0) { diff --git a/erpnext/regional/doctype/gst_settings/gst_settings.json b/erpnext/regional/doctype/gst_settings/gst_settings.json index 95b930c4c86..fc579d4b38c 100644 --- a/erpnext/regional/doctype/gst_settings/gst_settings.json +++ b/erpnext/regional/doctype/gst_settings/gst_settings.json @@ -6,8 +6,10 @@ "engine": "InnoDB", "field_order": [ "gst_summary", - "column_break_2", + "gst_tax_settings_section", "round_off_gst_values", + "column_break_4", + "hsn_wise_tax_breakup", "gstin_email_sent_on", "section_break_4", "gst_accounts", @@ -17,37 +19,23 @@ { "fieldname": "gst_summary", "fieldtype": "HTML", - "label": "GST Summary", - "show_days": 1, - "show_seconds": 1 - }, - { - "fieldname": "column_break_2", - "fieldtype": "Column Break", - "show_days": 1, - "show_seconds": 1 + "label": "GST Summary" }, { "fieldname": "gstin_email_sent_on", "fieldtype": "Date", "label": "GSTIN Email Sent On", - "read_only": 1, - "show_days": 1, - "show_seconds": 1 + "read_only": 1 }, { "fieldname": "section_break_4", - "fieldtype": "Section Break", - "show_days": 1, - "show_seconds": 1 + "fieldtype": "Section Break" }, { "fieldname": "gst_accounts", "fieldtype": "Table", "label": "GST Accounts", - "options": "GST Account", - "show_days": 1, - "show_seconds": 1 + "options": "GST Account" }, { "default": "250000", @@ -56,24 +44,35 @@ "fieldtype": "Data", "in_list_view": 1, "label": "B2C Limit", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "default": "0", "description": "Enabling this option will round off individual GST components in all the Invoices", "fieldname": "round_off_gst_values", "fieldtype": "Check", - "label": "Round Off GST Values", - "show_days": 1, - "show_seconds": 1 + "label": "Round Off GST Values" + }, + { + "default": "0", + "fieldname": "hsn_wise_tax_breakup", + "fieldtype": "Check", + "label": "Tax Breakup Table Based On HSN Code" + }, + { + "fieldname": "gst_tax_settings_section", + "fieldtype": "Section Break", + "label": "GST Tax Settings" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-01-28 17:19:47.969260", + "modified": "2021-10-11 18:10:14.242614", "modified_by": "Administrator", "module": "Regional", "name": "GST Settings", @@ -83,4 +82,4 @@ "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 - } \ No newline at end of file +} \ No newline at end of file diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 19699243f9e..f7aa65776b0 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -927,7 +927,7 @@ class GSPConnector(): return errors - def raise_error(self, raise_exception=False, errors=[]): + def raise_error(self, raise_exception=False, errors=None): title = _('E Invoice Request Failed') if errors: frappe.throw(errors, title=title, as_list=1) diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py index ded0dae0d80..09207c17744 100644 --- a/erpnext/regional/india/setup.py +++ b/erpnext/regional/india/setup.py @@ -139,6 +139,10 @@ def make_property_setters(patch=False): make_property_setter('Journal Entry', 'voucher_type', 'options', '\n'.join(journal_entry_types), '') def make_custom_fields(update=True): + custom_fields = get_custom_fields() + create_custom_fields(custom_fields, update=update) + +def get_custom_fields(): hsn_sac_field = dict(fieldname='gst_hsn_code', label='HSN/SAC', fieldtype='Data', fetch_from='item_code.gst_hsn_code', insert_after='description', allow_on_submit=1, print_hide=1, fetch_if_empty=1) @@ -172,12 +176,12 @@ def make_custom_fields(update=True): dict(fieldname='gst_category', label='GST Category', fieldtype='Select', insert_after='gst_section', print_hide=1, options='\nRegistered Regular\nRegistered Composition\nUnregistered\nSEZ\nOverseas\nConsumer\nDeemed Export\nUIN Holders', - fetch_from='customer.gst_category', fetch_if_empty=1), + fetch_from='customer.gst_category', fetch_if_empty=1, length=25), dict(fieldname='export_type', label='Export Type', fieldtype='Select', insert_after='gst_category', print_hide=1, depends_on='eval:in_list(["SEZ", "Overseas", "Deemed Export"], doc.gst_category)', options='\nWith Payment of Tax\nWithout Payment of Tax', fetch_from='customer.export_type', - fetch_if_empty=1), + fetch_if_empty=1, length=25), ] delivery_note_gst_category = [ @@ -188,18 +192,18 @@ def make_custom_fields(update=True): ] invoice_gst_fields = [ - dict(fieldname='invoice_copy', label='Invoice Copy', + dict(fieldname='invoice_copy', label='Invoice Copy', length=30, fieldtype='Select', insert_after='export_type', print_hide=1, allow_on_submit=1, options='Original for Recipient\nDuplicate for Transporter\nDuplicate for Supplier\nTriplicate for Supplier'), - dict(fieldname='reverse_charge', label='Reverse Charge', + dict(fieldname='reverse_charge', label='Reverse Charge', length=2, fieldtype='Select', insert_after='invoice_copy', print_hide=1, options='Y\nN', default='N'), - dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN', + dict(fieldname='ecommerce_gstin', label='E-commerce GSTIN', length=15, fieldtype='Data', insert_after='export_type', print_hide=1), dict(fieldname='gst_col_break', fieldtype='Column Break', insert_after='ecommerce_gstin'), dict(fieldname='reason_for_issuing_document', label='Reason For Issuing document', fieldtype='Select', insert_after='gst_col_break', print_hide=1, - depends_on='eval:doc.is_return==1', + depends_on='eval:doc.is_return==1', length=45, options='\n01-Sales Return\n02-Post Sale Discount\n03-Deficiency in services\n04-Correction in Invoice\n05-Change in POS\n06-Finalization of Provisional assessment\n07-Others') ] @@ -237,25 +241,25 @@ def make_custom_fields(update=True): sales_invoice_gst_fields = [ dict(fieldname='billing_address_gstin', label='Billing Address GSTIN', fieldtype='Data', insert_after='customer_address', read_only=1, - fetch_from='customer_address.gstin', print_hide=1), + fetch_from='customer_address.gstin', print_hide=1, length=15), dict(fieldname='customer_gstin', label='Customer GSTIN', fieldtype='Data', insert_after='shipping_address_name', - fetch_from='shipping_address_name.gstin', print_hide=1), + fetch_from='shipping_address_name.gstin', print_hide=1, length=15), dict(fieldname='place_of_supply', label='Place of Supply', fieldtype='Data', insert_after='customer_gstin', - print_hide=1, read_only=1), + print_hide=1, read_only=1, length=50), dict(fieldname='company_gstin', label='Company GSTIN', fieldtype='Data', insert_after='company_address', - fetch_from='company_address.gstin', print_hide=1, read_only=1), + fetch_from='company_address.gstin', print_hide=1, read_only=1, length=15), ] sales_invoice_shipping_fields = [ dict(fieldname='port_code', label='Port Code', fieldtype='Data', insert_after='reason_for_issuing_document', print_hide=1, - depends_on="eval:doc.gst_category=='Overseas' "), + depends_on="eval:doc.gst_category=='Overseas' ", length=15), dict(fieldname='shipping_bill_number', label=' Shipping Bill Number', fieldtype='Data', insert_after='port_code', print_hide=1, - depends_on="eval:doc.gst_category=='Overseas' "), + depends_on="eval:doc.gst_category=='Overseas' ", length=50), dict(fieldname='shipping_bill_date', label='Shipping Bill Date', fieldtype='Date', insert_after='shipping_bill_number', print_hide=1, depends_on="eval:doc.gst_category=='Overseas' "), @@ -361,7 +365,8 @@ def make_custom_fields(update=True): 'insert_after': 'transporter', 'fetch_from': 'transporter.gst_transporter_id', 'print_hide': 1, - 'translatable': 0 + 'translatable': 0, + 'length': 20 }, { 'fieldname': 'driver', @@ -377,7 +382,8 @@ def make_custom_fields(update=True): 'fieldtype': 'Data', 'insert_after': 'driver', 'print_hide': 1, - 'translatable': 0 + 'translatable': 0, + 'length': 30 }, { 'fieldname': 'vehicle_no', @@ -385,7 +391,8 @@ def make_custom_fields(update=True): 'fieldtype': 'Data', 'insert_after': 'lr_no', 'print_hide': 1, - 'translatable': 0 + 'translatable': 0, + 'length': 10 }, { 'fieldname': 'distance', @@ -402,7 +409,7 @@ def make_custom_fields(update=True): { 'fieldname': 'transporter_name', 'label': 'Transporter Name', - 'fieldtype': 'Data', + 'fieldtype': 'Small Text', 'insert_after': 'transporter_col_break', 'fetch_from': 'transporter.name', 'read_only': 1, @@ -416,12 +423,13 @@ def make_custom_fields(update=True): 'options': '\nRoad\nAir\nRail\nShip', 'insert_after': 'transporter_name', 'print_hide': 1, - 'translatable': 0 + 'translatable': 0, + 'length': 5 }, { 'fieldname': 'driver_name', 'label': 'Driver Name', - 'fieldtype': 'Data', + 'fieldtype': 'Small Text', 'insert_after': 'mode_of_transport', 'fetch_from': 'driver.full_name', 'print_hide': 1, @@ -444,7 +452,8 @@ def make_custom_fields(update=True): 'default': 'Regular', 'insert_after': 'lr_date', 'print_hide': 1, - 'translatable': 0 + 'translatable': 0, + 'length': 30 }, { 'fieldname': 'ewaybill', @@ -453,7 +462,8 @@ def make_custom_fields(update=True): 'depends_on': 'eval:((doc.docstatus === 1 || doc.ewaybill) && doc.eway_bill_cancelled === 0)', 'allow_on_submit': 1, 'insert_after': 'tax_id', - 'translatable': 0 + 'translatable': 0, + 'length': 20 } ] @@ -719,7 +729,8 @@ def make_custom_fields(update=True): } ] } - create_custom_fields(custom_fields, update=update) + + return custom_fields def make_fixtures(company=None): docs = [] diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 38e17705a6a..254a293dbf9 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -112,7 +112,11 @@ def validate_gstin_check_digit(gstin, label='GSTIN'): frappe.throw(_("""Invalid {0}! The check digit validation has failed. Please ensure you've typed the {0} correctly.""").format(label)) def get_itemised_tax_breakup_header(item_doctype, tax_accounts): - return [_("Item"), _("Taxable Amount")] + tax_accounts + hsn_wise_in_gst_settings = frappe.db.get_single_value('GST Settings','hsn_wise_tax_breakup') + if frappe.get_meta(item_doctype).has_field('gst_hsn_code') and hsn_wise_in_gst_settings: + return [_("HSN/SAC"), _("Taxable Amount")] + tax_accounts + else: + return [_("Item"), _("Taxable Amount")] + tax_accounts def get_itemised_tax_breakup_data(doc, account_wise=False, hsn_wise=False): itemised_tax = get_itemised_tax(doc.taxes, with_tax_account=account_wise) @@ -122,14 +126,17 @@ def get_itemised_tax_breakup_data(doc, account_wise=False, hsn_wise=False): if not frappe.get_meta(doc.doctype + " Item").has_field('gst_hsn_code'): return itemised_tax, itemised_taxable_amount - if hsn_wise: + hsn_wise_in_gst_settings = frappe.db.get_single_value('GST Settings','hsn_wise_tax_breakup') + + tax_breakup_hsn_wise = hsn_wise or hsn_wise_in_gst_settings + if tax_breakup_hsn_wise: item_hsn_map = frappe._dict() for d in doc.items: item_hsn_map.setdefault(d.item_code or d.item_name, d.get("gst_hsn_code")) hsn_tax = {} for item, taxes in itemised_tax.items(): - item_or_hsn = item if not hsn_wise else item_hsn_map.get(item) + item_or_hsn = item if not tax_breakup_hsn_wise else item_hsn_map.get(item) hsn_tax.setdefault(item_or_hsn, frappe._dict()) for tax_desc, tax_detail in taxes.items(): key = tax_desc @@ -142,7 +149,7 @@ def get_itemised_tax_breakup_data(doc, account_wise=False, hsn_wise=False): # set taxable amount hsn_taxable_amount = frappe._dict() for item in itemised_taxable_amount: - item_or_hsn = item if not hsn_wise else item_hsn_map.get(item) + item_or_hsn = item if not tax_breakup_hsn_wise else item_hsn_map.get(item) hsn_taxable_amount.setdefault(item_or_hsn, 0) hsn_taxable_amount[item_or_hsn] += itemised_taxable_amount.get(item) diff --git a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py index a068a380776..9b593eebc69 100644 --- a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py +++ b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py @@ -15,8 +15,8 @@ def execute(filters=None): return columns, data -def validate_filters(filters={}): - filters = frappe._dict(filters) +def validate_filters(filters=None): + filters = frappe._dict(filters or {}) if not filters.company: frappe.throw(_('{} is mandatory for generating E-Invoice Summary Report').format(_('Company')), title=_('Invalid Filter')) @@ -28,7 +28,9 @@ def validate_filters(filters={}): if filters.from_date > filters.to_date: frappe.throw(_('From Date must be before To Date'), title=_('Invalid Filter')) -def get_data(filters={}): +def get_data(filters=None): + if not filters: + filters = {} query_filters = { 'posting_date': ['between', [filters.from_date, filters.to_date]], 'einvoice_status': ['is', 'set'], diff --git a/erpnext/regional/report/gstr_1/gstr_1.py b/erpnext/regional/report/gstr_1/gstr_1.py index 23924c5fb66..7d401bab669 100644 --- a/erpnext/regional/report/gstr_1/gstr_1.py +++ b/erpnext/regional/report/gstr_1/gstr_1.py @@ -172,13 +172,6 @@ class Gstr1Report(object): self.invoices = frappe._dict() conditions = self.get_conditions() - company_gstins = get_company_gstin_number(self.filters.get('company'), all_gstins=True) - - if company_gstins: - self.filters.update({ - 'company_gstins': company_gstins - }) - invoice_data = frappe.db.sql(""" select {select_columns} @@ -242,7 +235,7 @@ class Gstr1Report(object): elif self.filters.get("type_of_business") == "EXPORT": conditions += """ AND is_return !=1 and gst_category = 'Overseas' """ - conditions += " AND IFNULL(billing_address_gstin, '') NOT IN %(company_gstins)s" + conditions += " AND IFNULL(billing_address_gstin, '') != company_gstin" return conditions diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index b33c6e5c618..ea840e2ce4c 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -116,14 +116,15 @@ frappe.ui.form.on("Customer", { frappe.contacts.render_address_and_contact(frm); // custom buttons - frm.add_custom_button(__('Accounting Ledger'), function() { - frappe.set_route('query-report', 'General Ledger', - {party_type:'Customer', party:frm.doc.name}); - }); - frm.add_custom_button(__('Accounts Receivable'), function() { + frm.add_custom_button(__('Accounts Receivable'), function () { frappe.set_route('query-report', 'Accounts Receivable', {customer:frm.doc.name}); - }); + }, __('View')); + + frm.add_custom_button(__('Accounting Ledger'), function () { + frappe.set_route('query-report', 'General Ledger', + {party_type: 'Customer', party: frm.doc.name}); + }, __('View')); frm.add_custom_button(__('Pricing Rule'), function () { erpnext.utils.make_pricing_rule(frm.doc.doctype, frm.doc.name); diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 93676094218..dcf478bda6e 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -110,7 +110,7 @@ class SalesOrder(SellingController): if self.order_type == 'Sales' and not self.skip_delivery_note: delivery_date_list = [d.delivery_date for d in self.get("items") if d.delivery_date] max_delivery_date = max(delivery_date_list) if delivery_date_list else None - if not self.delivery_date: + if (max_delivery_date and not self.delivery_date) or (max_delivery_date and getdate(self.delivery_date) != getdate(max_delivery_date)): self.delivery_date = max_delivery_date if self.delivery_date: for d in self.get("items"): @@ -119,8 +119,6 @@ class SalesOrder(SellingController): if getdate(self.transaction_date) > getdate(d.delivery_date): frappe.msgprint(_("Expected Delivery Date should be after Sales Order Date"), indicator='orange', title=_('Warning')) - if getdate(self.delivery_date) != getdate(max_delivery_date): - self.delivery_date = max_delivery_date else: frappe.throw(_("Please enter Delivery Date")) diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index 62ea44df435..804bc6a95e7 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -1350,7 +1350,6 @@ def make_sales_order_workflow(): frappe.get_doc(dict(doctype='Role', role_name='Test Junior Approver')).insert(ignore_if_duplicate=True) frappe.get_doc(dict(doctype='Role', role_name='Test Approver')).insert(ignore_if_duplicate=True) - frappe.db.commit() frappe.cache().hdel('roles', frappe.session.user) workflow = frappe.get_doc({ 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 805c3d804fa..5c4d8b601f4 100644 --- a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py +++ b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py @@ -73,7 +73,7 @@ def get_data(conditions, filters): `tabSales Order` so, `tabSales Order Item` soi LEFT JOIN `tabSales Invoice Item` sii - ON sii.so_detail = soi.name + ON sii.so_detail = soi.name and sii.docstatus = 1 WHERE soi.parent = so.name and so.status not in ('Stopped', 'Closed', 'On Hold') diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index f9f70264f6d..2e78168b8b6 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -388,6 +388,7 @@ class Company(NestedSet): frappe.db.sql("delete from tabEmployee where company=%s", self.name) frappe.db.sql("delete from tabDepartment where company=%s", self.name) frappe.db.sql("delete from `tabTax Withholding Account` where company=%s", self.name) + frappe.db.sql("delete from `tabTransaction Deletion Record` where company=%s", self.name) # delete tax templates frappe.db.sql("delete from `tabSales Taxes and Charges Template` where company=%s", self.name) diff --git a/erpnext/setup/setup_wizard/operations/defaults_setup.py b/erpnext/setup/setup_wizard/operations/defaults_setup.py index 3f90f72b608..92e4985f509 100644 --- a/erpnext/setup/setup_wizard/operations/defaults_setup.py +++ b/erpnext/setup/setup_wizard/operations/defaults_setup.py @@ -64,6 +64,13 @@ def set_default_settings(args): hr_settings.emp_created_by = "Naming Series" hr_settings.leave_approval_notification_template = _("Leave Approval Notification") hr_settings.leave_status_notification_template = _("Leave Status Notification") + + hr_settings.send_interview_reminder = 1 + hr_settings.interview_reminder_template = _("Interview Reminder") + hr_settings.remind_before = "00:15:00" + + hr_settings.send_interview_feedback_reminder = 1 + hr_settings.feedback_reminder_notification_template = _("Interview Feedback Reminder") hr_settings.save() def set_no_copy_fields_in_variant_settings(): diff --git a/erpnext/setup/setup_wizard/operations/install_fixtures.py b/erpnext/setup/setup_wizard/operations/install_fixtures.py index fc89e3ccf1f..fbfcb102dd2 100644 --- a/erpnext/setup/setup_wizard/operations/install_fixtures.py +++ b/erpnext/setup/setup_wizard/operations/install_fixtures.py @@ -264,16 +264,26 @@ def install(country=None): base_path = frappe.get_app_path("erpnext", "hr", "doctype") response = frappe.read_file(os.path.join(base_path, "leave_application/leave_application_email_template.html")) - records += [{'doctype': 'Email Template', 'name': _("Leave Approval Notification"), 'response': response,\ + records += [{'doctype': 'Email Template', 'name': _("Leave Approval Notification"), 'response': response, 'subject': _("Leave Approval Notification"), 'owner': frappe.session.user}] - records += [{'doctype': 'Email Template', 'name': _("Leave Status Notification"), 'response': response,\ + records += [{'doctype': 'Email Template', 'name': _("Leave Status Notification"), 'response': response, 'subject': _("Leave Status Notification"), 'owner': frappe.session.user}] + response = frappe.read_file(os.path.join(base_path, "interview/interview_reminder_notification_template.html")) + + records += [{'doctype': 'Email Template', 'name': _('Interview Reminder'), 'response': response, + 'subject': _('Interview Reminder'), 'owner': frappe.session.user}] + + response = frappe.read_file(os.path.join(base_path, "interview/interview_feedback_reminder_template.html")) + + records += [{'doctype': 'Email Template', 'name': _('Interview Feedback Reminder'), 'response': response, + 'subject': _('Interview Feedback Reminder'), 'owner': frappe.session.user}] + base_path = frappe.get_app_path("erpnext", "stock", "doctype") response = frappe.read_file(os.path.join(base_path, "delivery_trip/dispatch_notification_template.html")) - records += [{'doctype': 'Email Template', 'name': _("Dispatch Notification"), 'response': response,\ + records += [{'doctype': 'Email Template', 'name': _("Dispatch Notification"), 'response': response, 'subject': _("Your order is out for delivery!"), 'owner': frappe.session.user}] # Records for the Supplier Scorecard @@ -317,6 +327,14 @@ def update_hr_defaults(): hr_settings.emp_created_by = "Naming Series" hr_settings.leave_approval_notification_template = _("Leave Approval Notification") hr_settings.leave_status_notification_template = _("Leave Status Notification") + + hr_settings.send_interview_reminder = 1 + hr_settings.interview_reminder_template = _("Interview Reminder") + hr_settings.remind_before = "00:15:00" + + hr_settings.send_interview_feedback_reminder = 1 + hr_settings.feedback_reminder_notification_template = _("Interview Feedback Reminder") + hr_settings.save() def update_item_variant_settings(): diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 79989307efc..0a663c2a188 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -1,8 +1,5 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt -from __future__ import unicode_literals - -import unittest import frappe from frappe.exceptions import ValidationError @@ -11,9 +8,10 @@ from frappe.utils import cint, flt from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice from erpnext.stock.doctype.batch.batch import UnableToSelectBatchError, get_batch_no, get_batch_qty from erpnext.stock.get_item_details import get_item_details +from erpnext.tests.utils import ERPNextTestCase -class TestBatch(unittest.TestCase): +class TestBatch(ERPNextTestCase): def test_item_has_batch_enabled(self): self.assertRaises(ValidationError, frappe.get_doc({ "doctype": "Batch", diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 5fbc2d8dee1..4be0415564d 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -14,51 +14,6 @@ class Bin(Document): self.stock_uom = frappe.get_cached_value('Item', self.item_code, 'stock_uom') self.set_projected_qty() - def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False): - '''Called from erpnext.stock.utils.update_bin''' - self.update_qty(args) - - if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": - from erpnext.stock.stock_ledger import update_entries_after, update_qty_in_future_sle - - if not args.get("posting_date"): - args["posting_date"] = nowdate() - - if args.get("is_cancelled") and via_landed_cost_voucher: - return - - # Reposts only current voucher SL Entries - # Updates valuation rate, stock value, stock queue for current transaction - update_entries_after({ - "item_code": self.item_code, - "warehouse": self.warehouse, - "posting_date": args.get("posting_date"), - "posting_time": args.get("posting_time"), - "voucher_type": args.get("voucher_type"), - "voucher_no": args.get("voucher_no"), - "sle_id": args.name, - "creation": args.creation - }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) - - # update qty in future ale and Validate negative qty - update_qty_in_future_sle(args, allow_negative_stock) - - - def update_qty(self, args): - # update the stock values (for current quantities) - if args.get("voucher_type")=="Stock Reconciliation": - self.actual_qty = args.get("qty_after_transaction") - else: - self.actual_qty = flt(self.actual_qty) + flt(args.get("actual_qty")) - - self.ordered_qty = flt(self.ordered_qty) + flt(args.get("ordered_qty")) - self.reserved_qty = flt(self.reserved_qty) + flt(args.get("reserved_qty")) - self.indented_qty = flt(self.indented_qty) + flt(args.get("indented_qty")) - self.planned_qty = flt(self.planned_qty) + flt(args.get("planned_qty")) - - self.set_projected_qty() - self.db_update() - def set_projected_qty(self): self.projected_qty = (flt(self.actual_qty) + flt(self.ordered_qty) + flt(self.indented_qty) + flt(self.planned_qty) - flt(self.reserved_qty) @@ -143,3 +98,67 @@ class Bin(Document): def on_doctype_update(): frappe.db.add_index("Bin", ["item_code", "warehouse"]) + + +def update_stock(bin_name, args, allow_negative_stock=False, via_landed_cost_voucher=False): + '''Called from erpnext.stock.utils.update_bin''' + update_qty(bin_name, args) + + if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": + from erpnext.stock.stock_ledger import update_entries_after, update_qty_in_future_sle + + if not args.get("posting_date"): + args["posting_date"] = nowdate() + + if args.get("is_cancelled") and via_landed_cost_voucher: + return + + # Reposts only current voucher SL Entries + # Updates valuation rate, stock value, stock queue for current transaction + update_entries_after({ + "item_code": args.get('item_code'), + "warehouse": args.get('warehouse'), + "posting_date": args.get("posting_date"), + "posting_time": args.get("posting_time"), + "voucher_type": args.get("voucher_type"), + "voucher_no": args.get("voucher_no"), + "sle_id": args.get('name'), + "creation": args.get('creation') + }, allow_negative_stock=allow_negative_stock, via_landed_cost_voucher=via_landed_cost_voucher) + + # update qty in future sle and Validate negative qty + update_qty_in_future_sle(args, allow_negative_stock) + +def get_bin_details(bin_name): + return frappe.db.get_value('Bin', bin_name, ['actual_qty', 'ordered_qty', + 'reserved_qty', 'indented_qty', 'planned_qty', 'reserved_qty_for_production', + 'reserved_qty_for_sub_contract'], as_dict=1) + +def update_qty(bin_name, args): + bin_details = get_bin_details(bin_name) + + # update the stock values (for current quantities) + if args.get("voucher_type")=="Stock Reconciliation": + actual_qty = args.get('qty_after_transaction') + else: + actual_qty = bin_details.actual_qty + flt(args.get("actual_qty")) + + ordered_qty = flt(bin_details.ordered_qty) + flt(args.get("ordered_qty")) + reserved_qty = flt(bin_details.reserved_qty) + flt(args.get("reserved_qty")) + indented_qty = flt(bin_details.indented_qty) + flt(args.get("indented_qty")) + planned_qty = flt(bin_details.planned_qty) + flt(args.get("planned_qty")) + + + # compute projected qty + projected_qty = (flt(actual_qty) + flt(ordered_qty) + + flt(indented_qty) + flt(planned_qty) - flt(reserved_qty) + - flt(bin_details.reserved_qty_for_production) - flt(bin_details.reserved_qty_for_sub_contract)) + + frappe.db.set_value('Bin', bin_name, { + 'actual_qty': actual_qty, + 'ordered_qty': ordered_qty, + 'reserved_qty': reserved_qty, + 'indented_qty': indented_qty, + 'planned_qty': planned_qty, + 'projected_qty': projected_qty + }) \ No newline at end of file diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json index 9bf142c4b44..ad1b3b43aee 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.json +++ b/erpnext/stock/doctype/delivery_note/delivery_note.json @@ -395,8 +395,7 @@ "fieldtype": "Link", "label": "Billing Address Name", "options": "Address", - "print_hide": 1, - "read_only": 1 + "print_hide": 1 }, { "fieldname": "tax_id", @@ -1309,7 +1308,7 @@ "idx": 146, "is_submittable": 1, "links": [], - "modified": "2021-09-28 13:10:09.761714", + "modified": "2021-10-08 14:29:13.428984", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note", diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 7fda94b269d..f58b586ab20 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import json -import unittest import frappe from frappe.utils import cstr, flt, nowdate, nowtime @@ -37,9 +36,10 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ) from erpnext.stock.doctype.warehouse.test_warehouse import get_warehouse from erpnext.stock.stock_ledger import get_previous_sle +from erpnext.tests.utils import ERPNextTestCase -class TestDeliveryNote(unittest.TestCase): +class TestDeliveryNote(ERPNextTestCase): def test_over_billing_against_dn(self): frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) diff --git a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py index c9081c908f7..c6ff73e633b 100644 --- a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py +++ b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py @@ -14,11 +14,12 @@ from erpnext.stock.doctype.delivery_trip.delivery_trip import ( make_expense_claim, notify_customers, ) -from erpnext.tests.utils import create_test_contact_and_address +from erpnext.tests.utils import ERPNextTestCase, create_test_contact_and_address -class TestDeliveryTrip(unittest.TestCase): +class TestDeliveryTrip(ERPNextTestCase): def setUp(self): + super().setUp() driver = create_driver() create_vehicle() create_delivery_notification() @@ -32,6 +33,7 @@ class TestDeliveryTrip(unittest.TestCase): frappe.db.sql("delete from `tabVehicle`") frappe.db.sql("delete from `tabEmail Template`") frappe.db.sql("delete from `tabDelivery Trip`") + return super().tearDown() def test_expense_claim_fields_are_fetched_properly(self): expense_claim = make_expense_claim(self.delivery_trip.name) diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index f3b69371066..ba7ace20cbf 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -159,6 +159,8 @@ class Item(Document): "doctype": "Item Price", "price_list": price_list, "item_code": self.name, + "uom": self.stock_uom, + "brand": self.brand, "currency": erpnext.get_default_currency(), "price_list_rate": self.standard_rate }) @@ -382,9 +384,21 @@ class Item(Document): _("An Item Group exists with same name, please change the item name or rename the item group")) def update_item_price(self): - frappe.db.sql("""update `tabItem Price` set item_name=%s, - item_description=%s, brand=%s where item_code=%s""", - (self.item_name, self.description, self.brand, self.name)) + frappe.db.sql(""" + UPDATE `tabItem Price` + SET + item_name=%(item_name)s, + item_description=%(item_description)s, + brand=%(brand)s + WHERE item_code=%(item_code)s + """, + dict( + item_name=self.item_name, + item_description=self.description, + brand=self.brand, + item_code=self.name + ) + ) def on_trash(self): frappe.db.sql("""delete from tabBin where item_code=%s""", self.name) diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index d4e7e940e3d..a8aecc4a898 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import json -import unittest import frappe from frappe.test_runner import make_test_objects @@ -25,7 +24,7 @@ from erpnext.stock.doctype.item.item import ( ) from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry from erpnext.stock.get_item_details import get_item_details -from erpnext.tests.utils import change_settings +from erpnext.tests.utils import ERPNextTestCase, change_settings test_ignore = ["BOM"] test_dependencies = ["Warehouse", "Item Group", "Item Tax Template", "Brand", "Item Attribute"] @@ -53,8 +52,9 @@ def make_item(item_code, properties=None): return item -class TestItem(unittest.TestCase): +class TestItem(ERPNextTestCase): def setUp(self): + super().setUp() frappe.flags.attribute_values = None def get_item(self, idx): diff --git a/erpnext/stock/doctype/item_alternative/test_item_alternative.py b/erpnext/stock/doctype/item_alternative/test_item_alternative.py index 2be8ef740a4..af6cc472e34 100644 --- a/erpnext/stock/doctype/item_alternative/test_item_alternative.py +++ b/erpnext/stock/doctype/item_alternative/test_item_alternative.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import json -import unittest import frappe from frappe.utils import flt @@ -21,10 +20,12 @@ from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( create_stock_reconciliation, ) +from erpnext.tests.utils import ERPNextTestCase -class TestItemAlternative(unittest.TestCase): +class TestItemAlternative(ERPNextTestCase): def setUp(self): + super().setUp() make_items() def test_alternative_item_for_subcontract_rm(self): diff --git a/erpnext/stock/doctype/item_attribute/test_item_attribute.py b/erpnext/stock/doctype/item_attribute/test_item_attribute.py index fc809f443e6..2cd711bbb19 100644 --- a/erpnext/stock/doctype/item_attribute/test_item_attribute.py +++ b/erpnext/stock/doctype/item_attribute/test_item_attribute.py @@ -3,17 +3,17 @@ from __future__ import unicode_literals -import unittest - import frappe test_records = frappe.get_test_records('Item Attribute') from erpnext.stock.doctype.item_attribute.item_attribute import ItemAttributeIncrementError +from erpnext.tests.utils import ERPNextTestCase -class TestItemAttribute(unittest.TestCase): +class TestItemAttribute(ERPNextTestCase): def setUp(self): + super().setUp() if frappe.db.exists("Item Attribute", "_Test_Length"): frappe.delete_doc("Item Attribute", "_Test_Length") diff --git a/erpnext/stock/doctype/item_price/test_item_price.py b/erpnext/stock/doctype/item_price/test_item_price.py index 5ed80921660..3a51fbbe17e 100644 --- a/erpnext/stock/doctype/item_price/test_item_price.py +++ b/erpnext/stock/doctype/item_price/test_item_price.py @@ -3,17 +3,17 @@ from __future__ import unicode_literals -import unittest - import frappe from frappe.test_runner import make_test_records_for_doctype from erpnext.stock.doctype.item_price.item_price import ItemPriceDuplicateItem from erpnext.stock.get_item_details import get_price_list_rate_for, process_args +from erpnext.tests.utils import ERPNextTestCase -class TestItemPrice(unittest.TestCase): +class TestItemPrice(ERPNextTestCase): def setUp(self): + super().setUp() frappe.db.sql("delete from `tabItem Price`") make_test_records_for_doctype("Item Price", force=True) diff --git a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py index 58a72f72dd1..339eaaaf7a5 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/test_landed_cost_voucher.py @@ -4,8 +4,6 @@ from __future__ import unicode_literals -import unittest - import frappe from frappe.utils import flt @@ -16,9 +14,10 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import ( get_gl_entries, make_purchase_receipt, ) +from erpnext.tests.utils import ERPNextTestCase -class TestLandedCostVoucher(unittest.TestCase): +class TestLandedCostVoucher(ERPNextTestCase): def test_landed_cost_voucher(self): frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index cf98b19e7a1..17df9777b19 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -296,7 +296,7 @@ def make_purchase_order(source_name, target_doc=None, args=None): return d.ordered_qty < d.stock_qty and child_filter - doclist = get_mapped_doc("Material Request", source_name, { + doclist = get_mapped_doc("Material Request", source_name, { "Material Request": { "doctype": "Purchase Order", "validation": { @@ -323,7 +323,7 @@ def make_purchase_order(source_name, target_doc=None, args=None): @frappe.whitelist() def make_request_for_quotation(source_name, target_doc=None): - doclist = get_mapped_doc("Material Request", source_name, { + doclist = get_mapped_doc("Material Request", source_name, { "Material Request": { "doctype": "Request for Quotation", "validation": { diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py index 5c2ac2584f7..f66a228e35e 100644 --- a/erpnext/stock/doctype/material_request/test_material_request.py +++ b/erpnext/stock/doctype/material_request/test_material_request.py @@ -6,8 +6,6 @@ from __future__ import unicode_literals -import unittest - import frappe from frappe.utils import flt, today @@ -18,9 +16,10 @@ from erpnext.stock.doctype.material_request.material_request import ( make_supplier_quotation, raise_work_orders, ) +from erpnext.tests.utils import ERPNextTestCase -class TestMaterialRequest(unittest.TestCase): +class TestMaterialRequest(ERPNextTestCase): def test_make_purchase_order(self): mr = frappe.copy_doc(test_records[0]).insert() diff --git a/erpnext/stock/doctype/packing_slip/test_packing_slip.py b/erpnext/stock/doctype/packing_slip/test_packing_slip.py index 193adfcf1cb..c70cba67f2b 100644 --- a/erpnext/stock/doctype/packing_slip/test_packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/test_packing_slip.py @@ -6,6 +6,8 @@ from __future__ import unicode_literals import unittest # test_records = frappe.get_test_records('Packing Slip') +from erpnext.tests.utils import ERPNextTestCase + class TestPackingSlip(unittest.TestCase): pass diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index aa710ad0e97..fd0b3680df2 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -3,8 +3,6 @@ # See license.txt from __future__ import unicode_literals -import unittest - import frappe test_dependencies = ['Item', 'Sales Invoice', 'Stock Entry', 'Batch'] @@ -15,9 +13,10 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import ( EmptyStockReconciliationItemsError, ) +from erpnext.tests.utils import ERPNextTestCase -class TestPickList(unittest.TestCase): +class TestPickList(ERPNextTestCase): def test_pick_list_picks_warehouse_for_each_item(self): try: diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 475ac2f06f0..cd8b1bf48a0 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -803,7 +803,8 @@ def make_stock_entry(source_name,target_doc=None): "doctype": "Stock Entry Detail", "field_map": { "warehouse": "s_warehouse", - "parent": "reference_purchase_receipt" + "parent": "reference_purchase_receipt", + "batch_no": "batch_no" }, }, }, target_doc, set_missing_values) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index c61304098f4..53e0e488f9e 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -17,9 +17,10 @@ from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchas from erpnext.stock.doctype.serial_no.serial_no import SerialNoDuplicateError, get_serial_nos from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.stock_ledger import SerialNoExistsInFutureTransaction +from erpnext.tests.utils import ERPNextTestCase -class TestPurchaseReceipt(unittest.TestCase): +class TestPurchaseReceipt(ERPNextTestCase): def setUp(self): frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) diff --git a/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py b/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py index 0aa7610575e..c25bca94dbb 100644 --- a/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py +++ b/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py @@ -3,8 +3,6 @@ # See license.txt from __future__ import unicode_literals -import unittest - import frappe from erpnext.stock.doctype.batch.test_batch import make_new_batch @@ -13,9 +11,10 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.get_item_details import get_conversion_factor +from erpnext.tests.utils import ERPNextTestCase -class TestPutawayRule(unittest.TestCase): +class TestPutawayRule(ERPNextTestCase): def setUp(self): if not frappe.db.exists("Item", "_Rice"): make_item("_Rice", { diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index f5d076a077a..308c62875d5 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -1,8 +1,6 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and Contributors # See license.txt -import unittest - import frappe from frappe.utils import nowdate @@ -15,12 +13,14 @@ from erpnext.controllers.stock_controller import ( from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestCase # test_records = frappe.get_test_records('Quality Inspection') -class TestQualityInspection(unittest.TestCase): +class TestQualityInspection(ERPNextTestCase): def setUp(self): + super().setUp() create_item("_Test Item with QA") frappe.db.set_value( "Item", "_Test Item with QA", "inspection_required_before_delivery", 1 diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index 82d8aaed5b3..a9254fb9ecf 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -611,7 +611,9 @@ def get_pos_reserved_serial_nos(filters): return reserved_sr_nos -def fetch_serial_numbers(filters, qty, do_not_include=[]): +def fetch_serial_numbers(filters, qty, do_not_include=None): + if do_not_include is None: + do_not_include = [] batch_join_selection = "" batch_no_condition = "" batch_nos = filters.get("batch_no") diff --git a/erpnext/stock/doctype/serial_no/test_serial_no.py b/erpnext/stock/doctype/serial_no/test_serial_no.py index 818c163c681..570f22e6af3 100644 --- a/erpnext/stock/doctype/serial_no/test_serial_no.py +++ b/erpnext/stock/doctype/serial_no/test_serial_no.py @@ -6,8 +6,6 @@ from __future__ import unicode_literals -import unittest - import frappe from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note @@ -20,9 +18,10 @@ test_dependencies = ["Item"] test_records = frappe.get_test_records('Serial No') from erpnext.stock.doctype.serial_no.serial_no import * +from erpnext.tests.utils import ERPNextTestCase -class TestSerialNo(unittest.TestCase): +class TestSerialNo(ERPNextTestCase): def test_cannot_create_direct(self): frappe.delete_doc_if_exists("Serial No", "_TCSER0001") @@ -185,14 +184,14 @@ class TestSerialNo(unittest.TestCase): se = frappe.copy_doc(test_records[0]) se.get("items")[0].item_code = item_code - se.get("items")[0].qty = 3 - se.get("items")[0].serial_no = " _TS1, _TS2 , _TS3 " - se.get("items")[0].transfer_qty = 3 + se.get("items")[0].qty = 4 + se.get("items")[0].serial_no = " _TS1, _TS2 , _TS3 , _TS4 - 2021" + se.get("items")[0].transfer_qty = 4 se.set_stock_entry_type() se.insert() se.submit() - self.assertEqual(se.get("items")[0].serial_no, "_TS1\n_TS2\n_TS3") + self.assertEqual(se.get("items")[0].serial_no, "_TS1\n_TS2\n_TS3\n_TS4 - 2021") frappe.db.rollback() diff --git a/erpnext/stock/doctype/shipment/test_shipment.py b/erpnext/stock/doctype/shipment/test_shipment.py index 9914cf80158..dcd0b7c17c7 100644 --- a/erpnext/stock/doctype/shipment/test_shipment.py +++ b/erpnext/stock/doctype/shipment/test_shipment.py @@ -3,15 +3,15 @@ # See license.txt from __future__ import unicode_literals -import unittest from datetime import date, timedelta import frappe from erpnext.stock.doctype.delivery_note.delivery_note import make_shipment +from erpnext.tests.utils import ERPNextTestCase -class TestShipment(unittest.TestCase): +class TestShipment(ERPNextTestCase): def test_shipment_from_delivery_note(self): delivery_note = create_test_delivery_note() delivery_note.submit() @@ -47,7 +47,6 @@ def create_test_delivery_note(): } ) delivery_note.insert() - frappe.db.commit() return delivery_note @@ -91,7 +90,6 @@ def create_test_shipment(delivery_notes = None): } ) shipment.insert() - frappe.db.commit() return shipment diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 6d1df8fb599..dfd827b62d5 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -323,6 +323,12 @@ frappe.ui.form.on('Stock Entry', { attach_bom_items(frm.doc.bom_no) }, + before_save: function(frm) { + frm.doc.items.forEach((item) => { + item.uom = item.uom || item.stock_uom; + }) + }, + stock_entry_type: function(frm){ frm.remove_custom_button('Bill of Materials', "Get Items From"); frm.events.show_bom_custom_button(frm); diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json index 2463a21ed61..6de40984cd7 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.json @@ -142,6 +142,7 @@ "oldfieldtype": "Data", "print_width": "150px", "read_only": 1, + "search_index": 1, "width": "150px" }, { @@ -316,7 +317,7 @@ "in_create": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2020-09-07 11:10:35.318872", + "modified": "2021-10-08 13:44:51.857631", "modified_by": "Administrator", "module": "Stock", "name": "Stock Ledger Entry", @@ -338,4 +339,4 @@ ], "sort_field": "modified", "sort_order": "DESC" -} \ No newline at end of file +} diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index caa1d42b662..2cf71accf83 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -181,4 +181,4 @@ def on_doctype_update(): frappe.db.add_index("Stock Ledger Entry", ["voucher_no", "voucher_type"]) frappe.db.add_index("Stock Ledger Entry", ["batch_no", "item_code", "warehouse"]) - frappe.db.add_index("Stock Ledger Entry", ["voucher_detail_no"]) + frappe.db.add_index("Stock Ledger Entry", ["warehouse", "item_code"], "item_warehouse") diff --git a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py index 61bae49b0bd..ff33c2789b7 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/test_stock_ledger_entry.py @@ -3,8 +3,6 @@ # See license.txt from __future__ import unicode_literals -import unittest - import frappe from frappe.core.page.permission_manager.permission_manager import reset from frappe.utils import add_days, today @@ -21,9 +19,10 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import create_stock_reconciliation, ) from erpnext.stock.stock_ledger import get_previous_sle +from erpnext.tests.utils import ERPNextTestCase -class TestStockLedgerEntry(unittest.TestCase): +class TestStockLedgerEntry(ERPNextTestCase): def setUp(self): items = create_items() reset('Stock Entry') diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js index 99694690bbc..26bfcb116b1 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -56,25 +56,40 @@ frappe.ui.form.on("Stock Reconciliation", { }, get_items: function(frm) { - let fields = [{ - label: 'Warehouse', fieldname: 'warehouse', fieldtype: 'Link', options: 'Warehouse', reqd: 1, - "get_query": function() { - return { - "filters": { - "company": frm.doc.company, - } - }; + let fields = [ + { + label: 'Warehouse', + fieldname: 'warehouse', + fieldtype: 'Link', + options: 'Warehouse', + reqd: 1, + "get_query": function() { + return { + "filters": { + "company": frm.doc.company, + } + }; + } + }, + { + label: "Item Code", + fieldname: "item_code", + fieldtype: "Link", + options: "Item", + "get_query": function() { + return { + "filters": { + "disabled": 0, + } + }; + } + }, + { + label: __("Ignore Empty Stock"), + fieldname: "ignore_empty_stock", + fieldtype: "Check" } - }, { - label: "Item Code", fieldname: "item_code", fieldtype: "Link", options: "Item", - "get_query": function() { - return { - "filters": { - "disabled": 0, - } - }; - } - }]; + ]; frappe.prompt(fields, function(data) { frappe.call({ @@ -84,22 +99,21 @@ frappe.ui.form.on("Stock Reconciliation", { posting_date: frm.doc.posting_date, posting_time: frm.doc.posting_time, company: frm.doc.company, - item_code: data.item_code + item_code: data.item_code, + ignore_empty_stock: data.ignore_empty_stock }, callback: function(r) { + if (r.exc || !r.message || !r.message.length) return; + frm.clear_table("items"); - for (var i=0; i { + let item = frm.add_child("items"); + $.extend(item, row); - if (!d.valuation_rate) { - d.valuation_rate = 0; - } - } + item.qty = item.qty || 0; + item.valuation_rate = item.valuation_rate || 0; + }); frm.refresh_field("items"); } }); diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 6676acf87e0..1769a4e3663 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -490,7 +490,8 @@ class StockReconciliation(StockController): self._cancel() @frappe.whitelist() -def get_items(warehouse, posting_date, posting_time, company, item_code=None): +def get_items(warehouse, posting_date, posting_time, company, item_code=None, ignore_empty_stock=False): + ignore_empty_stock = cint(ignore_empty_stock) items = [frappe._dict({ 'item_code': item_code, 'warehouse': warehouse @@ -504,18 +505,24 @@ def get_items(warehouse, posting_date, posting_time, company, item_code=None): for d in items: if d.item_code in itemwise_batch_data: - stock_bal = get_stock_balance(d.item_code, d.warehouse, - posting_date, posting_time, with_valuation_rate=True) + valuation_rate = get_stock_balance(d.item_code, d.warehouse, + posting_date, posting_time, with_valuation_rate=True)[1] for row in itemwise_batch_data.get(d.item_code): - args = get_item_data(row, row.qty, stock_bal[1]) + if ignore_empty_stock and not row.qty: + continue + + args = get_item_data(row, row.qty, valuation_rate) res.append(args) else: stock_bal = get_stock_balance(d.item_code, d.warehouse, posting_date, posting_time, with_valuation_rate=True , with_serial_no=cint(d.has_serial_no)) + qty, valuation_rate, serial_no = stock_bal[0], stock_bal[1], stock_bal[2] if cint(d.has_serial_no) else '' - args = get_item_data(d, stock_bal[0], stock_bal[1], - stock_bal[2] if cint(d.has_serial_no) else '') + if ignore_empty_stock and not stock_bal[0]: + continue + + args = get_item_data(d, qty, valuation_rate, serial_no) res.append(args) @@ -523,24 +530,44 @@ def get_items(warehouse, posting_date, posting_time, company, item_code=None): def get_items_for_stock_reco(warehouse, company): lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"]) - items = frappe.db.sql(""" - select i.name as item_code, i.item_name, bin.warehouse as warehouse, i.has_serial_no, i.has_batch_no - from tabBin bin, tabItem i - where i.name=bin.item_code and IFNULL(i.disabled, 0) = 0 and i.is_stock_item = 1 - and i.has_variants = 0 and exists( - select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=bin.warehouse - ) - """, (lft, rgt), as_dict=1) + items = frappe.db.sql(f""" + select + i.name as item_code, i.item_name, bin.warehouse as warehouse, i.has_serial_no, i.has_batch_no + from + tabBin bin, tabItem i + where + i.name = bin.item_code + and IFNULL(i.disabled, 0) = 0 + and i.is_stock_item = 1 + and i.has_variants = 0 + and exists( + select name from `tabWarehouse` where lft >= {lft} and rgt <= {rgt} and name = bin.warehouse + ) + """, as_dict=1) items += frappe.db.sql(""" - select i.name as item_code, i.item_name, id.default_warehouse as warehouse, i.has_serial_no, i.has_batch_no - from tabItem i, `tabItem Default` id - where i.name = id.parent - and exists(select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=id.default_warehouse) - and i.is_stock_item = 1 and i.has_variants = 0 and IFNULL(i.disabled, 0) = 0 and id.company=%s + select + i.name as item_code, i.item_name, id.default_warehouse as warehouse, i.has_serial_no, i.has_batch_no + from + tabItem i, `tabItem Default` id + where + i.name = id.parent + and exists( + select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=id.default_warehouse + ) + and i.is_stock_item = 1 + and i.has_variants = 0 + and IFNULL(i.disabled, 0) = 0 + and id.company = %s group by i.name """, (lft, rgt, company), as_dict=1) + # remove duplicates + # check if item-warehouse key extracted from each entry exists in set iw_keys + # and update iw_keys + iw_keys = set() + items = [item for item in items if [(item.item_code, item.warehouse) not in iw_keys, iw_keys.add((item.item_code, item.warehouse))][0]] + return items def get_item_data(row, qty, valuation_rate, serial_no=None): diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 8647bee40ec..415ac5eb267 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -6,8 +6,6 @@ from __future__ import unicode_literals -import unittest - import frappe from frappe.utils import add_days, flt, nowdate, nowtime, random_string @@ -22,12 +20,13 @@ from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import ( from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse from erpnext.stock.stock_ledger import get_previous_sle, update_entries_after from erpnext.stock.utils import get_incoming_rate, get_stock_value_on, get_valuation_method -from erpnext.tests.utils import change_settings +from erpnext.tests.utils import ERPNextTestCase, change_settings -class TestStockReconciliation(unittest.TestCase): +class TestStockReconciliation(ERPNextTestCase): @classmethod def setUpClass(self): + super().setUpClass() create_batch_or_serial_no_items() frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) @@ -372,7 +371,6 @@ class TestStockReconciliation(unittest.TestCase): """ from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note from erpnext.stock.stock_ledger import NegativeStockError - frappe.db.commit() item_code = "Backdated-Reco-Cancellation-Item" warehouse = "_Test Warehouse - _TC" @@ -395,10 +393,6 @@ class TestStockReconciliation(unittest.TestCase): repost_exists = bool(frappe.db.exists("Repost Item Valuation", {"voucher_no": sr.name})) self.assertFalse(repost_exists, msg="Negative stock validation not working on reco cancellation") - # teardown - frappe.db.rollback() - - def test_valid_batch(self): create_batch_item_with_batch("Testing Batch Item 1", "001") create_batch_item_with_batch("Testing Batch Item 2", "002") diff --git a/erpnext/stock/doctype/stock_settings/test_stock_settings.py b/erpnext/stock/doctype/stock_settings/test_stock_settings.py index 7e8090499fb..bf8ac5dc79a 100644 --- a/erpnext/stock/doctype/stock_settings/test_stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/test_stock_settings.py @@ -7,9 +7,12 @@ import unittest import frappe +from erpnext.tests.utils import ERPNextTestCase -class TestStockSettings(unittest.TestCase): + +class TestStockSettings(ERPNextTestCase): def setUp(self): + super().setUp() frappe.db.set_value("Stock Settings", None, "clean_description_html", 0) def test_settings(self): diff --git a/erpnext/stock/doctype/warehouse/test_warehouse.py b/erpnext/stock/doctype/warehouse/test_warehouse.py index 1ca7181f279..98317ec9c57 100644 --- a/erpnext/stock/doctype/warehouse/test_warehouse.py +++ b/erpnext/stock/doctype/warehouse/test_warehouse.py @@ -2,8 +2,6 @@ # License: GNU General Public License v3. See license.txt from __future__ import unicode_literals -import unittest - import frappe from frappe.test_runner import make_test_records from frappe.utils import cint @@ -12,11 +10,13 @@ import erpnext from erpnext.accounts.doctype.account.test_account import create_account, get_inventory_account from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.tests.utils import ERPNextTestCase test_records = frappe.get_test_records('Warehouse') -class TestWarehouse(unittest.TestCase): +class TestWarehouse(ERPNextTestCase): def setUp(self): + super().setUp() if not frappe.get_value('Item', '_Test Item'): make_test_records('Item') diff --git a/erpnext/stock/form_tour/material_request/material_request.json b/erpnext/stock/form_tour/material_request/material_request.json new file mode 100644 index 00000000000..145b4a06c2b --- /dev/null +++ b/erpnext/stock/form_tour/material_request/material_request.json @@ -0,0 +1,97 @@ +{ + "creation": "2021-07-29 12:32:08.929900", + "docstatus": 0, + "doctype": "Form Tour", + "idx": 0, + "is_standard": 1, + "modified": "2021-10-05 13:11:13.119453", + "modified_by": "Administrator", + "module": "Stock", + "name": "Material Request", + "owner": "Administrator", + "reference_doctype": "Material Request", + "save_on_complete": 1, + "steps": [ + { + "description": "The purpose of the material request can be selected here. For now select \"Purchase\" as the purpose.", + "field": "", + "fieldname": "material_request_type", + "fieldtype": "Select", + "has_next_condition": 1, + "is_table_field": 0, + "label": "Purpose", + "next_step_condition": "eval: doc.material_request_type == \"Purchase\"", + "parent_field": "", + "position": "Bottom", + "title": "Purpose" + }, + { + "description": "Set the \"Required By\" date for the materials. This sets the \"Required By\" date for all the items.", + "field": "", + "fieldname": "schedule_date", + "fieldtype": "Date", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Required By", + "next_step_condition": "", + "parent_field": "", + "position": "Left", + "title": "Required By" + }, + { + "description": "Setting the target warehouse sets it for all the items.", + "field": "", + "fieldname": "set_warehouse", + "fieldtype": "Link", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Set Target Warehouse", + "next_step_condition": "", + "parent_field": "", + "position": "Left", + "title": "Target Warehouse" + }, + { + "description": "Items table", + "field": "", + "fieldname": "items", + "fieldtype": "Table", + "has_next_condition": 0, + "is_table_field": 0, + "label": "Items", + "parent_field": "", + "position": "Bottom", + "title": "Items" + }, + { + "child_doctype": "Material Request Item", + "description": "Select an Item code. Item details will be fetched automatically.", + "field": "", + "fieldname": "item_code", + "fieldtype": "Link", + "has_next_condition": 1, + "is_table_field": 1, + "label": "Item Code", + "next_step_condition": "eval: doc.item_code", + "parent_field": "", + "parent_fieldname": "items", + "position": "Right", + "title": "Item Code" + }, + { + "child_doctype": "Material Request Item", + "description": "Enter the required quantity for the material.", + "field": "", + "fieldname": "qty", + "fieldtype": "Float", + "has_next_condition": 0, + "is_table_field": 1, + "label": "Quantity", + "parent_field": "", + "parent_fieldname": "items", + "position": "Bottom", + "title": "Quantity" + } + ], + "title": "Material Request" +} \ No newline at end of file diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 19597c3d993..cbff2149d64 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -382,7 +382,7 @@ def get_basic_details(args, item, overwrite_warehouse=True): return out -def get_item_warehouse(item, args, overwrite_warehouse, defaults={}): +def get_item_warehouse(item, args, overwrite_warehouse, defaults=None): if not defaults: defaults = frappe._dict({ 'item_defaults' : get_item_defaults(item.name, args.company), diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py index 3cd4cd27617..7c6fbfd9cd1 100644 --- a/erpnext/stock/reorder_item.py +++ b/erpnext/stock/reorder_item.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import json +from math import ceil import frappe from frappe import _ @@ -149,11 +150,16 @@ def create_material_request(material_requests): conversion_factor = frappe.db.get_value("UOM Conversion Detail", {'parent': item.name, 'uom': uom}, 'conversion_factor') or 1.0 + must_be_whole_number = frappe.db.get_value("UOM", uom, "must_be_whole_number", cache=True) + qty = d.reorder_qty / conversion_factor + if must_be_whole_number: + qty = ceil(qty) + mr.append("items", { "doctype": "Material Request Item", "item_code": d.item_code, "schedule_date": add_days(nowdate(),cint(item.lead_time_days)), - "qty": d.reorder_qty / conversion_factor, + "qty": qty, "uom": uom, "stock_uom": item.stock_uom, "warehouse": d.warehouse, diff --git a/erpnext/stock/report/stock_analytics/test_stock_analytics.py b/erpnext/stock/report/stock_analytics/test_stock_analytics.py index 21e1205bfcc..32df5859375 100644 --- a/erpnext/stock/report/stock_analytics/test_stock_analytics.py +++ b/erpnext/stock/report/stock_analytics/test_stock_analytics.py @@ -5,9 +5,10 @@ from frappe import _dict from erpnext.accounts.utils import get_fiscal_year from erpnext.stock.report.stock_analytics.stock_analytics import get_period_date_ranges +from erpnext.tests.utils import ERPNextTestCase -class TestStockAnalyticsReport(unittest.TestCase): +class TestStockAnalyticsReport(ERPNextTestCase): def test_get_period_date_ranges(self): filters = _dict(range="Monthly", from_date="2020-12-28", to_date="2021-02-06") diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 8e364a5062e..e8768c4aed3 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -13,8 +13,8 @@ from six import iteritems import erpnext from erpnext.stock.utils import ( - get_bin, get_incoming_outgoing_rate_for_cancel, + get_or_make_bin, get_valuation_method, ) @@ -797,14 +797,13 @@ class update_entries_after(object): def update_bin(self): # update bin for each warehouse for warehouse, data in iteritems(self.data): - bin_doc = get_bin(self.item_code, warehouse) - bin_doc.update({ + bin_record = get_or_make_bin(self.item_code, warehouse) + + frappe.db.set_value('Bin', bin_record, { "valuation_rate": data.valuation_rate, "actual_qty": data.qty_after_transaction, "stock_value": data.stock_value }) - bin_doc.flags.via_stock_ledger_entry = True - bin_doc.save(ignore_permissions=True) def get_previous_sle_of_current_voucher(args, exclude_current_voucher=False): @@ -910,7 +909,7 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, company = erpnext.get_default_company() last_valuation_rate = frappe.db.sql("""select valuation_rate - from `tabStock Ledger Entry` + from `tabStock Ledger Entry` force index (item_warehouse) where item_code = %s AND warehouse = %s @@ -921,7 +920,7 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, if not last_valuation_rate: # Get valuation rate from last sle for the item against any warehouse last_valuation_rate = frappe.db.sql("""select valuation_rate - from `tabStock Ledger Entry` + from `tabStock Ledger Entry` force index (item_code) where item_code = %s AND valuation_rate > 0 diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index aeb06e987f8..c4a0497b744 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -180,12 +180,27 @@ def get_bin(item_code, warehouse): bin_obj.flags.ignore_permissions = True return bin_obj +def get_or_make_bin(item_code, warehouse) -> str: + bin_record = frappe.db.get_value('Bin', {'item_code': item_code, 'warehouse': warehouse}) + + if not bin_record: + bin_obj = frappe.get_doc({ + "doctype": "Bin", + "item_code": item_code, + "warehouse": warehouse, + }) + bin_obj.flags.ignore_permissions = 1 + bin_obj.insert() + bin_record = bin_obj.name + + return bin_record + def update_bin(args, allow_negative_stock=False, via_landed_cost_voucher=False): + from erpnext.stock.doctype.bin.bin import update_stock is_stock_item = frappe.get_cached_value('Item', args.get("item_code"), 'is_stock_item') if is_stock_item: - bin = get_bin(args.get("item_code"), args.get("warehouse")) - bin.update_stock(args, allow_negative_stock, via_landed_cost_voucher) - return bin + bin_record = get_or_make_bin(args.get("item_code"), args.get("warehouse")) + update_stock(bin_record, args, allow_negative_stock, via_landed_cost_voucher) else: frappe.msgprint(_("Item {0} ignored since it is not a stock item").format(args.get("item_code"))) diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py index 272e3be2648..91ef68ae001 100644 --- a/erpnext/support/doctype/issue/issue.py +++ b/erpnext/support/doctype/issue/issue.py @@ -539,7 +539,7 @@ def get_time_in_timedelta(time): def set_first_response_time(communication, method): if communication.get('reference_doctype') == "Issue": issue = get_parent_doc(communication) - if is_first_response(issue): + if is_first_response(issue) and issue.service_level_agreement: first_response_time = calculate_first_response_time(issue, get_datetime(issue.first_responded_on)) issue.db_set("first_response_time", first_response_time) diff --git a/erpnext/templates/generators/item/item_configure.html b/erpnext/templates/generators/item/item_configure.html index fcab594402b..e97a275fbd8 100644 --- a/erpnext/templates/generators/item/item_configure.html +++ b/erpnext/templates/generators/item/item_configure.html @@ -4,8 +4,8 @@
{% if cart_settings.enable_variants | int %} diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py index a3cab4b59da..91df5480e35 100644 --- a/erpnext/tests/utils.py +++ b/erpnext/tests/utils.py @@ -2,6 +2,7 @@ # License: GNU General Public License v3. See license.txt import copy +import unittest from contextlib import contextmanager from typing import Any, Dict, NewType, Optional @@ -12,6 +13,21 @@ ReportFilters = Dict[str, Any] ReportName = NewType("ReportName", str) +class ERPNextTestCase(unittest.TestCase): + """A sane default test class for ERPNext tests.""" + + + @classmethod + def setUpClass(cls) -> None: + frappe.db.commit() + return super().setUpClass() + + @classmethod + def tearDownClass(cls) -> None: + frappe.db.rollback() + return super().tearDownClass() + + def create_test_contact_and_address(): frappe.db.sql('delete from tabContact') frappe.db.sql('delete from `tabContact Email`')