diff --git a/.flake8 b/.flake8 index 56c9b9a3699..5735456ae7d 100644 --- a/.flake8 +++ b/.flake8 @@ -28,6 +28,7 @@ ignore = B007, B950, W191, + E124, # closing bracket, irritating while writing QB code max-line-length = 200 exclude=.github/helper/semgrep_rules diff --git a/.github/helper/install.sh b/.github/helper/install.sh index 903196847dc..859146bbcde 100644 --- a/.github/helper/install.sh +++ b/.github/helper/install.sh @@ -8,7 +8,10 @@ sudo apt-get install redis-server libcups2-dev pip install frappe-bench -git clone https://github.com/frappe/frappe --branch "${GITHUB_BASE_REF:-${GITHUB_REF##*/}}" --depth 1 +frappeuser=${FRAPPE_USER:-"frappe"} +frappebranch=${FRAPPE_BRANCH:-${GITHUB_BASE_REF:-${GITHUB_REF##*/}}} + +git clone "https://github.com/${frappeuser}/frappe" --branch "${frappebranch}" --depth 1 bench init --skip-assets --frappe-path ~/frappe --python "$(which python)" frappe-bench mkdir ~/frappe-bench/sites/test_site @@ -37,10 +40,14 @@ if [ "$DB" == "postgres" ];then echo "travis" | psql -h 127.0.0.1 -p 5432 -c "CREATE USER test_frappe WITH PASSWORD 'test_frappe'" -U postgres; fi -wget -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz -tar -xf /tmp/wkhtmltox.tar.xz -C /tmp -sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf -sudo chmod o+x /usr/local/bin/wkhtmltopdf + +install_whktml() { + wget -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz + tar -xf /tmp/wkhtmltox.tar.xz -C /tmp + sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf + sudo chmod o+x /usr/local/bin/wkhtmltopdf +} +install_whktml & cd ~/frappe-bench || exit @@ -54,5 +61,5 @@ bench get-app erpnext "${GITHUB_WORKSPACE}" if [ "$TYPE" == "server" ]; then bench setup requirements --dev; fi bench start &> bench_run_logs.txt & +CI=Yes bench build --app frappe & bench --site test_site reinstall --yes -bench build --app frappe diff --git a/.github/stale.yml b/.github/stale.yml index 8b7cb9be3ef..1c2dcf3ba9c 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -30,6 +30,7 @@ issues: exemptLabels: - valid - to-validate + - QA markComment: > This issue has been automatically marked as inactive because it has not had recent activity and it wasn't validated by maintainer team. It will be diff --git a/.github/workflows/server-tests-mariadb.yml b/.github/workflows/server-tests-mariadb.yml index 7347a5856a2..40f93651f4a 100644 --- a/.github/workflows/server-tests-mariadb.yml +++ b/.github/workflows/server-tests-mariadb.yml @@ -6,12 +6,23 @@ on: - '**.js' - '**.md' - '**.html' - workflow_dispatch: push: branches: [ develop ] paths-ignore: - '**.js' - '**.md' + workflow_dispatch: + inputs: + user: + description: 'user' + required: true + default: 'frappe' + type: string + branch: + description: 'Branch name' + default: 'develop' + required: false + type: string concurrency: group: server-mariadb-develop-${{ github.event.number }} @@ -95,6 +106,8 @@ jobs: env: DB: mariadb TYPE: server + FRAPPE_USER: ${{ github.event.inputs.user }} + FRAPPE_BRANCH: ${{ github.event.inputs.branch }} - name: Run Tests run: cd ~/frappe-bench/ && bench --site test_site run-parallel-tests --app erpnext --use-orchestrator --with-coverage diff --git a/.mergify.yml b/.mergify.yml index f3d04096cfc..b7d1df4524f 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -14,9 +14,39 @@ pull_request_rules: 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. + @{{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 develop + conditions: + - label="backport develop" + actions: + backport: + branches: + - develop + assignees: + - "{{ author }}" + + - name: backport to version-14-hotfix + conditions: + - label="backport version-14-hotfix" + actions: + backport: + branches: + - version-14-hotfix + assignees: + - "{{ author }}" + + - name: backport to version-14-pre-release + conditions: + - label="backport version-14-pre-release" + actions: + backport: + branches: + - version-14-pre-release + assignees: + - "{{ author }}" + - name: backport to version-13-hotfix conditions: - label="backport version-13-hotfix" @@ -55,4 +85,4 @@ pull_request_rules: branches: - version-12-pre-release assignees: - - "{{ author }}" \ No newline at end of file + - "{{ author }}" diff --git a/cypress/integration/test_bulk_transaction_processing.js b/cypress/integration/test_bulk_transaction_processing.js new file mode 100644 index 00000000000..428ec5100b5 --- /dev/null +++ b/cypress/integration/test_bulk_transaction_processing.js @@ -0,0 +1,44 @@ +describe("Bulk Transaction Processing", () => { + before(() => { + cy.login(); + cy.visit("/app/website"); + }); + + it("Creates To Sales Order", () => { + cy.visit("/app/sales-order"); + cy.url().should("include", "/sales-order"); + cy.window() + .its("frappe.csrf_token") + .then((csrf_token) => { + return cy + .request({ + url: "/api/method/erpnext.tests.ui_test_bulk_transaction_processing.create_records", + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + "X-Frappe-CSRF-Token": csrf_token, + }, + timeout: 60000, + }) + .then((res) => { + expect(res.status).eq(200); + }); + }); + cy.wait(5000); + cy.get( + ".list-row-head > .list-header-subject > .list-row-col > .list-check-all" + ).check({ force: true }); + cy.wait(3000); + cy.get(".actions-btn-group > .btn-primary").click({ force: true }); + cy.wait(3000); + cy.get(".dropdown-menu-right > .user-action > .dropdown-item") + .contains("Sales Invoice") + .click({ force: true }); + cy.wait(3000); + cy.get(".modal-content > .modal-footer > .standard-actions") + .contains("Yes") + .click({ force: true }); + cy.contains("Creation of Sales Invoice successful"); + }); +}); diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 0b4696c8034..dcfad1f100e 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -2,8 +2,6 @@ import inspect import frappe -from erpnext.hooks import regional_overrides - __version__ = '14.0.0-dev' def get_default_company(user=None): @@ -121,20 +119,15 @@ def allow_regional(fn): @erpnext.allow_regional def myfunction(): pass''' + def caller(*args, **kwargs): - region = get_region() - fn_name = inspect.getmodule(fn).__name__ + '.' + fn.__name__ - if region in regional_overrides and fn_name in regional_overrides[region]: - return frappe.get_attr(regional_overrides[region][fn_name])(*args, **kwargs) - else: + overrides = frappe.get_hooks("regional_overrides", {}).get(get_region()) + function_path = f"{inspect.getmodule(fn).__name__}.{fn.__name__}" + + if not overrides or function_path not in overrides: return fn(*args, **kwargs) + # Priority given to last installed app + return frappe.get_attr(overrides[function_path][-1])(*args, **kwargs) + return caller - -def get_last_membership(member): - '''Returns last membership if exists''' - last_membership = frappe.get_all('Membership', 'name,to_date,membership_type', - dict(member=member, paid=1), order_by='to_date desc', limit=1) - - if last_membership: - return last_membership[0] diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index 9e2cdfffd9a..ab1061beeb3 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -120,6 +120,7 @@ def get_booking_dates(doc, item, posting_date=None): prev_gl_entry = frappe.db.sql(''' select name, posting_date from `tabGL Entry` where company=%s and account=%s and voucher_type=%s and voucher_no=%s and voucher_detail_no=%s + and is_cancelled = 0 order by posting_date desc limit 1 ''', (doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name), as_dict=True) @@ -227,6 +228,7 @@ def get_already_booked_amount(doc, item): gl_entries_details = frappe.db.sql(''' select sum({0}) as total_credit, sum({1}) as total_credit_in_account_currency, voucher_detail_no from `tabGL Entry` where company=%s and account=%s and voucher_type=%s and voucher_no=%s and voucher_detail_no=%s + and is_cancelled = 0 group by voucher_detail_no '''.format(total_credit_debit, total_credit_debit_currency), (doc.company, item.get(deferred_account), doc.doctype, doc.name, item.name), as_dict=True) @@ -282,7 +284,7 @@ def book_deferred_income_or_expense(doc, deferred_process, posting_date=None): return # check if books nor frozen till endate: - if getdate(end_date) >= getdate(accounts_frozen_upto): + if accounts_frozen_upto and (end_date) <= getdate(accounts_frozen_upto): end_date = get_last_day(add_days(accounts_frozen_upto, 1)) if via_journal_entry: diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json index 55ea571ebf8..9a35a247ddd 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.json +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.json @@ -7,35 +7,30 @@ "editable_grid": 1, "engine": "InnoDB", "field_order": [ - "accounts_transactions_settings_section", - "over_billing_allowance", - "role_allowed_to_over_bill", - "credit_controller", - "make_payment_via_journal_entry", - "column_break_11", - "check_supplier_invoice_uniqueness", + "invoice_and_billing_tab", + "enable_features_section", "unlink_payment_on_cancellation_of_invoice", - "automatically_fetch_payment_terms", - "delete_linked_ledger_entries", - "book_asset_depreciation_entry_automatically", "unlink_advance_payment_on_cancelation_of_order", + "column_break_13", + "delete_linked_ledger_entries", + "invoicing_features_section", + "check_supplier_invoice_uniqueness", + "automatically_fetch_payment_terms", + "column_break_17", "enable_common_party_accounting", - "post_change_gl_entries", "enable_discount_accounting", - "tax_settings_section", - "determine_address_tax_category_from", - "column_break_19", - "add_taxes_from_item_tax_template", - "period_closing_settings_section", - "acc_frozen_upto", - "frozen_accounts_modifier", - "column_break_4", + "report_setting_section", + "use_custom_cash_flow", "deferred_accounting_settings_section", "book_deferred_entries_based_on", "column_break_18", "automatically_process_deferred_accounting_entry", "book_deferred_entries_via_journal_entry", "submit_journal_entries", + "tax_settings_section", + "determine_address_tax_category_from", + "column_break_19", + "add_taxes_from_item_tax_template", "print_settings", "show_inclusive_tax_in_print", "column_break_12", @@ -43,8 +38,25 @@ "currency_exchange_section", "allow_stale", "stale_days", - "report_settings_sb", - "use_custom_cash_flow" + "invoicing_settings_tab", + "accounts_transactions_settings_section", + "over_billing_allowance", + "column_break_11", + "role_allowed_to_over_bill", + "credit_controller", + "make_payment_via_journal_entry", + "pos_tab", + "pos_setting_section", + "post_change_gl_entries", + "assets_tab", + "asset_settings_section", + "book_asset_depreciation_entry_automatically", + "closing_settings_tab", + "period_closing_settings_section", + "acc_frozen_upto", + "column_break_25", + "frozen_accounts_modifier", + "report_settings_sb" ], "fields": [ { @@ -70,10 +82,6 @@ "label": "Determine Address Tax Category From", "options": "Billing Address\nShipping Address" }, - { - "fieldname": "column_break_4", - "fieldtype": "Column Break" - }, { "fieldname": "credit_controller", "fieldtype": "Link", @@ -83,6 +91,7 @@ }, { "default": "0", + "description": "Enabling ensure each Sales Invoice has a unique value in Supplier Invoice No. field", "fieldname": "check_supplier_invoice_uniqueness", "fieldtype": "Check", "label": "Check Supplier Invoice Number Uniqueness" @@ -168,7 +177,7 @@ "description": "Only select this if you have set up the Cash Flow Mapper documents", "fieldname": "use_custom_cash_flow", "fieldtype": "Check", - "label": "Use Custom Cash Flow Format" + "label": "Enable Custom Cash Flow Format" }, { "default": "0", @@ -241,7 +250,7 @@ { "fieldname": "accounts_transactions_settings_section", "fieldtype": "Section Break", - "label": "Transactions Settings" + "label": "Credit Limit Settings" }, { "fieldname": "column_break_11", @@ -272,9 +281,72 @@ }, { "default": "0", + "description": "Learn about Common Party", "fieldname": "enable_common_party_accounting", "fieldtype": "Check", "label": "Enable Common Party Accounting" + }, + { + "fieldname": "enable_features_section", + "fieldtype": "Section Break", + "label": "Invoice Cancellation" + }, + { + "fieldname": "column_break_13", + "fieldtype": "Column Break" + }, + { + "fieldname": "column_break_25", + "fieldtype": "Column Break" + }, + { + "fieldname": "asset_settings_section", + "fieldtype": "Section Break", + "label": "Asset Settings" + }, + { + "fieldname": "invoicing_settings_tab", + "fieldtype": "Tab Break", + "label": "Credit Limits" + }, + { + "fieldname": "assets_tab", + "fieldtype": "Tab Break", + "label": "Assets" + }, + { + "fieldname": "closing_settings_tab", + "fieldtype": "Tab Break", + "label": "Accounts Closing" + }, + { + "fieldname": "pos_setting_section", + "fieldtype": "Section Break", + "label": "POS Setting" + }, + { + "fieldname": "invoice_and_billing_tab", + "fieldtype": "Tab Break", + "label": "Invoice and Billing" + }, + { + "fieldname": "invoicing_features_section", + "fieldtype": "Section Break", + "label": "Invoicing Features" + }, + { + "fieldname": "column_break_17", + "fieldtype": "Column Break" + }, + { + "fieldname": "pos_tab", + "fieldtype": "Tab Break", + "label": "POS" + }, + { + "fieldname": "report_setting_section", + "fieldtype": "Section Break", + "label": "Report Setting" } ], "icon": "icon-cog", @@ -282,7 +354,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-10-11 17:42:36.427699", + "modified": "2022-02-04 12:32:36.805652", "modified_by": "Administrator", "module": "Accounts", "name": "Accounts Settings", @@ -309,5 +381,6 @@ "quick_entry": 1, "sort_field": "modified", "sort_order": "ASC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js index 335f8502c7a..46ba27c004d 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.js @@ -14,6 +14,10 @@ frappe.ui.form.on("Bank Reconciliation Tool", { }); }, + onload: function (frm) { + frm.trigger('bank_account'); + }, + refresh: function (frm) { frappe.require("bank-reconciliation-tool.bundle.js", () => frm.trigger("make_reconciliation_tool") @@ -51,7 +55,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", { bank_account: function (frm) { frappe.db.get_value( "Bank Account", - frm.bank_account, + frm.doc.bank_account, "account", (r) => { frappe.db.get_value( @@ -60,6 +64,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", { "account_currency", (r) => { frm.currency = r.account_currency; + frm.trigger("render_chart"); } ); } @@ -124,7 +129,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", { } }, - render_chart(frm) { + render_chart: frappe.utils.debounce((frm) => { frm.cards_manager = new erpnext.accounts.bank_reconciliation.NumberCardManager( { $reconciliation_tool_cards: frm.get_field( @@ -136,7 +141,7 @@ frappe.ui.form.on("Bank Reconciliation Tool", { currency: frm.currency, } ); - }, + }, 500), render(frm) { if (frm.doc.bank_account) { diff --git a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py index 4211bd0169d..f3351ddcba4 100644 --- a/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py +++ b/erpnext/accounts/doctype/bank_reconciliation_tool/bank_reconciliation_tool.py @@ -7,6 +7,7 @@ import json import frappe from frappe import _ from frappe.model.document import Document +from frappe.query_builder.custom import ConstantColumn from frappe.utils import flt from erpnext import get_company_currency @@ -275,6 +276,10 @@ def check_matching(bank_account, company, transaction, document_types): } matching_vouchers = [] + + matching_vouchers.extend(get_loan_vouchers(bank_account, transaction, + document_types, filters)) + for query in subquery: matching_vouchers.extend( frappe.db.sql(query, filters,) @@ -311,6 +316,114 @@ def get_queries(bank_account, company, transaction, document_types): return queries +def get_loan_vouchers(bank_account, transaction, document_types, filters): + vouchers = [] + amount_condition = True if "exact_match" in document_types else False + + if transaction.withdrawal > 0 and "loan_disbursement" in document_types: + vouchers.extend(get_ld_matching_query(bank_account, amount_condition, filters)) + + if transaction.deposit > 0 and "loan_repayment" in document_types: + vouchers.extend(get_lr_matching_query(bank_account, amount_condition, filters)) + + return vouchers + +def get_ld_matching_query(bank_account, amount_condition, filters): + loan_disbursement = frappe.qb.DocType("Loan Disbursement") + matching_reference = loan_disbursement.reference_number == filters.get("reference_number") + matching_party = loan_disbursement.applicant_type == filters.get("party_type") and \ + loan_disbursement.applicant == filters.get("party") + + rank = ( + frappe.qb.terms.Case() + .when(matching_reference, 1) + .else_(0) + ) + + rank1 = ( + frappe.qb.terms.Case() + .when(matching_party, 1) + .else_(0) + ) + + query = frappe.qb.from_(loan_disbursement).select( + rank + rank1 + 1, + ConstantColumn("Loan Disbursement").as_("doctype"), + loan_disbursement.name, + loan_disbursement.disbursed_amount, + loan_disbursement.reference_number, + loan_disbursement.reference_date, + loan_disbursement.applicant_type, + loan_disbursement.disbursement_date + ).where( + loan_disbursement.docstatus == 1 + ).where( + loan_disbursement.clearance_date.isnull() + ).where( + loan_disbursement.disbursement_account == bank_account + ) + + if amount_condition: + query.where( + loan_disbursement.disbursed_amount == filters.get('amount') + ) + else: + query.where( + loan_disbursement.disbursed_amount <= filters.get('amount') + ) + + vouchers = query.run(as_list=True) + + return vouchers + +def get_lr_matching_query(bank_account, amount_condition, filters): + loan_repayment = frappe.qb.DocType("Loan Repayment") + matching_reference = loan_repayment.reference_number == filters.get("reference_number") + matching_party = loan_repayment.applicant_type == filters.get("party_type") and \ + loan_repayment.applicant == filters.get("party") + + rank = ( + frappe.qb.terms.Case() + .when(matching_reference, 1) + .else_(0) + ) + + rank1 = ( + frappe.qb.terms.Case() + .when(matching_party, 1) + .else_(0) + ) + + query = frappe.qb.from_(loan_repayment).select( + rank + rank1 + 1, + ConstantColumn("Loan Repayment").as_("doctype"), + loan_repayment.name, + loan_repayment.amount_paid, + loan_repayment.reference_number, + loan_repayment.reference_date, + loan_repayment.applicant_type, + loan_repayment.posting_date + ).where( + loan_repayment.docstatus == 1 + ).where( + loan_repayment.clearance_date.isnull() + ).where( + loan_repayment.payment_account == bank_account + ) + + if amount_condition: + query.where( + loan_repayment.amount_paid == filters.get('amount') + ) + else: + query.where( + loan_repayment.amount_paid <= filters.get('amount') + ) + + vouchers = query.run() + + return vouchers + def get_pe_matching_query(amount_condition, account_from_to, transaction): # get matching payment entries query if transaction.deposit > 0: @@ -348,7 +461,6 @@ def get_je_matching_query(amount_condition, transaction): # We have mapping at the bank level # So one bank could have both types of bank accounts like asset and liability # So cr_or_dr should be judged only on basis of withdrawal and deposit and not account type - company_account = frappe.get_value("Bank Account", transaction.bank_account, "account") cr_or_dr = "credit" if transaction.withdrawal > 0 else "debit" return f""" diff --git a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py index e786d13c95d..1403303f53c 100644 --- a/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py +++ b/erpnext/accounts/doctype/bank_statement_import/bank_statement_import.py @@ -16,6 +16,7 @@ from frappe.utils.xlsxutils import ILLEGAL_CHARACTERS_RE, handle_html from openpyxl.styles import Font from openpyxl.utils import get_column_letter +INVALID_VALUES = ("", None) class BankStatementImport(DataImport): def __init__(self, *args, **kwargs): @@ -95,6 +96,18 @@ def download_errored_template(data_import_name): data_import = frappe.get_doc("Bank Statement Import", data_import_name) data_import.export_errored_rows() +def parse_data_from_template(raw_data): + data = [] + + for i, row in enumerate(raw_data): + if all(v in INVALID_VALUES for v in row): + # empty row + continue + + data.append(row) + + return data + def start_import(data_import, bank_account, import_file_path, google_sheets_url, bank, template_options): """This method runs in background job""" @@ -104,7 +117,8 @@ def start_import(data_import, bank_account, import_file_path, google_sheets_url, file = import_file_path if import_file_path else google_sheets_url import_file = ImportFile("Bank Transaction", file = file, import_type="Insert New Records") - data = import_file.raw_data + + data = parse_data_from_template(import_file.raw_data) if import_file_path: add_bank_account(data, bank_account) diff --git a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py index 44cea31ed38..a476cab55f7 100644 --- a/erpnext/accounts/doctype/bank_transaction/bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/bank_transaction.py @@ -2,9 +2,10 @@ # For license information, please see license.txt +from functools import reduce + import frappe from frappe.utils import flt -from six.moves import reduce from erpnext.controllers.status_updater import StatusUpdater @@ -48,7 +49,8 @@ class BankTransaction(StatusUpdater): def clear_linked_payment_entries(self, for_cancel=False): for payment_entry in self.payment_entries: - if payment_entry.payment_document in ["Payment Entry", "Journal Entry", "Purchase Invoice", "Expense Claim"]: + if payment_entry.payment_document in ["Payment Entry", "Journal Entry", "Purchase Invoice", "Expense Claim", "Loan Repayment", + "Loan Disbursement"]: self.clear_simple_entry(payment_entry, for_cancel=for_cancel) elif payment_entry.payment_document == "Sales Invoice": @@ -115,11 +117,18 @@ def get_paid_amount(payment_entry, currency, bank_account): payment_entry.payment_entry, paid_amount_field) elif payment_entry.payment_document == "Journal Entry": - return frappe.db.get_value('Journal Entry Account', {'parent': payment_entry.payment_entry, 'account': bank_account}, "sum(credit_in_account_currency)") + return frappe.db.get_value('Journal Entry Account', {'parent': payment_entry.payment_entry, 'account': bank_account}, + "sum(credit_in_account_currency)") elif payment_entry.payment_document == "Expense Claim": return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "total_amount_reimbursed") + elif payment_entry.payment_document == "Loan Disbursement": + return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "disbursed_amount") + + elif payment_entry.payment_document == "Loan Repayment": + return frappe.db.get_value(payment_entry.payment_document, payment_entry.payment_entry, "amount_paid") + else: frappe.throw("Please reconcile {0}: {1} manually".format(payment_entry.payment_document, payment_entry.payment_entry)) diff --git a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py index 72b6893faf5..d84b8e07d35 100644 --- a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py +++ b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py @@ -109,7 +109,7 @@ def create_bank_account(bank_name="Citi Bank", account_name="_Test Bank - _TC"): frappe.get_doc({ "doctype": "Bank", "bank_name":bank_name, - }).insert() + }).insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass @@ -119,7 +119,7 @@ def create_bank_account(bank_name="Citi Bank", account_name="_Test Bank - _TC"): "account_name":"Checking Account", "bank": bank_name, "account": account_name - }).insert() + }).insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass @@ -184,7 +184,7 @@ def add_vouchers(): "supplier_group":"All Supplier Groups", "supplier_type": "Company", "supplier_name": "Conrad Electronic" - }).insert() + }).insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass @@ -203,7 +203,7 @@ def add_vouchers(): "supplier_group":"All Supplier Groups", "supplier_type": "Company", "supplier_name": "Mr G" - }).insert() + }).insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass @@ -227,7 +227,7 @@ def add_vouchers(): "supplier_group":"All Supplier Groups", "supplier_type": "Company", "supplier_name": "Poore Simon's" - }).insert() + }).insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass @@ -237,7 +237,7 @@ def add_vouchers(): "customer_group":"All Customer Groups", "customer_type": "Company", "customer_name": "Poore Simon's" - }).insert() + }).insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass @@ -266,7 +266,7 @@ def add_vouchers(): "customer_group":"All Customer Groups", "customer_type": "Company", "customer_name": "Fayva" - }).insert() + }).insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass diff --git a/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.json b/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.json index 22cf797fc3f..02c6875fb36 100644 --- a/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.json +++ b/erpnext/accounts/doctype/cash_flow_mapping_template_details/cash_flow_mapping_template_details.json @@ -1,94 +1,34 @@ { - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "field:mapping", - "beta": 0, - "creation": "2018-02-08 10:18:48.513608", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", + "actions": [], + "creation": "2018-02-08 10:18:48.513608", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "mapping" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "mapping", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Mapping", - "length": 0, - "no_copy": 0, - "options": "Cash Flow Mapping", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 + "fieldname": "mapping", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Mapping", + "options": "Cash Flow Mapping", + "reqd": 1, + "unique": 1 } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2018-02-08 10:33:39.413930", - "modified_by": "Administrator", - "module": "Accounts", - "name": "Cash Flow Mapping Template Details", - "name_case": "", - "owner": "Administrator", - "permissions": [ - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 + ], + "istable": 1, + "links": [], + "modified": "2022-02-21 03:34:57.902332", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Cash Flow Mapping Template Details", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/cost_center/cost_center.js b/erpnext/accounts/doctype/cost_center/cost_center.js index ee23b1be5c5..632fab0197c 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.js +++ b/erpnext/accounts/doctype/cost_center/cost_center.js @@ -15,17 +15,6 @@ frappe.ui.form.on('Cost Center', { } } }); - - frm.set_query("cost_center", "distributed_cost_center", function() { - return { - filters: { - company: frm.doc.company, - is_group: 0, - enable_distributed_cost_center: 0, - name: ['!=', frm.doc.name] - } - }; - }); }, refresh: function(frm) { if (!frm.is_new()) { diff --git a/erpnext/accounts/doctype/cost_center/cost_center.json b/erpnext/accounts/doctype/cost_center/cost_center.json index e7fa954e018..7cbb290947e 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.json +++ b/erpnext/accounts/doctype/cost_center/cost_center.json @@ -16,9 +16,6 @@ "cb0", "is_group", "disabled", - "section_break_9", - "enable_distributed_cost_center", - "distributed_cost_center", "lft", "rgt", "old_parent" @@ -122,31 +119,13 @@ "fieldname": "disabled", "fieldtype": "Check", "label": "Disabled" - }, - { - "default": "0", - "fieldname": "enable_distributed_cost_center", - "fieldtype": "Check", - "label": "Enable Distributed Cost Center" - }, - { - "depends_on": "eval:doc.is_group==0", - "fieldname": "section_break_9", - "fieldtype": "Section Break" - }, - { - "depends_on": "enable_distributed_cost_center", - "fieldname": "distributed_cost_center", - "fieldtype": "Table", - "label": "Distributed Cost Center", - "options": "Distributed Cost Center" } ], "icon": "fa fa-money", "idx": 1, "is_tree": 1, "links": [], - "modified": "2020-06-17 16:09:30.025214", + "modified": "2022-01-31 13:22:58.916273", "modified_by": "Administrator", "module": "Accounts", "name": "Cost Center", @@ -189,5 +168,6 @@ "search_fields": "parent_cost_center, is_group", "show_name_in_global_search": 1, "sort_field": "modified", - "sort_order": "ASC" + "sort_order": "ASC", + "states": [] } \ No newline at end of file diff --git a/erpnext/accounts/doctype/cost_center/cost_center.py b/erpnext/accounts/doctype/cost_center/cost_center.py index 7ae0a72e3d1..07cc0764e38 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.py +++ b/erpnext/accounts/doctype/cost_center/cost_center.py @@ -4,7 +4,6 @@ import frappe from frappe import _ -from frappe.utils import cint from frappe.utils.nestedset import NestedSet from erpnext.accounts.utils import validate_field_number @@ -20,24 +19,6 @@ class CostCenter(NestedSet): def validate(self): self.validate_mandatory() self.validate_parent_cost_center() - self.validate_distributed_cost_center() - - def validate_distributed_cost_center(self): - if cint(self.enable_distributed_cost_center): - if not self.distributed_cost_center: - frappe.throw(_("Please enter distributed cost center")) - if sum(x.percentage_allocation for x in self.distributed_cost_center) != 100: - frappe.throw(_("Total percentage allocation for distributed cost center should be equal to 100")) - if not self.get('__islocal'): - if not cint(frappe.get_cached_value("Cost Center", {"name": self.name}, "enable_distributed_cost_center")) \ - and self.check_if_part_of_distributed_cost_center(): - frappe.throw(_("Cannot enable Distributed Cost Center for a Cost Center already allocated in another Distributed Cost Center")) - if next((True for x in self.distributed_cost_center if x.cost_center == x.parent), False): - frappe.throw(_("Parent Cost Center cannot be added in Distributed Cost Center")) - if check_if_distributed_cost_center_enabled(list(x.cost_center for x in self.distributed_cost_center)): - frappe.throw(_("A Distributed Cost Center cannot be added in the Distributed Cost Center allocation table.")) - else: - self.distributed_cost_center = [] def validate_mandatory(self): if self.cost_center_name != self.company and not self.parent_cost_center: @@ -64,10 +45,10 @@ class CostCenter(NestedSet): @frappe.whitelist() def convert_ledger_to_group(self): - if cint(self.enable_distributed_cost_center): - frappe.throw(_("Cost Center with enabled distributed cost center can not be converted to group")) - if self.check_if_part_of_distributed_cost_center(): - frappe.throw(_("Cost Center Already Allocated in a Distributed Cost Center cannot be converted to group")) + if self.if_allocation_exists_against_cost_center(): + frappe.throw(_("Cost Center with Allocation records can not be converted to a group")) + if self.check_if_part_of_cost_center_allocation(): + frappe.throw(_("Cost Center is a part of Cost Center Allocation, hence cannot be converted to a group")) if self.check_gle_exists(): frappe.throw(_("Cost Center with existing transactions can not be converted to group")) self.is_group = 1 @@ -81,8 +62,17 @@ class CostCenter(NestedSet): return frappe.db.sql("select name from `tabCost Center` where \ parent_cost_center = %s and docstatus != 2", self.name) - def check_if_part_of_distributed_cost_center(self): - return frappe.db.get_value("Distributed Cost Center", {"cost_center": self.name}) + def if_allocation_exists_against_cost_center(self): + return frappe.db.get_value("Cost Center Allocation", filters = { + "main_cost_center": self.name, + "docstatus": 1 + }) + + def check_if_part_of_cost_center_allocation(self): + return frappe.db.get_value("Cost Center Allocation Percentage", filters = { + "cost_center": self.name, + "docstatus": 1 + }) def before_rename(self, olddn, newdn, merge=False): # Add company abbr if not provided @@ -126,8 +116,4 @@ def on_doctype_update(): def get_name_with_number(new_account, account_number): if account_number and not new_account[0].isdigit(): new_account = account_number + " - " + new_account - return new_account - -def check_if_distributed_cost_center_enabled(cost_center_list): - value_list = frappe.get_list("Cost Center", {"name": ["in", cost_center_list]}, "enable_distributed_cost_center", as_list=1) - return next((True for x in value_list if x[0]), False) + return new_account \ No newline at end of file diff --git a/erpnext/accounts/doctype/cost_center/test_cost_center.py b/erpnext/accounts/doctype/cost_center/test_cost_center.py index f8615ec03a5..ff50a211241 100644 --- a/erpnext/accounts/doctype/cost_center/test_cost_center.py +++ b/erpnext/accounts/doctype/cost_center/test_cost_center.py @@ -23,33 +23,6 @@ class TestCostCenter(unittest.TestCase): self.assertRaises(frappe.ValidationError, cost_center.save) - def test_validate_distributed_cost_center(self): - - if not frappe.db.get_value('Cost Center', {'name': '_Test Cost Center - _TC'}): - frappe.get_doc(test_records[0]).insert() - - if not frappe.db.get_value('Cost Center', {'name': '_Test Cost Center 2 - _TC'}): - frappe.get_doc(test_records[1]).insert() - - invalid_distributed_cost_center = frappe.get_doc({ - "company": "_Test Company", - "cost_center_name": "_Test Distributed Cost Center", - "doctype": "Cost Center", - "is_group": 0, - "parent_cost_center": "_Test Company - _TC", - "enable_distributed_cost_center": 1, - "distributed_cost_center": [{ - "cost_center": "_Test Cost Center - _TC", - "percentage_allocation": 40 - }, { - "cost_center": "_Test Cost Center 2 - _TC", - "percentage_allocation": 50 - } - ] - }) - - self.assertRaises(frappe.ValidationError, invalid_distributed_cost_center.save) - def create_cost_center(**args): args = frappe._dict(args) if args.cost_center_name: diff --git a/erpnext/accounts/doctype/distributed_cost_center/__init__.py b/erpnext/accounts/doctype/cost_center_allocation/__init__.py similarity index 100% rename from erpnext/accounts/doctype/distributed_cost_center/__init__.py rename to erpnext/accounts/doctype/cost_center_allocation/__init__.py diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js new file mode 100644 index 00000000000..ab0baab24a0 --- /dev/null +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.js @@ -0,0 +1,19 @@ +// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Cost Center Allocation', { + setup: function(frm) { + let filters = {"is_group": 0}; + if (frm.doc.company) { + $.extend(filters, { + "company": frm.doc.company + }); + } + + frm.set_query('main_cost_center', function() { + return { + filters: filters + }; + }); + } +}); diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.json b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.json new file mode 100644 index 00000000000..45ab886d33d --- /dev/null +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.json @@ -0,0 +1,128 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "CC-ALLOC-.#####", + "creation": "2022-01-13 20:07:29.871109", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "main_cost_center", + "company", + "column_break_2", + "valid_from", + "section_break_5", + "allocation_percentages", + "amended_from" + ], + "fields": [ + { + "fieldname": "main_cost_center", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Main Cost Center", + "options": "Cost Center", + "reqd": 1 + }, + { + "default": "Today", + "fieldname": "valid_from", + "fieldtype": "Date", + "in_list_view": 1, + "label": "Valid From", + "reqd": 1 + }, + { + "fieldname": "column_break_2", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_5", + "fieldtype": "Section Break" + }, + { + "fetch_from": "main_cost_center.company", + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "reqd": 1 + }, + { + "fieldname": "allocation_percentages", + "fieldtype": "Table", + "label": "Cost Center Allocation Percentages", + "options": "Cost Center Allocation Percentage", + "reqd": 1 + }, + { + "fieldname": "amended_from", + "fieldtype": "Link", + "label": "Amended From", + "no_copy": 1, + "options": "Cost Center Allocation", + "print_hide": 1, + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "is_submittable": 1, + "links": [], + "modified": "2022-01-31 11:47:12.086253", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Cost Center Allocation", + "name_case": "UPPER CASE", + "naming_rule": "Expression (old style)", + "owner": "Administrator", + "permissions": [ + { + "amend": 1, + "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 + }, + { + "amend": 1, + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "share": 1, + "submit": 1, + "write": 1 + }, + { + "amend": 1, + "cancel": 1, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1, + "submit": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py new file mode 100644 index 00000000000..bad3fb4f96c --- /dev/null +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py @@ -0,0 +1,90 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +import frappe +from frappe import _ +from frappe.model.document import Document +from frappe.utils import add_days, format_date, getdate + + +class MainCostCenterCantBeChild(frappe.ValidationError): + pass +class InvalidMainCostCenter(frappe.ValidationError): + pass +class InvalidChildCostCenter(frappe.ValidationError): + pass +class WrongPercentageAllocation(frappe.ValidationError): + pass +class InvalidDateError(frappe.ValidationError): + pass + +class CostCenterAllocation(Document): + def validate(self): + self.validate_total_allocation_percentage() + self.validate_from_date_based_on_existing_gle() + self.validate_backdated_allocation() + self.validate_main_cost_center() + self.validate_child_cost_centers() + + def validate_total_allocation_percentage(self): + total_percentage = sum([d.percentage for d in self.get("allocation_percentages", [])]) + + if total_percentage != 100: + frappe.throw(_("Total percentage against cost centers should be 100"), WrongPercentageAllocation) + + def validate_from_date_based_on_existing_gle(self): + # Check if GLE exists against the main cost center + # If exists ensure from date is set after posting date of last GLE + + last_gle_date = frappe.db.get_value("GL Entry", + {"cost_center": self.main_cost_center, "is_cancelled": 0}, + "posting_date", order_by="posting_date desc") + + if last_gle_date: + if getdate(self.valid_from) <= getdate(last_gle_date): + frappe.throw(_("Valid From must be after {0} as last GL Entry against the cost center {1} posted on this date") + .format(last_gle_date, self.main_cost_center), InvalidDateError) + + def validate_backdated_allocation(self): + # Check if there are any future existing allocation records against the main cost center + # If exists, warn the user about it + + future_allocation = frappe.db.get_value("Cost Center Allocation", filters = { + "main_cost_center": self.main_cost_center, + "valid_from": (">=", self.valid_from), + "name": ("!=", self.name), + "docstatus": 1 + }, fieldname=['valid_from', 'name'], order_by='valid_from', as_dict=1) + + if future_allocation: + frappe.msgprint(_("Another Cost Center Allocation record {0} applicable from {1}, hence this allocation will be applicable upto {2}") + .format(frappe.bold(future_allocation.name), frappe.bold(format_date(future_allocation.valid_from)), + frappe.bold(format_date(add_days(future_allocation.valid_from, -1)))), + title=_("Warning!"), indicator="orange", alert=1 + ) + + def validate_main_cost_center(self): + # Main cost center itself cannot be entered in child table + if self.main_cost_center in [d.cost_center for d in self.allocation_percentages]: + frappe.throw(_("Main Cost Center {0} cannot be entered in the child table") + .format(self.main_cost_center), MainCostCenterCantBeChild) + + # If main cost center is used for allocation under any other cost center, + # allocation cannot be done against it + parent = frappe.db.get_value("Cost Center Allocation Percentage", filters = { + "cost_center": self.main_cost_center, + "docstatus": 1 + }, fieldname='parent') + if parent: + frappe.throw(_("{0} cannot be used as a Main Cost Center because it has been used as child in Cost Center Allocation {1}") + .format(self.main_cost_center, parent), InvalidMainCostCenter) + + def validate_child_cost_centers(self): + # Check if child cost center is used as main cost center in any existing allocation + main_cost_centers = [d.main_cost_center for d in + frappe.get_all("Cost Center Allocation", {'docstatus': 1}, 'main_cost_center')] + + for d in self.allocation_percentages: + if d.cost_center in main_cost_centers: + frappe.throw(_("Cost Center {0} cannot be used for allocation as it is used as main cost center in other allocation record.") + .format(d.cost_center), InvalidChildCostCenter) \ No newline at end of file diff --git a/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py new file mode 100644 index 00000000000..9cf4c002172 --- /dev/null +++ b/erpnext/accounts/doctype/cost_center_allocation/test_cost_center_allocation.py @@ -0,0 +1,156 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +import unittest + +import frappe +from frappe.utils import add_days, today + +from erpnext.accounts.doctype.cost_center.test_cost_center import create_cost_center +from erpnext.accounts.doctype.cost_center_allocation.cost_center_allocation import ( + InvalidChildCostCenter, + InvalidDateError, + InvalidMainCostCenter, + MainCostCenterCantBeChild, + WrongPercentageAllocation, +) +from erpnext.accounts.doctype.journal_entry.test_journal_entry import make_journal_entry + + +class TestCostCenterAllocation(unittest.TestCase): + def setUp(self): + cost_centers = ["Main Cost Center 1", "Main Cost Center 2", "Sub Cost Center 1", "Sub Cost Center 2"] + for cc in cost_centers: + create_cost_center(cost_center_name=cc, company="_Test Company") + + def test_gle_based_on_cost_center_allocation(self): + cca = create_cost_center_allocation("_Test Company", "Main Cost Center 1 - _TC", + { + "Sub Cost Center 1 - _TC": 60, + "Sub Cost Center 2 - _TC": 40 + } + ) + + jv = make_journal_entry("_Test Cash - _TC", "Sales - _TC", 100, + cost_center = "Main Cost Center 1 - _TC", submit=True) + + expected_values = [ + ["Sub Cost Center 1 - _TC", 0.0, 60], + ["Sub Cost Center 2 - _TC", 0.0, 40] + ] + + gle = frappe.qb.DocType("GL Entry") + gl_entries = ( + frappe.qb.from_(gle) + .select(gle.cost_center, gle.debit, gle.credit) + .where(gle.voucher_type == 'Journal Entry') + .where(gle.voucher_no == jv.name) + .where(gle.account == 'Sales - _TC') + .orderby(gle.cost_center) + ).run(as_dict=1) + + self.assertTrue(gl_entries) + + for i, gle in enumerate(gl_entries): + self.assertEqual(expected_values[i][0], gle.cost_center) + self.assertEqual(expected_values[i][1], gle.debit) + self.assertEqual(expected_values[i][2], gle.credit) + + cca.cancel() + jv.cancel() + + def test_main_cost_center_cant_be_child(self): + # Main cost center itself cannot be entered in child table + cca = create_cost_center_allocation("_Test Company", "Main Cost Center 1 - _TC", + { + "Sub Cost Center 1 - _TC": 60, + "Main Cost Center 1 - _TC": 40 + }, save=False + ) + + self.assertRaises(MainCostCenterCantBeChild, cca.save) + + def test_invalid_main_cost_center(self): + # If main cost center is used for allocation under any other cost center, + # allocation cannot be done against it + cca1 = create_cost_center_allocation("_Test Company", "Main Cost Center 1 - _TC", + { + "Sub Cost Center 1 - _TC": 60, + "Sub Cost Center 2 - _TC": 40 + } + ) + + cca2 = create_cost_center_allocation("_Test Company", "Sub Cost Center 1 - _TC", + { + "Sub Cost Center 2 - _TC": 100 + }, save=False + ) + + self.assertRaises(InvalidMainCostCenter, cca2.save) + + cca1.cancel() + + def test_if_child_cost_center_has_any_allocation_record(self): + # Check if any child cost center is used as main cost center in any other existing allocation + cca1 = create_cost_center_allocation("_Test Company", "Main Cost Center 1 - _TC", + { + "Sub Cost Center 1 - _TC": 60, + "Sub Cost Center 2 - _TC": 40 + } + ) + + cca2 = create_cost_center_allocation("_Test Company", "Main Cost Center 2 - _TC", + { + "Main Cost Center 1 - _TC": 60, + "Sub Cost Center 1 - _TC": 40 + }, save=False + ) + + self.assertRaises(InvalidChildCostCenter, cca2.save) + + cca1.cancel() + + def test_total_percentage(self): + cca = create_cost_center_allocation("_Test Company", "Main Cost Center 1 - _TC", + { + "Sub Cost Center 1 - _TC": 40, + "Sub Cost Center 2 - _TC": 40 + }, save=False + ) + self.assertRaises(WrongPercentageAllocation, cca.save) + + def test_valid_from_based_on_existing_gle(self): + # GLE posted against Sub Cost Center 1 on today + jv = make_journal_entry("_Test Cash - _TC", "Sales - _TC", 100, + cost_center = "Main Cost Center 1 - _TC", posting_date=today(), submit=True) + + # try to set valid from as yesterday + cca = create_cost_center_allocation("_Test Company", "Main Cost Center 1 - _TC", + { + "Sub Cost Center 1 - _TC": 60, + "Sub Cost Center 2 - _TC": 40 + }, valid_from=add_days(today(), -1), save=False + ) + + self.assertRaises(InvalidDateError, cca.save) + + jv.cancel() + +def create_cost_center_allocation(company, main_cost_center, allocation_percentages, + valid_from=None, valid_upto=None, save=True, submit=True): + doc = frappe.new_doc("Cost Center Allocation") + doc.main_cost_center = main_cost_center + doc.company = company + doc.valid_from = valid_from or today() + doc.valid_upto = valid_upto + for cc, percentage in allocation_percentages.items(): + doc.append("allocation_percentages", { + "cost_center": cc, + "percentage": percentage + }) + if save: + doc.save() + if submit: + doc.submit() + + return doc \ No newline at end of file diff --git a/erpnext/accounts/print_format/gst_pos_invoice/__init__.py b/erpnext/accounts/doctype/cost_center_allocation_percentage/__init__.py similarity index 100% rename from erpnext/accounts/print_format/gst_pos_invoice/__init__.py rename to erpnext/accounts/doctype/cost_center_allocation_percentage/__init__.py diff --git a/erpnext/accounts/doctype/distributed_cost_center/distributed_cost_center.json b/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.json similarity index 63% rename from erpnext/accounts/doctype/distributed_cost_center/distributed_cost_center.json rename to erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.json index 45b0e2df9ba..7e50962a87f 100644 --- a/erpnext/accounts/doctype/distributed_cost_center/distributed_cost_center.json +++ b/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.json @@ -1,12 +1,13 @@ { "actions": [], - "creation": "2020-03-19 12:34:01.500390", + "allow_rename": 1, + "creation": "2022-01-13 20:07:30.096306", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", "field_order": [ "cost_center", - "percentage_allocation" + "percentage" ], "fields": [ { @@ -18,23 +19,23 @@ "reqd": 1 }, { - "fieldname": "percentage_allocation", - "fieldtype": "Float", + "fieldname": "percentage", + "fieldtype": "Percent", "in_list_view": 1, - "label": "Percentage Allocation", + "label": "Percentage (%)", "reqd": 1 } ], + "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-03-19 12:54:43.674655", + "modified": "2022-02-01 22:22:31.589523", "modified_by": "Administrator", "module": "Accounts", - "name": "Distributed Cost Center", + "name": "Cost Center Allocation Percentage", "owner": "Administrator", "permissions": [], - "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", - "track_changes": 1 + "states": [] } \ No newline at end of file diff --git a/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.py b/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.py new file mode 100644 index 00000000000..7d20efb6d5e --- /dev/null +++ b/erpnext/accounts/doctype/cost_center_allocation_percentage/cost_center_allocation_percentage.py @@ -0,0 +1,9 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class CostCenterAllocationPercentage(Document): + pass diff --git a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py index 5ba06913310..ca482c8c4ec 100644 --- a/erpnext/accounts/doctype/coupon_code/test_coupon_code.py +++ b/erpnext/accounts/doctype/coupon_code/test_coupon_code.py @@ -39,9 +39,6 @@ def test_create_test_data(): "selling_cost_center": "Main - _TC", "income_account": "Sales - _TC" }], - "show_in_website": 1, - "route":"-test-tesla-car", - "website_warehouse": "Stores - _TC" }) item.insert() # create test item price diff --git a/erpnext/accounts/doctype/item_tax_template/item_tax_template.json b/erpnext/accounts/doctype/item_tax_template/item_tax_template.json index 77c9e95b759..b42d712d88a 100644 --- a/erpnext/accounts/doctype/item_tax_template/item_tax_template.json +++ b/erpnext/accounts/doctype/item_tax_template/item_tax_template.json @@ -2,7 +2,7 @@ "actions": [], "allow_import": 1, "allow_rename": 1, - "creation": "2018-11-22 22:45:00.370913", + "creation": "2022-01-19 01:09:13.297137", "doctype": "DocType", "document_type": "Setup", "editable_grid": 1, @@ -10,6 +10,9 @@ "field_order": [ "title", "company", + "column_break_3", + "disabled", + "section_break_5", "taxes" ], "fields": [ @@ -36,10 +39,24 @@ "label": "Company", "options": "Company", "reqd": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "disabled", + "fieldtype": "Check", + "label": "Disabled" + }, + { + "fieldname": "section_break_5", + "fieldtype": "Section Break" } ], "links": [], - "modified": "2021-03-08 19:50:21.416513", + "modified": "2022-01-18 21:11:23.105589", "modified_by": "Administrator", "module": "Accounts", "name": "Item Tax Template", @@ -82,6 +99,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "title_field": "title", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 617b376128b..3cc28a3dc8f 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -8,6 +8,7 @@ frappe.provide("erpnext.journal_entry"); frappe.ui.form.on("Journal Entry", { setup: function(frm) { frm.add_fetch("bank_account", "account", "account"); + frm.ignore_doctypes_on_cancel_all = ['Sales Invoice', 'Purchase Invoice']; }, refresh: function(frm) { diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py index ddb833ff3bd..6e7b80e7310 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/opening_invoice_creation_tool.py @@ -135,7 +135,7 @@ class OpeningInvoiceCreationTool(Document): default_uom = frappe.db.get_single_value("Stock Settings", "stock_uom") or _("Nos") rate = flt(row.outstanding_amount) / flt(row.qty) - return frappe._dict({ + item_dict = frappe._dict({ "uom": default_uom, "rate": rate or 0.0, "qty": row.qty, @@ -146,6 +146,13 @@ class OpeningInvoiceCreationTool(Document): "cost_center": cost_center }) + for dimension in get_accounting_dimensions(): + item_dict.update({ + dimension: row.get(dimension) + }) + + return item_dict + item = get_item_dict() invoice = frappe._dict({ @@ -159,14 +166,15 @@ class OpeningInvoiceCreationTool(Document): frappe.scrub(row.party_type): row.party, "is_pos": 0, "doctype": "Sales Invoice" if self.invoice_type == "Sales" else "Purchase Invoice", - "update_stock": 0, - "invoice_number": row.invoice_number + "update_stock": 0, # important: https://github.com/frappe/erpnext/pull/23559 + "invoice_number": row.invoice_number, + "disable_rounded_total": 1 }) accounting_dimension = get_accounting_dimensions() for dimension in accounting_dimension: invoice.update({ - dimension: item.get(dimension) + dimension: self.get(dimension) or item.get(dimension) }) return invoice diff --git a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py index b5aae9845b6..77d54a605e5 100644 --- a/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py +++ b/erpnext/accounts/doctype/opening_invoice_creation_tool/test_opening_invoice_creation_tool.py @@ -1,51 +1,49 @@ # Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest - import frappe -from frappe.cache_manager import clear_doctype_cache -from frappe.custom.doctype.property_setter.property_setter import make_property_setter +from frappe.tests.utils import FrappeTestCase +from erpnext.accounts.doctype.accounting_dimension.test_accounting_dimension import ( + create_dimension, + disable_dimension, +) from erpnext.accounts.doctype.opening_invoice_creation_tool.opening_invoice_creation_tool import ( get_temporary_opening_account, ) -test_dependencies = ["Customer", "Supplier"] +test_dependencies = ["Customer", "Supplier", "Accounting Dimension"] -class TestOpeningInvoiceCreationTool(unittest.TestCase): - def setUp(self): +class TestOpeningInvoiceCreationTool(FrappeTestCase): + @classmethod + def setUpClass(self): if not frappe.db.exists("Company", "_Test Opening Invoice Company"): make_company() + create_dimension() + return super().setUpClass() - def make_invoices(self, invoice_type="Sales", company=None, party_1=None, party_2=None, invoice_number=None): + def make_invoices(self, invoice_type="Sales", company=None, party_1=None, party_2=None, invoice_number=None, department=None): doc = frappe.get_single("Opening Invoice Creation Tool") args = get_opening_invoice_creation_dict(invoice_type=invoice_type, company=company, - party_1=party_1, party_2=party_2, invoice_number=invoice_number) + party_1=party_1, party_2=party_2, invoice_number=invoice_number, department=department) doc.update(args) return doc.make_invoices() def test_opening_sales_invoice_creation(self): - property_setter = make_property_setter("Sales Invoice", "update_stock", "default", 1, "Check") - try: - invoices = self.make_invoices(company="_Test Opening Invoice Company") + invoices = self.make_invoices(company="_Test Opening Invoice Company") - self.assertEqual(len(invoices), 2) - expected_value = { - "keys": ["customer", "outstanding_amount", "status"], - 0: ["_Test Customer", 300, "Overdue"], - 1: ["_Test Customer 1", 250, "Overdue"], - } - self.check_expected_values(invoices, expected_value) + self.assertEqual(len(invoices), 2) + expected_value = { + "keys": ["customer", "outstanding_amount", "status"], + 0: ["_Test Customer", 300, "Overdue"], + 1: ["_Test Customer 1", 250, "Overdue"], + } + self.check_expected_values(invoices, expected_value) - si = frappe.get_doc("Sales Invoice", invoices[0]) + si = frappe.get_doc("Sales Invoice", invoices[0]) - # Check if update stock is not enabled - self.assertEqual(si.update_stock, 0) - - finally: - property_setter.delete() - clear_doctype_cache("Sales Invoice") + # Check if update stock is not enabled + self.assertEqual(si.update_stock, 0) def check_expected_values(self, invoices, expected_value, invoice_type="Sales"): doctype = "Sales Invoice" if invoice_type == "Sales" else "Purchase Invoice" @@ -106,6 +104,19 @@ class TestOpeningInvoiceCreationTool(unittest.TestCase): doc = frappe.get_doc('Sales Invoice', inv) doc.cancel() + def test_opening_invoice_with_accounting_dimension(self): + invoices = self.make_invoices(invoice_type="Sales", company="_Test Opening Invoice Company", department='Sales - _TOIC') + + expected_value = { + "keys": ["customer", "outstanding_amount", "status", "department"], + 0: ["_Test Customer", 300, "Overdue", "Sales - _TOIC"], + 1: ["_Test Customer 1", 250, "Overdue", "Sales - _TOIC"], + } + self.check_expected_values(invoices, expected_value, invoice_type="Sales") + + def tearDown(self): + disable_dimension() + def get_opening_invoice_creation_dict(**args): party = "Customer" if args.get("invoice_type", "Sales") == "Sales" else "Supplier" company = args.get("company", "_Test Company") diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 3be3925b5a9..cc32a6ccd9e 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -114,8 +114,6 @@ frappe.ui.form.on('Payment Entry', { var doctypes = ["Expense Claim", "Journal Entry"]; } else if (frm.doc.party_type == "Student") { var doctypes = ["Fees"]; - } else if (frm.doc.party_type == "Donor") { - var doctypes = ["Donation"]; } else { var doctypes = ["Journal Entry"]; } @@ -144,7 +142,7 @@ frappe.ui.form.on('Payment Entry', { const child = locals[cdt][cdn]; const filters = {"docstatus": 1, "company": doc.company}; const party_type_doctypes = ['Sales Invoice', 'Sales Order', 'Purchase Invoice', - 'Purchase Order', 'Expense Claim', 'Fees', 'Dunning', 'Donation']; + 'Purchase Order', 'Expense Claim', 'Fees', 'Dunning']; if (in_list(party_type_doctypes, child.reference_doctype)) { filters[doc.party_type.toLowerCase()] = doc.party; @@ -196,8 +194,14 @@ frappe.ui.form.on('Payment Entry', { frm.doc.paid_from_account_currency != frm.doc.paid_to_account_currency)); frm.toggle_display("base_paid_amount", frm.doc.paid_from_account_currency != company_currency); - frm.toggle_display("base_total_taxes_and_charges", frm.doc.total_taxes_and_charges && - (frm.doc.paid_from_account_currency != company_currency)); + + if (frm.doc.payment_type == "Pay") { + frm.toggle_display("base_total_taxes_and_charges", frm.doc.total_taxes_and_charges && + (frm.doc.paid_to_account_currency != company_currency)); + } else { + frm.toggle_display("base_total_taxes_and_charges", frm.doc.total_taxes_and_charges && + (frm.doc.paid_from_account_currency != company_currency)); + } frm.toggle_display("base_received_amount", ( frm.doc.paid_to_account_currency != company_currency @@ -232,7 +236,8 @@ frappe.ui.form.on('Payment Entry', { var company_currency = frm.doc.company? frappe.get_doc(":Company", frm.doc.company).default_currency: ""; frm.set_currency_labels(["base_paid_amount", "base_received_amount", "base_total_allocated_amount", - "difference_amount", "base_paid_amount_after_tax", "base_received_amount_after_tax"], company_currency); + "difference_amount", "base_paid_amount_after_tax", "base_received_amount_after_tax", + "base_total_taxes_and_charges"], company_currency); frm.set_currency_labels(["paid_amount"], frm.doc.paid_from_account_currency); frm.set_currency_labels(["received_amount"], frm.doc.paid_to_account_currency); @@ -747,8 +752,7 @@ frappe.ui.form.on('Payment Entry', { (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") || - (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") || - (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Donor") + (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") ) { if(total_positive_outstanding > total_negative_outstanding) if (!frm.doc.paid_amount) @@ -791,8 +795,7 @@ frappe.ui.form.on('Payment Entry', { (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Customer") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Supplier") || (frm.doc.payment_type=="Pay" && frm.doc.party_type=="Employee") || - (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") || - (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Donor") + (frm.doc.payment_type=="Receive" && frm.doc.party_type=="Student") ) { if(total_positive_outstanding_including_order > paid_amount) { var remaining_outstanding = total_positive_outstanding_including_order - paid_amount; @@ -951,12 +954,6 @@ frappe.ui.form.on('Payment Entry', { frappe.msgprint(__("Row #{0}: Reference Document Type must be one of Expense Claim or Journal Entry", [row.idx])); return false; } - - if (frm.doc.party_type == "Donor" && row.reference_doctype != "Donation") { - frappe.model.set_value(row.doctype, row.name, "reference_doctype", null); - frappe.msgprint(__("Row #{0}: Reference Document Type must be Donation", [row.idx])); - return false; - } } if (row) { diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json index c8d1db91f54..3fc1adff2d3 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.json +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json @@ -66,7 +66,9 @@ "tax_withholding_category", "section_break_56", "taxes", + "section_break_60", "base_total_taxes_and_charges", + "column_break_61", "total_taxes_and_charges", "deductions_or_loss_section", "deductions", @@ -715,12 +717,21 @@ "fieldtype": "Data", "hidden": 1, "label": "Paid To Account Type" + }, + { + "fieldname": "column_break_61", + "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_60", + "fieldtype": "Section Break", + "hide_border": 1 } ], "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-11-24 18:58:24.919764", + "modified": "2022-02-23 20:08:39.559814", "modified_by": "Administrator", "module": "Accounts", "name": "Payment Entry", @@ -763,6 +774,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "title_field": "title", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 02a144d3e79..f9f33502d37 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -91,7 +91,6 @@ class PaymentEntry(AccountsController): self.update_expense_claim() self.update_outstanding_amounts() self.update_advance_paid() - self.update_donation() self.update_payment_schedule() self.set_status() @@ -101,7 +100,6 @@ class PaymentEntry(AccountsController): self.update_expense_claim() self.update_outstanding_amounts() self.update_advance_paid() - self.update_donation(cancel=1) self.delink_advance_entry_references() self.update_payment_schedule(cancel=1) self.set_payment_req_status() @@ -284,8 +282,6 @@ class PaymentEntry(AccountsController): valid_reference_doctypes = ("Expense Claim", "Journal Entry", "Employee Advance", "Gratuity") elif self.party_type == "Shareholder": valid_reference_doctypes = ("Journal Entry") - elif self.party_type == "Donor": - valid_reference_doctypes = ("Donation") for d in self.get("references"): if not d.allocated_amount: @@ -843,13 +839,6 @@ class PaymentEntry(AccountsController): else: update_reimbursed_amount(doc, d.allocated_amount) - def update_donation(self, cancel=0): - if self.payment_type == "Receive" and self.party_type == "Donor" and self.party: - for d in self.get("references"): - if d.reference_doctype=="Donation" and d.reference_name: - is_paid = 0 if cancel else 1 - frappe.db.set_value("Donation", d.reference_name, "paid", is_paid) - def on_recurring(self, reference_doc, auto_repeat_doc): self.reference_no = reference_doc.name self.reference_date = nowdate() @@ -945,8 +934,12 @@ class PaymentEntry(AccountsController): tax.base_total = tax.total * self.source_exchange_rate - self.total_taxes_and_charges += current_tax_amount - self.base_total_taxes_and_charges += current_tax_amount * self.source_exchange_rate + if self.payment_type == 'Pay': + self.base_total_taxes_and_charges += flt(current_tax_amount / self.source_exchange_rate) + self.total_taxes_and_charges += flt(current_tax_amount / self.target_exchange_rate) + else: + self.base_total_taxes_and_charges += flt(current_tax_amount / self.target_exchange_rate) + self.total_taxes_and_charges += flt(current_tax_amount / self.source_exchange_rate) if self.get('taxes'): self.paid_amount_after_tax = self.get('taxes')[-1].base_total @@ -1077,7 +1070,7 @@ def get_outstanding_reference_documents(args): if d.voucher_type in ("Purchase Invoice"): d["bill_no"] = frappe.db.get_value(d.voucher_type, d.voucher_no, "bill_no") - # Get all SO / PO which are not fully billed or aginst which full advance not paid + # Get all SO / PO which are not fully billed or against which full advance not paid orders_to_be_billed = [] if (args.get("party_type") != "Student"): orders_to_be_billed = get_orders_to_be_billed(args.get("posting_date"),args.get("party_type"), @@ -1337,10 +1330,6 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre total_amount = ref_doc.get("grand_total") exchange_rate = 1 outstanding_amount = ref_doc.get("outstanding_amount") - elif reference_doctype == "Donation": - total_amount = ref_doc.get("amount") - outstanding_amount = total_amount - exchange_rate = 1 elif reference_doctype == "Dunning": total_amount = ref_doc.get("dunning_amount") exchange_rate = 1 @@ -1611,8 +1600,6 @@ def set_party_type(dt): party_type = "Employee" elif dt == "Fees": party_type = "Student" - elif dt == "Donation": - party_type = "Donor" return party_type def set_party_account(dt, dn, doc, party_type): @@ -1640,7 +1627,7 @@ def set_party_account_currency(dt, party_account, doc): return party_account_currency def set_payment_type(dt, doc): - if (dt in ("Sales Order", "Donation") or (dt in ("Sales Invoice", "Fees", "Dunning") and doc.outstanding_amount > 0)) \ + if (dt == "Sales Order" or (dt in ("Sales Invoice", "Fees", "Dunning") and doc.outstanding_amount > 0)) \ or (dt=="Purchase Invoice" and doc.outstanding_amount < 0): payment_type = "Receive" else: @@ -1673,9 +1660,6 @@ def set_grand_total_and_outstanding_amount(party_amount, dt, party_account_curre elif dt == "Dunning": grand_total = doc.grand_total outstanding_amount = doc.grand_total - elif dt == "Donation": - grand_total = doc.amount - outstanding_amount = doc.amount elif dt == "Gratuity": grand_total = doc.amount outstanding_amount = flt(doc.amount) - flt(doc.paid_amount) diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index cc3528e9aaa..349b8bb5b1b 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -633,6 +633,45 @@ class TestPaymentEntry(unittest.TestCase): self.assertEqual(flt(expected_party_balance), party_balance) self.assertEqual(flt(expected_party_account_balance), party_account_balance) + def test_multi_currency_payment_entry_with_taxes(self): + payment_entry = create_payment_entry(party='_Test Supplier USD', paid_to = '_Test Payable USD - _TC', + save=True) + payment_entry.append('taxes', { + 'account_head': '_Test Account Service Tax - _TC', + 'charge_type': 'Actual', + 'tax_amount': 10, + 'add_deduct_tax': 'Add', + 'description': 'Test' + }) + + payment_entry.save() + self.assertEqual(payment_entry.base_total_taxes_and_charges, 10) + self.assertEqual(flt(payment_entry.total_taxes_and_charges, 2), flt(10 / payment_entry.target_exchange_rate, 2)) + +def create_payment_entry(**args): + payment_entry = frappe.new_doc('Payment Entry') + payment_entry.company = args.get('company') or '_Test Company' + payment_entry.payment_type = args.get('payment_type') or 'Pay' + payment_entry.party_type = args.get('party_type') or 'Supplier' + payment_entry.party = args.get('party') or '_Test Supplier' + payment_entry.paid_from = args.get('paid_from') or '_Test Bank - _TC' + payment_entry.paid_to = args.get('paid_to') or 'Creditors - _TC' + payment_entry.paid_amount = args.get('paid_amount') or 1000 + + payment_entry.setup_party_account_field() + payment_entry.set_missing_values() + payment_entry.set_exchange_rate() + payment_entry.received_amount = payment_entry.paid_amount / payment_entry.target_exchange_rate + payment_entry.reference_no = 'Test001' + payment_entry.reference_date = nowdate() + + if args.get('save'): + payment_entry.save() + if args.get('submit'): + payment_entry.submit() + + return payment_entry + def create_payment_terms_template(): create_payment_term('Basic Amount Receivable') diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 6a84a65e713..d72d8f70180 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -291,7 +291,7 @@ class PaymentRequest(Document): if not status: return - shopping_cart_settings = frappe.get_doc("Shopping Cart Settings") + shopping_cart_settings = frappe.get_doc("E Commerce Settings") if status in ["Authorized", "Completed"]: redirect_to = None @@ -435,13 +435,13 @@ def get_existing_payment_request_amount(ref_dt, ref_dn): """, (ref_dt, ref_dn)) return flt(existing_payment_request_amount[0][0]) if existing_payment_request_amount else 0 -def get_gateway_details(args): +def get_gateway_details(args): # nosemgrep """return gateway and payment account of default payment gateway""" if args.get("payment_gateway_account"): return get_payment_gateway_account(args.get("payment_gateway_account")) if args.order_type == "Shopping Cart": - payment_gateway_account = frappe.get_doc("Shopping Cart Settings").payment_gateway_account + payment_gateway_account = frappe.get_doc("E Commerce Settings").payment_gateway_account return get_payment_gateway_account(payment_gateway_account) gateway_account = get_payment_gateway_account({"is_default": 1}) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 134bccf3d1a..9b3b3aa4149 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -42,7 +42,6 @@ class POSInvoice(SalesInvoice): self.validate_serialised_or_batched_item() self.validate_stock_availablility() self.validate_return_items_qty() - self.validate_non_stock_items() self.set_status() self.set_account_for_mode_of_payment() self.validate_pos() @@ -158,22 +157,40 @@ class POSInvoice(SalesInvoice): frappe.throw(_("Row #{}: Serial No. {} has already been transacted into another Sales Invoice. Please select valid serial no.") .format(item.idx, bold_delivered_serial_nos), title=_("Item Unavailable")) + def validate_invalid_serial_nos(self, item): + serial_nos = get_serial_nos(item.serial_no) + error_msg = [] + invalid_serials, msg = "", "" + for serial_no in serial_nos: + if not frappe.db.exists('Serial No', serial_no): + invalid_serials = invalid_serials + (", " if invalid_serials else "") + serial_no + msg = (_("Row #{}: Following Serial numbers for item {} are Invalid: {}").format(item.idx, frappe.bold(item.get("item_code")), frappe.bold(invalid_serials))) + if invalid_serials: + error_msg.append(msg) + + if error_msg: + frappe.throw(error_msg, title=_("Invalid Item"), as_list=True) + def validate_stock_availablility(self): + from erpnext.stock.stock_ledger import is_negative_stock_allowed + if self.is_return or self.docstatus != 1: return - - allow_negative_stock = frappe.db.get_single_value('Stock Settings', 'allow_negative_stock') for d in self.get('items'): + is_service_item = not (frappe.db.get_value('Item', d.get('item_code'), 'is_stock_item')) + if is_service_item: + return if d.serial_no: self.validate_pos_reserved_serial_nos(d) self.validate_delivered_serial_nos(d) + self.validate_invalid_serial_nos(d) elif d.batch_no: self.validate_pos_reserved_batch_qty(d) else: - if allow_negative_stock: + if is_negative_stock_allowed(item_code=d.item_code): return - available_stock = get_stock_availability(d.item_code, d.warehouse) + available_stock, is_stock_item = get_stock_availability(d.item_code, d.warehouse) item_code, warehouse, qty = frappe.bold(d.item_code), frappe.bold(d.warehouse), frappe.bold(d.qty) if flt(available_stock) <= 0: @@ -244,14 +261,6 @@ class POSInvoice(SalesInvoice): .format(d.idx, bold_serial_no, bold_return_against) ) - def validate_non_stock_items(self): - for d in self.get("items"): - is_stock_item = frappe.get_cached_value("Item", d.get("item_code"), "is_stock_item") - if not is_stock_item: - if not frappe.db.exists('Product Bundle', d.item_code): - frappe.throw(_("Row #{}: Item {} is a non stock item. You can only include stock items in a POS Invoice.") - .format(d.idx, frappe.bold(d.item_code)), title=_("Invalid Item")) - def validate_mode_of_payment(self): if len(self.payments) == 0: frappe.throw(_("At least one mode of payment is required for POS invoice.")) @@ -430,7 +439,6 @@ class POSInvoice(SalesInvoice): self.paid_amount = 0 def set_account_for_mode_of_payment(self): - self.payments = [d for d in self.payments if d.amount or d.base_amount or d.default] for pay in self.payments: if not pay.account: pay.account = get_bank_cash_account(pay.mode_of_payment, self.company).get("account") @@ -491,12 +499,18 @@ class POSInvoice(SalesInvoice): @frappe.whitelist() def get_stock_availability(item_code, warehouse): if frappe.db.get_value('Item', item_code, 'is_stock_item'): + is_stock_item = True bin_qty = get_bin_qty(item_code, warehouse) pos_sales_qty = get_pos_reserved_qty(item_code, warehouse) - return bin_qty - pos_sales_qty + return bin_qty - pos_sales_qty, is_stock_item else: + is_stock_item = False if frappe.db.exists('Product Bundle', item_code): - return get_bundle_availability(item_code, warehouse) + return get_bundle_availability(item_code, warehouse), is_stock_item + else: + # Is a service item + return 0, is_stock_item + def get_bundle_availability(bundle_item_code, warehouse): product_bundle = frappe.get_doc('Product Bundle', bundle_item_code) diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py index 56479a0b77d..cf8affdd010 100644 --- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py @@ -354,6 +354,24 @@ class TestPOSInvoice(unittest.TestCase): pos2.insert() self.assertRaises(frappe.ValidationError, pos2.submit) + def test_invalid_serial_no_validation(self): + from erpnext.stock.doctype.stock_entry.test_stock_entry import make_serialized_item + + se = make_serialized_item(company='_Test Company', + target_warehouse="Stores - _TC", cost_center='Main - _TC', expense_account='Cost of Goods Sold - _TC') + serial_nos = se.get("items")[0].serial_no + 'wrong' + + pos = create_pos_invoice(company='_Test Company', debit_to='Debtors - _TC', + account_for_change_amount='Cash - _TC', warehouse='Stores - _TC', income_account='Sales - _TC', + expense_account='Cost of Goods Sold - _TC', cost_center='Main - _TC', + item=se.get("items")[0].item_code, rate=1000, qty=2, do_not_save=1) + + pos.get('items')[0].has_serial_no = 1 + pos.get('items')[0].serial_no = serial_nos + pos.insert() + + self.assertRaises(frappe.ValidationError, pos.submit) + def test_loyalty_points(self): from erpnext.accounts.doctype.loyalty_program.loyalty_program import ( get_loyalty_program_details_with_points, @@ -568,23 +586,29 @@ class TestPOSInvoice(unittest.TestCase): item_price.insert() pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10) pr.save() - pos_inv = create_pos_invoice(qty=1, do_not_submit=1) - pos_inv.items[0].rate = 300 - pos_inv.save() - self.assertEquals(pos_inv.items[0].discount_percentage, 10) - # rate shouldn't change - self.assertEquals(pos_inv.items[0].rate, 405) - pos_inv.ignore_pricing_rule = 1 - pos_inv.items[0].rate = 300 - pos_inv.save() - self.assertEquals(pos_inv.ignore_pricing_rule, 1) - # rate should change since pricing rules are ignored - self.assertEquals(pos_inv.items[0].rate, 300) + try: + pos_inv = create_pos_invoice(qty=1, do_not_submit=1) + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEquals(pos_inv.items[0].discount_percentage, 10) + # rate shouldn't change + self.assertEquals(pos_inv.items[0].rate, 405) - item_price.delete() - pos_inv.delete() - pr.delete() + pos_inv.ignore_pricing_rule = 1 + pos_inv.save() + self.assertEquals(pos_inv.ignore_pricing_rule, 1) + # rate should reset since pricing rules are ignored + self.assertEquals(pos_inv.items[0].rate, 450) + + pos_inv.items[0].rate = 300 + pos_inv.save() + self.assertEquals(pos_inv.items[0].rate, 300) + + finally: + item_price.delete() + pos_inv.delete() + pr.delete() def create_pos_invoice(**args): diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 0720d9b2e91..ddca68a57b9 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -84,12 +84,20 @@ class POSInvoiceMergeLog(Document): sales_invoice.set_posting_time = 1 sales_invoice.posting_date = getdate(self.posting_date) sales_invoice.save() + self.write_off_fractional_amount(sales_invoice, data) sales_invoice.submit() self.consolidated_invoice = sales_invoice.name return sales_invoice.name + def write_off_fractional_amount(self, invoice, data): + pos_invoice_grand_total = sum(d.grand_total for d in data) + + if abs(pos_invoice_grand_total - invoice.grand_total) < 1: + invoice.write_off_amount += -1 * (pos_invoice_grand_total - invoice.grand_total) + invoice.save() + def process_merging_into_credit_note(self, data): credit_note = self.get_new_sales_invoice() credit_note.is_return = 1 @@ -102,6 +110,7 @@ class POSInvoiceMergeLog(Document): # TODO: return could be against multiple sales invoice which could also have been consolidated? # credit_note.return_against = self.consolidated_invoice credit_note.save() + self.write_off_fractional_amount(credit_note, data) credit_note.submit() self.consolidated_credit_note = credit_note.name @@ -135,9 +144,15 @@ class POSInvoiceMergeLog(Document): i.uom == item.uom and i.net_rate == item.net_rate and i.warehouse == item.warehouse): found = True i.qty = i.qty + item.qty + i.amount = i.amount + item.net_amount + i.net_amount = i.amount + i.base_amount = i.base_amount + item.base_net_amount + i.base_net_amount = i.base_amount if not found: item.rate = item.net_rate + item.amount = item.net_amount + item.base_amount = item.base_net_amount item.price_list_rate = 0 si_item = map_child_doc(item, invoice, {"doctype": "Sales Invoice Item"}) items.append(si_item) @@ -169,6 +184,7 @@ class POSInvoiceMergeLog(Document): found = True if not found: payments.append(payment) + rounding_adjustment += doc.rounding_adjustment rounded_total += doc.rounded_total base_rounding_adjustment += doc.base_rounding_adjustment diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py index 3555da83a40..5930aa097f7 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/test_pos_invoice_merge_log.py @@ -12,6 +12,7 @@ from erpnext.accounts.doctype.pos_invoice.test_pos_invoice import create_pos_inv from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import ( consolidate_pos_invoices, ) +from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry class TestPOSInvoiceMergeLog(unittest.TestCase): @@ -150,3 +151,132 @@ class TestPOSInvoiceMergeLog(unittest.TestCase): frappe.set_user("Administrator") frappe.db.sql("delete from `tabPOS Profile`") frappe.db.sql("delete from `tabPOS Invoice`") + + + def test_consolidation_round_off_error_1(self): + ''' + Test round off error in consolidated invoice creation if POS Invoice has inclusive tax + ''' + + frappe.db.sql("delete from `tabPOS Invoice`") + + try: + make_stock_entry( + to_warehouse="_Test Warehouse - _TC", + item_code="_Test Item", + rate=8000, + qty=10, + ) + + init_user_and_profile() + + inv = create_pos_invoice(qty=3, rate=10000, do_not_save=True) + inv.append("taxes", { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "rate": 7.5, + "included_in_print_rate": 1 + }) + inv.append('payments', { + 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 30000 + }) + inv.insert() + inv.submit() + + inv2 = create_pos_invoice(qty=3, rate=10000, do_not_save=True) + inv2.append("taxes", { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "rate": 7.5, + "included_in_print_rate": 1 + }) + inv2.append('payments', { + 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 30000 + }) + inv2.insert() + inv2.submit() + + consolidate_pos_invoices() + + inv.load_from_db() + consolidated_invoice = frappe.get_doc('Sales Invoice', inv.consolidated_invoice) + self.assertEqual(consolidated_invoice.outstanding_amount, 0) + self.assertEqual(consolidated_invoice.status, 'Paid') + + finally: + frappe.set_user("Administrator") + frappe.db.sql("delete from `tabPOS Profile`") + frappe.db.sql("delete from `tabPOS Invoice`") + + def test_consolidation_round_off_error_2(self): + ''' + Test the same case as above but with an Unpaid POS Invoice + ''' + frappe.db.sql("delete from `tabPOS Invoice`") + + try: + make_stock_entry( + to_warehouse="_Test Warehouse - _TC", + item_code="_Test Item", + rate=8000, + qty=10, + ) + + init_user_and_profile() + + inv = create_pos_invoice(qty=6, rate=10000, do_not_save=True) + inv.append("taxes", { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "rate": 7.5, + "included_in_print_rate": 1 + }) + inv.append('payments', { + 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 60000 + }) + inv.insert() + inv.submit() + + inv2 = create_pos_invoice(qty=6, rate=10000, do_not_save=True) + inv2.append("taxes", { + "account_head": "_Test Account VAT - _TC", + "charge_type": "On Net Total", + "cost_center": "_Test Cost Center - _TC", + "description": "VAT", + "doctype": "Sales Taxes and Charges", + "rate": 7.5, + "included_in_print_rate": 1 + }) + inv2.append('payments', { + 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 60000 + }) + inv2.insert() + inv2.submit() + + inv3 = create_pos_invoice(qty=3, rate=600, do_not_save=True) + inv3.append('payments', { + 'mode_of_payment': 'Cash', 'account': 'Cash - _TC', 'amount': 1000 + }) + inv3.insert() + inv3.submit() + + consolidate_pos_invoices() + + inv.load_from_db() + consolidated_invoice = frappe.get_doc('Sales Invoice', inv.consolidated_invoice) + self.assertEqual(consolidated_invoice.outstanding_amount, 800) + self.assertNotEqual(consolidated_invoice.status, 'Paid') + + finally: + frappe.set_user("Administrator") + frappe.db.sql("delete from `tabPOS Profile`") + frappe.db.sql("delete from `tabPOS Invoice`") diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index ac96b045a22..933fda8a0a5 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -249,13 +249,17 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa "free_item_data": [], "parent": args.parent, "parenttype": args.parenttype, - "child_docname": args.get('child_docname') + "child_docname": args.get('child_docname'), }) if args.ignore_pricing_rule or not args.item_code: if frappe.db.exists(args.doctype, args.name) and args.get("pricing_rules"): - item_details = remove_pricing_rule_for_item(args.get("pricing_rules"), - item_details, args.get('item_code')) + item_details = remove_pricing_rule_for_item( + args.get("pricing_rules"), + item_details, + item_code=args.get("item_code"), + rate=args.get("price_list_rate"), + ) return item_details update_args_for_pricing_rule(args) @@ -308,8 +312,12 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa if not doc: return item_details elif args.get("pricing_rules"): - item_details = remove_pricing_rule_for_item(args.get("pricing_rules"), - item_details, args.get('item_code')) + item_details = remove_pricing_rule_for_item( + args.get("pricing_rules"), + item_details, + item_code=args.get("item_code"), + rate=args.get("price_list_rate"), + ) return item_details @@ -390,7 +398,7 @@ def apply_price_discount_rule(pricing_rule, item_details, args): item_details[field] += (pricing_rule.get(field, 0) if pricing_rule else args.get(field, 0)) -def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None): +def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, rate=None): from erpnext.accounts.doctype.pricing_rule.utils import ( get_applied_pricing_rules, get_pricing_rule_items, @@ -403,6 +411,7 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None): if pricing_rule.rate_or_discount == 'Discount Percentage': item_details.discount_percentage = 0.0 item_details.discount_amount = 0.0 + item_details.rate = rate or 0.0 if pricing_rule.rate_or_discount == 'Discount Amount': item_details.discount_amount = 0.0 @@ -421,6 +430,7 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None): item_details.applied_on_items = ','.join(items) item_details.pricing_rules = '' + item_details.pricing_rule_removed = True return item_details @@ -432,9 +442,12 @@ def remove_pricing_rules(item_list): out = [] for item in item_list: item = frappe._dict(item) - if item.get('pricing_rules'): - out.append(remove_pricing_rule_for_item(item.get("pricing_rules"), - item, item.item_code)) + if item.get("pricing_rules"): + out.append( + remove_pricing_rule_for_item( + item.get("pricing_rules"), item, item.item_code, item.get("price_list_rate") + ) + ) return out diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 5746a840f30..8338a5b0ada 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -628,6 +628,67 @@ class TestPricingRule(unittest.TestCase): for doc in [si, si1]: doc.delete() + def test_remove_pricing_rule(self): + item = make_item("Water Flask") + make_item_price("Water Flask", "_Test Price List", 100) + + pricing_rule_record = { + "doctype": "Pricing Rule", + "title": "_Test Water Flask Rule", + "apply_on": "Item Code", + "price_or_product_discount": "Price", + "items": [{ + "item_code": "Water Flask", + }], + "selling": 1, + "currency": "INR", + "rate_or_discount": "Discount Percentage", + "discount_percentage": 20, + "company": "_Test Company" + } + rule = frappe.get_doc(pricing_rule_record) + rule.insert() + + si = create_sales_invoice(do_not_save=True, item_code="Water Flask") + si.selling_price_list = "_Test Price List" + si.save() + + self.assertEqual(si.items[0].price_list_rate, 100) + self.assertEqual(si.items[0].discount_percentage, 20) + self.assertEqual(si.items[0].rate, 80) + + si.ignore_pricing_rule = 1 + si.save() + + self.assertEqual(si.items[0].discount_percentage, 0) + self.assertEqual(si.items[0].rate, 100) + + si.delete() + rule.delete() + frappe.get_doc("Item Price", {"item_code": "Water Flask"}).delete() + item.delete() + + def test_multiple_pricing_rules_with_min_qty(self): + make_pricing_rule(discount_percentage=20, selling=1, priority=1, min_qty=4, + apply_multiple_pricing_rules=1, title="_Test Pricing Rule with Min Qty - 1") + make_pricing_rule(discount_percentage=10, selling=1, priority=2, min_qty=4, + apply_multiple_pricing_rules=1, title="_Test Pricing Rule with Min Qty - 2") + + si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1, currency="USD") + item = si.items[0] + item.stock_qty = 1 + si.save() + self.assertFalse(item.discount_percentage) + item.qty = 5 + item.stock_qty = 5 + si.save() + self.assertEqual(item.discount_percentage, 30) + si.delete() + + frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 1") + frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule with Min Qty - 2") + + test_dependencies = ["Campaign"] def make_pricing_rule(**args): diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 02bfc9defd7..7792590c9c7 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -73,7 +73,7 @@ def sorted_by_priority(pricing_rules, args, doc=None): for key in sorted(pricing_rule_dict): pricing_rules_list.extend(pricing_rule_dict.get(key)) - return pricing_rules_list or pricing_rules + return pricing_rules_list def filter_pricing_rule_based_on_condition(pricing_rules, doc=None): filtered_pricing_rules = [] diff --git a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py index 09aa72352e4..1b34d6d1f2f 100644 --- a/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py +++ b/erpnext/accounts/doctype/process_statement_of_accounts/process_statement_of_accounts.py @@ -73,7 +73,7 @@ def get_report_pdf(doc, consolidated=True): 'to_date': doc.to_date, 'company': doc.company, 'finance_book': doc.finance_book if doc.finance_book else None, - 'account': doc.account if doc.account else None, + 'account': [doc.account] if doc.account else None, 'party_type': 'Customer', 'party': [entry.customer], 'presentation_currency': presentation_currency, diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index b3642181ac0..2c3156175fb 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -178,8 +178,8 @@ class PurchaseInvoice(BuyingController): if self.supplier and account.account_type != "Payable": frappe.throw( - _("Please ensure {} account is a Payable account. Change the account type to Payable or select a different account.") - .format(frappe.bold("Credit To")), title=_("Invalid Account") + _("Please ensure {} account {} is a Payable account. Change the account type to Payable or select a different account.") + .format(frappe.bold("Credit To"), frappe.bold(self.credit_to)), title=_("Invalid Account") ) self.party_account_currency = account.account_currency @@ -537,8 +537,11 @@ class PurchaseInvoice(BuyingController): voucher_wise_stock_value = {} if self.update_stock: - for d in frappe.get_all('Stock Ledger Entry', - fields = ["voucher_detail_no", "stock_value_difference", "warehouse"], filters={'voucher_no': self.name}): + stock_ledger_entries = frappe.get_all("Stock Ledger Entry", + fields = ["voucher_detail_no", "stock_value_difference", "warehouse"], + filters={"voucher_no": self.name, "voucher_type": self.doctype, "is_cancelled": 0} + ) + for d in stock_ledger_entries: voucher_wise_stock_value.setdefault((d.voucher_detail_no, d.warehouse), d.stock_value_difference) valuation_tax_accounts = [d.account_head for d in self.get("taxes") @@ -548,6 +551,10 @@ class PurchaseInvoice(BuyingController): exchange_rate_map, net_rate_map = get_purchase_document_details(self) enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting')) + provisional_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, \ + 'enable_provisional_accounting_for_non_stock_items')) + + purchase_receipt_doc_map = {} for item in self.get("items"): if flt(item.base_net_amount): @@ -643,19 +650,23 @@ class PurchaseInvoice(BuyingController): else: amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount")) - auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items')) - - if auto_accounting_for_non_stock_items: - service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") - + if provisional_accounting_for_non_stock_items: if item.purchase_receipt: + provisional_account = self.get_company_default("default_provisional_account") + purchase_receipt_doc = purchase_receipt_doc_map.get(item.purchase_receipt) + + if not purchase_receipt_doc: + purchase_receipt_doc = frappe.get_doc("Purchase Receipt", item.purchase_receipt) + purchase_receipt_doc_map[item.purchase_receipt] = purchase_receipt_doc + # Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt expense_booked_in_pr = frappe.db.get_value('GL Entry', {'is_cancelled': 0, 'voucher_type': 'Purchase Receipt', 'voucher_no': item.purchase_receipt, 'voucher_detail_no': item.pr_detail, - 'account':service_received_but_not_billed_account}, ['name']) + 'account':provisional_account}, ['name']) if expense_booked_in_pr: - expense_account = service_received_but_not_billed_account + # Intentionally passing purchase invoice item to handle partial billing + purchase_receipt_doc.add_provisional_gl_entry(item, gl_entries, self.posting_date, reverse=1) if not self.is_internal_transfer(): gl_entries.append(self.get_gl_dict({ diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js index f6ff83add8c..82d00308db4 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice_list.js @@ -56,4 +56,14 @@ frappe.listview_settings["Purchase Invoice"] = { ]; } }, + + onload: function(listview) { + listview.page.add_action_item(__("Purchase Receipt"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Purchase Invoice", "Purchase Receipt"); + }); + + listview.page.add_action_item(__("Payment"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Purchase Invoice", "Payment"); + }); + } }; diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 21846bb76c8..d51a008d943 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -11,12 +11,17 @@ from frappe.utils import add_days, cint, flt, getdate, nowdate, today import erpnext from erpnext.accounts.doctype.account.test_account import create_account, get_inventory_account from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry +from erpnext.buying.doctype.purchase_order.purchase_order import get_mapped_purchase_invoice +from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order from erpnext.buying.doctype.supplier.test_supplier import create_supplier from erpnext.controllers.accounts_controller import get_payment_terms from erpnext.controllers.buying_controller import QtyMismatchError from erpnext.exceptions import InvalidCurrency from erpnext.projects.doctype.project.test_project import make_project from erpnext.stock.doctype.item.test_item import create_item +from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( + make_purchase_invoice as create_purchase_invoice_from_receipt, +) from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import ( get_taxes, make_purchase_receipt, @@ -1147,8 +1152,6 @@ class TestPurchaseInvoice(unittest.TestCase): def test_purchase_invoice_advance_taxes(self): from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry - from erpnext.buying.doctype.purchase_order.purchase_order import get_mapped_purchase_invoice - from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order # create a new supplier to test supplier = create_supplier(supplier_name = '_Test TDS Advance Supplier', @@ -1221,6 +1224,45 @@ class TestPurchaseInvoice(unittest.TestCase): payment_entry.load_from_db() self.assertEqual(payment_entry.taxes[0].allocated_amount, 0) + def test_provisional_accounting_entry(self): + item = create_item("_Test Non Stock Item", is_stock_item=0) + provisional_account = create_account(account_name="Provision Account", + parent_account="Current Liabilities - _TC", company="_Test Company") + + company = frappe.get_doc('Company', '_Test Company') + company.enable_provisional_accounting_for_non_stock_items = 1 + company.default_provisional_account = provisional_account + company.save() + + pr = make_purchase_receipt(item_code="_Test Non Stock Item", posting_date=add_days(nowdate(), -2)) + + pi = create_purchase_invoice_from_receipt(pr.name) + pi.set_posting_time = 1 + pi.posting_date = add_days(pr.posting_date, -1) + pi.items[0].expense_account = 'Cost of Goods Sold - _TC' + pi.save() + pi.submit() + + # Check GLE for Purchase Invoice + expected_gle = [ + ['Cost of Goods Sold - _TC', 250, 0, add_days(pr.posting_date, -1)], + ['Creditors - _TC', 0, 250, add_days(pr.posting_date, -1)] + ] + + check_gl_entries(self, pi.name, expected_gle, pi.posting_date) + + expected_gle_for_purchase_receipt = [ + ["Provision Account - _TC", 250, 0, pr.posting_date], + ["_Test Account Cost for Goods Sold - _TC", 0, 250, pr.posting_date], + ["Provision Account - _TC", 0, 250, pi.posting_date], + ["_Test Account Cost for Goods Sold - _TC", 250, 0, pi.posting_date] + ] + + check_gl_entries(self, pr.name, expected_gle_for_purchase_receipt, pr.posting_date) + + company.enable_provisional_accounting_for_non_stock_items = 0 + company.save() + def check_gl_entries(doc, voucher_no, expected_gle, posting_date): gl_entries = frappe.db.sql("""select account, debit, credit, posting_date from `tabGL Entry` diff --git a/erpnext/accounts/doctype/sales_invoice/regional/india.js b/erpnext/accounts/doctype/sales_invoice/regional/india.js index 6336db16ebc..f54bce8aac7 100644 --- a/erpnext/accounts/doctype/sales_invoice/regional/india.js +++ b/erpnext/accounts/doctype/sales_invoice/regional/india.js @@ -1,6 +1,8 @@ {% include "erpnext/regional/india/taxes.js" %} +{% include "erpnext/regional/india/e_invoice/einvoice.js" %} erpnext.setup_auto_gst_taxation('Sales Invoice'); +erpnext.setup_einvoice_actions('Sales Invoice') frappe.ui.form.on("Sales Invoice", { setup: function(frm) { diff --git a/erpnext/accounts/doctype/sales_invoice/regional/india_list.js b/erpnext/accounts/doctype/sales_invoice/regional/india_list.js index d9d6634c397..f01325d80bd 100644 --- a/erpnext/accounts/doctype/sales_invoice/regional/india_list.js +++ b/erpnext/accounts/doctype/sales_invoice/regional/india_list.js @@ -36,4 +36,139 @@ frappe.listview_settings['Sales Invoice'].onload = function (list_view) { }; list_view.page.add_actions_menu_item(__('Generate E-Way Bill JSON'), action, false); + + const generate_irns = () => { + const docnames = list_view.get_checked_items(true); + if (docnames && docnames.length) { + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.generate_einvoices', + args: { docnames }, + freeze: true, + freeze_message: __('Generating E-Invoices...') + }); + } else { + frappe.msgprint({ + message: __('Please select at least one sales invoice to generate IRN'), + title: __('No Invoice Selected'), + indicator: 'red' + }); + } + }; + + const cancel_irns = () => { + const docnames = list_view.get_checked_items(true); + + const fields = [ + { + "label": "Reason", + "fieldname": "reason", + "fieldtype": "Select", + "reqd": 1, + "default": "1-Duplicate", + "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"] + }, + { + "label": "Remark", + "fieldname": "remark", + "fieldtype": "Data", + "reqd": 1 + } + ]; + + const d = new frappe.ui.Dialog({ + title: __("Cancel IRN"), + fields: fields, + primary_action: function() { + const data = d.get_values(); + frappe.call({ + method: 'erpnext.regional.india.e_invoice.utils.cancel_irns', + args: { + doctype: list_view.doctype, + docnames, + reason: data.reason.split('-')[0], + remark: data.remark + }, + freeze: true, + freeze_message: __('Cancelling E-Invoices...'), + }); + d.hide(); + }, + primary_action_label: __('Submit') + }); + d.show(); + }; + + let einvoicing_enabled = false; + frappe.db.get_single_value("E Invoice Settings", "enable").then(enabled => { + einvoicing_enabled = enabled; + }); + + list_view.$result.on("change", "input[type=checkbox]", () => { + if (einvoicing_enabled) { + const docnames = list_view.get_checked_items(true); + // show/hide e-invoicing actions when no sales invoices are checked + if (docnames && docnames.length) { + // prevent adding actions twice if e-invoicing action group already exists + if (list_view.page.get_inner_group_button(__('E-Invoicing')).length == 0) { + list_view.page.add_inner_button(__('Generate IRNs'), generate_irns, __('E-Invoicing')); + list_view.page.add_inner_button(__('Cancel IRNs'), cancel_irns, __('E-Invoicing')); + } + } else { + list_view.page.remove_inner_button(__('Generate IRNs'), __('E-Invoicing')); + list_view.page.remove_inner_button(__('Cancel IRNs'), __('E-Invoicing')); + } + } + }); + + frappe.realtime.on("bulk_einvoice_generation_complete", (data) => { + const { failures, user, invoices } = data; + + if (invoices.length != failures.length) { + frappe.msgprint({ + message: __('{0} e-invoices generated successfully', [invoices.length]), + title: __('Bulk E-Invoice Generation Complete'), + indicator: 'orange' + }); + } + + if (failures && failures.length && user == frappe.session.user) { + let message = ` + Failed to generate IRNs for following ${failures.length} sales invoices: +
{{ seller.Gstin }}
+{{ seller.LglNm }}
+{{ seller.Addr1 }}
+ {%- if seller.Addr2 -%}{{ seller.Addr2 }}
{% endif %} +{{ seller.Loc }}
+{{ frappe.db.get_value("Address", doc.company_address, "gst_state") }} - {{ seller.Pin }}
+ + {%- if einvoice.ShipDtls -%} + {%- set shipping = einvoice.ShipDtls -%} +{{ shipping.Gstin }}
+{{ shipping.LglNm }}
+{{ shipping.Addr1 }}
+ {%- if shipping.Addr2 -%}{{ shipping.Addr2 }}
{% endif %} +{{ shipping.Loc }}
+{{ frappe.db.get_value("Address", doc.shipping_address_name, "gst_state") }} - {{ shipping.Pin }}
+ {% endif %} +{{ buyer.Gstin }}
+{{ buyer.LglNm }}
+{{ buyer.Addr1 }}
+ {%- if buyer.Addr2 -%}{{ buyer.Addr2 }}
{% endif %} +{{ buyer.Loc }}
+{{ frappe.db.get_value("Address", doc.customer_address, "gst_state") }} - {{ buyer.Pin }}
+ + {%- if einvoice.DispDtls -%} + {%- set dispatch = einvoice.DispDtls -%} +{{ dispatch.Gstin }}
{% endif %} +{{ dispatch.LglNm }}
+{{ dispatch.Addr1 }}
+ {%- if dispatch.Addr2 -%}{{ dispatch.Addr2 }}
{% endif %} +{{ dispatch.Loc }}
+{{ frappe.db.get_value("Address", doc.dispatch_address_name, "gst_state") }} - {{ dispatch.Pin }}
+ {% endif %} +| Sr. No. | +Item | +HSN Code | +Qty | +UOM | +Rate | +Discount | +Taxable Amount | +Tax Rate | +Other Charges | +Total | +
|---|---|---|---|---|---|---|---|---|---|---|
| {{ item.SlNo }} | +{{ item.PrdDesc }} | +{{ item.HsnCd }} | +{{ item.Qty }} | +{{ item.Unit }} | +{{ frappe.utils.fmt_money(item.UnitPrice, None, "INR") }} | +{{ frappe.utils.fmt_money(item.Discount, None, "INR") }} | +{{ frappe.utils.fmt_money(item.AssAmt, None, "INR") }} | +{{ item.GstRt + item.CesRt }} % | +{{ frappe.utils.fmt_money(0, None, "INR") }} | +{{ frappe.utils.fmt_money(item.TotItemVal, None, "INR") }} | +
| Taxable Amount | +CGST | +SGST | +IGST | +CESS | +State CESS | +Discount | +Other Charges | +Round Off | +Total Value | +
|---|---|---|---|---|---|---|---|---|---|
| {{ frappe.utils.fmt_money(value_details.AssVal, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.CgstVal, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.SgstVal, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.IgstVal, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.CesVal, None, "INR") }} | +{{ frappe.utils.fmt_money(0, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.Discount, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.OthChrg, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.RndOffAmt, None, "INR") }} | +{{ frappe.utils.fmt_money(value_details.TotInvVal, None, "INR") }} | +
\n\t{{ doc.company }}
\n\t{% if doc.company_address_display %}\n\t\t{% set company_address = doc.company_address_display.replace(\"\\n\", \" \").replace(\"
\", \" \") %}\n\t\t{% if \"GSTIN\" not in company_address %}\n\t\t\t{{ company_address }}\n\t\t\t{{ _(\"GSTIN\") }}:{{ doc.company_gstin }}\n\t\t{% else %}\n\t\t\t{{ company_address.replace(\"GSTIN\", \"
GSTIN\") }}\n\t\t{% endif %}\n\t{% endif %}\n\t
\n\t{% if doc.docstatus == 0 %}\n\t\t{{ doc.status + \" \"+ (doc.select_print_heading or _(\"Invoice\")) }}
\n\t{% else %}\n\t\t{{ doc.select_print_heading or _(\"Invoice\") }}
\n\t{% endif %}\n
\n\t{{ _(\"Receipt No\") }}: {{ doc.name }}
\n\t{{ _(\"Date\") }}: {{ doc.get_formatted(\"posting_date\") }}
\n\t{% if doc.grand_total > 50000 %}\n\t\t{% set customer_address = doc.address_display.replace(\"\\n\", \" \").replace(\"
\", \" \") %}\n\t\t{{ _(\"Customer\") }}:
\n\t\t{{ doc.customer_name }}
\n\t\t{{ customer_address }}\n\t{% endif %}\n
| {{ _(\"Item\") }} | \n\t\t\t{{ _(\"Qty\") }} | \n\t\t\t{{ _(\"Amount\") }} | \n\t\t
|---|---|---|
| \n\t\t\t\t{{ item.item_code }}\n\t\t\t\t{%- if item.item_name != item.item_code -%}\n\t\t\t\t\t {{ item.item_name }}\n\t\t\t\t{%- endif -%}\n\t\t\t\t{%- if item.gst_hsn_code -%}\n\t\t\t\t\t {{ _(\"HSN/SAC\") }}: {{ item.gst_hsn_code }}\n\t\t\t\t{%- endif -%}\n\t\t\t\t{%- if item.serial_no -%}\n\t\t\t\t\t {{ _(\"Serial No\") }}: {{ item.serial_no }}\n\t\t\t\t{%- endif -%}\n\t\t\t | \n\t\t\t{{ item.qty }} @ {{ item.rate }} | \n\t\t\t{{ item.get_formatted(\"amount\") }} | \n\t\t
| \n\t\t\t\t\t{{ _(\"Total Excl. Tax\") }}\n\t\t\t\t | \n\t\t\t\t\n\t\t\t\t\t{{ doc.get_formatted(\"net_total\", doc) }}\n\t\t\t\t | \n\t\t\t{% else %}\n\t\t\t\t\n\t\t\t\t\t{{ _(\"Total\") }}\n\t\t\t\t | \n\t\t\t\t\n\t\t\t\t\t{{ doc.get_formatted(\"total\", doc) }}\n\t\t\t\t | \n\t\t\t{% endif %}\n\t\t
| \n\t\t\t\t\t{{ row.description }}\n\t\t\t\t | \n\t\t\t\t\n\t\t\t\t\t{{ row.get_formatted(\"tax_amount\", doc) }}\n\t\t\t\t | \n\t\t\t||
| \n\t\t\t\t{{ _(\"Discount\") }}\n\t\t\t | \n\t\t\t\n\t\t\t\t{{ doc.get_formatted(\"discount_amount\") }}\n\t\t\t | \n\t\t||
| \n\t\t\t\t{{ _(\"Grand Total\") }}\n\t\t\t | \n\t\t\t\n\t\t\t\t{{ doc.get_formatted(\"grand_total\") }}\n\t\t\t | \n\t\t||
| \n\t\t\t\t{{ _(\"Rounded Total\") }}\n\t\t\t | \n\t\t\t\n\t\t\t\t{{ doc.get_formatted(\"rounded_total\") }}\n\t\t\t | \n\t\t||
| \n\t\t\t\t{{ _(\"Paid Amount\") }}\n\t\t\t | \n\t\t\t\n\t\t\t\t{{ doc.get_formatted(\"paid_amount\") }}\n\t\t\t | \n\t\t||
| \n\t\t\t\t{{ _(\"Change Amount\") }}\n\t\t\t | \n\t\t\t\n\t\t\t\t{{ doc.get_formatted(\"change_amount\") }}\n\t\t\t | \n\t\t
{{ doc.terms or \"\" }}
\n{{ _(\"Thank you, please visit again.\") }}
", - "idx": 0, - "line_breaks": 0, - "modified": "2020-04-29 16:39:12.936215", - "modified_by": "Administrator", - "module": "Accounts", - "name": "GST POS Invoice", - "owner": "Administrator", - "print_format_builder": 0, - "print_format_type": "Jinja", - "raw_printing": 0, - "show_section_headings": 0, - "standard": "Yes" -} \ No newline at end of file diff --git a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py index 4559fa94a4a..8e3bd8be1b9 100644 --- a/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py +++ b/erpnext/accounts/report/accounts_receivable_summary/accounts_receivable_summary.py @@ -5,7 +5,6 @@ import frappe from frappe import _, scrub from frappe.utils import cint, flt -from six import iteritems from erpnext.accounts.party import get_partywise_advanced_payment_amount from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport @@ -40,7 +39,7 @@ class AccountsReceivableSummary(ReceivablePayableReport): if self.filters.show_gl_balance: gl_balance_map = get_gl_balance(self.filters.report_date) - for party, party_dict in iteritems(self.party_total): + for party, party_dict in self.party_total.items(): if party_dict.outstanding == 0: continue diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index dc1f7aae42e..f10a5eab102 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py @@ -120,11 +120,11 @@ def check_opening_balance(asset, liability, equity): opening_balance = 0 float_precision = cint(frappe.db.get_default("float_precision")) or 2 if asset: - opening_balance = flt(asset[0].get("opening_balance", 0), float_precision) + opening_balance = flt(asset[-1].get("opening_balance", 0), float_precision) if liability: - opening_balance -= flt(liability[0].get("opening_balance", 0), float_precision) + opening_balance -= flt(liability[-1].get("opening_balance", 0), float_precision) if equity: - opening_balance -= flt(equity[0].get("opening_balance", 0), float_precision) + opening_balance -= flt(equity[-1].get("opening_balance", 0), float_precision) opening_balance = flt(opening_balance, float_precision) if opening_balance: diff --git a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py index 6c401fb8f3b..b72d2669775 100644 --- a/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py +++ b/erpnext/accounts/report/bank_reconciliation_statement/bank_reconciliation_statement.py @@ -4,7 +4,12 @@ import frappe from frappe import _ -from frappe.utils import flt, getdate, nowdate +from frappe.query_builder.custom import ConstantColumn +from frappe.query_builder.functions import Sum +from frappe.utils import flt, getdate +from pypika import CustomFunction + +from erpnext.accounts.utils import get_balance_on def execute(filters=None): @@ -18,7 +23,6 @@ def execute(filters=None): data = get_entries(filters) - from erpnext.accounts.utils import get_balance_on balance_as_per_system = get_balance_on(filters["account"], filters["report_date"]) total_debit, total_credit = 0,0 @@ -118,7 +122,21 @@ def get_columns(): ] def get_entries(filters): - journal_entries = frappe.db.sql(""" + journal_entries = get_journal_entries(filters) + + payment_entries = get_payment_entries(filters) + + loan_entries = get_loan_entries(filters) + + pos_entries = [] + if filters.include_pos_transactions: + pos_entries = get_pos_entries(filters) + + return sorted(list(payment_entries)+list(journal_entries+list(pos_entries) + list(loan_entries)), + key=lambda k: getdate(k['posting_date'])) + +def get_journal_entries(filters): + return frappe.db.sql(""" select "Journal Entry" as payment_document, jv.posting_date, jv.name as payment_entry, jvd.debit_in_account_currency as debit, jvd.credit_in_account_currency as credit, jvd.against_account, @@ -130,7 +148,8 @@ def get_entries(filters): and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s and ifnull(jv.is_opening, 'No') = 'No'""", filters, as_dict=1) - payment_entries = frappe.db.sql(""" +def get_payment_entries(filters): + return frappe.db.sql(""" select "Payment Entry" as payment_document, name as payment_entry, reference_no, reference_date as ref_date, @@ -145,9 +164,8 @@ def get_entries(filters): and ifnull(clearance_date, '4000-01-01') > %(report_date)s """, filters, as_dict=1) - pos_entries = [] - if filters.include_pos_transactions: - pos_entries = frappe.db.sql(""" +def get_pos_entries(filters): + return frappe.db.sql(""" select "Sales Invoice Payment" as payment_document, sip.name as payment_entry, sip.amount as debit, si.posting_date, si.debit_to as against_account, sip.clearance_date, @@ -161,8 +179,42 @@ def get_entries(filters): si.posting_date ASC, si.name DESC """, filters, as_dict=1) - return sorted(list(payment_entries)+list(journal_entries+list(pos_entries)), - key=lambda k: k['posting_date'] or getdate(nowdate())) +def get_loan_entries(filters): + loan_docs = [] + for doctype in ["Loan Disbursement", "Loan Repayment"]: + loan_doc = frappe.qb.DocType(doctype) + ifnull = CustomFunction('IFNULL', ['value', 'default']) + + if doctype == "Loan Disbursement": + amount_field = (loan_doc.disbursed_amount).as_("credit") + posting_date = (loan_doc.disbursement_date).as_("posting_date") + account = loan_doc.disbursement_account + else: + amount_field = (loan_doc.amount_paid).as_("debit") + posting_date = (loan_doc.posting_date).as_("posting_date") + account = loan_doc.payment_account + + entries = frappe.qb.from_(loan_doc).select( + ConstantColumn(doctype).as_("payment_document"), + (loan_doc.name).as_("payment_entry"), + (loan_doc.reference_number).as_("reference_no"), + (loan_doc.reference_date).as_("ref_date"), + amount_field, + posting_date, + ).where( + loan_doc.docstatus == 1 + ).where( + account == filters.get('account') + ).where( + posting_date <= getdate(filters.get('report_date')) + ).where( + ifnull(loan_doc.clearance_date, '4000-01-01') > getdate(filters.get('report_date')) + ).run(as_dict=1) + + loan_docs.extend(entries) + + return loan_docs + def get_amounts_not_reflected_in_system(filters): je_amount = frappe.db.sql(""" @@ -182,7 +234,40 @@ def get_amounts_not_reflected_in_system(filters): pe_amount = flt(pe_amount[0][0]) if pe_amount else 0.0 - return je_amount + pe_amount + loan_amount = get_loan_amount(filters) + + return je_amount + pe_amount + loan_amount + +def get_loan_amount(filters): + total_amount = 0 + for doctype in ["Loan Disbursement", "Loan Repayment"]: + loan_doc = frappe.qb.DocType(doctype) + ifnull = CustomFunction('IFNULL', ['value', 'default']) + + if doctype == "Loan Disbursement": + amount_field = Sum(loan_doc.disbursed_amount) + posting_date = (loan_doc.disbursement_date).as_("posting_date") + account = loan_doc.disbursement_account + else: + amount_field = Sum(loan_doc.amount_paid) + posting_date = (loan_doc.posting_date).as_("posting_date") + account = loan_doc.payment_account + + amount = frappe.qb.from_(loan_doc).select( + amount_field + ).where( + loan_doc.docstatus == 1 + ).where( + account == filters.get('account') + ).where( + posting_date > getdate(filters.get('report_date')) + ).where( + ifnull(loan_doc.clearance_date, '4000-01-01') <= getdate(filters.get('report_date')) + ).run()[0][0] + + total_amount += flt(amount) + + return amount def get_balance_row(label, amount, account_currency): if amount > 0: diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py index 3bb590a564d..56ee5008cf6 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py @@ -29,18 +29,6 @@ def execute(filters=None): dimension_items = cam_map.get(dimension) if dimension_items: data = get_final_data(dimension, dimension_items, filters, period_month_ranges, data, 0) - else: - DCC_allocation = frappe.db.sql('''SELECT parent, sum(percentage_allocation) as percentage_allocation - FROM `tabDistributed Cost Center` - WHERE cost_center IN %(dimension)s - AND parent NOT IN %(dimension)s - GROUP BY parent''',{'dimension':[dimension]}) - if DCC_allocation: - filters['budget_against_filter'] = [DCC_allocation[0][0]] - ddc_cam_map = get_dimension_account_month_map(filters) - dimension_items = ddc_cam_map.get(DCC_allocation[0][0]) - if dimension_items: - data = get_final_data(dimension, dimension_items, filters, period_month_ranges, data, DCC_allocation[0][1]) chart = get_chart_data(filters, columns, data) 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 758e3e93379..1e20f7be3e4 100644 --- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py +++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py @@ -354,9 +354,6 @@ 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 - for company in companies: accounts_by_name[account][company] = \ accounts_by_name[account].get(company, 0.0) + d.get(company, 0.0) @@ -367,7 +364,7 @@ def accumulate_values_into_parents(accounts, accounts_by_name, companies): 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) + accounts = get_accounts(root_type, companies) if not accounts: return None, None, None @@ -396,7 +393,7 @@ def update_parent_account_names(accounts): for account in accounts: if account.parent_account: - account["parent_account_name"] = name_to_account_map[account.parent_account] + account["parent_account_name"] = name_to_account_map.get(account.parent_account) return accounts @@ -419,12 +416,19 @@ def get_subsidiary_companies(company): return frappe.db.sql_list("""select name from `tabCompany` where lft >= {0} and rgt <= {1} order by lft, rgt""".format(lft, rgt)) -def get_accounts(root_type, filters): - return frappe.db.sql(""" select name, is_group, company, - parent_account, lft, rgt, root_type, report_type, account_name, account_number - from - `tabAccount` where company = %s and root_type = %s - """ , (filters.get('company'), root_type), as_dict=1) +def get_accounts(root_type, companies): + accounts = [] + added_accounts = [] + + for company in companies: + for account in frappe.get_all("Account", fields=["name", "is_group", "company", + "parent_account", "lft", "rgt", "root_type", "report_type", "account_name", "account_number"], + filters={"company": company, "root_type": root_type}): + if account.account_name not in added_accounts: + accounts.append(account) + added_accounts.append(account.account_name) + + return accounts def prepare_data(accounts, start_date, end_date, balance_must_be, companies, company_currency, filters): data = [] diff --git a/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py b/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py index 1de6fb68241..86eb2134fe8 100644 --- a/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py +++ b/erpnext/accounts/report/deferred_revenue_and_expense/test_deferred_revenue_and_expense.py @@ -17,10 +17,42 @@ from erpnext.stock.doctype.item.test_item import create_item class TestDeferredRevenueAndExpense(unittest.TestCase): @classmethod def setUpClass(self): - clear_old_entries() + clear_accounts_and_items() create_company() + self.maxDiff = None + + def clear_old_entries(self): + sinv = qb.DocType("Sales Invoice") + sinv_item = qb.DocType("Sales Invoice Item") + pinv = qb.DocType("Purchase Invoice") + pinv_item = qb.DocType("Purchase Invoice Item") + + # delete existing invoices with deferred items + deferred_invoices = ( + qb.from_(sinv) + .join(sinv_item) + .on(sinv.name == sinv_item.parent) + .select(sinv.name) + .where(sinv_item.enable_deferred_revenue == 1) + .run() + ) + if deferred_invoices: + qb.from_(sinv).delete().where(sinv.name.isin(deferred_invoices)).run() + + deferred_invoices = ( + qb.from_(pinv) + .join(pinv_item) + .on(pinv.name == pinv_item.parent) + .select(pinv.name) + .where(pinv_item.enable_deferred_expense == 1) + .run() + ) + if deferred_invoices: + qb.from_(pinv).delete().where(pinv.name.isin(deferred_invoices)).run() def test_deferred_revenue(self): + self.clear_old_entries() + # created deferred expense accounts, if not found deferred_revenue_account = create_account( account_name="Deferred Revenue", @@ -108,6 +140,8 @@ class TestDeferredRevenueAndExpense(unittest.TestCase): self.assertEqual(report.period_total, expected) def test_deferred_expense(self): + self.clear_old_entries() + # created deferred expense accounts, if not found deferred_expense_account = create_account( account_name="Deferred Expense", @@ -198,6 +232,91 @@ class TestDeferredRevenueAndExpense(unittest.TestCase): ] self.assertEqual(report.period_total, expected) + def test_zero_months(self): + self.clear_old_entries() + # created deferred expense accounts, if not found + deferred_revenue_account = create_account( + account_name="Deferred Revenue", + parent_account="Current Liabilities - _CD", + company="_Test Company DR", + ) + + acc_settings = frappe.get_doc("Accounts Settings", "Accounts Settings") + acc_settings.book_deferred_entries_based_on = "Months" + acc_settings.save() + + customer = frappe.new_doc("Customer") + customer.customer_name = "_Test Customer DR" + customer.type = "Individual" + customer.insert() + + item = create_item( + "_Test Internet Subscription", + is_stock_item=0, + warehouse="All Warehouses - _CD", + company="_Test Company DR", + ) + item.enable_deferred_revenue = 1 + item.deferred_revenue_account = deferred_revenue_account + item.no_of_months = 0 + item.save() + + si = create_sales_invoice( + item=item.name, + company="_Test Company DR", + customer="_Test Customer DR", + debit_to="Debtors - _CD", + posting_date="2021-05-01", + parent_cost_center="Main - _CD", + cost_center="Main - _CD", + do_not_submit=True, + rate=300, + price_list_rate=300, + ) + si.items[0].enable_deferred_revenue = 1 + si.items[0].deferred_revenue_account = deferred_revenue_account + si.items[0].income_account = "Sales - _CD" + si.save() + si.submit() + + pda = frappe.get_doc( + dict( + doctype="Process Deferred Accounting", + posting_date=nowdate(), + start_date="2021-05-01", + end_date="2021-08-01", + type="Income", + company="_Test Company DR", + ) + ) + pda.insert() + pda.submit() + + # execute report + fiscal_year = frappe.get_doc("Fiscal Year", frappe.defaults.get_user_default("fiscal_year")) + self.filters = frappe._dict( + { + "company": frappe.defaults.get_user_default("Company"), + "filter_based_on": "Date Range", + "period_start_date": "2021-05-01", + "period_end_date": "2021-08-01", + "from_fiscal_year": fiscal_year.year, + "to_fiscal_year": fiscal_year.year, + "periodicity": "Monthly", + "type": "Revenue", + "with_upcoming_postings": False, + } + ) + + report = Deferred_Revenue_and_Expense_Report(filters=self.filters) + report.run() + expected = [ + {"key": "may_2021", "total": 300.0, "actual": 300.0}, + {"key": "jun_2021", "total": 0, "actual": 0}, + {"key": "jul_2021", "total": 0, "actual": 0}, + {"key": "aug_2021", "total": 0, "actual": 0}, + ] + self.assertEqual(report.period_total, expected) def create_company(): company = frappe.db.exists("Company", "_Test Company DR") @@ -209,15 +328,11 @@ def create_company(): company.insert() -def clear_old_entries(): +def clear_accounts_and_items(): item = qb.DocType("Item") account = qb.DocType("Account") customer = qb.DocType("Customer") supplier = qb.DocType("Supplier") - sinv = qb.DocType("Sales Invoice") - sinv_item = qb.DocType("Sales Invoice Item") - pinv = qb.DocType("Purchase Invoice") - pinv_item = qb.DocType("Purchase Invoice Item") qb.from_(account).delete().where( (account.account_name == "Deferred Revenue") @@ -228,26 +343,3 @@ def clear_old_entries(): ).run() qb.from_(customer).delete().where(customer.customer_name == "_Test Customer DR").run() qb.from_(supplier).delete().where(supplier.supplier_name == "_Test Furniture Supplier").run() - - # delete existing invoices with deferred items - deferred_invoices = ( - qb.from_(sinv) - .join(sinv_item) - .on(sinv.name == sinv_item.parent) - .select(sinv.name) - .where(sinv_item.enable_deferred_revenue == 1) - .run() - ) - if deferred_invoices: - qb.from_(sinv).delete().where(sinv.name.isin(deferred_invoices)).run() - - deferred_invoices = ( - qb.from_(pinv) - .join(pinv_item) - .on(pinv.name == pinv_item.parent) - .select(pinv.name) - .where(pinv_item.enable_deferred_expense == 1) - .run() - ) - if deferred_invoices: - qb.from_(pinv).delete().where(pinv.name.isin(deferred_invoices)).run() diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 1e89b650c71..db28cdfdd3c 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -282,7 +282,8 @@ def add_total_row(out, root_type, balance_must_be, period_list, company_currency total_row = { "account_name": _("Total {0} ({1})").format(_(root_type), _(balance_must_be)), "account": _("Total {0} ({1})").format(_(root_type), _(balance_must_be)), - "currency": company_currency + "currency": company_currency, + "opening_balance": 0.0 } for row in out: @@ -294,6 +295,7 @@ def add_total_row(out, root_type, balance_must_be, period_list, company_currency total_row.setdefault("total", 0.0) total_row["total"] += flt(row["total"]) + total_row["opening_balance"] += row["opening_balance"] row["total"] = "" if "total" in total_row: @@ -387,42 +389,15 @@ def set_gl_entries_by_account( key: value }) - distributed_cost_center_query = "" - if filters and filters.get('cost_center'): - distributed_cost_center_query = """ - UNION ALL - SELECT posting_date, - account, - debit*(DCC_allocation.percentage_allocation/100) as debit, - credit*(DCC_allocation.percentage_allocation/100) as credit, - is_opening, - fiscal_year, - debit_in_account_currency*(DCC_allocation.percentage_allocation/100) as debit_in_account_currency, - credit_in_account_currency*(DCC_allocation.percentage_allocation/100) as credit_in_account_currency, - account_currency - FROM `tabGL Entry`, - ( - SELECT parent, sum(percentage_allocation) as percentage_allocation - FROM `tabDistributed Cost Center` - WHERE cost_center IN %(cost_center)s - AND parent NOT IN %(cost_center)s - GROUP BY parent - ) as DCC_allocation - WHERE company=%(company)s - {additional_conditions} - AND posting_date <= %(to_date)s - AND is_cancelled = 0 - AND cost_center = DCC_allocation.parent - """.format(additional_conditions=additional_conditions.replace("and cost_center in %(cost_center)s ", '')) - - gl_entries = frappe.db.sql("""select posting_date, account, debit, credit, is_opening, fiscal_year, debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry` + gl_entries = frappe.db.sql(""" + select posting_date, account, debit, credit, is_opening, fiscal_year, + debit_in_account_currency, credit_in_account_currency, account_currency from `tabGL Entry` where company=%(company)s {additional_conditions} and posting_date <= %(to_date)s - and is_cancelled = 0 - {distributed_cost_center_query}""".format( - additional_conditions=additional_conditions, - distributed_cost_center_query=distributed_cost_center_query), gl_filters, as_dict=True) #nosec + and is_cancelled = 0""".format( + additional_conditions=additional_conditions), gl_filters, as_dict=True + ) if filters and filters.get('presentation_currency'): convert_to_presentation_currency(gl_entries, get_currency(filters), filters.get('company')) diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index 7f279205477..4ff0297dba7 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -176,44 +176,7 @@ def get_gl_entries(filters, accounting_dimensions): if accounting_dimensions: dimension_fields = ', '.join(accounting_dimensions) + ',' - distributed_cost_center_query = "" - if filters and filters.get('cost_center'): - select_fields_with_percentage = """, debit*(DCC_allocation.percentage_allocation/100) as debit, - credit*(DCC_allocation.percentage_allocation/100) as credit, - debit_in_account_currency*(DCC_allocation.percentage_allocation/100) as debit_in_account_currency, - credit_in_account_currency*(DCC_allocation.percentage_allocation/100) as credit_in_account_currency """ - - distributed_cost_center_query = """ - UNION ALL - SELECT name as gl_entry, - posting_date, - account, - party_type, - party, - voucher_type, - voucher_no, {dimension_fields} - cost_center, project, - against_voucher_type, - against_voucher, - account_currency, - remarks, against, - is_opening, `tabGL Entry`.creation {select_fields_with_percentage} - FROM `tabGL Entry`, - ( - SELECT parent, sum(percentage_allocation) as percentage_allocation - FROM `tabDistributed Cost Center` - WHERE cost_center IN %(cost_center)s - AND parent NOT IN %(cost_center)s - GROUP BY parent - ) as DCC_allocation - WHERE company=%(company)s - {conditions} - AND posting_date <= %(to_date)s - AND cost_center = DCC_allocation.parent - """.format(dimension_fields=dimension_fields,select_fields_with_percentage=select_fields_with_percentage, conditions=get_conditions(filters).replace("and cost_center in %(cost_center)s ", '')) - - gl_entries = frappe.db.sql( - """ + gl_entries = frappe.db.sql(""" select name as gl_entry, posting_date, account, party_type, party, voucher_type, voucher_no, {dimension_fields} @@ -222,13 +185,11 @@ def get_gl_entries(filters, accounting_dimensions): remarks, against, is_opening, creation {select_fields} from `tabGL Entry` where company=%(company)s {conditions} - {distributed_cost_center_query} {order_by_statement} - """.format( - dimension_fields=dimension_fields, select_fields=select_fields, conditions=get_conditions(filters), distributed_cost_center_query=distributed_cost_center_query, - order_by_statement=order_by_statement - ), - filters, as_dict=1) + """.format( + dimension_fields=dimension_fields, select_fields=select_fields, + conditions=get_conditions(filters), order_by_statement=order_by_statement + ), filters, as_dict=1) if filters.get('presentation_currency'): return convert_to_presentation_currency(gl_entries, currency_map, filters.get('company')) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.js b/erpnext/accounts/report/gross_profit/gross_profit.js index 685f2d6176b..158ff4d3437 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.js +++ b/erpnext/accounts/report/gross_profit/gross_profit.js @@ -8,20 +8,22 @@ frappe.query_reports["Gross Profit"] = { "label": __("Company"), "fieldtype": "Link", "options": "Company", - "reqd": 1, - "default": frappe.defaults.get_user_default("Company") + "default": frappe.defaults.get_user_default("Company"), + "reqd": 1 }, { "fieldname":"from_date", "label": __("From Date"), "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_start_date") + "default": frappe.defaults.get_user_default("year_start_date"), + "reqd": 1 }, { "fieldname":"to_date", "label": __("To Date"), "fieldtype": "Date", - "default": frappe.defaults.get_user_default("year_end_date") + "default": frappe.defaults.get_user_default("year_end_date"), + "reqd": 1 }, { "fieldname":"sales_invoice", @@ -42,6 +44,11 @@ frappe.query_reports["Gross Profit"] = { "parent_field": "parent_invoice", "initial_depth": 3, "formatter": function(value, row, column, data, default_formatter) { + if (column.fieldname == "sales_invoice" && column.options == "Item" && data.indent == 0) { + column._options = "Sales Invoice"; + } else { + column._options = "Item"; + } value = default_formatter(value, row, column, data); if (data && (data.indent == 0.0 || row[1].content == "Total")) { diff --git a/erpnext/accounts/report/gross_profit/gross_profit.json b/erpnext/accounts/report/gross_profit/gross_profit.json index 76c560ad247..0730ffd77e5 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.json +++ b/erpnext/accounts/report/gross_profit/gross_profit.json @@ -1,5 +1,5 @@ { - "add_total_row": 0, + "add_total_row": 1, "columns": [], "creation": "2013-02-25 17:03:34", "disable_prepared_report": 0, @@ -9,7 +9,7 @@ "filters": [], "idx": 3, "is_standard": "Yes", - "modified": "2021-11-13 19:14:23.730198", + "modified": "2022-02-11 10:18:36.956558", "modified_by": "Administrator", "module": "Accounts", "name": "Gross Profit", diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 84effc0f467..b03bb9bb13f 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -70,43 +70,42 @@ def get_data_when_grouped_by_invoice(columns, gross_profit_data, filters, group_ data.append(row) def get_data_when_not_grouped_by_invoice(gross_profit_data, filters, group_wise_columns, data): - for idx, src in enumerate(gross_profit_data.grouped_data): + for src in gross_profit_data.grouped_data: row = [] for col in group_wise_columns.get(scrub(filters.group_by)): row.append(src.get(col)) row.append(filters.currency) - if idx == len(gross_profit_data.grouped_data)-1: - row[0] = "Total" data.append(row) def get_columns(group_wise_columns, filters): columns = [] column_map = frappe._dict({ - "parent": _("Sales Invoice") + ":Link/Sales Invoice:120", - "invoice_or_item": _("Sales Invoice") + ":Link/Sales Invoice:120", - "posting_date": _("Posting Date") + ":Date:100", - "posting_time": _("Posting Time") + ":Data:100", - "item_code": _("Item Code") + ":Link/Item:100", - "item_name": _("Item Name") + ":Data:100", - "item_group": _("Item Group") + ":Link/Item Group:100", - "brand": _("Brand") + ":Link/Brand:100", - "description": _("Description") +":Data:100", - "warehouse": _("Warehouse") + ":Link/Warehouse:100", - "qty": _("Qty") + ":Float:80", - "base_rate": _("Avg. Selling Rate") + ":Currency/currency:100", - "buying_rate": _("Valuation Rate") + ":Currency/currency:100", - "base_amount": _("Selling Amount") + ":Currency/currency:100", - "buying_amount": _("Buying Amount") + ":Currency/currency:100", - "gross_profit": _("Gross Profit") + ":Currency/currency:100", - "gross_profit_percent": _("Gross Profit %") + ":Percent:100", - "project": _("Project") + ":Link/Project:100", - "sales_person": _("Sales person"), - "allocated_amount": _("Allocated Amount") + ":Currency/currency:100", - "customer": _("Customer") + ":Link/Customer:100", - "customer_group": _("Customer Group") + ":Link/Customer Group:100", - "territory": _("Territory") + ":Link/Territory:100" + "parent": {"label": _('Sales Invoice'), "fieldname": "parent_invoice", "fieldtype": "Link", "options": "Sales Invoice", "width": 120}, + "invoice_or_item": {"label": _('Sales Invoice'), "fieldtype": "Link", "options": "Sales Invoice", "width": 120}, + "posting_date": {"label": _('Posting Date'), "fieldname": "posting_date", "fieldtype": "Date", "width": 100}, + "posting_time": {"label": _('Posting Time'), "fieldname": "posting_time", "fieldtype": "Data", "width": 100}, + "item_code": {"label": _('Item Code'), "fieldname": "item_code", "fieldtype": "Link", "options": "Item", "width": 100}, + "item_name": {"label": _('Item Name'), "fieldname": "item_name", "fieldtype": "Data", "width": 100}, + "item_group": {"label": _('Item Group'), "fieldname": "item_group", "fieldtype": "Link", "options": "Item Group", "width": 100}, + "brand": {"label": _('Brand'), "fieldtype": "Link", "options": "Brand", "width": 100}, + "description": {"label": _('Description'), "fieldname": "description", "fieldtype": "Data", "width": 100}, + "warehouse": {"label": _('Warehouse'), "fieldname": "warehouse", "fieldtype": "Link", "options": "warehouse", "width": 100}, + "qty": {"label": _('Qty'), "fieldname": "qty", "fieldtype": "Float", "width": 80}, + "base_rate": {"label": _('Avg. Selling Rate'), "fieldname": "avg._selling_rate", "fieldtype": "Currency", "options": "currency", "width": 100}, + "buying_rate": {"label": _('Valuation Rate'), "fieldname": "valuation_rate", "fieldtype": "Currency", "options": "currency", "width": 100}, + "base_amount": {"label": _('Selling Amount'), "fieldname": "selling_amount", "fieldtype": "Currency", "options": "currency", "width": 100}, + "buying_amount": {"label": _('Buying Amount'), "fieldname": "buying_amount", "fieldtype": "Currency", "options": "currency", "width": 100}, + "gross_profit": {"label": _('Gross Profit'), "fieldname": "gross_profit", "fieldtype": "Currency", "options": "currency", "width": 100}, + "gross_profit_percent": {"label": _('Gross Profit Percent'), "fieldname": "gross_profit_%", + "fieldtype": "Percent", "width": 100}, + "project": {"label": _('Project'), "fieldname": "project", "fieldtype": "Link", "options": "Project", "width": 100}, + "sales_person": {"label": _('Sales Person'), "fieldname": "sales_person", "fieldtype": "Data","width": 100}, + "allocated_amount": {"label": _('Allocated Amount'), "fieldname": "allocated_amount", "fieldtype": "Currency", "options": "currency", "width": 100}, + "customer": {"label": _('Customer'), "fieldname": "customer", "fieldtype": "Link", "options": "Customer", "width": 100}, + "customer_group": {"label": _('Customer Group'), "fieldname": "customer_group", "fieldtype": "Link", "options": "customer", "width": 100}, + "territory": {"label": _('Territory'), "fieldname": "territory", "fieldtype": "Link", "options": "territory", "width": 100}, }) for col in group_wise_columns.get(scrub(filters.group_by)): @@ -173,7 +172,7 @@ class GrossProfitGenerator(object): buying_amount = 0 for row in reversed(self.si_list): - if self.skip_row(row, self.product_bundles): + if self.skip_row(row): continue row.base_amount = flt(row.base_net_amount, self.currency_precision) @@ -223,16 +222,6 @@ class GrossProfitGenerator(object): self.get_average_rate_based_on_group_by() def get_average_rate_based_on_group_by(self): - # sum buying / selling totals for group - self.totals = frappe._dict( - qty=0, - base_amount=0, - buying_amount=0, - gross_profit=0, - gross_profit_percent=0, - base_rate=0, - buying_rate=0 - ) for key in list(self.grouped): if self.filters.get("group_by") != "Invoice": for i, row in enumerate(self.grouped[key]): @@ -244,7 +233,6 @@ class GrossProfitGenerator(object): new_row.base_amount += flt(row.base_amount, self.currency_precision) new_row = self.set_average_rate(new_row) self.grouped_data.append(new_row) - self.add_to_totals(new_row) else: for i, row in enumerate(self.grouped[key]): if row.indent == 1.0: @@ -258,17 +246,6 @@ class GrossProfitGenerator(object): if (flt(row.qty) or row.base_amount): row = self.set_average_rate(row) self.grouped_data.append(row) - self.add_to_totals(row) - - self.set_average_gross_profit(self.totals) - - if self.filters.get("group_by") == "Invoice": - self.totals.indent = 0.0 - self.totals.parent_invoice = "" - self.totals.invoice_or_item = "Total" - self.si_list.append(self.totals) - else: - self.grouped_data.append(self.totals) def is_not_invoice_row(self, row): return (self.filters.get("group_by") == "Invoice" and row.indent != 0.0) or self.filters.get("group_by") != "Invoice" @@ -284,11 +261,6 @@ class GrossProfitGenerator(object): new_row.gross_profit_percent = flt(((new_row.gross_profit / new_row.base_amount) * 100.0), self.currency_precision) \ if new_row.base_amount else 0 - def add_to_totals(self, new_row): - for key in self.totals: - if new_row.get(key): - self.totals[key] += new_row[key] - def get_returned_invoice_items(self): returned_invoices = frappe.db.sql(""" select @@ -306,12 +278,12 @@ class GrossProfitGenerator(object): self.returned_invoices.setdefault(inv.return_against, frappe._dict())\ .setdefault(inv.item_code, []).append(inv) - def skip_row(self, row, product_bundles): + def skip_row(self, row): if self.filters.get("group_by") != "Invoice": if not row.get(scrub(self.filters.get("group_by", ""))): return True - elif row.get("is_return") == 1: - return True + + return False def get_buying_amount_from_product_bundle(self, row, product_bundle): buying_amount = 0.0 @@ -369,20 +341,37 @@ class GrossProfitGenerator(object): return self.average_buying_rate[item_code] def get_last_purchase_rate(self, item_code, row): - condition = '' - if row.project: - condition += " AND a.project=%s" % (frappe.db.escape(row.project)) - elif row.cost_center: - condition += " AND a.cost_center=%s" % (frappe.db.escape(row.cost_center)) - if self.filters.to_date: - condition += " AND modified='%s'" % (self.filters.to_date) + purchase_invoice = frappe.qb.DocType("Purchase Invoice") + purchase_invoice_item = frappe.qb.DocType("Purchase Invoice Item") - last_purchase_rate = frappe.db.sql(""" - select (a.base_rate / a.conversion_factor) - from `tabPurchase Invoice Item` a - where a.item_code = %s and a.docstatus=1 - {0} - order by a.modified desc limit 1""".format(condition), item_code) + query = (frappe.qb.from_(purchase_invoice_item) + .inner_join( + purchase_invoice + ).on( + purchase_invoice.name == purchase_invoice_item.parent + ).select( + purchase_invoice_item.base_rate / purchase_invoice_item.conversion_factor + ).where( + purchase_invoice.docstatus == 1 + ).where( + purchase_invoice.posting_date <= self.filters.to_date + ).where( + purchase_invoice_item.item_code == item_code + )) + + if row.project: + query.where( + purchase_invoice_item.project == row.project + ) + + if row.cost_center: + query.where( + purchase_invoice_item.cost_center == row.cost_center + ) + + query.orderby(purchase_invoice.posting_date, order=frappe.qb.desc) + query.limit(1) + last_purchase_rate = query.run() return flt(last_purchase_rate[0][0]) if last_purchase_rate else 0 diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.py b/erpnext/accounts/report/profitability_analysis/profitability_analysis.py index 3dcb86267c1..f4b8731ba87 100644 --- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.py +++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.py @@ -109,7 +109,6 @@ def accumulate_values_into_parents(accounts, accounts_by_name): def prepare_data(accounts, filters, total_row, parent_children_map, based_on): data = [] - new_accounts = accounts company_currency = frappe.get_cached_value('Company', filters.get("company"), "default_currency") for d in accounts: @@ -123,19 +122,6 @@ def prepare_data(accounts, filters, total_row, parent_children_map, based_on): "currency": company_currency, "based_on": based_on } - if based_on == 'cost_center': - cost_center_doc = frappe.get_doc("Cost Center",d.name) - if not cost_center_doc.enable_distributed_cost_center: - DCC_allocation = frappe.db.sql("""SELECT parent, sum(percentage_allocation) as percentage_allocation - FROM `tabDistributed Cost Center` - WHERE cost_center IN %(cost_center)s - AND parent NOT IN %(cost_center)s - GROUP BY parent""",{'cost_center': [d.name]}) - if DCC_allocation: - for account in new_accounts: - if account['name'] == DCC_allocation[0][0]: - for value in value_fields: - d[value] += account[value]*(DCC_allocation[0][1]/100) for key in value_fields: row[key] = flt(d.get(key, 0.0), 3) diff --git a/erpnext/accounts/report/tax_detail/test_tax_detail.py b/erpnext/accounts/report/tax_detail/test_tax_detail.py index bf668ab779d..621de825ea3 100644 --- a/erpnext/accounts/report/tax_detail/test_tax_detail.py +++ b/erpnext/accounts/report/tax_detail/test_tax_detail.py @@ -61,7 +61,7 @@ class TestTaxDetail(unittest.TestCase): # Create GL Entries: db_doc.submit() else: - db_doc.insert() + db_doc.insert(ignore_if_duplicate=True) except frappe.exceptions.DuplicateEntryError: pass diff --git a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py index caee1a10bbb..e6cbff5d429 100644 --- a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py +++ b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py @@ -23,7 +23,7 @@ def validate_filters(filters): def get_result(filters, tds_docs, tds_accounts, tax_category_map): supplier_map = get_supplier_pan_map() tax_rate_map = get_tax_rate_map(filters) - gle_map = get_gle_map(filters, tds_docs) + gle_map = get_gle_map(tds_docs) out = [] for name, details in gle_map.items(): @@ -43,7 +43,7 @@ def get_result(filters, tds_docs, tds_accounts, tax_category_map): if entry.account in tds_accounts: tds_deducted += (entry.credit - entry.debit) - total_amount_credited += (entry.credit - entry.debit) + total_amount_credited += entry.credit if tds_deducted: row = { @@ -78,7 +78,7 @@ def get_supplier_pan_map(): return supplier_map -def get_gle_map(filters, documents): +def get_gle_map(documents): # create gle_map of the form # {"purchase_invoice": list of dict of all gle created for this invoice} gle_map = {} @@ -86,7 +86,7 @@ def get_gle_map(filters, documents): gle = frappe.db.get_all('GL Entry', { "voucher_no": ["in", documents], - "credit": (">", 0) + "is_cancelled": 0 }, ["credit", "debit", "account", "voucher_no", "posting_date", "voucher_type", "against", "party"], ) @@ -184,21 +184,28 @@ def get_tds_docs(filters): payment_entries = [] journal_entries = [] tax_category_map = {} + or_filters = {} + bank_accounts = frappe.get_all('Account', {'is_group': 0, 'account_type': 'Bank'}, pluck="name") tds_accounts = frappe.get_all("Tax Withholding Account", {'company': filters.get('company')}, pluck="account") query_filters = { - "credit": ('>', 0), "account": ("in", tds_accounts), "posting_date": ("between", [filters.get("from_date"), filters.get("to_date")]), - "is_cancelled": 0 + "is_cancelled": 0, + "against": ("not in", bank_accounts) } - if filters.get('supplier'): - query_filters.update({'against': filters.get('supplier')}) + if filters.get("supplier"): + del query_filters["account"] + del query_filters["against"] + or_filters = { + "against": filters.get('supplier'), + "party": filters.get('supplier') + } - tds_docs = frappe.get_all("GL Entry", query_filters, ["voucher_no", "voucher_type", "against", "party"]) + tds_docs = frappe.get_all("GL Entry", filters=query_filters, or_filters=or_filters, fields=["voucher_no", "voucher_type", "against", "party"]) for d in tds_docs: if d.voucher_type == "Purchase Invoice": diff --git a/erpnext/accounts/test/test_reports.py b/erpnext/accounts/test/test_reports.py index 78c109ab947..4ed966dcb9d 100644 --- a/erpnext/accounts/test/test_reports.py +++ b/erpnext/accounts/test/test_reports.py @@ -39,10 +39,11 @@ class TestReports(unittest.TestCase): def test_execute_all_accounts_reports(self): """Test that all script report in stock modules are executable with supported filters""" for report, filter in REPORT_FILTER_TEST_CASES: - execute_script_report( - report_name=report, - module="Accounts", - filters=filter, - default_filters=DEFAULT_FILTERS, - optional_filters=OPTIONAL_FILTERS if filter.get("_optional") else None, - ) + with self.subTest(report=report): + execute_script_report( + report_name=report, + module="Accounts", + filters=filter, + default_filters=DEFAULT_FILTERS, + optional_filters=OPTIONAL_FILTERS if filter.get("_optional") else None, + ) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 39e84e3ceff..b17b90ba6ee 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -847,7 +847,7 @@ def create_payment_gateway_account(gateway, payment_channel="Email"): "payment_account": bank_account.name, "currency": bank_account.account_currency, "payment_channel": payment_channel - }).insert(ignore_permissions=True) + }).insert(ignore_permissions=True, ignore_if_duplicate=True) except frappe.DuplicateEntryError: # already exists, due to a reinstall? diff --git a/erpnext/accounts/workspace/accounting/accounting.json b/erpnext/accounts/workspace/accounting/accounting.json index 203ea20882f..a456c7fb57a 100644 --- a/erpnext/accounts/workspace/accounting/accounting.json +++ b/erpnext/accounts/workspace/accounting/accounting.json @@ -1023,6 +1023,17 @@ "onboard": 0, "type": "Link" }, + { + "dependencies": "Cost Center", + "hidden": 0, + "is_query_report": 0, + "label": "Cost Center Allocation", + "link_count": 0, + "link_to": "Cost Center Allocation", + "link_type": "DocType", + "onboard": 0, + "type": "Link" + }, { "dependencies": "Cost Center", "hidden": 0, diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index 153f5c537a2..f414930d722 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -108,6 +108,10 @@ frappe.ui.form.on('Asset', { frm.trigger("create_asset_repair"); }, __("Manage")); + frm.add_custom_button(__("Split Asset"), function() { + frm.trigger("split_asset"); + }, __("Manage")); + if (frm.doc.status != 'Fully Depreciated') { frm.add_custom_button(__("Adjust Asset Value"), function() { frm.trigger("create_asset_value_adjustment"); @@ -322,6 +326,43 @@ frappe.ui.form.on('Asset', { }); }, + split_asset: function(frm) { + const title = __('Split Asset'); + + const fields = [ + { + fieldname: 'split_qty', + fieldtype: 'Int', + label: __('Split Qty'), + reqd: 1 + } + ]; + + let dialog = new frappe.ui.Dialog({ + title: title, + fields: fields + }); + + dialog.set_primary_action(__('Split'), function() { + const dialog_data = dialog.get_values(); + frappe.call({ + args: { + "asset_name": frm.doc.name, + "split_qty": cint(dialog_data.split_qty) + }, + method: "erpnext.assets.doctype.asset.asset.split_asset", + callback: function(r) { + let doclist = frappe.model.sync(r.message); + frappe.set_route("Form", doclist[0].doctype, doclist[0].name); + } + }); + + dialog.hide(); + }); + + dialog.show(); + }, + create_asset_value_adjustment: function(frm) { frappe.call({ args: { diff --git a/erpnext/assets/doctype/asset/asset.json b/erpnext/assets/doctype/asset/asset.json index de060757e2e..6e6bbf1cd29 100644 --- a/erpnext/assets/doctype/asset/asset.json +++ b/erpnext/assets/doctype/asset/asset.json @@ -3,7 +3,7 @@ "allow_import": 1, "allow_rename": 1, "autoname": "naming_series:", - "creation": "2016-03-01 17:01:27.920130", + "creation": "2022-01-18 02:26:55.975005", "doctype": "DocType", "document_type": "Document", "engine": "InnoDB", @@ -23,6 +23,7 @@ "asset_name", "asset_category", "location", + "split_from", "custodian", "department", "disposal_date", @@ -35,6 +36,7 @@ "available_for_use_date", "column_break_23", "gross_purchase_amount", + "asset_quantity", "purchase_date", "section_break_23", "calculate_depreciation", @@ -141,6 +143,7 @@ }, { "allow_on_submit": 1, + "fetch_from": "item_code.image", "fieldname": "image", "fieldtype": "Attach Image", "hidden": 1, @@ -480,6 +483,19 @@ "fieldname": "section_break_36", "fieldtype": "Section Break", "label": "Finance Books" + }, + { + "fieldname": "split_from", + "fieldtype": "Link", + "label": "Split From", + "options": "Asset", + "read_only": 1 + }, + { + "fieldname": "asset_quantity", + "fieldtype": "Int", + "label": "Asset Quantity", + "read_only_depends_on": "eval:!doc.is_existing_asset" } ], "idx": 72, @@ -502,10 +518,11 @@ "link_fieldname": "asset" } ], - "modified": "2021-06-24 14:58:51.097908", + "modified": "2022-01-30 20:19:24.680027", "modified_by": "Administrator", "module": "Assets", "name": "Asset", + "naming_rule": "By \"Naming Series\" field", "owner": "Administrator", "permissions": [ { @@ -542,6 +559,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "title_field": "asset_name", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index ee3ec8e63ac..ea473fa7bb5 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -36,8 +36,10 @@ class Asset(AccountsController): self.validate_asset_values() self.validate_asset_and_reference() self.validate_item() + self.validate_cost_center() self.set_missing_values() - self.prepare_depreciation_data() + if not self.split_from: + self.prepare_depreciation_data() self.validate_gross_and_purchase_amount() if self.get("schedules"): self.validate_expected_value_after_useful_life() @@ -95,6 +97,19 @@ class Asset(AccountsController): elif item.is_stock_item: frappe.throw(_("Item {0} must be a non-stock item").format(self.item_code)) + def validate_cost_center(self): + if not self.cost_center: return + + cost_center_company = frappe.db.get_value('Cost Center', self.cost_center, 'company') + if cost_center_company != self.company: + frappe.throw( + _("Selected Cost Center {} doesn't belongs to {}").format( + frappe.bold(self.cost_center), + frappe.bold(self.company) + ), + title=_("Invalid Cost Center") + ) + def validate_in_use_date(self): if not self.available_for_use_date: frappe.throw(_("Available for use date is required")) @@ -188,142 +203,143 @@ class Asset(AccountsController): start = self.clear_depreciation_schedule() for finance_book in self.get('finance_books'): - self.validate_asset_finance_books(finance_book) + self._make_depreciation_schedule(finance_book, start, date_of_sale) - # value_after_depreciation - current Asset value - if self.docstatus == 1 and finance_book.value_after_depreciation: - value_after_depreciation = flt(finance_book.value_after_depreciation) - else: - value_after_depreciation = (flt(self.gross_purchase_amount) - - flt(self.opening_accumulated_depreciation)) + def _make_depreciation_schedule(self, finance_book, start, date_of_sale): + self.validate_asset_finance_books(finance_book) - finance_book.value_after_depreciation = value_after_depreciation + value_after_depreciation = self._get_value_after_depreciation(finance_book) + finance_book.value_after_depreciation = value_after_depreciation - number_of_pending_depreciations = cint(finance_book.total_number_of_depreciations) - \ - cint(self.number_of_depreciations_booked) + number_of_pending_depreciations = cint(finance_book.total_number_of_depreciations) - \ + cint(self.number_of_depreciations_booked) - has_pro_rata = self.check_is_pro_rata(finance_book) + has_pro_rata = self.check_is_pro_rata(finance_book) + if has_pro_rata: + number_of_pending_depreciations += 1 - if has_pro_rata: - number_of_pending_depreciations += 1 + skip_row = False - skip_row = False + for n in range(start[finance_book.idx-1], number_of_pending_depreciations): + # If depreciation is already completed (for double declining balance) + if skip_row: continue - for n in range(start[finance_book.idx-1], number_of_pending_depreciations): - # If depreciation is already completed (for double declining balance) - if skip_row: continue + depreciation_amount = get_depreciation_amount(self, value_after_depreciation, finance_book) - depreciation_amount = get_depreciation_amount(self, value_after_depreciation, finance_book) + if not has_pro_rata or n < cint(number_of_pending_depreciations) - 1: + schedule_date = add_months(finance_book.depreciation_start_date, + n * cint(finance_book.frequency_of_depreciation)) - if not has_pro_rata or n < cint(number_of_pending_depreciations) - 1: - schedule_date = add_months(finance_book.depreciation_start_date, - n * cint(finance_book.frequency_of_depreciation)) + # schedule date will be a year later from start date + # so monthly schedule date is calculated by removing 11 months from it + monthly_schedule_date = add_months(schedule_date, - finance_book.frequency_of_depreciation + 1) - # schedule date will be a year later from start date - # so monthly schedule date is calculated by removing 11 months from it - monthly_schedule_date = add_months(schedule_date, - finance_book.frequency_of_depreciation + 1) - - # if asset is being sold - if date_of_sale: - from_date = self.get_from_date(finance_book.finance_book) - depreciation_amount, days, months = self.get_pro_rata_amt(finance_book, depreciation_amount, - from_date, date_of_sale) - - if depreciation_amount > 0: - self.append("schedules", { - "schedule_date": date_of_sale, - "depreciation_amount": depreciation_amount, - "depreciation_method": finance_book.depreciation_method, - "finance_book": finance_book.finance_book, - "finance_book_id": finance_book.idx - }) - - break - - # For first row - if has_pro_rata and not self.opening_accumulated_depreciation and n==0: - depreciation_amount, days, months = self.get_pro_rata_amt(finance_book, depreciation_amount, - self.available_for_use_date, finance_book.depreciation_start_date) - - # For first depr schedule date will be the start date - # so monthly schedule date is calculated by removing month difference between use date and start date - monthly_schedule_date = add_months(finance_book.depreciation_start_date, - months + 1) - - # For last row - elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1: - if not self.flags.increase_in_asset_life: - # In case of increase_in_asset_life, the self.to_date is already set on asset_repair submission - self.to_date = add_months(self.available_for_use_date, - (n + self.number_of_depreciations_booked) * cint(finance_book.frequency_of_depreciation)) - - depreciation_amount_without_pro_rata = depreciation_amount - - depreciation_amount, days, months = self.get_pro_rata_amt(finance_book, - depreciation_amount, schedule_date, self.to_date) - - depreciation_amount = self.get_adjusted_depreciation_amount(depreciation_amount_without_pro_rata, - depreciation_amount, finance_book.finance_book) - - monthly_schedule_date = add_months(schedule_date, 1) - schedule_date = add_days(schedule_date, days) - last_schedule_date = schedule_date - - if not depreciation_amount: continue - value_after_depreciation -= flt(depreciation_amount, - self.precision("gross_purchase_amount")) - - # Adjust depreciation amount in the last period based on the expected value after useful life - if finance_book.expected_value_after_useful_life and ((n == cint(number_of_pending_depreciations) - 1 - and value_after_depreciation != finance_book.expected_value_after_useful_life) - or value_after_depreciation < finance_book.expected_value_after_useful_life): - depreciation_amount += (value_after_depreciation - finance_book.expected_value_after_useful_life) - skip_row = True + # if asset is being sold + if date_of_sale: + from_date = self.get_from_date(finance_book.finance_book) + depreciation_amount, days, months = self.get_pro_rata_amt(finance_book, depreciation_amount, + from_date, date_of_sale) if depreciation_amount > 0: - # With monthly depreciation, each depreciation is divided by months remaining until next date - if self.allow_monthly_depreciation: - # month range is 1 to 12 - # In pro rata case, for first and last depreciation, month range would be different - month_range = months \ - if (has_pro_rata and n==0) or (has_pro_rata and n == cint(number_of_pending_depreciations) - 1) \ - else finance_book.frequency_of_depreciation + self._add_depreciation_row(date_of_sale, depreciation_amount, finance_book.depreciation_method, + finance_book.finance_book, finance_book.idx) - for r in range(month_range): - if (has_pro_rata and n == 0): - # For first entry of monthly depr - if r == 0: - days_until_first_depr = date_diff(monthly_schedule_date, self.available_for_use_date) - per_day_amt = depreciation_amount / days - depreciation_amount_for_current_month = per_day_amt * days_until_first_depr - depreciation_amount -= depreciation_amount_for_current_month - date = monthly_schedule_date - amount = depreciation_amount_for_current_month - else: - date = add_months(monthly_schedule_date, r) - amount = depreciation_amount / (month_range - 1) - elif (has_pro_rata and n == cint(number_of_pending_depreciations) - 1) and r == cint(month_range) - 1: - # For last entry of monthly depr - date = last_schedule_date - amount = depreciation_amount / month_range + break + + # For first row + if has_pro_rata and not self.opening_accumulated_depreciation and n==0: + from_date = add_days(self.available_for_use_date, -1) # needed to calc depr amount for available_for_use_date too + depreciation_amount, days, months = self.get_pro_rata_amt(finance_book, depreciation_amount, + from_date, finance_book.depreciation_start_date) + + # For first depr schedule date will be the start date + # so monthly schedule date is calculated by removing month difference between use date and start date + monthly_schedule_date = add_months(finance_book.depreciation_start_date, - months + 1) + + # For last row + elif has_pro_rata and n == cint(number_of_pending_depreciations) - 1: + if not self.flags.increase_in_asset_life: + # In case of increase_in_asset_life, the self.to_date is already set on asset_repair submission + self.to_date = add_months(self.available_for_use_date, + (n + self.number_of_depreciations_booked) * cint(finance_book.frequency_of_depreciation)) + + depreciation_amount_without_pro_rata = depreciation_amount + + depreciation_amount, days, months = self.get_pro_rata_amt(finance_book, + depreciation_amount, schedule_date, self.to_date) + + depreciation_amount = self.get_adjusted_depreciation_amount(depreciation_amount_without_pro_rata, + depreciation_amount, finance_book.finance_book) + + monthly_schedule_date = add_months(schedule_date, 1) + schedule_date = add_days(schedule_date, days) + last_schedule_date = schedule_date + + if not depreciation_amount: continue + value_after_depreciation -= flt(depreciation_amount, + self.precision("gross_purchase_amount")) + + # Adjust depreciation amount in the last period based on the expected value after useful life + if finance_book.expected_value_after_useful_life and ((n == cint(number_of_pending_depreciations) - 1 + and value_after_depreciation != finance_book.expected_value_after_useful_life) + or value_after_depreciation < finance_book.expected_value_after_useful_life): + depreciation_amount += (value_after_depreciation - finance_book.expected_value_after_useful_life) + skip_row = True + + if depreciation_amount > 0: + # With monthly depreciation, each depreciation is divided by months remaining until next date + if self.allow_monthly_depreciation: + # month range is 1 to 12 + # In pro rata case, for first and last depreciation, month range would be different + month_range = months \ + if (has_pro_rata and n==0) or (has_pro_rata and n == cint(number_of_pending_depreciations) - 1) \ + else finance_book.frequency_of_depreciation + + for r in range(month_range): + if (has_pro_rata and n == 0): + # For first entry of monthly depr + if r == 0: + days_until_first_depr = date_diff(monthly_schedule_date, self.available_for_use_date) + per_day_amt = depreciation_amount / days + depreciation_amount_for_current_month = per_day_amt * days_until_first_depr + depreciation_amount -= depreciation_amount_for_current_month + date = monthly_schedule_date + amount = depreciation_amount_for_current_month else: date = add_months(monthly_schedule_date, r) - amount = depreciation_amount / month_range + amount = depreciation_amount / (month_range - 1) + elif (has_pro_rata and n == cint(number_of_pending_depreciations) - 1) and r == cint(month_range) - 1: + # For last entry of monthly depr + date = last_schedule_date + amount = depreciation_amount / month_range + else: + date = add_months(monthly_schedule_date, r) + amount = depreciation_amount / month_range - self.append("schedules", { - "schedule_date": date, - "depreciation_amount": amount, - "depreciation_method": finance_book.depreciation_method, - "finance_book": finance_book.finance_book, - "finance_book_id": finance_book.idx - }) - else: - self.append("schedules", { - "schedule_date": schedule_date, - "depreciation_amount": depreciation_amount, - "depreciation_method": finance_book.depreciation_method, - "finance_book": finance_book.finance_book, - "finance_book_id": finance_book.idx - }) + self._add_depreciation_row(date, amount, finance_book.depreciation_method, + finance_book.finance_book, finance_book.idx) + else: + self._add_depreciation_row(schedule_date, depreciation_amount, finance_book.depreciation_method, + finance_book.finance_book, finance_book.idx) + + def _add_depreciation_row(self, schedule_date, depreciation_amount, depreciation_method, finance_book, finance_book_id): + self.append("schedules", { + "schedule_date": schedule_date, + "depreciation_amount": depreciation_amount, + "depreciation_method": depreciation_method, + "finance_book": finance_book, + "finance_book_id": finance_book_id + }) + + def _get_value_after_depreciation(self, finance_book): + # value_after_depreciation - current Asset value + if self.docstatus == 1 and finance_book.value_after_depreciation: + value_after_depreciation = flt(finance_book.value_after_depreciation) + else: + value_after_depreciation = (flt(self.gross_purchase_amount) - + flt(self.opening_accumulated_depreciation)) + + return value_after_depreciation # depreciation schedules need to be cleared before modification due to increase in asset life/asset sales # JE: Journal Entry, FB: Finance Book @@ -333,7 +349,6 @@ class Asset(AccountsController): depr_schedule = [] for schedule in self.get('schedules'): - # to update start when there are JEs linked with all the schedule rows corresponding to an FB if len(start) == (int(schedule.finance_book_id) - 2): start.append(num_of_depreciations_completed) @@ -374,7 +389,9 @@ class Asset(AccountsController): if from_date: return from_date - return self.available_for_use_date + + # since depr for available_for_use_date is not yet booked + return add_days(self.available_for_use_date, -1) # if it returns True, depreciation_amount will not be equal for the first and last rows def check_is_pro_rata(self, row): @@ -400,11 +417,12 @@ class Asset(AccountsController): def validate_asset_finance_books(self, row): if flt(row.expected_value_after_useful_life) >= flt(self.gross_purchase_amount): frappe.throw(_("Row {0}: Expected Value After Useful Life must be less than Gross Purchase Amount") - .format(row.idx)) + .format(row.idx), title=_("Invalid Schedule")) if not row.depreciation_start_date: if not self.available_for_use_date: - frappe.throw(_("Row {0}: Depreciation Start Date is required").format(row.idx)) + frappe.throw(_("Row {0}: Depreciation Start Date is required") + .format(row.idx), title=_("Invalid Schedule")) row.depreciation_start_date = get_last_day(self.available_for_use_date) if not self.is_existing_asset: @@ -422,8 +440,9 @@ class Asset(AccountsController): else: self.number_of_depreciations_booked = 0 - if cint(self.number_of_depreciations_booked) > cint(row.total_number_of_depreciations): - frappe.throw(_("Number of Depreciations Booked cannot be greater than Total Number of Depreciations")) + if flt(row.total_number_of_depreciations) <= cint(self.number_of_depreciations_booked): + frappe.throw(_("Row {0}: Total Number of Depreciations cannot be less than or equal to Number of Depreciations Booked") + .format(row.idx), title=_("Invalid Schedule")) if row.depreciation_start_date and getdate(row.depreciation_start_date) < getdate(self.purchase_date): frappe.throw(_("Depreciation Row {0}: Next Depreciation Date cannot be before Purchase Date") @@ -907,3 +926,113 @@ def get_depreciation_amount(asset, depreciable_value, row): depreciation_amount = flt(depreciable_value * (flt(row.rate_of_depreciation) / 100)) return depreciation_amount + +@frappe.whitelist() +def split_asset(asset_name, split_qty): + asset = frappe.get_doc("Asset", asset_name) + split_qty = cint(split_qty) + + if split_qty >= asset.asset_quantity: + frappe.throw(_("Split qty cannot be grater than or equal to asset qty")) + + remaining_qty = asset.asset_quantity - split_qty + + new_asset = create_new_asset_after_split(asset, split_qty) + update_existing_asset(asset, remaining_qty) + + return new_asset + +def update_existing_asset(asset, remaining_qty): + remaining_gross_purchase_amount = flt((asset.gross_purchase_amount * remaining_qty) / asset.asset_quantity) + opening_accumulated_depreciation = flt((asset.opening_accumulated_depreciation * remaining_qty) / asset.asset_quantity) + + frappe.db.set_value("Asset", asset.name, { + 'opening_accumulated_depreciation': opening_accumulated_depreciation, + 'gross_purchase_amount': remaining_gross_purchase_amount, + 'asset_quantity': remaining_qty + }) + + for finance_book in asset.get('finance_books'): + value_after_depreciation = flt((finance_book.value_after_depreciation * remaining_qty)/asset.asset_quantity) + expected_value_after_useful_life = flt((finance_book.expected_value_after_useful_life * remaining_qty)/asset.asset_quantity) + frappe.db.set_value('Asset Finance Book', finance_book.name, 'value_after_depreciation', value_after_depreciation) + frappe.db.set_value('Asset Finance Book', finance_book.name, 'expected_value_after_useful_life', expected_value_after_useful_life) + + accumulated_depreciation = 0 + + for term in asset.get('schedules'): + depreciation_amount = flt((term.depreciation_amount * remaining_qty)/asset.asset_quantity) + frappe.db.set_value('Depreciation Schedule', term.name, 'depreciation_amount', depreciation_amount) + accumulated_depreciation += depreciation_amount + frappe.db.set_value('Depreciation Schedule', term.name, 'accumulated_depreciation_amount', accumulated_depreciation) + +def create_new_asset_after_split(asset, split_qty): + new_asset = frappe.copy_doc(asset) + new_gross_purchase_amount = flt((asset.gross_purchase_amount * split_qty) / asset.asset_quantity) + opening_accumulated_depreciation = flt((asset.opening_accumulated_depreciation * split_qty) / asset.asset_quantity) + + new_asset.gross_purchase_amount = new_gross_purchase_amount + new_asset.opening_accumulated_depreciation = opening_accumulated_depreciation + new_asset.asset_quantity = split_qty + new_asset.split_from = asset.name + accumulated_depreciation = 0 + + for finance_book in new_asset.get('finance_books'): + finance_book.value_after_depreciation = flt((finance_book.value_after_depreciation * split_qty)/asset.asset_quantity) + finance_book.expected_value_after_useful_life = flt((finance_book.expected_value_after_useful_life * split_qty)/asset.asset_quantity) + + for term in new_asset.get('schedules'): + depreciation_amount = flt((term.depreciation_amount * split_qty)/asset.asset_quantity) + term.depreciation_amount = depreciation_amount + accumulated_depreciation += depreciation_amount + term.accumulated_depreciation_amount = accumulated_depreciation + + new_asset.submit() + new_asset.set_status() + + for term in new_asset.get('schedules'): + # Update references in JV + if term.journal_entry: + add_reference_in_jv_on_split(term.journal_entry, new_asset.name, asset.name, term.depreciation_amount) + + return new_asset + +def add_reference_in_jv_on_split(entry_name, new_asset_name, old_asset_name, depreciation_amount): + journal_entry = frappe.get_doc('Journal Entry', entry_name) + entries_to_add = [] + idx = len(journal_entry.get('accounts')) + 1 + + for account in journal_entry.get('accounts'): + if account.reference_name == old_asset_name: + entries_to_add.append(frappe.copy_doc(account).as_dict()) + if account.credit: + account.credit = account.credit - depreciation_amount + account.credit_in_account_currency = account.credit_in_account_currency - \ + account.exchange_rate * depreciation_amount + elif account.debit: + account.debit = account.debit - depreciation_amount + account.debit_in_account_currency = account.debit_in_account_currency - \ + account.exchange_rate * depreciation_amount + + for entry in entries_to_add: + entry.reference_name = new_asset_name + if entry.credit: + entry.credit = depreciation_amount + entry.credit_in_account_currency = entry.exchange_rate * depreciation_amount + elif entry.debit: + entry.debit = depreciation_amount + entry.debit_in_account_currency = entry.exchange_rate * depreciation_amount + + entry.idx = idx + idx += 1 + + journal_entry.append('accounts', entry) + + journal_entry.flags.ignore_validate_update_after_submit = True + journal_entry.save() + + # Repost GL Entries + journal_entry.docstatus = 2 + journal_entry.make_gl_entries(1) + journal_entry.docstatus = 1 + journal_entry.make_gl_entries() \ No newline at end of file diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 44c4ce542d0..ffd1065efc0 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -7,7 +7,7 @@ import frappe from frappe.utils import add_days, add_months, cstr, flt, get_last_day, getdate, nowdate from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice -from erpnext.assets.doctype.asset.asset import make_sales_invoice +from erpnext.assets.doctype.asset.asset import make_sales_invoice, split_asset from erpnext.assets.doctype.asset.depreciation import ( post_depreciation_entries, restore_asset, @@ -134,6 +134,29 @@ class TestAsset(AssetSetup): pr.cancel() self.assertEqual(asset.docstatus, 2) + def test_purchase_of_grouped_asset(self): + create_fixed_asset_item("Rack", is_grouped_asset=1) + pr = make_purchase_receipt(item_code="Rack", qty=3, rate=100000.0, location="Test Location") + + asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name') + asset = frappe.get_doc('Asset', asset_name) + self.assertEqual(asset.asset_quantity, 3) + asset.calculate_depreciation = 1 + + month_end_date = get_last_day(nowdate()) + purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15) + + asset.available_for_use_date = purchase_date + asset.purchase_date = purchase_date + asset.append("finance_books", { + "expected_value_after_useful_life": 10000, + "depreciation_method": "Straight Line", + "total_number_of_depreciations": 3, + "frequency_of_depreciation": 10, + "depreciation_start_date": month_end_date + }) + asset.submit() + def test_is_fixed_asset_set(self): asset = create_asset(is_existing_asset = 1) doc = frappe.new_doc('Purchase Invoice') @@ -207,9 +230,9 @@ class TestAsset(AssetSetup): self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Sold") expected_gle = ( - ("_Test Accumulated Depreciations - _TC", 20392.16, 0.0), + ("_Test Accumulated Depreciations - _TC", 20490.2, 0.0), ("_Test Fixed Asset - _TC", 0.0, 100000.0), - ("_Test Gain/Loss on Asset Disposal - _TC", 54607.84, 0.0), + ("_Test Gain/Loss on Asset Disposal - _TC", 54509.8, 0.0), ("Debtors - _TC", 25000.0, 0.0) ) @@ -222,6 +245,57 @@ class TestAsset(AssetSetup): si.cancel() self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Partially Depreciated") + def test_asset_splitting(self): + asset = create_asset( + calculate_depreciation = 1, + asset_quantity=10, + available_for_use_date = '2020-01-01', + purchase_date = '2020-01-01', + expected_value_after_useful_life = 0, + total_number_of_depreciations = 6, + number_of_depreciations_booked = 1, + frequency_of_depreciation = 10, + depreciation_start_date = '2021-01-01', + opening_accumulated_depreciation=20000, + gross_purchase_amount=120000, + submit = 1 + ) + + post_depreciation_entries(date="2021-01-01") + + self.assertEqual(asset.asset_quantity, 10) + self.assertEqual(asset.gross_purchase_amount, 120000) + self.assertEqual(asset.opening_accumulated_depreciation, 20000) + + new_asset = split_asset(asset.name, 2) + asset.load_from_db() + + self.assertEqual(new_asset.asset_quantity, 2) + self.assertEqual(new_asset.gross_purchase_amount, 24000) + self.assertEqual(new_asset.opening_accumulated_depreciation, 4000) + self.assertEqual(new_asset.split_from, asset.name) + self.assertEqual(new_asset.schedules[0].depreciation_amount, 4000) + self.assertEqual(new_asset.schedules[1].depreciation_amount, 4000) + + self.assertEqual(asset.asset_quantity, 8) + self.assertEqual(asset.gross_purchase_amount, 96000) + self.assertEqual(asset.opening_accumulated_depreciation, 16000) + self.assertEqual(asset.schedules[0].depreciation_amount, 16000) + self.assertEqual(asset.schedules[1].depreciation_amount, 16000) + + journal_entry = asset.schedules[0].journal_entry + + jv = frappe.get_doc('Journal Entry', journal_entry) + self.assertEqual(jv.accounts[0].credit_in_account_currency, 16000) + self.assertEqual(jv.accounts[1].debit_in_account_currency, 16000) + self.assertEqual(jv.accounts[2].credit_in_account_currency, 4000) + self.assertEqual(jv.accounts[3].debit_in_account_currency, 4000) + + self.assertEqual(jv.accounts[0].reference_name, asset.name) + self.assertEqual(jv.accounts[1].reference_name, asset.name) + self.assertEqual(jv.accounts[2].reference_name, new_asset.name) + self.assertEqual(jv.accounts[3].reference_name, new_asset.name) + def test_expense_head(self): pr = make_purchase_receipt(item_code="Macbook Pro", qty=2, rate=200000.0, location="Test Location") @@ -491,10 +565,10 @@ class TestDepreciationMethods(AssetSetup): ) expected_schedules = [ - ["2030-12-31", 27534.25, 27534.25], - ["2031-12-31", 30000.0, 57534.25], - ["2032-12-31", 30000.0, 87534.25], - ["2033-01-30", 2465.75, 90000.0] + ['2030-12-31', 27616.44, 27616.44], + ['2031-12-31', 30000.0, 57616.44], + ['2032-12-31', 30000.0, 87616.44], + ['2033-01-30', 2383.56, 90000.0] ] schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] @@ -544,10 +618,10 @@ class TestDepreciationMethods(AssetSetup): self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0) expected_schedules = [ - ["2030-12-31", 28493.15, 28493.15], - ["2031-12-31", 35753.43, 64246.58], - ["2032-12-31", 17876.71, 82123.29], - ["2033-06-06", 5376.71, 87500.0] + ['2030-12-31', 28630.14, 28630.14], + ['2031-12-31', 35684.93, 64315.07], + ['2032-12-31', 17842.47, 82157.54], + ['2033-06-06', 5342.46, 87500.0] ] schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] @@ -580,10 +654,10 @@ class TestDepreciationMethods(AssetSetup): self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0) expected_schedules = [ - ["2030-12-31", 11780.82, 11780.82], - ["2031-12-31", 44109.59, 55890.41], - ["2032-12-31", 22054.8, 77945.21], - ["2033-07-12", 9554.79, 87500.0] + ["2030-12-31", 11849.32, 11849.32], + ["2031-12-31", 44075.34, 55924.66], + ["2032-12-31", 22037.67, 77962.33], + ["2033-07-12", 9537.67, 87500.0] ] schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)] @@ -621,7 +695,7 @@ class TestDepreciationBasics(AssetSetup): asset = create_asset( item_code = "Macbook Pro", calculate_depreciation = 1, - available_for_use_date = getdate("2019-12-31"), + available_for_use_date = getdate("2020-01-01"), total_number_of_depreciations = 3, expected_value_after_useful_life = 10000, depreciation_start_date = getdate("2020-07-01"), @@ -632,7 +706,7 @@ class TestDepreciationBasics(AssetSetup): ["2020-07-01", 15000, 15000], ["2021-07-01", 30000, 45000], ["2022-07-01", 30000, 75000], - ["2022-12-31", 15000, 90000] + ["2023-01-01", 15000, 90000] ] for i, schedule in enumerate(asset.schedules): @@ -799,8 +873,9 @@ class TestDepreciationBasics(AssetSetup): self.assertRaises(frappe.ValidationError, asset.save) def test_number_of_depreciations(self): - """Tests if an error is raised when number_of_depreciations_booked > total_number_of_depreciations.""" + """Tests if an error is raised when number_of_depreciations_booked >= total_number_of_depreciations.""" + # number_of_depreciations_booked > total_number_of_depreciations asset = create_asset( item_code = "Macbook Pro", calculate_depreciation = 1, @@ -815,6 +890,21 @@ class TestDepreciationBasics(AssetSetup): self.assertRaises(frappe.ValidationError, asset.save) + # number_of_depreciations_booked = total_number_of_depreciations + asset_2 = create_asset( + item_code = "Macbook Pro", + calculate_depreciation = 1, + available_for_use_date = "2019-12-31", + total_number_of_depreciations = 5, + expected_value_after_useful_life = 10000, + depreciation_start_date = "2020-07-01", + opening_accumulated_depreciation = 10000, + number_of_depreciations_booked = 5, + do_not_save = 1 + ) + + self.assertRaises(frappe.ValidationError, asset_2.save) + def test_depreciation_start_date_is_before_purchase_date(self): asset = create_asset( item_code = "Macbook Pro", @@ -1109,6 +1199,7 @@ class TestDepreciationBasics(AssetSetup): self.assertEqual(gle, expected_gle) self.assertEqual(asset.get("value_after_depreciation"), 0) + def test_expected_value_change(self): """ tests if changing `expected_value_after_useful_life` @@ -1130,6 +1221,15 @@ class TestDepreciationBasics(AssetSetup): asset.reload() self.assertEquals(asset.finance_books[0].value_after_depreciation, 98000.0) + def test_asset_cost_center(self): + asset = create_asset(is_existing_asset = 1, do_not_save=1) + asset.cost_center = "Main - WP" + + self.assertRaises(frappe.ValidationError, asset.submit) + + asset.cost_center = "Main - _TC" + asset.submit() + def create_asset_data(): if not frappe.db.exists("Asset Category", "Computers"): create_asset_category() @@ -1164,7 +1264,8 @@ def create_asset(**args): "available_for_use_date": args.available_for_use_date or "2020-06-06", "location": args.location or "Test Location", "asset_owner": args.asset_owner or "Company", - "is_existing_asset": args.is_existing_asset or 1 + "is_existing_asset": args.is_existing_asset or 1, + "asset_quantity": args.get("asset_quantity") or 1 }) if asset.calculate_depreciation: @@ -1179,7 +1280,7 @@ def create_asset(**args): if not args.do_not_save: try: - asset.save() + asset.insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass @@ -1202,13 +1303,13 @@ def create_asset_category(): }) asset_category.insert() -def create_fixed_asset_item(): +def create_fixed_asset_item(item_code=None, auto_create_assets=1, is_grouped_asset=0): meta = frappe.get_meta('Asset') naming_series = meta.get_field("naming_series").options.splitlines()[0] or 'ACC-ASS-.YYYY.-' try: - frappe.get_doc({ + item = frappe.get_doc({ "doctype": "Item", - "item_code": "Macbook Pro", + "item_code": item_code or "Macbook Pro", "item_name": "Macbook Pro", "description": "Macbook Pro Retina Display", "asset_category": "Computers", @@ -1216,11 +1317,14 @@ def create_fixed_asset_item(): "stock_uom": "Nos", "is_stock_item": 0, "is_fixed_asset": 1, - "auto_create_assets": 1, + "auto_create_assets": auto_create_assets, + "is_grouped_asset": is_grouped_asset, "asset_naming_series": naming_series - }).insert() + }) + item.insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass + return item def set_depreciation_settings_in_company(): company = frappe.get_doc("Company", "_Test Company") diff --git a/erpnext/assets/doctype/asset_category/test_asset_category.py b/erpnext/assets/doctype/asset_category/test_asset_category.py index 3d19fa39d1e..2f52248edb0 100644 --- a/erpnext/assets/doctype/asset_category/test_asset_category.py +++ b/erpnext/assets/doctype/asset_category/test_asset_category.py @@ -23,7 +23,7 @@ class TestAssetCategory(unittest.TestCase): }) try: - asset_category.insert() + asset_category.insert(ignore_if_duplicate=True) except frappe.DuplicateEntryError: pass diff --git a/erpnext/demo/setup/__init__.py b/erpnext/bulk_transaction/__init__.py similarity index 100% rename from erpnext/demo/setup/__init__.py rename to erpnext/bulk_transaction/__init__.py diff --git a/erpnext/demo/user/__init__.py b/erpnext/bulk_transaction/doctype/__init__.py similarity index 100% rename from erpnext/demo/user/__init__.py rename to erpnext/bulk_transaction/doctype/__init__.py diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/__init__.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log/__init__.py similarity index 100% rename from erpnext/erpnext_integrations/doctype/amazon_mws_settings/__init__.py rename to erpnext/bulk_transaction/doctype/bulk_transaction_log/__init__.py diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.js b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.js new file mode 100644 index 00000000000..a739cc37306 --- /dev/null +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.js @@ -0,0 +1,34 @@ +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Bulk Transaction Log', { + + before_load: function(frm) { + query(frm); + }, + + refresh: function(frm) { + frm.disable_save(); + frm.add_custom_button(__('Retry Failed Transactions'), ()=>{ + frappe.confirm(__("Retry Failing Transactions ?"), ()=>{ + query(frm); + } + ); + }); + } +}); + +function query(frm) { + frappe.call({ + method: "erpnext.bulk_transaction.doctype.bulk_transaction_log.bulk_transaction_log.retry_failing_transaction", + args: { + log_date: frm.doc.log_date + } + }).then((r) => { + if (r.message) { + frm.remove_custom_button("Retry Failed Transactions"); + } else { + frappe.show_alert(__("Retrying Failed Transactions"), 5); + } + }); +} \ No newline at end of file diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.json b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.json new file mode 100644 index 00000000000..da42cf1bd4b --- /dev/null +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.json @@ -0,0 +1,51 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2021-11-30 13:41:16.343827", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "log_date", + "logger_data" + ], + "fields": [ + { + "fieldname": "log_date", + "fieldtype": "Date", + "label": "Log Date", + "read_only": 1 + }, + { + "fieldname": "logger_data", + "fieldtype": "Table", + "label": "Logger Data", + "options": "Bulk Transaction Log Detail" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-02-03 17:23:02.935325", + "modified_by": "Administrator", + "module": "Bulk Transaction", + "name": "Bulk Transaction Log", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.py new file mode 100644 index 00000000000..de7cde5a6d3 --- /dev/null +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/bulk_transaction_log.py @@ -0,0 +1,66 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from datetime import date + +import frappe +from frappe.model.document import Document + +from erpnext.utilities.bulk_transaction import task, update_logger + + +class BulkTransactionLog(Document): + pass + + +@frappe.whitelist() +def retry_failing_transaction(log_date=None): + btp = frappe.qb.DocType("Bulk Transaction Log Detail") + data = ( + frappe.qb.from_(btp) + .select(btp.transaction_name, btp.from_doctype, btp.to_doctype) + .distinct() + .where(btp.retried != 1) + .where(btp.transaction_status == "Failed") + .where(btp.date == log_date) + ).run(as_dict=True) + + if data: + if not log_date: + log_date = str(date.today()) + if len(data) > 10: + frappe.enqueue(job, queue="long", job_name="bulk_retry", data=data, log_date=log_date) + else: + job(data, log_date) + else: + return "No Failed Records" + +def job(data, log_date): + for d in data: + failed = [] + try: + frappe.db.savepoint("before_creation_of_record") + task(d.transaction_name, d.from_doctype, d.to_doctype) + except Exception as e: + frappe.db.rollback(save_point="before_creation_of_record") + failed.append(e) + update_logger( + d.transaction_name, + e, + d.from_doctype, + d.to_doctype, + status="Failed", + log_date=log_date, + restarted=1 + ) + + if not failed: + update_logger( + d.transaction_name, + None, + d.from_doctype, + d.to_doctype, + status="Success", + log_date=log_date, + restarted=1, + ) diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py new file mode 100644 index 00000000000..a78e697b6f9 --- /dev/null +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log/test_bulk_transaction_log.py @@ -0,0 +1,81 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt + +import unittest +from datetime import date + +import frappe + +from erpnext.utilities.bulk_transaction import transaction_processing + + +class TestBulkTransactionLog(unittest.TestCase): + + def setUp(self): + create_company() + create_customer() + create_item() + + def test_for_single_record(self): + so_name = create_so() + transaction_processing([{"name": so_name}], "Sales Order", "Sales Invoice") + data = frappe.db.get_list("Sales Invoice", filters = {"posting_date": date.today(), "customer": "Bulk Customer"}, fields=["*"]) + if not data: + self.fail("No Sales Invoice Created !") + + def test_entry_in_log(self): + so_name = create_so() + transaction_processing([{"name": so_name}], "Sales Order", "Sales Invoice") + doc = frappe.get_doc("Bulk Transaction Log", str(date.today())) + for d in doc.get("logger_data"): + if d.transaction_name == so_name: + self.assertEqual(d.transaction_name, so_name) + self.assertEqual(d.transaction_status, "Success") + self.assertEqual(d.from_doctype, "Sales Order") + self.assertEqual(d.to_doctype, "Sales Invoice") + self.assertEqual(d.retried, 0) + + + +def create_company(): + if not frappe.db.exists('Company', '_Test Company'): + frappe.get_doc({ + 'doctype': 'Company', + 'company_name': '_Test Company', + 'country': 'India', + 'default_currency': 'INR' + }).insert() + +def create_customer(): + if not frappe.db.exists('Customer', 'Bulk Customer'): + frappe.get_doc({ + 'doctype': 'Customer', + 'customer_name': 'Bulk Customer' + }).insert() + +def create_item(): + if not frappe.db.exists("Item", "MK"): + frappe.get_doc({ + "doctype": "Item", + "item_code": "MK", + "item_name": "Milk", + "description": "Milk", + "item_group": "Products" + }).insert() + +def create_so(intent=None): + so = frappe.new_doc("Sales Order") + so.customer = "Bulk Customer" + so.company = "_Test Company" + so.transaction_date = date.today() + + so.set_warehouse = "Finished Goods - _TC" + so.append("items", { + "item_code": "MK", + "delivery_date": date.today(), + "qty": 10, + "rate": 80, + }) + so.insert() + so.submit() + return so.name \ No newline at end of file diff --git a/erpnext/hotels/__init__.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/__init__.py similarity index 100% rename from erpnext/hotels/__init__.py rename to erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/__init__.py diff --git a/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/bulk_transaction_log_detail.json b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/bulk_transaction_log_detail.json new file mode 100644 index 00000000000..8262caa0209 --- /dev/null +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/bulk_transaction_log_detail.json @@ -0,0 +1,86 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2021-11-30 13:38:30.926047", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "transaction_name", + "date", + "time", + "transaction_status", + "error_description", + "from_doctype", + "to_doctype", + "retried" + ], + "fields": [ + { + "fieldname": "transaction_name", + "fieldtype": "Dynamic Link", + "in_list_view": 1, + "label": "Name", + "options": "from_doctype" + }, + { + "fieldname": "transaction_status", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Status", + "read_only": 1 + }, + { + "fieldname": "error_description", + "fieldtype": "Long Text", + "label": "Error Description", + "read_only": 1 + }, + { + "fieldname": "from_doctype", + "fieldtype": "Link", + "label": "From Doctype", + "options": "DocType", + "read_only": 1 + }, + { + "fieldname": "to_doctype", + "fieldtype": "Link", + "label": "To Doctype", + "options": "DocType", + "read_only": 1 + }, + { + "fieldname": "date", + "fieldtype": "Date", + "in_list_view": 1, + "label": "Date ", + "read_only": 1 + }, + { + "fieldname": "time", + "fieldtype": "Time", + "label": "Time", + "read_only": 1 + }, + { + "fieldname": "retried", + "fieldtype": "Int", + "label": "Retried", + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2022-02-03 19:57:31.650359", + "modified_by": "Administrator", + "module": "Bulk Transaction", + "name": "Bulk Transaction Log Detail", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.py b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/bulk_transaction_log_detail.py similarity index 78% rename from erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.py rename to erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/bulk_transaction_log_detail.py index bb7f07f6883..67795b9d490 100644 --- a/erpnext/regional/doctype/tax_exemption_80g_certificate_detail/tax_exemption_80g_certificate_detail.py +++ b/erpnext/bulk_transaction/doctype/bulk_transaction_log_detail/bulk_transaction_log_detail.py @@ -1,10 +1,9 @@ # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt - # import frappe from frappe.model.document import Document -class TaxExemption80GCertificateDetail(Document): +class BulkTransactionLogDetail(Document): pass diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json index b828a43d3cf..50321baa2e2 100644 --- a/erpnext/buying/doctype/buying_settings/buying_settings.json +++ b/erpnext/buying/doctype/buying_settings/buying_settings.json @@ -6,14 +6,17 @@ "document_type": "Other", "engine": "InnoDB", "field_order": [ + "supplier_and_price_defaults_section", "supp_master_name", "supplier_group", + "column_break_4", "buying_price_list", "maintain_same_rate_action", "role_to_override_stop_action", - "column_break_3", + "transaction_settings_section", "po_required", "pr_required", + "column_break_12", "maintain_same_rate", "allow_multiple_items", "bill_for_rejected_quantity_in_purchase_invoice", @@ -42,10 +45,6 @@ "label": "Default Buying Price List", "options": "Price List" }, - { - "fieldname": "column_break_3", - "fieldtype": "Column Break" - }, { "fieldname": "po_required", "fieldtype": "Select", @@ -73,7 +72,7 @@ { "fieldname": "subcontract", "fieldtype": "Section Break", - "label": "Subcontract" + "label": "Subcontracting Settings" }, { "default": "Material Transferred for Subcontract", @@ -116,6 +115,24 @@ "fieldname": "bill_for_rejected_quantity_in_purchase_invoice", "fieldtype": "Check", "label": "Bill for Rejected Quantity in Purchase Invoice" + }, + { + "fieldname": "supplier_and_price_defaults_section", + "fieldtype": "Section Break", + "label": "Supplier and Price Defaults" + }, + { + "fieldname": "column_break_4", + "fieldtype": "Column Break" + }, + { + "fieldname": "transaction_settings_section", + "fieldtype": "Section Break", + "label": "Transaction Settings" + }, + { + "fieldname": "column_break_12", + "fieldtype": "Column Break" } ], "icon": "fa fa-cog", @@ -123,7 +140,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-09-08 19:26:23.548837", + "modified": "2022-01-27 17:57:58.367048", "modified_by": "Administrator", "module": "Buying", "name": "Buying Settings", @@ -141,5 +158,6 @@ ], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order/purchase_order_list.js b/erpnext/buying/doctype/purchase_order/purchase_order_list.js index 8413eb65c3f..d7907e4274b 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order_list.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order_list.js @@ -29,8 +29,22 @@ frappe.listview_settings['Purchase Order'] = { listview.call_for_selected_items(method, { "status": "Closed" }); }); - listview.page.add_menu_item(__("Re-open"), function () { + listview.page.add_menu_item(__("Reopen"), function () { listview.call_for_selected_items(method, { "status": "Submitted" }); }); + + + listview.page.add_action_item(__("Purchase Invoice"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Purchase Invoice"); + }); + + listview.page.add_action_item(__("Purchase Receipt"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Purchase Receipt"); + }); + + listview.page.add_action_item(__("Advance Payment"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Purchase Order", "Advance Payment"); + }); + } }; diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 9a63afc1303..efa2ab12685 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -3,9 +3,9 @@ import json -import unittest import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import add_days, flt, getdate, nowdate from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry @@ -27,7 +27,7 @@ from erpnext.stock.doctype.purchase_receipt.purchase_receipt import ( from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry -class TestPurchaseOrder(unittest.TestCase): +class TestPurchaseOrder(FrappeTestCase): def test_make_purchase_receipt(self): po = create_purchase_order(do_not_submit=True) self.assertRaises(frappe.ValidationError, make_purchase_receipt, po.name) @@ -682,17 +682,18 @@ class TestPurchaseOrder(unittest.TestCase): bin1 = frappe.db.get_value("Bin", filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"}, - fieldname=["reserved_qty_for_sub_contract", "projected_qty"], as_dict=1) + fieldname=["reserved_qty_for_sub_contract", "projected_qty", "modified"], as_dict=1) # Submit PO po = create_purchase_order(item_code="_Test FG Item", is_subcontracted="Yes") bin2 = frappe.db.get_value("Bin", filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"}, - fieldname=["reserved_qty_for_sub_contract", "projected_qty"], as_dict=1) + fieldname=["reserved_qty_for_sub_contract", "projected_qty", "modified"], as_dict=1) self.assertEqual(bin2.reserved_qty_for_sub_contract, bin1.reserved_qty_for_sub_contract + 10) self.assertEqual(bin2.projected_qty, bin1.projected_qty - 10) + self.assertNotEqual(bin1.modified, bin2.modified) # Create stock transfer rm_item = [{"item_code":"_Test FG Item","rm_item_code":"_Test Item","item_name":"_Test Item", diff --git a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py index 51901991b5a..5b2112424c9 100644 --- a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py @@ -1,9 +1,9 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import nowdate from erpnext.buying.doctype.request_for_quotation.request_for_quotation import ( @@ -16,7 +16,7 @@ from erpnext.stock.doctype.item.test_item import make_item from erpnext.templates.pages.rfq import check_supplier_has_docname_access -class TestRequestforQuotation(unittest.TestCase): +class TestRequestforQuotation(FrappeTestCase): def test_quote_status(self): rfq = make_request_for_quotation() diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 14d2ccdb50d..4f9ff43cd43 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -131,28 +131,6 @@ class Supplier(TransactionBase): if frappe.defaults.get_global_default('supp_master_name') == 'Supplier Name': frappe.db.set(self, "supplier_name", newdn) - def create_onboarding_docs(self, args): - company = frappe.defaults.get_defaults().get('company') or \ - frappe.db.get_single_value('Global Defaults', 'default_company') - - for i in range(1, args.get('max_count')): - supplier = args.get('supplier_name_' + str(i)) - if supplier: - try: - doc = frappe.get_doc({ - 'doctype': self.doctype, - 'supplier_name': supplier, - 'supplier_group': _('Local'), - 'company': company - }).insert() - - if args.get('supplier_email_' + str(i)): - from erpnext.selling.doctype.customer.customer import create_contact - create_contact(supplier, 'Supplier', - doc.name, args.get('supplier_email_' + str(i))) - except frappe.NameError: - pass - @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs def get_supplier_primary_contact(doctype, txt, searchfield, start, page_len, filters): diff --git a/erpnext/buying/doctype/supplier/test_supplier.py b/erpnext/buying/doctype/supplier/test_supplier.py index 13fe9df13ee..7358e2af223 100644 --- a/erpnext/buying/doctype/supplier/test_supplier.py +++ b/erpnext/buying/doctype/supplier/test_supplier.py @@ -1,7 +1,6 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt -import unittest import frappe from frappe.test_runner import make_test_records @@ -12,153 +11,154 @@ from erpnext.exceptions import PartyDisabled test_dependencies = ['Payment Term', 'Payment Terms Template'] test_records = frappe.get_test_records('Supplier') +from frappe.tests.utils import FrappeTestCase -class TestSupplier(unittest.TestCase): - def test_get_supplier_group_details(self): - doc = frappe.new_doc("Supplier Group") - doc.supplier_group_name = "_Testing Supplier Group" - doc.payment_terms = "_Test Payment Term Template 3" - doc.accounts = [] - test_account_details = { - "company": "_Test Company", - "account": "Creditors - _TC", - } - doc.append("accounts", test_account_details) - doc.save() - s_doc = frappe.new_doc("Supplier") - s_doc.supplier_name = "Testing Supplier" - s_doc.supplier_group = "_Testing Supplier Group" - s_doc.payment_terms = "" - s_doc.accounts = [] - s_doc.insert() - s_doc.get_supplier_group_details() - self.assertEqual(s_doc.payment_terms, "_Test Payment Term Template 3") - self.assertEqual(s_doc.accounts[0].company, "_Test Company") - self.assertEqual(s_doc.accounts[0].account, "Creditors - _TC") - s_doc.delete() - doc.delete() - def test_supplier_default_payment_terms(self): - # Payment Term based on Days after invoice date - frappe.db.set_value( - "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 3") +class TestSupplier(FrappeTestCase): + def test_get_supplier_group_details(self): + doc = frappe.new_doc("Supplier Group") + doc.supplier_group_name = "_Testing Supplier Group" + doc.payment_terms = "_Test Payment Term Template 3" + doc.accounts = [] + test_account_details = { + "company": "_Test Company", + "account": "Creditors - _TC", + } + doc.append("accounts", test_account_details) + doc.save() + s_doc = frappe.new_doc("Supplier") + s_doc.supplier_name = "Testing Supplier" + s_doc.supplier_group = "_Testing Supplier Group" + s_doc.payment_terms = "" + s_doc.accounts = [] + s_doc.insert() + s_doc.get_supplier_group_details() + self.assertEqual(s_doc.payment_terms, "_Test Payment Term Template 3") + self.assertEqual(s_doc.accounts[0].company, "_Test Company") + self.assertEqual(s_doc.accounts[0].account, "Creditors - _TC") + s_doc.delete() + doc.delete() - due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") - self.assertEqual(due_date, "2016-02-21") + def test_supplier_default_payment_terms(self): + # Payment Term based on Days after invoice date + frappe.db.set_value( + "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 3") - due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") - self.assertEqual(due_date, "2017-02-21") + due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") + self.assertEqual(due_date, "2016-02-21") - # Payment Term based on last day of month - frappe.db.set_value( - "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 1") + due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") + self.assertEqual(due_date, "2017-02-21") - due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") - self.assertEqual(due_date, "2016-02-29") + # Payment Term based on last day of month + frappe.db.set_value( + "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 1") - due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") - self.assertEqual(due_date, "2017-02-28") + due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") + self.assertEqual(due_date, "2016-02-29") - frappe.db.set_value("Supplier", "_Test Supplier With Template 1", "payment_terms", "") + due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") + self.assertEqual(due_date, "2017-02-28") - # Set credit limit for the supplier group instead of supplier and evaluate the due date - frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 3") + frappe.db.set_value("Supplier", "_Test Supplier With Template 1", "payment_terms", "") - due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") - self.assertEqual(due_date, "2016-02-21") + # Set credit limit for the supplier group instead of supplier and evaluate the due date + frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 3") - # Payment terms for Supplier Group instead of supplier and evaluate the due date - frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 1") + due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") + self.assertEqual(due_date, "2016-02-21") - # Leap year - due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") - self.assertEqual(due_date, "2016-02-29") - # # Non Leap year - due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") - self.assertEqual(due_date, "2017-02-28") + # Payment terms for Supplier Group instead of supplier and evaluate the due date + frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 1") - # Supplier with no default Payment Terms Template - frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "") - frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", "") + # Leap year + due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1") + self.assertEqual(due_date, "2016-02-29") + # # Non Leap year + due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1") + self.assertEqual(due_date, "2017-02-28") - due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier") - self.assertEqual(due_date, "2016-01-22") - # # Non Leap year - due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier") - self.assertEqual(due_date, "2017-01-22") + # Supplier with no default Payment Terms Template + frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "") + frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", "") - def test_supplier_disabled(self): - make_test_records("Item") + due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier") + self.assertEqual(due_date, "2016-01-22") + # # Non Leap year + due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier") + self.assertEqual(due_date, "2017-01-22") - frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 1) + def test_supplier_disabled(self): + make_test_records("Item") - from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order + frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 1) - po = create_purchase_order(do_not_save=True) + from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order - self.assertRaises(PartyDisabled, po.save) + po = create_purchase_order(do_not_save=True) - frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 0) + self.assertRaises(PartyDisabled, po.save) - po.save() + frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 0) - def test_supplier_country(self): - # Test that country field exists in Supplier DocType - supplier = frappe.get_doc('Supplier', '_Test Supplier with Country') - self.assertTrue('country' in supplier.as_dict()) + po.save() - # Test if test supplier field record is 'Greece' - self.assertEqual(supplier.country, "Greece") + def test_supplier_country(self): + # Test that country field exists in Supplier DocType + supplier = frappe.get_doc('Supplier', '_Test Supplier with Country') + self.assertTrue('country' in supplier.as_dict()) - # Test update Supplier instance country value - supplier = frappe.get_doc('Supplier', '_Test Supplier') - supplier.country = 'Greece' - supplier.save() - self.assertEqual(supplier.country, "Greece") + # Test if test supplier field record is 'Greece' + self.assertEqual(supplier.country, "Greece") - def test_party_details_tax_category(self): - from erpnext.accounts.party import get_party_details + # Test update Supplier instance country value + supplier = frappe.get_doc('Supplier', '_Test Supplier') + supplier.country = 'Greece' + supplier.save() + self.assertEqual(supplier.country, "Greece") - frappe.delete_doc_if_exists("Address", "_Test Address With Tax Category-Billing") + def test_party_details_tax_category(self): + from erpnext.accounts.party import get_party_details - # Tax Category without Address - details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier") - self.assertEqual(details.tax_category, "_Test Tax Category 1") + frappe.delete_doc_if_exists("Address", "_Test Address With Tax Category-Billing") - address = frappe.get_doc(dict( - doctype='Address', - address_title='_Test Address With Tax Category', - tax_category='_Test Tax Category 2', - address_type='Billing', - address_line1='Station Road', - city='_Test City', - country='India', - links=[dict( - link_doctype='Supplier', - link_name='_Test Supplier With Tax Category' - )] - )).insert() + # Tax Category without Address + details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier") + self.assertEqual(details.tax_category, "_Test Tax Category 1") - # Tax Category with Address - details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier") - self.assertEqual(details.tax_category, "_Test Tax Category 2") + address = frappe.get_doc(dict( + doctype='Address', + address_title='_Test Address With Tax Category', + tax_category='_Test Tax Category 2', + address_type='Billing', + address_line1='Station Road', + city='_Test City', + country='India', + links=[dict( + link_doctype='Supplier', + link_name='_Test Supplier With Tax Category' + )] + )).insert() - # Rollback - address.delete() + # Tax Category with Address + details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier") + self.assertEqual(details.tax_category, "_Test Tax Category 2") + + # Rollback + address.delete() def create_supplier(**args): - args = frappe._dict(args) + args = frappe._dict(args) - try: - doc = frappe.get_doc({ - "doctype": "Supplier", - "supplier_name": args.supplier_name, - "supplier_group": args.supplier_group or "Services", - "supplier_type": args.supplier_type or "Company", - "tax_withholding_category": args.tax_withholding_category - }).insert() + if frappe.db.exists("Supplier", args.supplier_name): + return frappe.get_doc("Supplier", args.supplier_name) - return doc + doc = frappe.get_doc({ + "doctype": "Supplier", + "supplier_name": args.supplier_name, + "supplier_group": args.supplier_group or "Services", + "supplier_type": args.supplier_type or "Company", + "tax_withholding_category": args.tax_withholding_category + }).insert() - except frappe.DuplicateEntryError: - return frappe.get_doc("Supplier", args.supplier_name) + return doc diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py index d65ab94a6d3..171de7882dc 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py @@ -142,6 +142,26 @@ def make_purchase_order(source_name, target_doc=None): return doclist +@frappe.whitelist() +def make_purchase_invoice(source_name, target_doc=None): + doc = get_mapped_doc("Supplier Quotation", source_name, { + "Supplier Quotation": { + "doctype": "Purchase Invoice", + "validation": { + "docstatus": ["=", 1], + } + }, + "Supplier Quotation Item": { + "doctype": "Purchase Invoice Item" + }, + "Purchase Taxes and Charges": { + "doctype": "Purchase Taxes and Charges" + } + }, target_doc) + + return doc + + @frappe.whitelist() def make_quotation(source_name, target_doc=None): doclist = get_mapped_doc("Supplier Quotation", source_name, { diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js index 5ab6c980d00..73685caa0b4 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation_list.js @@ -8,5 +8,15 @@ frappe.listview_settings['Supplier Quotation'] = { } else if(doc.status==="Expired") { return [__("Expired"), "gray", "status,=,Expired"]; } + }, + + onload: function(listview) { + listview.page.add_action_item(__("Purchase Order"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Supplier Quotation", "Purchase Order"); + }); + + listview.page.add_action_item(__("Purchase Invoice"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Supplier Quotation", "Purchase Invoice"); + }); } }; diff --git a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py index d48ac7eb3b4..a4d45975c30 100644 --- a/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/test_supplier_quotation.py @@ -3,12 +3,12 @@ -import unittest import frappe +from frappe.tests.utils import FrappeTestCase -class TestPurchaseOrder(unittest.TestCase): +class TestPurchaseOrder(FrappeTestCase): def test_make_purchase_order(self): from erpnext.buying.doctype.supplier_quotation.supplier_quotation import make_purchase_order diff --git a/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py b/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py index 49e33517e6f..8ecc2cd4667 100644 --- a/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py +++ b/erpnext/buying/doctype/supplier_scorecard/test_supplier_scorecard.py @@ -1,12 +1,12 @@ # Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest import frappe +from frappe.tests.utils import FrappeTestCase -class TestSupplierScorecard(unittest.TestCase): +class TestSupplierScorecard(FrappeTestCase): def test_create_scorecard(self): doc = make_supplier_scorecard().insert() @@ -49,7 +49,7 @@ valid_scorecard = [ "min_grade":0.0,"name":"Very Poor", "prevent_rfqs":1, "notify_supplier":0, - "doctype":"Supplier Scorecard Standing", + "doctype":"Supplier Scorecard Scoring Standing", "max_grade":30.0, "prevent_pos":1, "warn_pos":0, @@ -65,7 +65,7 @@ valid_scorecard = [ "name":"Poor", "prevent_rfqs":1, "notify_supplier":0, - "doctype":"Supplier Scorecard Standing", + "doctype":"Supplier Scorecard Scoring Standing", "max_grade":50.0, "prevent_pos":0, "warn_pos":0, @@ -81,7 +81,7 @@ valid_scorecard = [ "name":"Average", "prevent_rfqs":0, "notify_supplier":0, - "doctype":"Supplier Scorecard Standing", + "doctype":"Supplier Scorecard Scoring Standing", "max_grade":80.0, "prevent_pos":0, "warn_pos":0, @@ -97,7 +97,7 @@ valid_scorecard = [ "name":"Excellent", "prevent_rfqs":0, "notify_supplier":0, - "doctype":"Supplier Scorecard Standing", + "doctype":"Supplier Scorecard Scoring Standing", "max_grade":100.0, "prevent_pos":0, "warn_pos":0, diff --git a/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py b/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py index dacc982420e..7ff84c15e52 100644 --- a/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py +++ b/erpnext/buying/doctype/supplier_scorecard_criteria/test_supplier_scorecard_criteria.py @@ -1,12 +1,12 @@ # Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest import frappe +from frappe.tests.utils import FrappeTestCase -class TestSupplierScorecardCriteria(unittest.TestCase): +class TestSupplierScorecardCriteria(FrappeTestCase): def test_variables_exist(self): delete_test_scorecards() for d in test_good_criteria: diff --git a/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py b/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py index 4d75981125f..32005a37dc7 100644 --- a/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py +++ b/erpnext/buying/doctype/supplier_scorecard_variable/test_supplier_scorecard_variable.py @@ -1,16 +1,16 @@ # Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.buying.doctype.supplier_scorecard_variable.supplier_scorecard_variable import ( VariablePathNotFound, ) -class TestSupplierScorecardVariable(unittest.TestCase): +class TestSupplierScorecardVariable(FrappeTestCase): def test_variable_exist(self): for d in test_existing_variables: my_doc = frappe.get_doc("Supplier Scorecard Variable", d.get("name")) diff --git a/erpnext/buying/onboarding_slide/add_a_few_suppliers/add_a_few_suppliers.json b/erpnext/buying/onboarding_slide/add_a_few_suppliers/add_a_few_suppliers.json deleted file mode 100644 index ce3d8cfb7b2..00000000000 --- a/erpnext/buying/onboarding_slide/add_a_few_suppliers/add_a_few_suppliers.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "add_more_button": 1, - "app": "ERPNext", - "creation": "2019-11-15 14:45:32.626641", - "docstatus": 0, - "doctype": "Onboarding Slide", - "domains": [], - "help_links": [ - { - "label": "Learn More", - "video_id": "zsrrVDk6VBs" - } - ], - "idx": 0, - "image_src": "", - "is_completed": 0, - "max_count": 3, - "modified": "2019-12-09 17:54:18.452038", - "modified_by": "Administrator", - "name": "Add A Few Suppliers", - "owner": "Administrator", - "ref_doctype": "Supplier", - "slide_desc": "", - "slide_fields": [ - { - "align": "", - "fieldname": "supplier_name", - "fieldtype": "Data", - "label": "Supplier Name", - "placeholder": "", - "reqd": 1 - }, - { - "align": "", - "fieldtype": "Column Break", - "reqd": 0 - }, - { - "align": "", - "fieldname": "supplier_email", - "fieldtype": "Data", - "label": "Supplier Email", - "reqd": 1 - } - ], - "slide_order": 50, - "slide_title": "Add A Few Suppliers", - "slide_type": "Create" -} \ 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 84de8c67438..44524527e3a 100644 --- a/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py +++ b/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py @@ -2,10 +2,10 @@ # For license information, please see license.txt -import unittest from datetime import datetime import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt from erpnext.buying.report.procurement_tracker.procurement_tracker import execute @@ -14,7 +14,7 @@ from erpnext.stock.doctype.material_request.test_material_request import make_ma from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse -class TestProcurementTracker(unittest.TestCase): +class TestProcurementTracker(FrappeTestCase): def test_result_for_procurement_tracker(self): filters = { 'company': '_Test Procurement Company', diff --git a/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py b/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py index 144523ad522..c2b38d38e18 100644 --- a/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py +++ b/erpnext/buying/report/subcontracted_item_to_be_received/test_subcontracted_item_to_be_received.py @@ -3,9 +3,9 @@ # Compiled at: 2019-05-06 09:51:46 # Decompiled by https://python-decompiler.com -import unittest import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order @@ -15,7 +15,7 @@ from erpnext.buying.report.subcontracted_item_to_be_received.subcontracted_item_ from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry -class TestSubcontractedItemToBeReceived(unittest.TestCase): +class TestSubcontractedItemToBeReceived(FrappeTestCase): def test_pending_and_received_qty(self): po = create_purchase_order(item_code='_Test FG Item', is_subcontracted='Yes') diff --git a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py index 3c203ac23fa..fc9acabc81d 100644 --- a/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py +++ b/erpnext/buying/report/subcontracted_raw_materials_to_be_transferred/test_subcontracted_raw_materials_to_be_transferred.py @@ -4,9 +4,9 @@ # Decompiled by https://python-decompiler.com import json -import unittest import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.buying.doctype.purchase_order.purchase_order import make_rm_stock_entry from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order @@ -16,7 +16,7 @@ from erpnext.buying.report.subcontracted_raw_materials_to_be_transferred.subcont from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry -class TestSubcontractedItemToBeTransferred(unittest.TestCase): +class TestSubcontractedItemToBeTransferred(FrappeTestCase): def test_pending_and_transferred_qty(self): po = create_purchase_order(item_code='_Test FG Item', is_subcontracted='Yes', supplier_warehouse="_Test Warehouse 1 - _TC") diff --git a/erpnext/commands/__init__.py b/erpnext/commands/__init__.py index 59311192148..8e12fad3d75 100644 --- a/erpnext/commands/__init__.py +++ b/erpnext/commands/__init__.py @@ -1,49 +1,10 @@ -# Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors -# MIT License. See license.txt +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# GPL v3 License. See license.txt import click -import frappe -from frappe.commands import get_site, pass_context def call_command(cmd, context): return click.Context(cmd, obj=context).forward(cmd) -@click.command('make-demo') -@click.option('--site', help='site name') -@click.option('--domain', default='Manufacturing') -@click.option('--days', default=100, - help='Run the demo for so many days. Default 100') -@click.option('--resume', default=False, is_flag=True, - help='Continue running the demo for given days') -@click.option('--reinstall', default=False, is_flag=True, - help='Reinstall site before demo') -@pass_context -def make_demo(context, site, domain='Manufacturing', days=100, - resume=False, reinstall=False): - "Reinstall site and setup demo" - from frappe.commands.site import _reinstall - from frappe.installer import install_app - - site = get_site(context) - - if resume: - with frappe.init_site(site): - frappe.connect() - from erpnext.demo import demo - demo.simulate(days=days) - else: - if reinstall: - _reinstall(site, yes=True) - with frappe.init_site(site=site): - frappe.connect() - if not 'erpnext' in frappe.get_installed_apps(): - install_app('erpnext') - - # import needs site - from erpnext.demo import demo - demo.make(domain, days) - -commands = [ - make_demo -] +commands = [] diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 4775f56a01b..a94af10cde4 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -167,9 +167,14 @@ class AccountsController(TransactionBase): validate_regional(self) + validate_einvoice_fields(self) + if self.doctype != 'Material Request': apply_pricing_rule_on_transaction(self) + def before_cancel(self): + validate_einvoice_fields(self) + def on_trash(self): # delete sl and gl entries on deletion of transaction if frappe.db.get_single_value('Accounts Settings', 'delete_linked_ledger_entries'): @@ -402,6 +407,22 @@ class AccountsController(TransactionBase): if item_qty != len(get_serial_nos(item.get('serial_no'))): item.set(fieldname, value) + elif ( + ret.get("pricing_rule_removed") + and value is not None + and fieldname + in [ + "discount_percentage", + "discount_amount", + "rate", + "margin_rate_or_amount", + "margin_type", + "remove_free_item", + ] + ): + # reset pricing rule fields if pricing_rule_removed + item.set(fieldname, value) + if self.doctype in ["Purchase Invoice", "Sales Invoice"] and item.meta.get_field('is_fixed_asset'): item.set('is_fixed_asset', ret.get('is_fixed_asset', 0)) @@ -1313,6 +1334,9 @@ class AccountsController(TransactionBase): payment_schedule['discount_type'] = schedule.discount_type payment_schedule['discount'] = schedule.discount + if not schedule.invoice_portion: + payment_schedule['payment_amount'] = schedule.payment_amount + self.append("payment_schedule", payment_schedule) def set_due_date(self): @@ -1542,13 +1566,12 @@ def validate_taxes_and_charges(tax): tax.rate = None -def validate_account_head(tax, doc): - company = frappe.get_cached_value('Account', - tax.account_head, 'company') +def validate_account_head(idx, account, company): + account_company = frappe.get_cached_value('Account', account, 'company') - if company != doc.company: + if account_company != company: frappe.throw(_('Row {0}: Account {1} does not belong to Company {2}') - .format(tax.idx, frappe.bold(tax.account_head), frappe.bold(doc.company)), title=_('Invalid Account')) + .format(idx, frappe.bold(account), frappe.bold(company)), title=_('Invalid Account')) def validate_cost_center(tax, doc): @@ -1931,7 +1954,8 @@ def update_bin_on_delete(row, doctype): qty_dict["ordered_qty"] = get_ordered_qty(row.item_code, row.warehouse) - update_bin_qty(row.item_code, row.warehouse, qty_dict) + if row.warehouse: + update_bin_qty(row.item_code, row.warehouse, qty_dict) def validate_and_delete_children(parent, data): deleted_children = [] @@ -2151,3 +2175,7 @@ def update_child_qty_rate(parent_doctype, trans_items, parent_doctype_name, chil @erpnext.allow_regional def validate_regional(doc): pass + +@erpnext.allow_regional +def validate_einvoice_fields(doc): + pass diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index a3d2502268e..b740476481f 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -70,9 +70,18 @@ class BuyingController(StockController, Subcontracting): # set contact and address details for supplier, if they are not mentioned if getattr(self, "supplier", None): - self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions, - doctype=self.doctype, company=self.company, party_address=self.supplier_address, shipping_address=self.get('shipping_address'), - fetch_payment_terms_template= not self.get('ignore_default_payment_terms_template'))) + self.update_if_missing( + get_party_details( + self.supplier, + party_type="Supplier", + doctype=self.doctype, + company=self.company, + party_address=self.get("supplier_address"), + shipping_address=self.get('shipping_address'), + fetch_payment_terms_template= not self.get('ignore_default_payment_terms_template'), + ignore_permissions=self.flags.ignore_permissions + ) + ) self.set_missing_item_details(for_validate) @@ -240,6 +249,7 @@ class BuyingController(StockController, Subcontracting): "posting_time": self.get('posting_time'), "qty": -1 * flt(d.get('stock_qty')), "serial_no": d.get('serial_no'), + "batch_no": d.get("batch_no"), "company": self.company, "voucher_type": self.doctype, "voucher_no": self.name, @@ -269,7 +279,8 @@ class BuyingController(StockController, Subcontracting): "posting_date": self.posting_date, "posting_time": self.posting_time, "qty": -1 * d.consumed_qty, - "serial_no": d.serial_no + "serial_no": d.serial_no, + "batch_no": d.batch_no, }) if rate > 0: @@ -554,10 +565,13 @@ class BuyingController(StockController, Subcontracting): # Check for asset naming series if item_data.get('asset_naming_series'): created_assets = [] - - for qty in range(cint(d.qty)): - asset = self.make_asset(d) + if item_data.get('is_grouped_asset'): + asset = self.make_asset(d, is_grouped_asset=True) created_assets.append(asset) + else: + for qty in range(cint(d.qty)): + asset = self.make_asset(d) + created_assets.append(asset) if len(created_assets) > 5: # dont show asset form links if more than 5 assets are created @@ -580,14 +594,18 @@ class BuyingController(StockController, Subcontracting): for message in messages: frappe.msgprint(message, title="Success", indicator="green") - def make_asset(self, row): + def make_asset(self, row, is_grouped_asset=False): if not row.asset_location: frappe.throw(_("Row {0}: Enter location for the asset item {1}").format(row.idx, row.item_code)) item_data = frappe.db.get_value('Item', row.item_code, ['asset_naming_series', 'asset_category'], as_dict=1) - purchase_amount = flt(row.base_rate + row.item_tax_amount) + if is_grouped_asset: + purchase_amount = flt(row.base_amount + row.item_tax_amount) + else: + purchase_amount = flt(row.base_rate + row.item_tax_amount) + asset = frappe.get_doc({ 'doctype': 'Asset', 'item_code': row.item_code, @@ -601,6 +619,7 @@ class BuyingController(StockController, Subcontracting): 'calculate_depreciation': 1, 'purchase_receipt_amount': purchase_amount, 'gross_purchase_amount': purchase_amount, + 'asset_quantity': row.qty if is_grouped_asset else 0, 'purchase_receipt': self.name if self.doctype == 'Purchase Receipt' else None, 'purchase_invoice': self.name if self.doctype == 'Purchase Invoice' else None }) @@ -687,7 +706,7 @@ class BuyingController(StockController, Subcontracting): def get_asset_item_details(asset_items): asset_items_data = {} - for d in frappe.get_all('Item', fields = ["name", "auto_create_assets", "asset_naming_series"], + for d in frappe.get_all('Item', fields = ["name", "auto_create_assets", "asset_naming_series", "is_grouped_asset"], filters = {'name': ('in', asset_items)}): asset_items_data.setdefault(d.name, d) diff --git a/erpnext/controllers/employee_boarding_controller.py b/erpnext/controllers/employee_boarding_controller.py index b8dc92efdeb..dd02ce17487 100644 --- a/erpnext/controllers/employee_boarding_controller.py +++ b/erpnext/controllers/employee_boarding_controller.py @@ -104,11 +104,11 @@ class EmployeeBoardingController(Document): def get_task_dates(self, activity, holiday_list): start_date = end_date = None - if activity.begin_on: + if activity.begin_on is not None: start_date = add_days(self.boarding_begins_on, activity.begin_on) start_date = self.update_if_holiday(start_date, holiday_list) - if activity.duration: + if activity.duration is not None: end_date = add_days(self.boarding_begins_on, activity.begin_on + activity.duration) end_date = self.update_if_holiday(end_date, holiday_list) @@ -132,13 +132,17 @@ class EmployeeBoardingController(Document): def on_cancel(self): # delete task project - for task in frappe.get_all('Task', filters={'project': self.project}): + project = self.project + for task in frappe.get_all('Task', filters={'project': project}): frappe.delete_doc('Task', task.name, force=1) - frappe.delete_doc('Project', self.project, force=1) + frappe.delete_doc('Project', project, force=1) self.db_set('project', '') for activity in self.activities: activity.db_set('task', '') + frappe.msgprint(_('Linked Project {} and Tasks deleted.').format( + project), alert=True, indicator='blue') + @frappe.whitelist() def get_onboarding_details(parent, parenttype): diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index 2bad6f8e9f4..68ad702b979 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -132,7 +132,7 @@ def find_variant(template, args, variant_item_code=None): conditions = " or ".join(conditions) - from erpnext.portal.product_configurator.utils import get_item_codes_by_attributes + from erpnext.e_commerce.variant_selector.utils import get_item_codes_by_attributes possible_variants = [i for i in get_item_codes_by_attributes(args, template) if i != variant_item_code] for variant in possible_variants: @@ -262,9 +262,8 @@ def generate_keyed_value_combinations(args): def copy_attributes_to_variant(item, variant): # copy non no-copy fields - exclude_fields = ["naming_series", "item_code", "item_name", "show_in_website", - "show_variant_in_website", "opening_stock", "variant_of", "valuation_rate", - "has_variants", "attributes"] + exclude_fields = ["naming_series", "item_code", "item_name", "published_in_website", + "opening_stock", "variant_of", "valuation_rate"] if item.variant_based_on=='Manufacturer': # don't copy manufacturer values if based on part no diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index dc04dab84c3..dd9b45cc3f9 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -249,6 +249,9 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals del filters['customer'] else: del filters['supplier'] + else: + filters.pop('customer', None) + filters.pop('supplier', None) description_cond = '' @@ -707,6 +710,7 @@ def get_tax_template(doctype, txt, searchfield, start, page_len, filters): item_doc = frappe.get_cached_doc('Item', filters.get('item_code')) item_group = filters.get('item_group') + company = filters.get('company') taxes = item_doc.taxes or [] while item_group: @@ -715,7 +719,7 @@ def get_tax_template(doctype, txt, searchfield, start, page_len, filters): item_group = item_group_doc.parent_item_group if not taxes: - return frappe.db.sql(""" SELECT name FROM `tabItem Tax Template` """) + return frappe.get_all('Item Tax Template', filters={'disabled': 0, 'company': company}, as_list=True) else: valid_from = filters.get('valid_from') valid_from = valid_from[1] if isinstance(valid_from, list) else valid_from @@ -724,7 +728,7 @@ def get_tax_template(doctype, txt, searchfield, start, page_len, filters): 'item_code': filters.get('item_code'), 'posting_date': valid_from, 'tax_category': filters.get('tax_category'), - 'company': filters.get('company') + 'company': company } taxes = _get_item_tax_template(args, taxes, for_validate=True) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index df3c5f10c1b..8c3aab442bb 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -420,6 +420,7 @@ def get_rate_for_return(voucher_type, voucher_no, item_code, return_against=None "posting_time": sle.get('posting_time'), "qty": sle.actual_qty, "serial_no": sle.get('serial_no'), + "batch_no": sle.get("batch_no"), "company": sle.company, "voucher_type": sle.voucher_type, "voucher_no": sle.voucher_no diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 4ff851d7f94..e918cde7c48 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -74,7 +74,8 @@ class SellingController(StockController): doctype=self.doctype, company=self.company, posting_date=self.get('posting_date'), fetch_payment_terms_template=fetch_payment_terms_template, - party_address=self.customer_address, shipping_address=self.shipping_address_name) + party_address=self.customer_address, shipping_address=self.shipping_address_name, + company_address=self.get('company_address')) if not self.meta.get_field("sales_team"): party_details.pop("sales_team") self.update_if_missing(party_details) @@ -204,7 +205,7 @@ class SellingController(StockController): valuation_rate_map = {} for item in self.items: - if not item.item_code: + if not item.item_code or item.is_free_item: continue last_purchase_rate, is_stock_item = frappe.get_cached_value( @@ -251,7 +252,7 @@ class SellingController(StockController): valuation_rate_map[(rate.item_code, rate.warehouse)] = rate.valuation_rate for item in self.items: - if not item.item_code: + if not item.item_code or item.is_free_item: continue last_valuation_rate = valuation_rate_map.get( @@ -393,6 +394,7 @@ class SellingController(StockController): "posting_time": self.get('posting_time') or nowtime(), "qty": qty if cint(self.get("is_return")) else (-1 * qty), "serial_no": d.get('serial_no'), + "batch_no": d.get("batch_no"), "company": self.company, "voucher_type": self.doctype, "voucher_no": self.name, diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 76a7cdab516..affde4aa8ab 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -400,6 +400,16 @@ class StatusUpdater(Document): ref_doc = frappe.get_doc(ref_dt, ref_dn) ref_doc.db_set("per_billed", per_billed) + + # set billling status + if hasattr(ref_doc, 'billing_status'): + if ref_doc.per_billed < 0.001: + ref_doc.db_set("billing_status", "Not Billed") + elif ref_doc.per_billed > 99.999999: + ref_doc.db_set("billing_status", "Fully Billed") + else: + ref_doc.db_set("billing_status", "Partly Billed") + ref_doc.set_status(update=True) def get_allowance_for(item_code, item_allowance=None, global_qty_allowance=None, global_amount_allowance=None, qty_or_amount="qty"): diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index f22669b2555..c8e5eddfeac 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -3,6 +3,7 @@ import json from collections import defaultdict +from typing import List, Tuple import frappe from frappe import _ @@ -40,7 +41,10 @@ class StockController(AccountsController): if self.docstatus == 2: make_reverse_gl_entries(voucher_type=self.doctype, voucher_no=self.name) - if cint(erpnext.is_perpetual_inventory_enabled(self.company)): + provisional_accounting_for_non_stock_items = \ + cint(frappe.db.get_value('Company', self.company, 'enable_provisional_accounting_for_non_stock_items')) + + if cint(erpnext.is_perpetual_inventory_enabled(self.company)) or provisional_accounting_for_non_stock_items: warehouse_account = get_warehouse_account_map(self.company) if self.docstatus==1: @@ -77,17 +81,17 @@ class StockController(AccountsController): .format(d.idx, get_link_to_form("Batch", d.get("batch_no")))) def clean_serial_nos(self): + from erpnext.stock.doctype.serial_no.serial_no import clean_serial_no_string + for row in self.get("items"): if hasattr(row, "serial_no") and row.serial_no: - # replace commas by linefeed - row.serial_no = row.serial_no.replace(",", "\n") + # remove extra whitespace and store one serial no on each line + row.serial_no = clean_serial_no_string(row.serial_no) - # 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) + for row in self.get('packed_items') or []: + if hasattr(row, "serial_no") and row.serial_no: + # remove extra whitespace and store one serial no on each line + row.serial_no = clean_serial_no_string(row.serial_no) def get_gl_entries(self, warehouse_account=None, default_expense_account=None, default_cost_center=None): @@ -178,33 +182,28 @@ class StockController(AccountsController): return details - def get_items_and_warehouses(self): - items, warehouses = [], [] + def get_items_and_warehouses(self) -> Tuple[List[str], List[str]]: + """Get list of items and warehouses affected by a transaction""" - if hasattr(self, "items"): - item_doclist = self.get("items") - elif self.doctype == "Stock Reconciliation": - item_doclist = [] - data = json.loads(self.reconciliation_json) - for row in data[data.index(self.head_row)+1:]: - d = frappe._dict(zip(["item_code", "warehouse", "qty", "valuation_rate"], row)) - item_doclist.append(d) + if not (hasattr(self, "items") or hasattr(self, "packed_items")): + return [], [] - if item_doclist: - for d in item_doclist: - if d.item_code and d.item_code not in items: - items.append(d.item_code) + item_rows = (self.get("items") or []) + (self.get("packed_items") or []) - if d.get("warehouse") and d.warehouse not in warehouses: - warehouses.append(d.warehouse) + items = {d.item_code for d in item_rows if d.item_code} - if self.doctype == "Stock Entry": - if d.get("s_warehouse") and d.s_warehouse not in warehouses: - warehouses.append(d.s_warehouse) - if d.get("t_warehouse") and d.t_warehouse not in warehouses: - warehouses.append(d.t_warehouse) + warehouses = set() + for d in item_rows: + if d.get("warehouse"): + warehouses.add(d.warehouse) - return items, warehouses + if self.doctype == "Stock Entry": + if d.get("s_warehouse"): + warehouses.add(d.s_warehouse) + if d.get("t_warehouse"): + warehouses.add(d.t_warehouse) + + return list(items), list(warehouses) def get_stock_ledger_details(self): stock_ledger = {} @@ -216,7 +215,7 @@ class StockController(AccountsController): from `tabStock Ledger Entry` where - voucher_type=%s and voucher_no=%s + voucher_type=%s and voucher_no=%s and is_cancelled = 0 """, (self.doctype, self.name), as_dict=True) for sle in stock_ledger_entries: @@ -256,11 +255,7 @@ class StockController(AccountsController): for d in self.items: if not d.batch_no: continue - serial_nos = [sr.name for sr in frappe.get_all("Serial No", - {'batch_no': d.batch_no, 'status': 'Inactive'})] - - if serial_nos: - frappe.db.set_value("Serial No", { 'name': ['in', serial_nos] }, "batch_no", None) + frappe.db.set_value("Serial No", {"batch_no": d.batch_no, "status": "Inactive"}, "batch_no", None) d.batch_no = None d.db_set("batch_no", None) diff --git a/erpnext/controllers/subcontracting.py b/erpnext/controllers/subcontracting.py index 3addb91aaa0..c52c688b73e 100644 --- a/erpnext/controllers/subcontracting.py +++ b/erpnext/controllers/subcontracting.py @@ -363,8 +363,6 @@ class Subcontracting(): return for row in self.get(self.raw_material_table): - self.__validate_consumed_qty(row) - key = (row.rm_item_code, row.main_item_code, row.purchase_order) if not self.__transferred_items or not self.__transferred_items.get(key): return @@ -372,12 +370,6 @@ class Subcontracting(): self.__validate_batch_no(row, key) self.__validate_serial_no(row, key) - def __validate_consumed_qty(self, row): - if self.backflush_based_on != 'BOM' and flt(row.consumed_qty) == 0.0: - msg = f'Row {row.idx}: the consumed qty cannot be zero for the item {frappe.bold(row.rm_item_code)}' - - frappe.throw(_(msg),title=_('Consumed Items Qty Check')) - def __validate_batch_no(self, row, key): if row.get('batch_no') and row.get('batch_no') not in self.__transferred_items.get(key).get('batch_no'): link = get_link_to_form('Purchase Order', row.purchase_order) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 075e3e38fa5..27766282277 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -106,6 +106,9 @@ class calculate_taxes_and_totals(object): self.doc.conversion_rate = flt(self.doc.conversion_rate) def calculate_item_values(self): + if self.doc.get('is_consolidated'): + return + if not self.discount_amount_applied: for item in self.doc.get("items"): self.doc.round_floats_in(item) @@ -647,12 +650,12 @@ class calculate_taxes_and_totals(object): def calculate_change_amount(self): self.doc.change_amount = 0.0 self.doc.base_change_amount = 0.0 + grand_total = self.doc.rounded_total or self.doc.grand_total + base_grand_total = self.doc.base_rounded_total or self.doc.base_grand_total if self.doc.doctype == "Sales Invoice" \ - and self.doc.paid_amount > self.doc.grand_total and not self.doc.is_return \ + and self.doc.paid_amount > grand_total and not self.doc.is_return \ and any(d.type == "Cash" for d in self.doc.payments): - grand_total = self.doc.rounded_total or self.doc.grand_total - base_grand_total = self.doc.base_rounded_total or self.doc.base_grand_total self.doc.change_amount = flt(self.doc.paid_amount - grand_total + self.doc.write_off_amount, self.doc.precision("change_amount")) diff --git a/erpnext/controllers/tests/test_queries.py b/erpnext/controllers/tests/test_queries.py index 908d78c15bf..60d1733021c 100644 --- a/erpnext/controllers/tests/test_queries.py +++ b/erpnext/controllers/tests/test_queries.py @@ -56,6 +56,12 @@ class TestQueries(unittest.TestCase): bundled_stock_items = query(txt="_test product bundle item 5", filters={"is_stock_item": 1}) self.assertEqual(len(bundled_stock_items), 0) + # empty customer/supplier should be stripped of instead of failure + query(txt="", filters={"customer": None}) + query(txt="", filters={"customer": ""}) + query(txt="", filters={"supplier": None}) + query(txt="", filters={"supplier": ""}) + def test_bom_qury(self): query = add_default_params(queries.bom, "BOM") diff --git a/erpnext/crm/doctype/campaign/campaign.js b/erpnext/crm/doctype/campaign/campaign.js index 11bfa74b29c..cac45c682cb 100644 --- a/erpnext/crm/doctype/campaign/campaign.js +++ b/erpnext/crm/doctype/campaign/campaign.js @@ -5,7 +5,7 @@ frappe.ui.form.on('Campaign', { refresh: function(frm) { erpnext.toggle_naming_series(); - if (frm.doc.__islocal) { + if (frm.is_new()) { frm.toggle_display("naming_series", frappe.boot.sysdefaults.campaign_naming_by=="Naming Series"); } else { cur_frm.add_custom_button(__("View Leads"), function() { diff --git a/erpnext/crm/doctype/crm_settings/crm_settings.py b/erpnext/crm/doctype/crm_settings/crm_settings.py index bde52547c95..98cf7d845e0 100644 --- a/erpnext/crm/doctype/crm_settings/crm_settings.py +++ b/erpnext/crm/doctype/crm_settings/crm_settings.py @@ -1,9 +1,10 @@ # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt -# import frappe +import frappe from frappe.model.document import Document class CRMSettings(Document): - pass + def validate(self): + frappe.db.set_default("campaign_naming_by", self.get("campaign_naming_by", "")) diff --git a/erpnext/crm/doctype/linkedin_settings/linkedin_settings.py b/erpnext/crm/doctype/linkedin_settings/linkedin_settings.py index 8fd4978715f..d2ac10adea2 100644 --- a/erpnext/crm/doctype/linkedin_settings/linkedin_settings.py +++ b/erpnext/crm/doctype/linkedin_settings/linkedin_settings.py @@ -2,13 +2,14 @@ # For license information, please see license.txt +from urllib.parse import urlencode + import frappe import requests from frappe import _ from frappe.model.document import Document from frappe.utils import get_url_to_form from frappe.utils.file_manager import get_file_path -from six.moves.urllib.parse import urlencode class LinkedInSettings(Document): diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index f8376e6ca94..8e7d67e0575 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -24,6 +24,14 @@ frappe.ui.form.on("Opportunity", { frm.trigger('set_contact_link'); } }, + + validate: function(frm) { + if (frm.doc.status == "Lost" && !frm.doc.lost_reasons.length) { + frm.trigger('set_as_lost_dialog'); + frappe.throw(__("Lost Reasons are required in case opportunity is Lost.")); + } + }, + contact_date: function(frm) { if(frm.doc.contact_date < frappe.datetime.now_datetime()){ frm.set_value("contact_date", ""); @@ -82,7 +90,7 @@ frappe.ui.form.on("Opportunity", { frm.trigger('setup_opportunity_from'); erpnext.toggle_naming_series(); - if(!doc.__islocal && doc.status!=="Lost") { + if(!frm.is_new() && doc.status!=="Lost") { if(doc.with_items){ frm.add_custom_button(__('Supplier Quotation'), function() { @@ -187,11 +195,11 @@ frappe.ui.form.on("Opportunity", { change_form_labels: function(frm) { let company_currency = erpnext.get_currency(frm.doc.company); - frm.set_currency_labels(["base_opportunity_amount", "base_total", "base_grand_total"], company_currency); - frm.set_currency_labels(["opportunity_amount", "total", "grand_total"], frm.doc.currency); + frm.set_currency_labels(["base_opportunity_amount", "base_total"], company_currency); + frm.set_currency_labels(["opportunity_amount", "total"], frm.doc.currency); // toggle fields - frm.toggle_display(["conversion_rate", "base_opportunity_amount", "base_total", "base_grand_total"], + frm.toggle_display(["conversion_rate", "base_opportunity_amount", "base_total"], frm.doc.currency != company_currency); }, @@ -209,20 +217,15 @@ frappe.ui.form.on("Opportunity", { }, calculate_total: function(frm) { - let total = 0, base_total = 0, grand_total = 0, base_grand_total = 0; + let total = 0, base_total = 0; frm.doc.items.forEach(item => { total += item.amount; base_total += item.base_amount; }) - base_grand_total = base_total + frm.doc.base_opportunity_amount; - grand_total = total + frm.doc.opportunity_amount; - frm.set_value({ 'total': flt(total), - 'base_total': flt(base_total), - 'grand_total': flt(grand_total), - 'base_grand_total': flt(base_grand_total) + 'base_total': flt(base_total) }); } diff --git a/erpnext/crm/doctype/opportunity/opportunity.json b/erpnext/crm/doctype/opportunity/opportunity.json index dc32d9a4124..089f2d2faa8 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.json +++ b/erpnext/crm/doctype/opportunity/opportunity.json @@ -42,10 +42,8 @@ "items", "section_break_32", "base_total", - "base_grand_total", "column_break_33", "total", - "grand_total", "contact_info", "customer_address", "address_display", @@ -475,21 +473,6 @@ "fieldname": "column_break_33", "fieldtype": "Column Break" }, - { - "fieldname": "base_grand_total", - "fieldtype": "Currency", - "label": "Grand Total (Company Currency)", - "options": "Company:company:default_currency", - "print_hide": 1, - "read_only": 1 - }, - { - "fieldname": "grand_total", - "fieldtype": "Currency", - "label": "Grand Total", - "options": "currency", - "read_only": 1 - }, { "fieldname": "lost_detail_section", "fieldtype": "Section Break", @@ -510,7 +493,7 @@ "icon": "fa fa-info-sign", "idx": 195, "links": [], - "modified": "2021-10-21 12:04:30.151379", + "modified": "2022-01-29 19:32:26.382896", "modified_by": "Administrator", "module": "CRM", "name": "Opportunity", @@ -547,6 +530,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "subject_field": "title", "timeline_field": "party_name", "title_field": "title", diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index a4fd7658eed..2d538748ec2 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -69,8 +69,6 @@ class Opportunity(TransactionBase): self.total = flt(total) self.base_total = flt(base_total) - self.grand_total = flt(self.total) + flt(self.opportunity_amount) - self.base_grand_total = flt(self.base_total) + flt(self.base_opportunity_amount) def make_new_lead_if_required(self): """Set lead against new opportunity""" diff --git a/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.json b/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.json index 8a8d4252daa..0cfcf0e0ea4 100644 --- a/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.json +++ b/erpnext/crm/doctype/opportunity_lost_reason/opportunity_lost_reason.json @@ -3,7 +3,7 @@ "allow_events_in_timeline": 0, "allow_guest_to_view": 0, "allow_import": 0, - "allow_rename": 0, + "allow_rename": 1, "autoname": "field:lost_reason", "beta": 0, "creation": "2018-12-28 14:48:51.044975", @@ -57,7 +57,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2018-12-28 14:49:43.336437", + "modified": "2022-02-16 10:49:43.336437", "modified_by": "Administrator", "module": "CRM", "name": "Opportunity Lost Reason", @@ -150,4 +150,4 @@ "track_changes": 0, "track_seen": 0, "track_views": 0 -} \ No newline at end of file +} diff --git a/erpnext/crm/doctype/prospect/prospect.js b/erpnext/crm/doctype/prospect/prospect.js index 67018e1ef9c..8721a5b42d3 100644 --- a/erpnext/crm/doctype/prospect/prospect.js +++ b/erpnext/crm/doctype/prospect/prospect.js @@ -3,6 +3,8 @@ frappe.ui.form.on('Prospect', { refresh (frm) { + frappe.dynamic_link = { doc: frm.doc, fieldname: "name", doctype: frm.doctype }; + if (!frm.is_new() && frappe.boot.user.can_create.includes("Customer")) { frm.add_custom_button(__("Customer"), function() { frappe.model.open_mapped_doc({ diff --git a/erpnext/crm/module_onboarding/crm/crm.json b/erpnext/crm/module_onboarding/crm/crm.json index 8315218c842..0faad1d3151 100644 --- a/erpnext/crm/module_onboarding/crm/crm.json +++ b/erpnext/crm/module_onboarding/crm/crm.json @@ -16,7 +16,7 @@ "documentation_url": "https://docs.erpnext.com/docs/user/manual/en/CRM", "idx": 0, "is_complete": 0, - "modified": "2020-07-08 14:05:42.644448", + "modified": "2022-01-29 20:14:29.502145", "modified_by": "Administrator", "module": "CRM", "name": "CRM", @@ -33,6 +33,9 @@ }, { "step": "Create and Send Quotation" + }, + { + "step": "CRM Settings" } ], "subtitle": "Lead, Opportunity, Customer, and more.", diff --git a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json index 78f7e4de9c7..f0f50de5d16 100644 --- a/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json +++ b/erpnext/crm/onboarding_step/create_and_send_quotation/create_and_send_quotation.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-05-28 21:07:11.461172", @@ -13,6 +12,7 @@ "name": "Create and Send Quotation", "owner": "Administrator", "reference_document": "Quotation", + "show_form_tour": 0, "show_full_form": 1, "title": "Create and Send Quotation", "validate_action": 1 diff --git a/erpnext/crm/onboarding_step/create_lead/create_lead.json b/erpnext/crm/onboarding_step/create_lead/create_lead.json index c45e8b036c5..cb5cce66a5f 100644 --- a/erpnext/crm/onboarding_step/create_lead/create_lead.json +++ b/erpnext/crm/onboarding_step/create_lead/create_lead.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-05-28 21:07:01.373403", @@ -13,6 +12,7 @@ "name": "Create Lead", "owner": "Administrator", "reference_document": "Lead", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Lead", "validate_action": 1 diff --git a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json index 0ee9317c852..96e0256d700 100644 --- a/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json +++ b/erpnext/crm/onboarding_step/create_opportunity/create_opportunity.json @@ -5,7 +5,6 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2021-01-21 15:28:52.483839", @@ -13,6 +12,7 @@ "name": "Create Opportunity", "owner": "Administrator", "reference_document": "Opportunity", + "show_form_tour": 0, "show_full_form": 1, "title": "Create Opportunity", "validate_action": 1 diff --git a/erpnext/crm/onboarding_step/crm_settings/crm_settings.json b/erpnext/crm/onboarding_step/crm_settings/crm_settings.json new file mode 100644 index 00000000000..555d795987f --- /dev/null +++ b/erpnext/crm/onboarding_step/crm_settings/crm_settings.json @@ -0,0 +1,21 @@ +{ + "action": "Go to Page", + "creation": "2022-01-29 20:14:24.803844", + "description": "# CRM Settings\n\nCRM module\u2019s features are configurable as per your business needs. CRM Settings is the place where you can set your preferences for:\n- Campaign\n- Lead\n- Opportunity\n- Quotation", + "docstatus": 0, + "doctype": "Onboarding Step", + "idx": 0, + "is_complete": 0, + "is_single": 1, + "is_skipped": 0, + "modified": "2022-01-29 20:14:24.803844", + "modified_by": "Administrator", + "name": "CRM Settings", + "owner": "Administrator", + "path": "#crm-settings/CRM%20Settings", + "reference_document": "CRM Settings", + "show_form_tour": 0, + "show_full_form": 0, + "title": "CRM Settings", + "validate_action": 1 +} \ No newline at end of file diff --git a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json index fa26921ae2c..88717530945 100644 --- a/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json +++ b/erpnext/crm/onboarding_step/introduction_to_crm/introduction_to_crm.json @@ -5,13 +5,13 @@ "doctype": "Onboarding Step", "idx": 0, "is_complete": 0, - "is_mandatory": 0, "is_single": 0, "is_skipped": 0, "modified": "2020-05-14 17:28:16.448676", "modified_by": "Administrator", "name": "Introduction to CRM", "owner": "Administrator", + "show_form_tour": 0, "show_full_form": 0, "title": "Introduction to CRM", "validate_action": 1, diff --git a/erpnext/demo/data/account.json b/erpnext/demo/data/account.json deleted file mode 100644 index b50b0c94b0f..00000000000 --- a/erpnext/demo/data/account.json +++ /dev/null @@ -1,18 +0,0 @@ -[{ - "account_name": "Debtors EUR", - "parent_account": "Accounts Receivable", - "account_type": "Receivable", - "account_currency": "EUR" -}, -{ - "account_name": "Creditors EUR", - "parent_account": "Accounts Payable", - "account_type": "Payable", - "account_currency": "EUR" -}, -{ - "account_name": "Paypal", - "parent_account": "Bank Accounts", - "account_type": "Bank", - "account_currency": "EUR" -}] \ No newline at end of file diff --git a/erpnext/demo/data/address.json b/erpnext/demo/data/address.json deleted file mode 100644 index 7618c2cf337..00000000000 --- a/erpnext/demo/data/address.json +++ /dev/null @@ -1,218 +0,0 @@ -[ - { - "address_line1": "254 Theotokopoulou Str.", - "address_type": "Office", - "city": "Larnaka", - "country": "Cyprus", - "links": [{"link_doctype": "Customer", "link_name": "Adaptas"}], - "phone": "23566775757" - }, - { - "address_line1": "R Patr\u00e3o Caramelho 116", - "address_type": "Office", - "city": "Fajozes", - "country": "Portugal", - "links": [{"link_doctype": "Customer", "link_name": "Asian Fusion"}], - "phone": "23566775757" - }, - { - "address_line1": "30 Fulford Road", - "address_type": "Office", - "city": "PENTRE-PIOD", - "country": "United Kingdom", - "links": [{"link_doctype": "Customer", "link_name": "Asian Junction"}], - "phone": "23566775757" - }, - { - "address_line1": "Schoenebergerstrasse 13", - "address_type": "Office", - "city": "Raschau", - "country": "Germany", - "links": [{"link_doctype": "Customer", "link_name": "Big D Supermarkets"}], - "phone": "23566775757" - }, - { - "address_line1": "Hoheluftchaussee 43", - "address_type": "Office", - "city": "Kieritzsch", - "country": "Germany", - "links": [{"link_doctype": "Customer", "link_name": "Buttrey Food & Drug"}], - "phone": "23566775757" - }, - { - "address_line1": "R Cimo Vila 6", - "address_type": "Office", - "city": "Rebordosa", - "country": "Portugal", - "links": [{"link_doctype": "Customer", "link_name": "Chi-Chis"}], - "phone": "23566775757" - }, - { - "address_line1": "R 5 Outubro 9", - "address_type": "Office", - "city": "Quinta Nova S\u00e3o Domingos", - "country": "Portugal", - "links": [{"link_doctype": "Customer", "link_name": "Choices"}], - "phone": "23566775757" - }, - { - "address_line1": "Avenida Macambira 953", - "address_type": "Office", - "city": "Goi\u00e2nia", - "country": "Brazil", - "links": [{"link_doctype": "Customer", "link_name": "Consumers and Consumers Express"}], - "phone": "23566775757" - }, - { - "address_line1": "2342 Goyeau Ave", - "address_type": "Office", - "city": "Windsor", - "country": "Canada", - "links": [{"link_doctype": "Customer", "link_name": "Crafts Canada"}], - "phone": "23566775757" - }, - { - "address_line1": "Laukaantie 82", - "address_type": "Office", - "city": "KOKKOLA", - "country": "Finland", - "links": [{"link_doctype": "Customer", "link_name": "Endicott Shoes"}], - "phone": "23566775757" - }, - { - "address_line1": "9 Brown Street", - "address_type": "Office", - "city": "PETERSHAM", - "country": "Australia", - "links": [{"link_doctype": "Customer", "link_name": "Fayva"}], - "phone": "23566775757" - }, - { - "address_line1": "Via Donnalbina 41", - "address_type": "Office", - "city": "Cala Gonone", - "country": "Italy", - "links": [{"link_doctype": "Customer", "link_name": "Intelacard"}], - "phone": "23566775757" - }, - { - "address_line1": "Liljerum Grenadj\u00e4rtorpet 69", - "address_type": "Office", - "city": "TOMTEBODA", - "country": "Sweden", - "links": [{"link_doctype": "Customer", "link_name": "Landskip Yard Care"}], - "phone": "23566775757" - }, - { - "address_line1": "72 Bishopgate Street", - "address_type": "Office", - "city": "SEAHAM", - "country": "United Kingdom", - "links": [{"link_doctype": "Customer", "link_name": "Life Plan Counselling"}], - "phone": "23566775757" - }, - { - "address_line1": "\u03a3\u03ba\u03b1\u03c6\u03af\u03b4\u03b9\u03b1 105", - "address_type": "Office", - "city": "\u03a0\u0391\u03a1\u0395\u039a\u039a\u039b\u0397\u03a3\u0399\u0391", - "country": "Cyprus", - "links": [{"link_doctype": "Customer", "link_name": "Mr Fables"}], - "phone": "23566775757" - }, - { - "address_line1": "Mellemvej 7", - "address_type": "Office", - "city": "Aabybro", - "country": "Denmark", - "links": [{"link_doctype": "Customer", "link_name": "Nelson Brothers"}], - "phone": "23566775757" - }, - { - "address_line1": "Plougg\u00e5rdsvej 98", - "address_type": "Office", - "city": "Karby", - "country": "Denmark", - "links": [{"link_doctype": "Customer", "link_name": "Netobill"}], - "phone": "23566775757" - }, - { - "address_line1": "176 Michalakopoulou Street", - "address_type": "Office", - "city": "Agio Georgoudi", - "country": "Cyprus", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Helios Air"}] - }, - { - "address_line1": "Fibichova 1102", - "address_type": "Office", - "city": "Kokor\u00edn", - "country": "Czech Republic", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Ks Merchandise"}] - }, - { - "address_line1": "Zahradn\u00ed 888", - "address_type": "Office", - "city": "Cecht\u00edn", - "country": "Czech Republic", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "HomeBase"}] - }, - { - "address_line1": "ul. Grochowska 94", - "address_type": "Office", - "city": "Warszawa", - "country": "Poland", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Scott Ties"}] - }, - { - "address_line1": "Norra Esplanaden 87", - "address_type": "Office", - "city": "HELSINKI", - "country": "Finland", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Reliable Investments"}] - }, - { - "address_line1": "2038 Fallon Drive", - "address_type": "Office", - "city": "Dresden", - "country": "Canada", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Nan Duskin"}] - }, - { - "address_line1": "77 cours Franklin Roosevelt", - "address_type": "Office", - "city": "MARSEILLE", - "country": "France", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Rainbow Records"}] - }, - { - "address_line1": "ul. Tuwima Juliana 85", - "address_type": "Office", - "city": "\u0141\u00f3d\u017a", - "country": "Poland", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "New World Realty"}] - }, - { - "address_line1": "Gl. Sygehusvej 41", - "address_type": "Office", - "city": "Narsaq", - "country": "Greenland", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Asiatic Solutions"}] - }, - { - "address_line1": "Gosposka ulica 50", - "address_type": "Office", - "city": "Nova Gorica", - "country": "Slovenia", - "phone": "23566775757", - "links": [{"link_doctype": "Supplier", "link_name": "Eagle Hardware"}] - } -] \ No newline at end of file diff --git a/erpnext/demo/data/assessment_criteria.json b/erpnext/demo/data/assessment_criteria.json deleted file mode 100644 index 82956822a2a..00000000000 --- a/erpnext/demo/data/assessment_criteria.json +++ /dev/null @@ -1,18 +0,0 @@ -[ - { - "doctype": "Assessment Criteria", - "assessment_criteria": "Aptitude" - }, - { - "doctype": "Assessment Criteria", - "assessment_criteria": "Application" - }, - { - "doctype": "Assessment Criteria", - "assessment_criteria": "Understanding" - }, - { - "doctype": "Assessment Criteria", - "assessment_criteria": "Knowledge" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/asset.json b/erpnext/demo/data/asset.json deleted file mode 100644 index 44db2ae9e1b..00000000000 --- a/erpnext/demo/data/asset.json +++ /dev/null @@ -1,58 +0,0 @@ -[ - { - "asset_name": "Macbook Pro - 1", - "item_code": "Computer", - "gross_purchase_amount": 100000, - "asset_owner": "Company", - "available_for_use_date": "2017-01-02", - "location": "Main Location" - }, - { - "asset_name": "Macbook Air - 1", - "item_code": "Computer", - "gross_purchase_amount": 60000, - "asset_owner": "Company", - "available_for_use_date": "2017-10-02", - "location": "Avg Location" - }, - { - "asset_name": "Conferrence Table", - "item_code": "Table", - "gross_purchase_amount": 30000, - "asset_owner": "Company", - "available_for_use_date": "2018-10-02", - "location": "Zany Location" - }, - { - "asset_name": "Lunch Table", - "item_code": "Table", - "gross_purchase_amount": 20000, - "asset_owner": "Company", - "available_for_use_date": "2018-06-02", - "location": "Fletcher Location" - }, - { - "asset_name": "ERPNext", - "item_code": "ERP", - "gross_purchase_amount": 100000, - "asset_owner": "Company", - "available_for_use_date": "2018-09-02", - "location":"Main Location" - }, - { - "asset_name": "Chair 1", - "item_code": "Chair", - "gross_purchase_amount": 10000, - "asset_owner": "Company", - "available_for_use_date": "2018-07-02", - "location": "Zany Location" - }, - { - "asset_name": "Chair 2", - "item_code": "Chair", - "gross_purchase_amount": 10000, - "asset_owner": "Company", - "available_for_use_date": "2018-07-02", - "location": "Avg Location" - } -] diff --git a/erpnext/demo/data/asset_category.json b/erpnext/demo/data/asset_category.json deleted file mode 100644 index 54f779da96f..00000000000 --- a/erpnext/demo/data/asset_category.json +++ /dev/null @@ -1,38 +0,0 @@ -[ - { - "asset_category_name": "Furnitures", - "depreciation_method": "Straight Line", - "total_number_of_depreciations": 5, - "frequency_of_depreciation": 12, - "accounts": [{ - "company_name": "Wind Power LLC", - "fixed_asset_account": "Furnitures and Fixtures - WPL", - "accumulated_depreciation_account": "Accumulated Depreciation - WPL", - "depreciation_expense_account": "Depreciation - WPL" - }] - }, - { - "asset_category_name": "Electronic Equipments", - "depreciation_method": "Double Declining Balance", - "total_number_of_depreciations": 10, - "frequency_of_depreciation": 6, - "accounts": [{ - "company_name": "Wind Power LLC", - "fixed_asset_account": "Electronic Equipments - WPL", - "accumulated_depreciation_account": "Accumulated Depreciation - WPL", - "depreciation_expense_account": "Depreciation - WPL" - }] - }, - { - "asset_category_name": "Softwares", - "depreciation_method": "Straight Line", - "total_number_of_depreciations": 10, - "frequency_of_depreciation": 12, - "accounts": [{ - "company_name": "Wind Power LLC", - "fixed_asset_account": "Softwares - WPL", - "accumulated_depreciation_account": "Accumulated Depreciation - WPL", - "depreciation_expense_account": "Depreciation - WPL" - }] - } -] \ No newline at end of file diff --git a/erpnext/demo/data/bom.json b/erpnext/demo/data/bom.json deleted file mode 100644 index 30854359b29..00000000000 --- a/erpnext/demo/data/bom.json +++ /dev/null @@ -1,180 +0,0 @@ -[ - { - "item": "Bearing Assembly", - "items": [ - { - "item_code": "Base Bearing Plate", - "qty": 1.0, - "rate": 15.0 - }, - { - "item_code": "Bearing Block", - "qty": 1.0, - "rate": 10.0 - }, - { - "item_code": "Bearing Collar", - "qty": 2.0, - "rate": 20.0 - }, - { - "item_code": "Bearing Pipe", - "qty": 1.0, - "rate": 15.0 - }, - { - "item_code": "Upper Bearing Plate", - "qty": 1.0, - "rate": 50.0 - } - ] - }, - { - "item": "Wind Mill A Series", - "items": [ - { - "item_code": "Base Bearing Plate", - "qty": 1.0, - "rate": 15.0 - }, - { - "item_code": "Base Plate", - "qty": 1.0, - "rate": 20.0 - }, - { - "item_code": "Bearing Block", - "qty": 1.0, - "rate": 10.0 - }, - { - "item_code": "Bearing Pipe", - "qty": 1.0, - "rate": 15.0 - }, - { - "item_code": "External Disc", - "qty": 1.0, - "rate": 45.0 - }, - { - "item_code": "Shaft", - "qty": 1.0, - "rate": 30.0 - }, - { - "item_code": "Wing Sheet", - "qty": 4.0, - "rate": 22.0 - } - ] - }, - { - "item": "Wind MIll C Series", - "items": [ - { - "item_code": "Base Plate", - "qty": 2.0, - "rate": 20.0 - }, - { - "item_code": "Internal Disc", - "qty": 1.0, - "rate": 33.0 - }, - { - "item_code": "External Disc", - "qty": 1.0, - "rate": 45.0 - }, - { - "item_code": "Bearing Assembly", - "qty": 1.0, - "rate": 130.0 - }, - { - "item_code": "Wing Sheet", - "qty": 3.0, - "rate": 22.0 - } - ] - }, - { - "item": "Wind Turbine-S", - "with_operations": 1, - "operations": [ - { - "operation": "Prepare Frame", - "time_in_mins": 30.0, - "workstation": "Drilling Machine 1" - }, - { - "operation": "Setup Fixtures", - "time_in_mins": 15.0, - "workstation": "Assembly Station 1" - }, - { - "operation": "Assembly Operation", - "time_in_mins": 30.0, - "workstation": "Assembly Station 1" - }, - { - "operation": "Wiring", - "time_in_mins": 20.0, - "workstation": "Assembly Station 1" - }, - { - "operation": "Testing", - "time_in_mins": 10.0, - "workstation": "Packing and Testing Station" - }, - { - "operation": "Packing", - "time_in_mins": 25.0, - "workstation": "Packing and Testing Station" - } - ], - "items": [ - { - "item_code": "Base Bearing Plate", - "qty": 1.0, - "rate": 15.0 - }, - { - "item_code": "Base Plate", - "qty": 1.0, - "rate": 20.0 - }, - { - "item_code": "Bearing Collar", - "qty": 1.0, - "rate": 20.0 - }, - { - "item_code": "Blade Rib", - "qty": 1.0, - "rate": 10.0 - }, - { - "item_code": "Shaft", - "qty": 1.0, - "rate": 30.0 - }, - { - "item_code": "Wing Sheet", - "qty": 2.0, - "rate": 22.0 - } - ] - }, - { - "item": "Base Plate", - "items": [ - { - "item_code": "Base Plate Un Painted", - "qty": 1.0, - "rate": 16.0 - } - ] - } -] \ No newline at end of file diff --git a/erpnext/demo/data/contact.json b/erpnext/demo/data/contact.json deleted file mode 100644 index 113b561ce5a..00000000000 --- a/erpnext/demo/data/contact.json +++ /dev/null @@ -1,164 +0,0 @@ -[ - { - "email_id": "JanVaclavik@example.com", - "first_name": "January", - "last_name": "V\u00e1clav\u00edk", - "links": [{"link_doctype": "Customer", "link_name": "Adaptas"}] - }, - { - "email_id": "ChidumagaTobeolisa@example.com", - "first_name": "Chidumaga", - "last_name": "Tobeolisa", - "links": [{"link_doctype": "Customer", "link_name": "Asian Fusion"}] - }, - { - "email_id": "JanaKubanova@example.com", - "first_name": "Jana", - "last_name": "Kub\u00e1\u0148ov\u00e1", - "links": [{"link_doctype": "Customer", "link_name": "Asian Junction"}] - }, - { - "email_id": "XuChaoXuan@example.com", - "first_name": "\u7d39\u8431", - "last_name": "\u4e8e", - "links": [{"link_doctype": "Customer", "link_name": "Big D Supermarkets"}] - }, - { - "email_id": "OzlemVerwijmeren@example.com", - "first_name": "\u00d6zlem", - "last_name": "Verwijmeren", - "links": [{"link_doctype": "Customer", "link_name": "Buttrey Food & Drug"}] - }, - { - "email_id": "HansRasmussen@example.com", - "first_name": "Hans", - "last_name": "Rasmussen", - "links": [{"link_doctype": "Customer", "link_name": "Chi-Chis"}] - }, - { - "email_id": "SatomiShigeki@example.com", - "first_name": "Satomi", - "last_name": "Shigeki", - "links": [{"link_doctype": "Customer", "link_name": "Choices"}] - }, - { - "email_id": "SimonVJessen@example.com", - "first_name": "Simon", - "last_name": "Jessen", - "links": [{"link_doctype": "Customer", "link_name": "Consumers and Consumers Express"}] - }, - { - "email_id": "NeguaranShahsaah@example.com", - "first_name": "\u0646\u06af\u0627\u0631\u06cc\u0646", - "last_name": "\u0634\u0627\u0647 \u0633\u06cc\u0627\u0647", - "links": [{"link_doctype": "Customer", "link_name": "Crafts Canada"}] - }, - { - "email_id": "Lom-AliBataev@example.com", - "first_name": "Lom-Ali", - "last_name": "Bataev", - "links": [{"link_doctype": "Customer", "link_name": "Endicott Shoes"}] - }, - { - "email_id": "VanNgocTien@example.com", - "first_name": "Ti\u00ean", - "last_name": "V\u0103n", - "links": [{"link_doctype": "Customer", "link_name": "Fayva"}] - }, - { - "email_id": "QuimeyOsorioRuelas@example.com", - "first_name": "Quimey", - "last_name": "Osorio", - "links": [{"link_doctype": "Customer", "link_name": "Intelacard"}] - }, - { - "email_id": "EdgardaSalcedoRaya@example.com", - "first_name": "Edgarda", - "last_name": "Salcedo", - "links": [{"link_doctype": "Customer", "link_name": "Landskip Yard Care"}] - }, - { - "email_id": "HafsteinnBjarnarsonar@example.com", - "first_name": "Hafsteinn", - "last_name": "Bjarnarsonar", - "links": [{"link_doctype": "Customer", "link_name": "Life Plan Counselling"}] - }, - { - "email_id": "\u0434\u0430\u043d\u0438\u0438\u043b@example.com", - "first_name": "\u0414\u0430\u043d\u0438\u0438\u043b", - "last_name": "\u041a\u043e\u043d\u043e\u0432\u0430\u043b\u043e\u0432", - "links": [{"link_doctype": "Customer", "link_name": "Mr Fables"}] - }, - { - "email_id": "SelmaMAndersen@example.com", - "first_name": "Selma", - "last_name": "Andersen", - "links": [{"link_doctype": "Customer", "link_name": "Nelson Brothers"}] - }, - { - "email_id": "LadislavKolaja@example.com", - "first_name": "Ladislav", - "last_name": "Kolaja", - "links": [{"link_doctype": "Customer", "link_name": "Netobill"}] - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Helios Air"}], - "email_id": "TewoldeAbaalom@example.com", - "first_name": "Tewolde", - "last_name": "Abaalom" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Ks Merchandise"}], - "email_id": "LeilaFernandesRodrigues@example.com", - "first_name": "Leila", - "last_name": "Rodrigues" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "HomeBase"}], - "email_id": "DmitryBulgakov@example.com", - "first_name": "Dmitry", - "last_name": "Bulgakov" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Scott Ties"}], - "email_id": "HaiducWhitfoot@example.com", - "first_name": "Haiduc", - "last_name": "Whitfoot" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Reliable Investments"}], - "email_id": "SesseljaPetursdottir@example.com", - "first_name": "Sesselja", - "last_name": "P\u00e9tursd\u00f3ttir" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Nan Duskin"}], - "email_id": "HajdarPignar@example.com", - "first_name": "Hajdar", - "last_name": "Pignar" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Rainbow Records"}], - "email_id": "GustavaLorenzo@example.com", - "first_name": "Gustava", - "last_name": "Lorenzo" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "New World Realty"}], - "email_id": "BethanyWood@example.com", - "first_name": "Bethany", - "last_name": "Wood" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Asiatic Solutions"}], - "email_id": "GlorianaBrownlock@example.com", - "first_name": "Gloriana", - "last_name": "Brownlock" - }, - { - "links": [{"link_doctype": "Supplier", "link_name": "Eagle Hardware"}], - "email_id": "JensonFraser@gustr.com", - "first_name": "Jenson", - "last_name": "Fraser" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/course.json b/erpnext/demo/data/course.json deleted file mode 100644 index 15728d51d3b..00000000000 --- a/erpnext/demo/data/course.json +++ /dev/null @@ -1,134 +0,0 @@ -[ - { - "doctype": "Course", - "course_name": "Communication Skiils", - "course_code": "BCA2040", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Object Oriented Programing - C++", - "course_code": "BCA2030", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Data Structures and Algorithm", - "course_code": "BCA2020", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Operating System", - "course_code": "BCA2010", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Digital Logic", - "course_code": "BCA1040", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Basic Mathematics", - "course_code": "BCA1030", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Programing in C", - "course_code": "BCA1020", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Fundamentals of IT & Programing", - "course_code": "BCA1010", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Microprocessor", - "course_code": "MCA4010", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Probability and Statistics", - "course_code": "MCA4020", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Programing in Java", - "course_code": "MCA4030", - "department": "Information Technology" - }, - { - "doctype": "Course", - "course_name": "Communication Skills", - "course_code": "BBA 101", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Organizational Behavior", - "course_code": "BBA 102", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Business Environment", - "course_code": "BBA 103", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Legal and Regulatory Framework", - "course_code": "BBA 301", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Human Resource Management", - "course_code": "BBA 302", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Advertising and Sales", - "course_code": "BBA 304", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Entrepreneurship Management", - "course_code": "BBA 505", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Visual Merchandising", - "course_code": "BBR 504", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Warehouse Management", - "course_code": "BBR 505", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Store Operations and Job Knowledge", - "course_code": "BBR 501", - "department": "Management Studies" - }, - { - "doctype": "Course", - "course_name": "Management Development and Skills", - "course_code": "BBA 602", - "department": "Management Studies" - } -] diff --git a/erpnext/demo/data/department.json b/erpnext/demo/data/department.json deleted file mode 100644 index f4355ba1e79..00000000000 --- a/erpnext/demo/data/department.json +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "doctype": "Department", - "department_name": "Information Technology" - }, - { - "doctype": "Department", - "department_name": "Physics" - }, - { - "doctype": "Department", - "department_name": "Chemistry" - }, - { - "doctype": "Department", - "department_name": "Biology" - }, - { - "doctype": "Department", - "department_name": "Commerce" - }, - { - "doctype": "Department", - "department_name": "English" - }, - { - "doctype": "Department", - "department_name": "Management Studies" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/drug_list.json b/erpnext/demo/data/drug_list.json deleted file mode 100644 index 3069042843a..00000000000 --- a/erpnext/demo/data/drug_list.json +++ /dev/null @@ -1,5111 +0,0 @@ -[ - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Atocopherol", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Atocopherol", - "item_group": "Drug", - "item_name": "Atocopherol", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - - - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.577151", - "name": "Atocopherol", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Abacavir", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Abacavir", - "item_group": "Drug", - "item_name": "Abacavir", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - - - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.678257", - "name": "Abacavir", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Abciximab", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Abciximab", - "item_group": "Drug", - "item_name": "Abciximab", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.695413", - "name": "Abciximab", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Acacia", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Acacia", - "item_group": "Drug", - "item_name": "Acacia", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.797774", - "name": "Acacia", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Acamprosate", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Acamprosate", - "item_group": "Drug", - "item_name": "Acamprosate", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.826952", - "name": "Acamprosate", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Acarbose", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Acarbose", - "item_group": "Drug", - "item_name": "Acarbose", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.843890", - "name": "Acarbose", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Acebrofylline", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Acebrofylline", - "item_group": "Drug", - "item_name": "Acebrofylline", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.969984", - "name": "Acebrofylline", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Acebrofylline (SR)", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Acebrofylline (SR)", - "item_group": "Drug", - "item_name": "Acebrofylline (SR)", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:16.987354", - "name": "Acebrofylline (SR)", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Aceclofenac", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Aceclofenac", - "item_group": "Drug", - "item_name": "Aceclofenac", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.004369", - "name": "Aceclofenac", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Ash", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Ash", - "item_group": "Drug", - "item_name": "Ash", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.021192", - "name": "Ash", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Asparaginase", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Asparaginase", - "item_group": "Drug", - "item_name": "Asparaginase", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.038058", - "name": "Asparaginase", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Aspartame", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Aspartame", - "item_group": "Drug", - "item_name": "Aspartame", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.054463", - "name": "Aspartame", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Aspartic Acid", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Aspartic Acid", - "item_group": "Drug", - "item_name": "Aspartic Acid", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.071001", - "name": "Aspartic Acid", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Bleomycin", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Bleomycin", - "item_group": "Drug", - "item_name": "Bleomycin", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.087170", - "name": "Bleomycin", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Bleomycin Sulphate", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Bleomycin Sulphate", - "item_group": "Drug", - "item_name": "Bleomycin Sulphate", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.103691", - "name": "Bleomycin Sulphate", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Blue cap contains", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Blue cap contains", - "item_group": "Drug", - "item_name": "Blue cap contains", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.120040", - "name": "Blue cap contains", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Boran", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Boran", - "item_group": "Drug", - "item_name": "Boran", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.135964", - "name": "Boran", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Borax", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Borax", - "item_group": "Drug", - "item_name": "Borax", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.152575", - "name": "Borax", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorbutanol", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorbutanol", - "item_group": "Drug", - "item_name": "Chlorbutanol", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.168998", - "name": "Chlorbutanol", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorbutol", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorbutol", - "item_group": "Drug", - "item_name": "Chlorbutol", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.185316", - "name": "Chlorbutol", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlordiazepoxide", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlordiazepoxide", - "item_group": "Drug", - "item_name": "Chlordiazepoxide", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.208361", - "name": "Chlordiazepoxide", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlordiazepoxide and Clidinium Bromide", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlordiazepoxide and Clidinium Bromide", - "item_group": "Drug", - "item_name": "Chlordiazepoxide and Clidinium Bromide", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.224341", - "name": "Chlordiazepoxide and Clidinium Bromide", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorhexidine", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorhexidine", - "item_group": "Drug", - "item_name": "Chlorhexidine", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.240634", - "name": "Chlorhexidine", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorhexidine 40%", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorhexidine 40%", - "item_group": "Drug", - "item_name": "Chlorhexidine 40%", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.256922", - "name": "Chlorhexidine 40%", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorhexidine Acetate", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorhexidine Acetate", - "item_group": "Drug", - "item_name": "Chlorhexidine Acetate", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.274789", - "name": "Chlorhexidine Acetate", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorhexidine Gluconate", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorhexidine Gluconate", - "item_group": "Drug", - "item_name": "Chlorhexidine Gluconate", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.295371", - "name": "Chlorhexidine Gluconate", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorhexidine HCL", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorhexidine HCL", - "item_group": "Drug", - "item_name": "Chlorhexidine HCL", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.312916", - "name": "Chlorhexidine HCL", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chlorhexidine Hydrochloride", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chlorhexidine Hydrochloride", - "item_group": "Drug", - "item_name": "Chlorhexidine Hydrochloride", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.329570", - "name": "Chlorhexidine Hydrochloride", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Chloride", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Chloride", - "item_group": "Drug", - "item_name": "Chloride", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.346088", - "name": "Chloride", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Fosfomycin Tromethamine", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Fosfomycin Tromethamine", - "item_group": "Drug", - "item_name": "Fosfomycin Tromethamine", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.362777", - "name": "Fosfomycin Tromethamine", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Fosinopril", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Fosinopril", - "item_group": "Drug", - "item_name": "Fosinopril", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.379465", - "name": "Fosinopril", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Iodochlorhydroxyquinoline", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Iodochlorhydroxyquinoline", - "item_group": "Drug", - "item_name": "Iodochlorhydroxyquinoline", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.396068", - "name": "Iodochlorhydroxyquinoline", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Iodochlorohydroxyquinoline", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Iodochlorohydroxyquinoline", - "item_group": "Drug", - "item_name": "Iodochlorohydroxyquinoline", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.412734", - "name": "Iodochlorohydroxyquinoline", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Ipratropium", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Ipratropium", - "item_group": "Drug", - "item_name": "Ipratropium", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.429333", - "name": "Ipratropium", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Mebeverine hydrochloride", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Mebeverine hydrochloride", - "item_group": "Drug", - "item_name": "Mebeverine hydrochloride", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.445814", - "name": "Mebeverine hydrochloride", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Mecetronium ethylsulphate", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Mecetronium ethylsulphate", - "item_group": "Drug", - "item_name": "Mecetronium ethylsulphate", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.461696", - "name": "Mecetronium ethylsulphate", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Meclizine", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Meclizine", - "item_group": "Drug", - "item_name": "Meclizine", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.478020", - "name": "Meclizine", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Oxaprozin", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Oxaprozin", - "item_group": "Drug", - "item_name": "Oxaprozin", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - - - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.496221", - "name": "Oxaprozin", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Oxazepam", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Oxazepam", - "item_group": "Drug", - "item_name": "Oxazepam", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.511933", - "name": "Oxazepam", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Oxcarbazepine", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Oxcarbazepine", - "item_group": "Drug", - "item_name": "Oxcarbazepine", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.528472", - "name": "Oxcarbazepine", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Oxetacaine", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Oxetacaine", - "item_group": "Drug", - "item_name": "Oxetacaine", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.544177", - "name": "Oxetacaine", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Oxethazaine", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Oxethazaine", - "item_group": "Drug", - "item_name": "Oxethazaine", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.560193", - "name": "Oxethazaine", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Suxamethonium Chloride", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Suxamethonium Chloride", - "item_group": "Drug", - "item_name": "Suxamethonium Chloride", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.576447", - "name": "Suxamethonium Chloride", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Tacrolimus", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Tacrolimus", - "item_group": "Drug", - "item_name": "Tacrolimus", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.593481", - "name": "Tacrolimus", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Ubiquinol", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Ubiquinol", - "item_group": "Drug", - "item_name": "Ubiquinol", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.609930", - "name": "Ubiquinol", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Vitamin B12", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Vitamin B12", - "item_group": "Drug", - "item_name": "Vitamin B12", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.626225", - "name": "Vitamin B12", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Vitamin B1Hydrochloride", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Vitamin B1Hydrochloride", - "item_group": "Drug", - "item_name": "Vitamin B1Hydrochloride", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.642423", - "name": "Vitamin B1Hydrochloride", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Vitamin B1Monohydrate", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Vitamin B1Monohydrate", - "item_group": "Drug", - "item_name": "Vitamin B1Monohydrate", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.658946", - "name": "Vitamin B1Monohydrate", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Vitamin B2", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Vitamin B2", - "item_group": "Drug", - "item_name": "Vitamin B2", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.675234", - "name": "Vitamin B2", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Vitamin B3", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Vitamin B3", - "item_group": "Drug", - "item_name": "Vitamin B3", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.691598", - "name": "Vitamin B3", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Vitamin D4", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Vitamin D4", - "item_group": "Drug", - "item_name": "Vitamin D4", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.707840", - "name": "Vitamin D4", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Vitamin E", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Vitamin E", - "item_group": "Drug", - "item_name": "Vitamin E", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.723859", - "name": "Vitamin E", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Wheat Germ Oil", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Wheat Germ Oil", - "item_group": "Drug", - "item_name": "Wheat Germ Oil", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.739829", - "name": "Wheat Germ Oil", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Wheatgrass extr", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Wheatgrass extr", - "item_group": "Drug", - "item_name": "Wheatgrass extr", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.757695", - "name": "Wheatgrass extr", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Whey Protein", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Whey Protein", - "item_group": "Drug", - "item_name": "Whey Protein", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.774098", - "name": "Whey Protein", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Xylometazoline", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Xylometazoline", - "item_group": "Drug", - "item_name": "Xylometazoline", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.790224", - "name": "Xylometazoline", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Xylometazoline Hydrochloride", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Xylometazoline Hydrochloride", - "item_group": "Drug", - "item_name": "Xylometazoline Hydrochloride", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.806359", - "name": "Xylometazoline Hydrochloride", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Yeast", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Yeast", - "item_group": "Drug", - "item_name": "Yeast", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.823305", - "name": "Yeast", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Yellow Fever Vaccine", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Yellow Fever Vaccine", - "item_group": "Drug", - "item_name": "Yellow Fever Vaccine", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.840250", - "name": "Yellow Fever Vaccine", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Zafirlukast", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Zafirlukast", - "item_group": "Drug", - "item_name": "Zafirlukast", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.856856", - "name": "Zafirlukast", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Zaleplon", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Zaleplon", - "item_group": "Drug", - "item_name": "Zaleplon", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.873287", - "name": "Zaleplon", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Zaltoprofen", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Zaltoprofen", - "item_group": "Drug", - "item_name": "Zaltoprofen", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.889263", - "name": "Zaltoprofen", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - }, - { - "asset_category": null, - "attributes": [], - "barcode": null, - "brand": null, - "buying_cost_center": null, - "country_of_origin": null, - "create_new_batch": 0, - "customer_code": "", - "customer_items": [], - "customs_tariff_number": null, - "default_bom": null, - "default_material_request_type": null, - "default_supplier": null, - "default_warehouse": null, - "delivered_by_supplier": 0, - "description": "Zanamivir", - "disabled": 0, - "docstatus": 0, - "doctype": "Item", - "end_of_life": null, - "expense_account": null, - "gst_hsn_code": null, - "has_batch_no": 0, - "has_serial_no": 0, - "has_variants": 0, - "image": null, - "income_account": null, - "inspection_required_before_delivery": 0, - "inspection_required_before_purchase": 0, - "is_fixed_asset": 0, - "is_purchase_item": 1, - "is_sales_item": 1, - "is_stock_item": 1, - "is_sub_contracted_item": 0, - "item_code": "Zanamivir", - "item_group": "Drug", - "item_name": "Zanamivir", - "last_purchase_rate": 0.0, - "lead_time_days": 0, - "max_discount": 0.0, - "min_order_qty": 0.0, - "modified": "2017-07-06 12:53:17.905022", - "name": "Zanamivir", - "naming_series": null, - "net_weight": 0.0, - "opening_stock": 0.0, - "quality_parameters": [], - "reorder_levels": [], - "route": null, - "safety_stock": 0.0, - "selling_cost_center": null, - "serial_no_series": null, - "show_in_website": 0, - "show_variant_in_website": 0, - "slideshow": null, - "standard_rate": 0.0, - "stock_uom": "Nos", - "supplier_items": [], - "taxes": [], - "thumbnail": null, - "tolerance": 0.0, - "uoms": [ - { - "conversion_factor": 1.0, - "uom": "Nos" - } - ], - "valuation_method": null, - "valuation_rate": 0.0, - "variant_based_on": null, - "variant_of": null, - "warranty_period": null, - "web_long_description": null, - "website_image": null, - "website_item_groups": [], - "website_specifications": [], - "website_warehouse": null, - "weight_uom": null, - "weightage": 0 - } -] diff --git a/erpnext/demo/data/employee.json b/erpnext/demo/data/employee.json deleted file mode 100644 index 2d2dbe894bc..00000000000 --- a/erpnext/demo/data/employee.json +++ /dev/null @@ -1,92 +0,0 @@ -[ - { - "date_of_birth": "1982-01-03", - "date_of_joining": "2001-10-10", - "employee_name": "Diana Prince", - "first_name": "Diana", - "last_name": "Prince", - "gender": "Female", - "user_id": "DianaPrince@example.com" - }, - { - "date_of_birth": "1959-02-03", - "date_of_joining": "1976-09-16", - "employee_name": "Zatanna Zatara", - "gender": "Female", - "user_id": "ZatannaZatara@example.com", - "first_name": "Zatanna", - "last_name": "Zatara" - }, - { - "date_of_birth": "1982-03-03", - "date_of_joining": "2000-06-16", - "employee_name": "Holly Granger", - "gender": "Female", - "user_id": "HollyGranger@example.com", - "first_name": "Holly", - "last_name": "Granger" - }, - { - "date_of_birth": "1945-04-04", - "date_of_joining": "1969-07-01", - "employee_name": "Neptunia Aquaria", - "gender": "Female", - "user_id": "NeptuniaAquaria@example.com", - "first_name": "Neptunia", - "last_name": "Aquaria" - }, - { - "date_of_birth": "1978-05-03", - "date_of_joining": "1999-12-24", - "employee_name": "Arthur Curry", - "gender": "Male", - "user_id": "ArthurCurry@example.com", - "first_name": "Arthur", - "last_name": "Curry" - }, - { - "date_of_birth": "1964-06-03", - "date_of_joining": "1981-08-05", - "employee_name": "Thalia Al Ghul", - "gender": "Female", - "user_id": "ThaliaAlGhul@example.com", - "first_name": "Thalia", - "last_name": "Al Ghul" - }, - { - "date_of_birth": "1982-07-03", - "date_of_joining": "2006-06-10", - "employee_name": "Maxwell Lord", - "gender": "Male", - "user_id": "MaxwellLord@example.com", - "first_name": "Maxwell", - "last_name": "Lord" - }, - { - "date_of_birth": "1969-08-03", - "date_of_joining": "1993-10-21", - "employee_name": "Grace Choi", - "gender": "Female", - "user_id": "GraceChoi@example.com", - "first_name": "Grace", - "last_name": "Choi" - }, - { - "date_of_birth": "1982-09-03", - "date_of_joining": "2005-09-06", - "employee_name": "Vandal Savage", - "gender": "Male", - "user_id": "VandalSavage@example.com", - "first_name": "Vandal", - "last_name": "Savage" - }, - { - "date_of_birth": "1985-10-03", - "date_of_joining": "2007-12-25", - "employee_name": "Caitlin Snow", - "gender": "Female", - "user_id": "CaitlinSnow@example.com", - "first_name": "Caitlin", - "last_name": "Snow" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/grading_scale.json b/erpnext/demo/data/grading_scale.json deleted file mode 100644 index 07609197c45..00000000000 --- a/erpnext/demo/data/grading_scale.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "doctype": "Grading Scale", - "grading_scale_name": "Standard Grading", - "description": "Standard Grading Scale", - "intervals": [ - {"threshold": 100.0, "grade_code": "A", "grade_description": "Excellent"}, - {"threshold": 89.9, "grade_code": "B+", "grade_description": "Close to Excellence"}, - {"threshold": 80.0, "grade_code": "B", "grade_description": "Good"}, - {"threshold": 69.9, "grade_code": "C+", "grade_description": "Almost Good"}, - {"threshold": 60.0, "grade_code": "C", "grade_description": "Average"}, - {"threshold": 50.0, "grade_code": "D+", "grade_description": "Have to Work"}, - {"threshold": 40.0, "grade_code": "D", "grade_description": "Not met Baseline Expectations"}, - {"threshold": 0.0, "grade_code": "F", "grade_description": "Have to work a lot"} - ] - } -] \ No newline at end of file diff --git a/erpnext/demo/data/instructor.json b/erpnext/demo/data/instructor.json deleted file mode 100644 index a25d16304d7..00000000000 --- a/erpnext/demo/data/instructor.json +++ /dev/null @@ -1,128 +0,0 @@ -[ - { - "doctype": "Instructor", - "instructor_name": "Eddie Jessup", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "William Dyer", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Alastor Moody", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Charles Xavier", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Cuthbert Calculus", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Reed Richards", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Urban Chronotis", - "naming_series": "INS/", - "department": "Physics" - }, - { - "doctype": "Instructor", - "instructor_name": "River Song", - "naming_series": "INS/", - "department": "Physics" - }, - { - "doctype": "Instructor", - "instructor_name": "Yana", - "naming_series": "INS/", - "department": "Physics" - }, - { - "doctype": "Instructor", - "instructor_name": "Neil Lasrado", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Deepshi Garg", - "naming_series": "INS/", - "department": "Chemistry" - }, - { - "doctype": "Instructor", - "instructor_name": "Shubham Saxena", - "naming_series": "INS/", - "department": "Physics" - }, - { - "doctype": "Instructor", - "instructor_name": "Rushabh Mehta", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Umari Syed", - "naming_series": "INS/", - "department": "Chemistry" - }, - { - "doctype": "Instructor", - "instructor_name": "Aman Singh", - "naming_series": "INS/", - "department": "Physics" - }, - { - "doctype": "Instructor", - "instructor_name": "Nabin", - "naming_series": "INS/", - "department": "Chemistry" - }, - { - "doctype": "Instructor", - "instructor_name": "Kanchan Chauhan", - "naming_series": "INS/", - "department": "Information Technology" - }, - { - "doctype": "Instructor", - "instructor_name": "Valmik Jangla", - "naming_series": "INS/", - "department": "Chemistry" - }, - { - "doctype": "Instructor", - "instructor_name": "Amit Jain", - "naming_series": "INS/", - "department": "Physics" - }, - { - "doctype": "Instructor", - "instructor_name": "Shreyas P", - "naming_series": "INS/", - "department": "Chemistry" - }, - { - "doctype": "Instructor", - "instructor_name": "Rohit", - "naming_series": "INS/", - "department": "Information Technology" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/item.json b/erpnext/demo/data/item.json deleted file mode 100644 index 1d4ed343be6..00000000000 --- a/erpnext/demo/data/item.json +++ /dev/null @@ -1,493 +0,0 @@ -[ - { - "item_defaults": [ - { - "default_supplier": "Asiatic Solutions", - "default_warehouse": "Stores" - } - ], - "description": "For Upper Bearing", - "image": "/assets/erpnext_demo/images/disc.png", - "item_code": "Disc Collars", - "item_group": "Raw Material", - "item_name": "Disc Collars" - }, - { - "item_defaults": [ - { - "default_supplier": "Nan Duskin", - "default_warehouse": "Stores" - } - ], - "description": "CAST IRON, MCMASTER PART NO. 3710T13", - "image": "/assets/erpnext_demo/images/bearing.jpg", - "item_code": "Bearing Block", - "item_group": "Raw Material", - "item_name": "Bearing Block" - }, - { - "item_defaults": [ - { - "default_supplier": null, - "default_warehouse": "Finished Goods" - } - ], - "description": "Wind Mill C Series for Commercial Use 18ft", - "image": "/assets/erpnext_demo/images/wind-turbine-2.png", - "item_code": "Wind MIll C Series", - "item_group": "Products", - "item_name": "Wind MIll C Series" - }, - { - "item_defaults": [ - { - "default_supplier": null, - "default_warehouse": "Finished Goods" - } - ], - "description": "Wind Mill A Series for Home Use 9ft", - "image": "/assets/erpnext_demo/images/wind-turbine.png", - "item_code": "Wind Mill A Series", - "item_group": "Products", - "item_name": "Wind Mill A Series" - }, - { - "item_defaults": [ - { - "default_supplier": null, - "default_warehouse": "Finished Goods" - } - ], - "description": "Small Wind Turbine for Home Use\n\n\n", - "image": "/assets/erpnext_demo/images/wind-turbine-1.jpg", - "item_code": "Wind Turbine", - "item_group": "Products", - "item_name": "Wind Turbine", - "has_variants": 1, - "has_serial_no": 1, - "attributes": [ - { - "attribute": "Size" - } - ] - }, - { - "item_defaults": [ - { - "default_supplier": "HomeBase", - "default_warehouse": "Stores" - } - ], - "description": "1.5 in. Diameter x 36 in. Mild Steel Tubing", - "image": null, - "item_code": "Bearing Pipe", - "item_group": "Raw Material", - "item_name": "Bearing Pipe" - }, - { - "item_defaults": [ - { - "default_supplier": "New World Realty", - "default_warehouse": "Stores" - } - ], - "description": "1/32 in. x 24 in. x 47 in. HDPE Opaque Sheet", - "image": null, - "item_code": "Wing Sheet", - "item_group": "Raw Material", - "item_name": "Wing Sheet" - }, - { - "item_defaults": [ - { - "default_supplier": "Eagle Hardware", - "default_warehouse": "Stores" - } - ], - "description": "3/16 in. x 6 in. x 6 in. Low Carbon Steel Plate", - "image": null, - "item_code": "Upper Bearing Plate", - "item_group": "Raw Material", - "item_name": "Upper Bearing Plate" - }, - { - "item_defaults": [ - { - "default_supplier": "Asiatic Solutions", - "default_warehouse": "Stores" - } - ], - "description": "Bearing Assembly", - "image": null, - "item_code": "Bearing Assembly", - "item_group": "Sub Assemblies", - "item_name": "Bearing Assembly" - }, - { - "item_defaults": [ - { - "default_supplier": "HomeBase", - "default_warehouse": "Stores" - } - ], - "description": "3/4 in. x 2 ft. x 4 ft. Pine Plywood", - "image": null, - "item_code": "Base Plate", - "item_group": "Raw Material", - "item_name": "Base Plate", - "is_sub_contracted_item": 1 - }, - { - "item_defaults": [ - { - "default_supplier": "Scott Ties", - "default_warehouse": "Stores" - } - ], - "description": "N/A", - "image": null, - "item_code": "Stand", - "item_group": "Raw Material", - "item_name": "Stand" - }, - { - "item_defaults": [ - { - "default_supplier": "Eagle Hardware", - "default_warehouse": "Stores" - } - ], - "description": "1 in. x 3 in. x 1 ft. Multipurpose Al Alloy Bar", - "image": null, - "item_code": "Bearing Collar", - "item_group": "Raw Material", - "item_name": "Bearing Collar" - }, - { - "item_defaults": [ - { - "default_supplier": "Eagle Hardware", - "default_warehouse": "Stores" - } - ], - "description": "1/4 in. x 6 in. x 6 in. Mild Steel Plate", - "image": null, - "item_code": "Base Bearing Plate", - "item_group": "Raw Material", - "item_name": "Base Bearing Plate" - }, - { - "item_defaults": [ - { - "default_supplier": "HomeBase", - "default_warehouse": "Stores" - } - ], - "description": "15/32 in. x 4 ft. x 8 ft. 3-Ply Rtd Sheathing", - "image": null, - "item_code": "External Disc", - "item_group": "Raw Material", - "item_name": "External Disc" - }, - { - "item_defaults": [ - { - "default_supplier": "Eagle Hardware", - "default_warehouse": "Stores" - } - ], - "description": "1.25 in. Diameter x 6 ft. Mild Steel Tubing", - "image": null, - "item_code": "Shaft", - "item_group": "Raw Material", - "item_name": "Shaft" - }, - { - "item_defaults": [ - { - "default_supplier": "Ks Merchandise", - "default_warehouse": "Stores" - } - ], - "description": "1/2 in. x 2 ft. x 4 ft. Pine Plywood", - "image": null, - "item_code": "Blade Rib", - "item_group": "Raw Material", - "item_name": "Blade Rib" - }, - { - "item_defaults": [ - { - "default_supplier": "HomeBase", - "default_warehouse": "Stores" - } - ], - "description": "For Bearing Collar", - "image": null, - "item_code": "Internal Disc", - "item_group": "Raw Material", - "item_name": "Internal Disc" - }, - { - "item_defaults": [ - { - "default_supplier": null, - "default_warehouse": "Finished Goods" - } - ], - "description": "Small Wind Turbine for Home Use\n\n\n\nSize: Small
", - "image": "/assets/erpnext_demo/images/wind-turbine-1.jpg", - "item_code": "Wind Turbine-S", - "item_group": "Products", - "item_name": "Wind Turbine-S", - "variant_of": "Wind Turbine", - "valuation_rate": 300, - "attributes": [ - { - "attribute": "Size", - "attribute_value": "Small" - } - ] - }, - { - "item_defaults": [ - { - "default_supplier": null, - "default_warehouse": "Finished Goods" - } - ], - "description": "Small Wind Turbine for Home Use\n\n\n\nSize: Medium
", - "image": "/assets/erpnext_demo/images/wind-turbine-1.jpg", - "item_code": "Wind Turbine-M", - "item_group": "Products", - "item_name": "Wind Turbine-M", - "variant_of": "Wind Turbine", - "valuation_rate": 300, - "attributes": [ - { - "attribute": "Size", - "attribute_value": "Medium" - } - ] - }, - { - "item_defaults": [ - { - "default_supplier": null, - "default_warehouse": "Finished Goods" - } - ], - "description": "Small Wind Turbine for Home Use\n\n\n\nSize: Large
", - "image": "/assets/erpnext_demo/images/wind-turbine-1.jpg", - "item_code": "Wind Turbine-L", - "item_group": "Products", - "item_name": "Wind Turbine-L", - "variant_of": "Wind Turbine", - "valuation_rate": 300, - "attributes": [ - { - "attribute": "Size", - "attribute_value": "Large" - } - ] - }, - { - "is_stock_item": 0, - "description": "Wind Mill A Series with Spare Bearing", - "item_code": "Wind Mill A Series with Spare Bearing", - "item_group": "Products", - "item_name": "Wind Mill A Series with Spare Bearing" - }, - { - "item_defaults": [ - { - "default_supplier": "HomeBase", - "default_warehouse": "Stores" - } - ], - "description": "3/4 in. x 2 ft. x 4 ft. Pine Plywood", - "image": null, - "item_code": "Base Plate Un Painted", - "item_group": "Raw Material", - "item_name": "Base Plate Un Painted" - }, - { - "is_fixed_asset": 1, - "asset_category": "Furnitures", - "is_stock_item": 0, - "description": "Table", - "item_code": "Table", - "item_name": "Table", - "item_group": "Products" - }, - { - "is_fixed_asset": 1, - "asset_category": "Furnitures", - "is_stock_item": 0, - "description": "Chair", - "item_code": "Chair", - "item_name": "Chair", - "item_group": "Products" - }, - { - "is_fixed_asset": 1, - "asset_category": "Electronic Equipments", - "is_stock_item": 0, - "description": "Computer", - "item_code": "Computer", - "item_name": "Computer", - "item_group": "Products" - }, - { - "is_fixed_asset": 1, - "asset_category": "Electronic Equipments", - "is_stock_item": 0, - "description": "Mobile", - "item_code": "Mobile", - "item_name": "Mobile", - "item_group": "Products" - }, - { - "is_fixed_asset": 1, - "asset_category": "Softwares", - "is_stock_item": 0, - "description": "ERP", - "item_code": "ERP", - "item_name": "ERP", - "item_group": "All Item Groups" - }, - { - "is_fixed_asset": 1, - "asset_category": "Softwares", - "is_stock_item": 0, - "description": "Autocad", - "item_code": "Autocad", - "item_name": "Autocad", - "item_group": "All Item Groups" - }, - { - "is_stock_item": 1, - "has_batch_no": 1, - "create_new_batch": 1, - "valuation_rate": 200, - "item_defaults": [ - { - "default_warehouse": "Stores" - } - ], - "description": "Corrugated Box", - "item_code": "Corrugated Box", - "item_name": "Corrugated Box", - "item_group": "All Item Groups" - }, - { - "item_defaults": [ - { - "default_warehouse": "Finished Goods" - } - ], - "is_stock_item": 1, - "description": "OnePlus 6", - "item_code": "OnePlus 6", - "item_name": "OnePlus 6", - "item_group": "Products", - "domain": "Retail" - }, - { - "item_defaults": [ - { - "default_warehouse": "Finished Goods" - } - ], - "is_stock_item": 1, - "description": "OnePlus 6T", - "item_code": "OnePlus 6T", - "item_name": "OnePlus 6T", - "item_group": "Products", - "domain": "Retail" - }, - { - "item_defaults": [ - { - "default_warehouse": "Finished Goods" - } - ], - "is_stock_item": 1, - "description": "Xiaomi Poco F1", - "item_code": "Xiaomi Poco F1", - "item_name": "Xiaomi Poco F1", - "item_group": "Products", - "domain": "Retail" - }, - { - "item_defaults": [ - { - "default_warehouse": "Finished Goods" - } - ], - "is_stock_item": 1, - "description": "Iphone XS", - "item_code": "Iphone XS", - "item_name": "Iphone XS", - "item_group": "Products", - "domain": "Retail" - }, - { - "item_defaults": [ - { - "default_warehouse": "Finished Goods" - } - ], - "is_stock_item": 1, - "description": "Samsung Galaxy S9", - "item_code": "Samsung Galaxy S9", - "item_name": "Samsung Galaxy S9", - "item_group": "Products", - "domain": "Retail" - }, - { - "item_defaults": [ - { - "default_warehouse": "Finished Goods" - } - ], - "is_stock_item": 1, - "description": "Sony Bluetooth Headphone", - "item_code": "Sony Bluetooth Headphone", - "item_name": "Sony Bluetooth Headphone", - "item_group": "Products", - "domain": "Retail" - }, - { - "is_stock_item": 0, - "description": "Samsung Phone Repair", - "item_code": "Samsung Phone Repair", - "item_name": "Samsung Phone Repair", - "item_group": "Services", - "domain": "Retail" - }, - { - "is_stock_item": 0, - "description": "OnePlus Phone Repair", - "item_code": "OnePlus Phone Repair", - "item_name": "OnePlus Phone Repair", - "item_group": "Services", - "domain": "Retail" - }, - { - "is_stock_item": 0, - "description": "Xiaomi Phone Repair", - "item_code": "Xiaomi Phone Repair", - "item_name": "Xiaomi Phone Repair", - "item_group": "Services", - "domain": "Retail" - }, - { - "is_stock_item": 0, - "description": "Apple Phone Repair", - "item_code": "Apple Phone Repair", - "item_name": "Apple Phone Repair", - "item_group": "Services", - "domain": "Retail" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/item_education.json b/erpnext/demo/data/item_education.json deleted file mode 100644 index 40e4701596a..00000000000 --- a/erpnext/demo/data/item_education.json +++ /dev/null @@ -1,137 +0,0 @@ -[ - { - "default_supplier": "Asiatic Solutions", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Books", - "item_group": "Raw Material", - "item_name": "Books" - }, - { - "default_supplier": "HomeBase", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Pencil", - "item_group": "Raw Material", - "item_name": "Pencil" - }, - { - "default_supplier": "New World Realty", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Tables", - "item_group": "Raw Material", - "item_name": "Tables" - }, - { - "default_supplier": "Eagle Hardware", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Chair", - "item_group": "Raw Material", - "item_name": "Chair" - }, - { - "default_supplier": "Asiatic Solutions", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Black Board", - "item_group": "Sub Assemblies", - "item_name": "Black Board" - }, - { - "default_supplier": "HomeBase", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Chalk", - "item_group": "Raw Material", - "item_name": "Chalk" - }, - { - "default_supplier": "HomeBase", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Notepad", - "item_group": "Raw Material", - "item_name": "Notepad" - }, - { - "default_supplier": "Ks Merchandise", - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Uniform", - "item_group": "Raw Material", - "item_name": "Uniform" - }, - { - "is_stock_item": 0, - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "description": "Computer", - "item_code": "Computer", - "item_name": "Computer", - "item_group": "Products" - }, - { - "is_stock_item": 0, - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "description": "Mobile", - "item_code": "Mobile", - "item_name": "Mobile", - "item_group": "Products" - }, - { - "is_stock_item": 0, - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "description": "ERP", - "item_code": "ERP", - "item_name": "ERP", - "item_group": "All Item Groups" - }, - { - "is_stock_item": 0, - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "description": "Autocad", - "item_code": "Autocad", - "item_name": "Autocad", - "item_group": "All Item Groups" - }, - { - "item_defaults": [{ - "default_warehouse": "Stores", - "company": "Whitmore College" - }], - "item_code": "Service", - "item_group": "Services", - "item_name": "Service", - "has_variants": 0, - "is_stock_item": 0 - } -] \ No newline at end of file diff --git a/erpnext/demo/data/lead.json b/erpnext/demo/data/lead.json deleted file mode 100644 index ff788778977..00000000000 --- a/erpnext/demo/data/lead.json +++ /dev/null @@ -1,127 +0,0 @@ -[ - { - "company_name": "Zany Brainy", - "email_id": "MartLakeman@example.com", - "lead_name": "Mart Lakeman" - }, - { - "company_name": "Patterson-Fletcher", - "email_id": "SagaLundqvist@example.com", - "lead_name": "Saga Lundqvist" - }, - { - "company_name": "Griff's Hamburgers", - "email_id": "AdnaSjoberg@example.com", - "lead_name": "Adna Sj\u00f6berg" - }, - { - "company_name": "Rhodes Furniture", - "email_id": "IdaDSvendsen@example.com", - "lead_name": "Ida Svendsen" - }, - { - "company_name": "Burger Chef", - "email_id": "EmppuHameenniemi@example.com", - "lead_name": "Emppu H\u00e4meenniemi" - }, - { - "company_name": "Stratabiz", - "email_id": "EugenioPisano@example.com", - "lead_name": "Eugenio Pisano" - }, - { - "company_name": "Home Quarters Warehouse", - "email_id": "SemharHagos@example.com", - "lead_name": "Semhar Hagos" - }, - { - "company_name": "Enviro Architectural Designs", - "email_id": "BranimiraIvankovic@example.com", - "lead_name": "Branimira Ivankovi\u0107" - }, - { - "company_name": "Ideal Garden Management", - "email_id": "ShellyLFields@example.com", - "lead_name": "Shelly Fields" - }, - { - "company_name": "Listen Up", - "email_id": "LeoMikulic@example.com", - "lead_name": "Leo Mikuli\u0107" - }, - { - "company_name": "I. Magnin", - "email_id": "DenisaJarosova@example.com", - "lead_name": "Denisa Jaro\u0161ov\u00e1" - }, - { - "company_name": "First Rate Choice", - "email_id": "JanekRutkowski@example.com", - "lead_name": "Janek Rutkowski" - }, - { - "company_name": "Multi Tech Development", - "email_id": "mm@example.com", - "lead_name": "\u7f8e\u6708 \u5b87\u85e4" - }, - { - "company_name": "National Auto Parts", - "email_id": "dd@example.com", - "lead_name": "\u0414\u0430\u043d\u0438\u0438\u043b \u0410\u0444\u0430\u043d\u0430\u0441\u044c\u0435\u0432" - }, - { - "company_name": "Integra Investment Plan", - "email_id": "ZorislavPetkovic@example.com", - "lead_name": "Zorislav Petkovi\u0107" - }, - { - "company_name": "The Lawn Guru", - "email_id": "NanaoNiwa@example.com", - "lead_name": "Nanao Niwa" - }, - { - "company_name": "Buena Vista Realty Service", - "email_id": "HreiarJorundsson@example.com", - "lead_name": "Hrei\u00f0ar J\u00f6rundsson" - }, - { - "company_name": "Bountiful Harvest Health Food Store", - "email_id": "ChuThiBichLai@example.com", - "lead_name": "Lai Chu" - }, - { - "company_name": "P. Samuels Men's Clothiers", - "email_id": "VictorAksakov@example.com", - "lead_name": "Victor Aksakov" - }, - { - "company_name": "Vinyl Fever", - "email_id": "SaidalimBisliev@example.com", - "lead_name": "Saidalim Bisliev" - }, - { - "company_name": "Garden Master", - "email_id": "TotteJakobsson@example.com", - "lead_name": "Totte Jakobsson" - }, - { - "company_name": "Big Apple", - "email_id": "NanaArmasRobles@example.com", - "lead_name": "Nan\u00e1 Armas" - }, - { - "company_name": "Monk House Sales", - "email_id": "WalerianDuda@example.com", - "lead_name": "Walerian Duda" - }, - { - "company_name": "ManCharm", - "email_id": "Moarimikashi@example.com", - "lead_name": "Moarimikashi" - }, - { - "company_name": "Custom Lawn Care", - "email_id": "DobromilDabrowski@example.com", - "lead_name": "Dobromi\u0142 D\u0105browski" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/location.json b/erpnext/demo/data/location.json deleted file mode 100644 index b521aa08c48..00000000000 --- a/erpnext/demo/data/location.json +++ /dev/null @@ -1,22 +0,0 @@ -[ - { - "location_name": "Main Location", - "latitude": 40.0, - "longitude": 20.0 - }, - { - "location_name": "Avg Location", - "latitude": 63.0, - "longitude": 99.3 - }, - { - "location_name": "Zany Location", - "latitude": 47.5, - "longitude": 10.0 - }, - { - "location_name": "Fletcher Location", - "latitude": 100.90, - "longitude": 80 - } -] \ No newline at end of file diff --git a/erpnext/demo/data/operation.json b/erpnext/demo/data/operation.json deleted file mode 100644 index 47f26d1d521..00000000000 --- a/erpnext/demo/data/operation.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - { - "description": "Setup Fixtures for Assembly", - "name": "Setup Fixtures", - "workstation": "Assembly Station 1" - }, - { - "description": "Assemble Unit as per Standard Operating Procedures", - "name": "Assembly Operation", - "workstation": "Assembly Station 1" - }, - { - "description": "Final Testing Checklist", - "name": "Testing", - "workstation": "Packing and Testing Station" - }, - { - "description": "Final Packing and add Instructions", - "name": "Packing", - "workstation": "Packing and Testing Station" - }, - { - "description": "Prepare frame for assembly", - "name": "Prepare Frame", - "workstation": "Drilling Machine 1" - }, - { - "description": "Connect wires", - "name": "Wiring", - "workstation": "Assembly Station 1" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/patient.json b/erpnext/demo/data/patient.json deleted file mode 100644 index 6d95a202021..00000000000 --- a/erpnext/demo/data/patient.json +++ /dev/null @@ -1,27 +0,0 @@ -[ - { - "patient_name": "lila", - "gender": "Female" - }, - { - "patient_name": "charline", - "gender": "Female" - }, - { - "patient_name": "soren", - "last_name": "le gall", - "gender": "Male" - }, - { - "patient_name": "fanny", - "gender": "Female" - }, - { - "patient_name": "julie", - "gender": "Female" - }, - { - "patient_name": "louka", - "gender": "Male" - } -] diff --git a/erpnext/demo/data/practitioner.json b/erpnext/demo/data/practitioner.json deleted file mode 100644 index 39c960fcd7e..00000000000 --- a/erpnext/demo/data/practitioner.json +++ /dev/null @@ -1,17 +0,0 @@ -[ - { - "doctype": "Healthcare Practitioner", - "first_name": "Eddie Jessup", - "department": "Pathology" - }, - { - "doctype": "Healthcare Practitioner", - "first_name": "Deepshi Garg", - "department": "ENT" - }, - { - "doctype": "Healthcare Practitioner", - "first_name": "Amit Jain", - "department": "Microbiology" - } -] diff --git a/erpnext/demo/data/program.json b/erpnext/demo/data/program.json deleted file mode 100644 index 9c2ec77a4b9..00000000000 --- a/erpnext/demo/data/program.json +++ /dev/null @@ -1,46 +0,0 @@ -[ - { - "doctype": "Program", - "name": "MCA", - "program_name": "Masters of Computer Applications", - "program_code": "MCA", - "department": "Information Technology", - "courses": [ - { "course": "MCA4010" }, - { "course": "MCA4020" }, - { "course": "MCA4030" } - ] - }, - { - "doctype": "Program", - "name": "BCA", - "program_name": "Bachelor of Computer Applications", - "program_code": "BCA", - "department": "Information Technology", - "courses": [ - { "course": "BCA2030" }, - { "course": "BCA1030" }, - { "course": "BCA2020" }, - { "course": "BCA1040" }, - { "course": "BCA1010" }, - { "course": "BCA2010" }, - { "course": "BCA1020" } - ] - }, - { - "doctype": "Program", - "name": "BBA", - "program_name": "Bachelor of Business Administration", - "program_code": "BBA", - "department": "Management Studies", - "courses": [ - { "course": "BBA 101" }, - { "course": "BBA 102" }, - { "course": "BBA 103" }, - { "course": "BBA 301" }, - { "course": "BBA 302" }, - { "course": "BBA 304" }, - { "course": "BBA 505" } - ] - } -] \ No newline at end of file diff --git a/erpnext/demo/data/random_student_data.json b/erpnext/demo/data/random_student_data.json deleted file mode 100644 index babcc715760..00000000000 --- a/erpnext/demo/data/random_student_data.json +++ /dev/null @@ -1,1604 +0,0 @@ -[ -{ -"first_name": "amanda", -"last_name": "edwards", -"image": "https://randomuser.me/api/portraits/women/55.jpg", -"gender": "Female" -}, -{ -"first_name": "abbie", -"last_name": "johnston", -"image": "https://randomuser.me/api/portraits/women/46.jpg", -"gender": "Female" -}, -{ -"first_name": "heather", -"last_name": "nelson", -"image": "https://randomuser.me/api/portraits/women/13.jpg", -"gender": "Female" -}, -{ -"first_name": "maxwell", -"last_name": "gilbert", -"image": "https://randomuser.me/api/portraits/men/56.jpg", -"gender": "Male" -}, -{ -"first_name": "molly", -"last_name": "ramirez", -"image": "https://randomuser.me/api/portraits/women/71.jpg", -"gender": "Female" -}, -{ -"first_name": "ian", -"last_name": "barrett", -"image": "https://randomuser.me/api/portraits/men/68.jpg", -"gender": "Male" -}, -{ -"first_name": "kim", -"last_name": "hudson", -"image": "https://randomuser.me/api/portraits/women/53.jpg", -"gender": "Female" -}, -{ -"first_name": "bruce", -"last_name": "murray", -"image": "https://randomuser.me/api/portraits/men/59.jpg", -"gender": "Male" -}, -{ -"first_name": "henry", -"last_name": "powell", -"image": "https://randomuser.me/api/portraits/men/88.jpg", -"gender": "Male" -}, -{ -"first_name": "chris", -"last_name": "foster", -"image": "https://randomuser.me/api/portraits/men/5.jpg", -"gender": "Male" -}, -{ -"first_name": "billy", -"last_name": "kim", -"image": "https://randomuser.me/api/portraits/men/91.jpg", -"gender": "Male" -}, -{ -"first_name": "samuel", -"last_name": "harper", -"image": "https://randomuser.me/api/portraits/men/56.jpg", -"gender": "Male" -}, -{ -"first_name": "jayden", -"last_name": "kelly", -"image": "https://randomuser.me/api/portraits/men/31.jpg", -"gender": "Male" -}, -{ -"first_name": "grace", -"last_name": "berry", -"image": "https://randomuser.me/api/portraits/women/69.jpg", -"gender": "Female" -}, -{ -"first_name": "ronnie", -"last_name": "nelson", -"image": "https://randomuser.me/api/portraits/men/83.jpg", -"gender": "Male" -}, -{ -"first_name": "harvey", -"last_name": "harper", -"image": "https://randomuser.me/api/portraits/men/68.jpg", -"gender": "Male" -}, -{ -"first_name": "maya", -"last_name": "fernandez", -"image": "https://randomuser.me/api/portraits/women/79.jpg", -"gender": "Female" -}, -{ -"first_name": "faith", -"last_name": "lewis", -"image": "https://randomuser.me/api/portraits/women/84.jpg", -"gender": "Female" -}, -{ -"first_name": "kirk", -"last_name": "macrae", -"image": "https://randomuser.me/api/portraits/men/13.jpg", -"gender": "Male" -}, -{ -"first_name": "tracy", -"last_name": "holt", -"image": "https://randomuser.me/api/portraits/women/18.jpg", -"gender": "Female" -}, -{ -"first_name": "mandy", -"last_name": "dean", -"image": "https://randomuser.me/api/portraits/women/0.jpg", -"gender": "Female" -}, -{ -"first_name": "sam", -"last_name": "dunn", -"image": "https://randomuser.me/api/portraits/women/12.jpg", -"gender": "Female" -}, -{ -"first_name": "zoe", -"last_name": "fleming", -"image": "https://randomuser.me/api/portraits/women/9.jpg", -"gender": "Female" -}, -{ -"first_name": "jeffrey", -"last_name": "stewart", -"image": "https://randomuser.me/api/portraits/men/56.jpg", -"gender": "Male" -}, -{ -"first_name": "dick", -"last_name": "ryan", -"image": "https://randomuser.me/api/portraits/men/63.jpg", -"gender": "Male" -}, -{ -"first_name": "carl", -"last_name": "neal", -"image": "https://randomuser.me/api/portraits/men/41.jpg", -"gender": "Male" -}, -{ -"first_name": "scarlett", -"last_name": "ruiz", -"image": "https://randomuser.me/api/portraits/women/24.jpg", -"gender": "Female" -}, -{ -"first_name": "rene", -"last_name": "hughes", -"image": "https://randomuser.me/api/portraits/men/3.jpg", -"gender": "Male" -}, -{ -"first_name": "greg", -"last_name": "montgomery", -"image": "https://randomuser.me/api/portraits/men/12.jpg", -"gender": "Male" -}, -{ -"first_name": "matt", -"last_name": "lane", -"image": "https://randomuser.me/api/portraits/men/85.jpg", -"gender": "Male" -}, -{ -"first_name": "eleanor", -"last_name": "pearson", -"image": "https://randomuser.me/api/portraits/women/61.jpg", -"gender": "Female" -}, -{ -"first_name": "theodore", -"last_name": "burton", -"image": "https://randomuser.me/api/portraits/men/81.jpg", -"gender": "Male" -}, -{ -"first_name": "jesus", -"last_name": "hunt", -"image": "https://randomuser.me/api/portraits/men/50.jpg", -"gender": "Male" -}, -{ -"first_name": "taylor", -"last_name": "alvarez", -"image": "https://randomuser.me/api/portraits/men/0.jpg", -"gender": "Male" -}, -{ -"first_name": "barbara", -"last_name": "lucas", -"image": "https://randomuser.me/api/portraits/women/21.jpg", -"gender": "Female" -}, -{ -"first_name": "nicky", -"last_name": "simmons", -"image": "https://randomuser.me/api/portraits/women/29.jpg", -"gender": "Female" -}, -{ -"first_name": "arthur", -"last_name": "obrien", -"image": "https://randomuser.me/api/portraits/men/11.jpg", -"gender": "Male" -}, -{ -"first_name": "donna", -"last_name": "holmes", -"image": "https://randomuser.me/api/portraits/women/33.jpg", -"gender": "Female" -}, -{ -"first_name": "mitchell", -"last_name": "castro", -"image": "https://randomuser.me/api/portraits/men/26.jpg", -"gender": "Male" -}, -{ -"first_name": "byron", -"last_name": "marshall", -"image": "https://randomuser.me/api/portraits/men/57.jpg", -"gender": "Male" -}, -{ -"first_name": "larry", -"last_name": "king", -"image": "https://randomuser.me/api/portraits/men/58.jpg", -"gender": "Male" -}, -{ -"first_name": "deborah", -"last_name": "fuller", -"image": "https://randomuser.me/api/portraits/women/50.jpg", -"gender": "Female" -}, -{ -"first_name": "eleanor", -"last_name": "elliott", -"image": "https://randomuser.me/api/portraits/women/80.jpg", -"gender": "Female" -}, -{ -"first_name": "derrick", -"last_name": "shaw", -"image": "https://randomuser.me/api/portraits/men/78.jpg", -"gender": "Male" -}, -{ -"first_name": "barbara", -"last_name": "lynch", -"image": "https://randomuser.me/api/portraits/women/15.jpg", -"gender": "Female" -}, -{ -"first_name": "elijah", -"last_name": "allen", -"image": "https://randomuser.me/api/portraits/men/43.jpg", -"gender": "Male" -}, -{ -"first_name": "nicholas", -"last_name": "harper", -"image": "https://randomuser.me/api/portraits/men/2.jpg", -"gender": "Male" -}, -{ -"first_name": "sofia", -"last_name": "riley", -"image": "https://randomuser.me/api/portraits/women/96.jpg", -"gender": "Female" -}, -{ -"first_name": "jar", -"last_name": "hunt", -"image": "https://randomuser.me/api/portraits/men/72.jpg", -"gender": "Male" -}, -{ -"first_name": "philip", -"last_name": "rose", -"image": "https://randomuser.me/api/portraits/men/16.jpg", -"gender": "Male" -}, -{ -"first_name": "ella", -"last_name": "moore", -"image": "https://randomuser.me/api/portraits/women/83.jpg", -"gender": "Female" -}, -{ -"first_name": "seth", -"last_name": "tucker", -"image": "https://randomuser.me/api/portraits/men/6.jpg", -"gender": "Male" -}, -{ -"first_name": "abby", -"last_name": "gonzalez", -"image": "https://randomuser.me/api/portraits/women/18.jpg", -"gender": "Female" -}, -{ -"first_name": "noah", -"last_name": "williamson", -"image": "https://randomuser.me/api/portraits/men/54.jpg", -"gender": "Male" -}, -{ -"first_name": "cathy", -"last_name": "gray", -"image": "https://randomuser.me/api/portraits/women/88.jpg", -"gender": "Female" -}, -{ -"first_name": "barb", -"last_name": "snyder", -"image": "https://randomuser.me/api/portraits/women/49.jpg", -"gender": "Female" -}, -{ -"first_name": "rosalyn", -"last_name": "hale", -"image": "https://randomuser.me/api/portraits/women/64.jpg", -"gender": "Female" -}, -{ -"first_name": "jessica", -"last_name": "armstrong", -"image": "https://randomuser.me/api/portraits/women/95.jpg", -"gender": "Female" -}, -{ -"first_name": "vicki", -"last_name": "wheeler", -"image": "https://randomuser.me/api/portraits/women/49.jpg", -"gender": "Female" -}, -{ -"first_name": "luke", -"last_name": "fisher", -"image": "https://randomuser.me/api/portraits/men/77.jpg", -"gender": "Male" -}, -{ -"first_name": "joey", -"last_name": "wheeler", -"image": "https://randomuser.me/api/portraits/men/50.jpg", -"gender": "Male" -}, -{ -"first_name": "victoria", -"last_name": "jimenez", -"image": "https://randomuser.me/api/portraits/women/25.jpg", -"gender": "Female" -}, -{ -"first_name": "daryl", -"last_name": "patterson", -"image": "https://randomuser.me/api/portraits/men/30.jpg", -"gender": "Male" -}, -{ -"first_name": "dwayne", -"last_name": "jensen", -"image": "https://randomuser.me/api/portraits/men/71.jpg", -"gender": "Male" -}, -{ -"first_name": "herbert", -"last_name": "silva", -"image": "https://randomuser.me/api/portraits/men/83.jpg", -"gender": "Male" -}, -{ -"first_name": "walter", -"last_name": "walker", -"image": "https://randomuser.me/api/portraits/men/91.jpg", -"gender": "Male" -}, -{ -"first_name": "logan", -"last_name": "banks", -"image": "https://randomuser.me/api/portraits/men/67.jpg", -"gender": "Male" -}, -{ -"first_name": "shawn", -"last_name": "harvey", -"image": "https://randomuser.me/api/portraits/men/87.jpg", -"gender": "Male" -}, -{ -"first_name": "lawrence", -"last_name": "bradley", -"image": "https://randomuser.me/api/portraits/men/40.jpg", -"gender": "Male" -}, -{ -"first_name": "jack", -"last_name": "fleming", -"image": "https://randomuser.me/api/portraits/men/37.jpg", -"gender": "Male" -}, -{ -"first_name": "jackson", -"last_name": "boyd", -"image": "https://randomuser.me/api/portraits/men/68.jpg", -"gender": "Male" -}, -{ -"first_name": "cecil", -"last_name": "webb", -"image": "https://randomuser.me/api/portraits/men/9.jpg", -"gender": "Male" -}, -{ -"first_name": "eliza", -"last_name": "mills", -"image": "https://randomuser.me/api/portraits/women/20.jpg", -"gender": "Female" -}, -{ -"first_name": "jenny", -"last_name": "frazier", -"image": "https://randomuser.me/api/portraits/women/61.jpg", -"gender": "Female" -}, -{ -"first_name": "kent", -"last_name": "butler", -"image": "https://randomuser.me/api/portraits/men/64.jpg", -"gender": "Male" -}, -{ -"first_name": "rose", -"last_name": "perry", -"image": "https://randomuser.me/api/portraits/women/74.jpg", -"gender": "Female" -}, -{ -"first_name": "jack", -"last_name": "king", -"image": "https://randomuser.me/api/portraits/men/60.jpg", -"gender": "Male" -}, -{ -"first_name": "elmer", -"last_name": "williams", -"image": "https://randomuser.me/api/portraits/men/26.jpg", -"gender": "Male" -}, -{ -"first_name": "vanessa", -"last_name": "torres", -"image": "https://randomuser.me/api/portraits/women/41.jpg", -"gender": "Female" -}, -{ -"first_name": "tyrone", -"last_name": "coleman", -"image": "https://randomuser.me/api/portraits/men/59.jpg", -"gender": "Male" -}, -{ -"first_name": "julie", -"last_name": "bradley", -"image": "https://randomuser.me/api/portraits/women/50.jpg", -"gender": "Female" -}, -{ -"first_name": "fernando", -"last_name": "castro", -"image": "https://randomuser.me/api/portraits/men/44.jpg", -"gender": "Male" -}, -{ -"first_name": "sara", -"last_name": "craig", -"image": "https://randomuser.me/api/portraits/women/8.jpg", -"gender": "Female" -}, -{ -"first_name": "steven", -"last_name": "stone", -"image": "https://randomuser.me/api/portraits/men/47.jpg", -"gender": "Male" -}, -{ -"first_name": "barb", -"last_name": "rodriquez", -"image": "https://randomuser.me/api/portraits/women/73.jpg", -"gender": "Female" -}, -{ -"first_name": "charlie", -"last_name": "king", -"image": "https://randomuser.me/api/portraits/men/79.jpg", -"gender": "Male" -}, -{ -"first_name": "jessica", -"last_name": "davis", -"image": "https://randomuser.me/api/portraits/women/26.jpg", -"gender": "Female" -}, -{ -"first_name": "lewis", -"last_name": "watson", -"image": "https://randomuser.me/api/portraits/men/56.jpg", -"gender": "Male" -}, -{ -"first_name": "charlotte", -"last_name": "johnson", -"image": "https://randomuser.me/api/portraits/women/46.jpg", -"gender": "Female" -}, -{ -"first_name": "danielle", -"last_name": "bell", -"image": "https://randomuser.me/api/portraits/women/54.jpg", -"gender": "Female" -}, -{ -"first_name": "kristin", -"last_name": "dixon", -"image": "https://randomuser.me/api/portraits/women/23.jpg", -"gender": "Female" -}, -{ -"first_name": "andrea", -"last_name": "thompson", -"image": "https://randomuser.me/api/portraits/women/54.jpg", -"gender": "Female" -}, -{ -"first_name": "ashley", -"last_name": "andrews", -"image": "https://randomuser.me/api/portraits/women/46.jpg", -"gender": "Female" -}, -{ -"first_name": "sharon", -"last_name": "martinez", -"image": "https://randomuser.me/api/portraits/women/6.jpg", -"gender": "Female" -}, -{ -"first_name": "tristan", -"last_name": "cunningham", -"image": "https://randomuser.me/api/portraits/men/62.jpg", -"gender": "Male" -}, -{ -"first_name": "carol", -"last_name": "chavez", -"image": "https://randomuser.me/api/portraits/women/85.jpg", -"gender": "Female" -}, -{ -"first_name": "lauren", -"last_name": "hudson", -"image": "https://randomuser.me/api/portraits/women/88.jpg", -"gender": "Female" -}, -{ -"first_name": "guy", -"last_name": "robertson", -"image": "https://randomuser.me/api/portraits/men/78.jpg", -"gender": "Male" -}, -{ -"first_name": "debra", -"last_name": "long", -"image": "https://randomuser.me/api/portraits/women/23.jpg", -"gender": "Female" -}, -{ -"first_name": "taylor", -"last_name": "carpenter", -"image": "https://randomuser.me/api/portraits/men/0.jpg", -"gender": "Male" -}, -{ -"first_name": "eetu", -"last_name": "annala", -"image": "https://randomuser.me/api/portraits/men/31.jpg", -"gender": "Male" -}, -{ -"first_name": "oliver", -"last_name": "moilanen", -"image": "https://randomuser.me/api/portraits/men/14.jpg", -"gender": "Male" -}, -{ -"first_name": "leo", -"last_name": "maunu", -"image": "https://randomuser.me/api/portraits/men/72.jpg", -"gender": "Male" -}, -{ -"first_name": "iiris", -"last_name": "kalas", -"image": "https://randomuser.me/api/portraits/women/49.jpg", -"gender": "Female" -}, -{ -"first_name": "aada", -"last_name": "kinnunen", -"image": "https://randomuser.me/api/portraits/women/64.jpg", -"gender": "Female" -}, -{ -"first_name": "topias", -"last_name": "walli", -"image": "https://randomuser.me/api/portraits/men/58.jpg", -"gender": "Male" -}, -{ -"first_name": "viivi", -"last_name": "toivonen", -"image": "https://randomuser.me/api/portraits/women/16.jpg", -"gender": "Female" -}, -{ -"first_name": "iina", -"last_name": "makinen", -"image": "https://randomuser.me/api/portraits/women/44.jpg", -"gender": "Female" -}, -{ -"first_name": "lumi", -"last_name": "tuominen", -"image": "https://randomuser.me/api/portraits/women/11.jpg", -"gender": "Female" -}, -{ -"first_name": "ellen", -"last_name": "koski", -"image": "https://randomuser.me/api/portraits/women/22.jpg", -"gender": "Female" -}, -{ -"first_name": "onni", -"last_name": "laurila", -"image": "https://randomuser.me/api/portraits/men/74.jpg", -"gender": "Male" -}, -{ -"first_name": "eevi", -"last_name": "niskanen", -"image": "https://randomuser.me/api/portraits/women/72.jpg", -"gender": "Female" -}, -{ -"first_name": "julius", -"last_name": "maijala", -"image": "https://randomuser.me/api/portraits/men/8.jpg", -"gender": "Male" -}, -{ -"first_name": "sofia", -"last_name": "tuomi", -"image": "https://randomuser.me/api/portraits/women/1.jpg", -"gender": "Female" -}, -{ -"first_name": "oliver", -"last_name": "jarvela", -"image": "https://randomuser.me/api/portraits/men/60.jpg", -"gender": "Male" -}, -{ -"first_name": "luukas", -"last_name": "mikkola", -"image": "https://randomuser.me/api/portraits/men/90.jpg", -"gender": "Male" -}, -{ -"first_name": "amanda", -"last_name": "anttila", -"image": "https://randomuser.me/api/portraits/women/65.jpg", -"gender": "Female" -}, -{ -"first_name": "ella", -"last_name": "sakala", -"image": "https://randomuser.me/api/portraits/women/79.jpg", -"gender": "Female" -}, -{ -"first_name": "siiri", -"last_name": "kinnunen", -"image": "https://randomuser.me/api/portraits/women/37.jpg", -"gender": "Female" -}, -{ -"first_name": "joona", -"last_name": "korhonen", -"image": "https://randomuser.me/api/portraits/men/87.jpg", -"gender": "Male" -}, -{ -"first_name": "topias", -"last_name": "korpi", -"image": "https://randomuser.me/api/portraits/men/75.jpg", -"gender": "Male" -}, -{ -"first_name": "mikael", -"last_name": "remes", -"image": "https://randomuser.me/api/portraits/men/89.jpg", -"gender": "Male" -}, -{ -"first_name": "veera", -"last_name": "peltola", -"image": "https://randomuser.me/api/portraits/women/69.jpg", -"gender": "Female" -}, -{ -"first_name": "emil", -"last_name": "makela", -"image": "https://randomuser.me/api/portraits/men/98.jpg", -"gender": "Male" -}, -{ -"first_name": "luukas", -"last_name": "kujala", -"image": "https://randomuser.me/api/portraits/men/83.jpg", -"gender": "Male" -}, -{ -"first_name": "eemil", -"last_name": "honkala", -"image": "https://randomuser.me/api/portraits/men/85.jpg", -"gender": "Male" -}, -{ -"first_name": "peetu", -"last_name": "kalm", -"image": "https://randomuser.me/api/portraits/men/17.jpg", -"gender": "Male" -}, -{ -"first_name": "eemeli", -"last_name": "lehtonen", -"image": "https://randomuser.me/api/portraits/men/55.jpg", -"gender": "Male" -}, -{ -"first_name": "viivi", -"last_name": "koistinen", -"image": "https://randomuser.me/api/portraits/women/53.jpg", -"gender": "Female" -}, -{ -"first_name": "elli", -"last_name": "savela", -"image": "https://randomuser.me/api/portraits/women/77.jpg", -"gender": "Female" -}, -{ -"first_name": "venla", -"last_name": "walli", -"image": "https://randomuser.me/api/portraits/women/52.jpg", -"gender": "Female" -}, -{ -"first_name": "amanda", -"last_name": "wuollet", -"image": "https://randomuser.me/api/portraits/women/11.jpg", -"gender": "Female" -}, -{ -"first_name": "valtteri", -"last_name": "hokkanen", -"image": "https://randomuser.me/api/portraits/men/30.jpg", -"gender": "Male" -}, -{ -"first_name": "veera", -"last_name": "maki", -"image": "https://randomuser.me/api/portraits/women/34.jpg", -"gender": "Female" -}, -{ -"first_name": "kerttu", -"last_name": "maunu", -"image": "https://randomuser.me/api/portraits/women/1.jpg", -"gender": "Female" -}, -{ -"first_name": "nella", -"last_name": "hanka", -"image": "https://randomuser.me/api/portraits/women/70.jpg", -"gender": "Female" -}, -{ -"first_name": "iiris", -"last_name": "hakala", -"image": "https://randomuser.me/api/portraits/women/33.jpg", -"gender": "Female" -}, -{ -"first_name": "viivi", -"last_name": "ojala", -"image": "https://randomuser.me/api/portraits/women/69.jpg", -"gender": "Female" -}, -{ -"first_name": "iina", -"last_name": "peura", -"image": "https://randomuser.me/api/portraits/women/22.jpg", -"gender": "Female" -}, -{ -"first_name": "samuel", -"last_name": "mattila", -"image": "https://randomuser.me/api/portraits/men/88.jpg", -"gender": "Male" -}, -{ -"first_name": "julius", -"last_name": "kumpula", -"image": "https://randomuser.me/api/portraits/men/26.jpg", -"gender": "Male" -}, -{ -"first_name": "nooa", -"last_name": "haapala", -"image": "https://randomuser.me/api/portraits/men/77.jpg", -"gender": "Male" -}, -{ -"first_name": "elias", -"last_name": "leppo", -"image": "https://randomuser.me/api/portraits/men/50.jpg", -"gender": "Male" -}, -{ -"first_name": "niklas", -"last_name": "elo", -"image": "https://randomuser.me/api/portraits/men/64.jpg", -"gender": "Male" -}, -{ -"first_name": "olivia", -"last_name": "nurmi", -"image": "https://randomuser.me/api/portraits/women/82.jpg", -"gender": "Female" -}, -{ -"first_name": "milja", -"last_name": "lassila", -"image": "https://randomuser.me/api/portraits/women/47.jpg", -"gender": "Female" -}, -{ -"first_name": "daniel", -"last_name": "kalas", -"image": "https://randomuser.me/api/portraits/men/53.jpg", -"gender": "Male" -}, -{ -"first_name": "enni", -"last_name": "ramo", -"image": "https://randomuser.me/api/portraits/women/18.jpg", -"gender": "Female" -}, -{ -"first_name": "matilda", -"last_name": "salmi", -"image": "https://randomuser.me/api/portraits/women/84.jpg", -"gender": "Female" -}, -{ -"first_name": "valtteri", -"last_name": "wirta", -"image": "https://randomuser.me/api/portraits/men/26.jpg", -"gender": "Male" -}, -{ -"first_name": "julius", -"last_name": "maijala", -"image": "https://randomuser.me/api/portraits/men/39.jpg", -"gender": "Male" -}, -{ -"first_name": "kerttu", -"last_name": "peltola", -"image": "https://randomuser.me/api/portraits/women/39.jpg", -"gender": "Female" -}, -{ -"first_name": "aada", -"last_name": "kokko", -"image": "https://randomuser.me/api/portraits/women/26.jpg", -"gender": "Female" -}, -{ -"first_name": "elsa", -"last_name": "niska", -"image": "https://randomuser.me/api/portraits/women/26.jpg", -"gender": "Female" -}, -{ -"first_name": "ella", -"last_name": "kalm", -"image": "https://randomuser.me/api/portraits/women/61.jpg", -"gender": "Female" -}, -{ -"first_name": "lilja", -"last_name": "heinonen", -"image": "https://randomuser.me/api/portraits/women/65.jpg", -"gender": "Female" -}, -{ -"first_name": "akseli", -"last_name": "laakso", -"image": "https://randomuser.me/api/portraits/men/64.jpg", -"gender": "Male" -}, -{ -"first_name": "lotta", -"last_name": "saarela", -"image": "https://randomuser.me/api/portraits/women/69.jpg", -"gender": "Female" -}, -{ -"first_name": "leo", -"last_name": "polon", -"image": "https://randomuser.me/api/portraits/men/5.jpg", -"gender": "Male" -}, -{ -"first_name": "aleksi", -"last_name": "wuollet", -"image": "https://randomuser.me/api/portraits/men/87.jpg", -"gender": "Male" -}, -{ -"first_name": "eemil", -"last_name": "kalas", -"image": "https://randomuser.me/api/portraits/men/6.jpg", -"gender": "Male" -}, -{ -"first_name": "emmi", -"last_name": "koistinen", -"image": "https://randomuser.me/api/portraits/women/66.jpg", -"gender": "Female" -}, -{ -"first_name": "väinö", -"last_name": "halla", -"image": "https://randomuser.me/api/portraits/men/65.jpg", -"gender": "Male" -}, -{ -"first_name": "eemil", -"last_name": "heikkila", -"image": "https://randomuser.me/api/portraits/men/18.jpg", -"gender": "Male" -}, -{ -"first_name": "amanda", -"last_name": "lakso", -"image": "https://randomuser.me/api/portraits/women/29.jpg", -"gender": "Female" -}, -{ -"first_name": "vilho", -"last_name": "kivela", -"image": "https://randomuser.me/api/portraits/men/19.jpg", -"gender": "Male" -}, -{ -"first_name": "peppi", -"last_name": "lehtinen", -"image": "https://randomuser.me/api/portraits/women/80.jpg", -"gender": "Female" -}, -{ -"first_name": "onni", -"last_name": "lehtinen", -"image": "https://randomuser.me/api/portraits/men/0.jpg", -"gender": "Male" -}, -{ -"first_name": "onni", -"last_name": "ahonen", -"image": "https://randomuser.me/api/portraits/men/49.jpg", -"gender": "Male" -}, -{ -"first_name": "venla", -"last_name": "ranta", -"image": "https://randomuser.me/api/portraits/women/0.jpg", -"gender": "Female" -}, -{ -"first_name": "ronja", -"last_name": "korhonen", -"image": "https://randomuser.me/api/portraits/women/69.jpg", -"gender": "Female" -}, -{ -"first_name": "emmi", -"last_name": "niva", -"image": "https://randomuser.me/api/portraits/women/65.jpg", -"gender": "Female" -}, -{ -"first_name": "oskari", -"last_name": "leppanen", -"image": "https://randomuser.me/api/portraits/men/43.jpg", -"gender": "Male" -}, -{ -"first_name": "arttu", -"last_name": "heinonen", -"image": "https://randomuser.me/api/portraits/men/94.jpg", -"gender": "Male" -}, -{ -"first_name": "toivo", -"last_name": "makela", -"image": "https://randomuser.me/api/portraits/men/23.jpg", -"gender": "Male" -}, -{ -"first_name": "otto", -"last_name": "leino", -"image": "https://randomuser.me/api/portraits/men/51.jpg", -"gender": "Male" -}, -{ -"first_name": "milla", -"last_name": "kokko", -"image": "https://randomuser.me/api/portraits/women/66.jpg", -"gender": "Female" -}, -{ -"first_name": "konsta", -"last_name": "lehto", -"image": "https://randomuser.me/api/portraits/men/29.jpg", -"gender": "Male" -}, -{ -"first_name": "eeli", -"last_name": "heikkinen", -"image": "https://randomuser.me/api/portraits/men/50.jpg", -"gender": "Male" -}, -{ -"first_name": "matilda", -"last_name": "tanner", -"image": "https://randomuser.me/api/portraits/women/2.jpg", -"gender": "Female" -}, -{ -"first_name": "elias", -"last_name": "kivisto", -"image": "https://randomuser.me/api/portraits/men/40.jpg", -"gender": "Male" -}, -{ -"first_name": "akseli", -"last_name": "wirta", -"image": "https://randomuser.me/api/portraits/men/90.jpg", -"gender": "Male" -}, -{ -"first_name": "leevi", -"last_name": "kallio", -"image": "https://randomuser.me/api/portraits/men/89.jpg", -"gender": "Male" -}, -{ -"first_name": "emilia", -"last_name": "pelto", -"image": "https://randomuser.me/api/portraits/women/0.jpg", -"gender": "Female" -}, -{ -"first_name": "niilo", -"last_name": "keranen", -"image": "https://randomuser.me/api/portraits/men/29.jpg", -"gender": "Male" -}, -{ -"first_name": "mikael", -"last_name": "wainio", -"image": "https://randomuser.me/api/portraits/men/85.jpg", -"gender": "Male" -}, -{ -"first_name": "elias", -"last_name": "saksa", -"image": "https://randomuser.me/api/portraits/men/53.jpg", -"gender": "Male" -}, -{ -"first_name": "aatu", -"last_name": "erkkila", -"image": "https://randomuser.me/api/portraits/men/6.jpg", -"gender": "Male" -}, -{ -"first_name": "arttu", -"last_name": "jarvela", -"image": "https://randomuser.me/api/portraits/men/49.jpg", -"gender": "Male" -}, -{ -"first_name": "matilda", -"last_name": "lassila", -"image": "https://randomuser.me/api/portraits/women/46.jpg", -"gender": "Female" -}, -{ -"first_name": "alisa", -"last_name": "waara", -"image": "https://randomuser.me/api/portraits/women/67.jpg", -"gender": "Female" -}, -{ -"first_name": "emilia", -"last_name": "saksa", -"image": "https://randomuser.me/api/portraits/women/66.jpg", -"gender": "Female" -}, -{ -"first_name": "valtteri", -"last_name": "tikkanen", -"image": "https://randomuser.me/api/portraits/men/88.jpg", -"gender": "Male" -}, -{ -"first_name": "konsta", -"last_name": "rantala", -"image": "https://randomuser.me/api/portraits/men/50.jpg", -"gender": "Male" -}, -{ -"first_name": "minttu", -"last_name": "murto", -"image": "https://randomuser.me/api/portraits/women/14.jpg", -"gender": "Female" -}, -{ -"first_name": "vilma", -"last_name": "hatala", -"image": "https://randomuser.me/api/portraits/women/60.jpg", -"gender": "Female" -}, -{ -"first_name": "anni", -"last_name": "linna", -"image": "https://randomuser.me/api/portraits/women/59.jpg", -"gender": "Female" -}, -{ -"first_name": "niklas", -"last_name": "hautala", -"image": "https://randomuser.me/api/portraits/men/7.jpg", -"gender": "Male" -}, -{ -"first_name": "niilo", -"last_name": "lehtinen", -"image": "https://randomuser.me/api/portraits/men/54.jpg", -"gender": "Male" -}, -{ -"first_name": "oona", -"last_name": "saarinen", -"image": "https://randomuser.me/api/portraits/women/71.jpg", -"gender": "Female" -}, -{ -"first_name": "constance", -"last_name": "marie", -"image": "https://randomuser.me/api/portraits/women/40.jpg", -"gender": "Female" -}, -{ -"first_name": "charles", -"last_name": "pierre", -"image": "https://randomuser.me/api/portraits/men/96.jpg", -"gender": "Male" -}, -{ -"first_name": "bérénice", -"last_name": "leclerc", -"image": "https://randomuser.me/api/portraits/women/39.jpg", -"gender": "Female" -}, -{ -"first_name": "clémence", -"last_name": "arnaud", -"image": "https://randomuser.me/api/portraits/women/48.jpg", -"gender": "Female" -}, -{ -"first_name": "melvin", -"last_name": "lemoine", -"image": "https://randomuser.me/api/portraits/men/47.jpg", -"gender": "Male" -}, -{ -"first_name": "marceau", -"last_name": "joly", -"image": "https://randomuser.me/api/portraits/men/56.jpg", -"gender": "Male" -}, -{ -"first_name": "garance", -"last_name": "mathieu", -"image": "https://randomuser.me/api/portraits/women/87.jpg", -"gender": "Female" -}, -{ -"first_name": "angèle", -"last_name": "perrin", -"image": "https://randomuser.me/api/portraits/women/88.jpg", -"gender": "Female" -}, -{ -"first_name": "pauline", -"last_name": "simon", -"image": "https://randomuser.me/api/portraits/women/82.jpg", -"gender": "Female" -}, -{ -"first_name": "apolline", -"last_name": "laurent", -"image": "https://randomuser.me/api/portraits/women/27.jpg", -"gender": "Female" -}, -{ -"first_name": "luca", -"last_name": "lefevre", -"image": "https://randomuser.me/api/portraits/men/40.jpg", -"gender": "Male" -}, -{ -"first_name": "bastien", -"last_name": "roger", -"image": "https://randomuser.me/api/portraits/men/73.jpg", -"gender": "Male" -}, -{ -"first_name": "marie", -"last_name": "rodriguez", -"image": "https://randomuser.me/api/portraits/women/18.jpg", -"gender": "Female" -}, -{ -"first_name": "tristan", -"last_name": "renaud", -"image": "https://randomuser.me/api/portraits/men/41.jpg", -"gender": "Male" -}, -{ -"first_name": "eva", -"last_name": "philippe", -"image": "https://randomuser.me/api/portraits/women/26.jpg", -"gender": "Female" -}, -{ -"first_name": "coline", -"last_name": "dufour", -"image": "https://randomuser.me/api/portraits/women/64.jpg", -"gender": "Female" -}, -{ -"first_name": "marilou", -"last_name": "adam", -"image": "https://randomuser.me/api/portraits/women/53.jpg", -"gender": "Female" -}, -{ -"first_name": "lia", -"last_name": "renard", -"image": "https://randomuser.me/api/portraits/women/88.jpg", -"gender": "Female" -}, -{ -"first_name": "timothee", -"last_name": "rolland", -"image": "https://randomuser.me/api/portraits/men/75.jpg", -"gender": "Male" -}, -{ -"first_name": "hélèna", -"last_name": "boyer", -"image": "https://randomuser.me/api/portraits/women/8.jpg", -"gender": "Female" -}, -{ -"first_name": "mélody", -"last_name": "andre", -"image": "https://randomuser.me/api/portraits/women/75.jpg", -"gender": "Female" -}, -{ -"first_name": "jeanne", -"last_name": "duval", -"image": "https://randomuser.me/api/portraits/women/44.jpg", -"gender": "Female" -}, -{ -"first_name": "elias", -"last_name": "dupont", -"image": "https://randomuser.me/api/portraits/men/60.jpg", -"gender": "Male" -}, -{ -"first_name": "estelle", -"last_name": "bernard", -"image": "https://randomuser.me/api/portraits/women/23.jpg", -"gender": "Female" -}, -{ -"first_name": "roxane", -"last_name": "garnier", -"image": "https://randomuser.me/api/portraits/women/14.jpg", -"gender": "Female" -}, -{ -"first_name": "maëva", -"last_name": "guerin", -"image": "https://randomuser.me/api/portraits/women/44.jpg", -"gender": "Female" -}, -{ -"first_name": "liam", -"last_name": "carpentier", -"image": "https://randomuser.me/api/portraits/men/41.jpg", -"gender": "Male" -}, -{ -"first_name": "théo", -"last_name": "gaillard", -"image": "https://randomuser.me/api/portraits/men/40.jpg", -"gender": "Male" -}, -{ -"first_name": "angelina", -"last_name": "clement", -"image": "https://randomuser.me/api/portraits/women/53.jpg", -"gender": "Female" -}, -{ -"first_name": "emma", -"last_name": "bertrand", -"image": "https://randomuser.me/api/portraits/women/86.jpg", -"gender": "Female" -}, -{ -"first_name": "charles", -"last_name": "rolland", -"image": "https://randomuser.me/api/portraits/men/14.jpg", -"gender": "Male" -}, -{ -"first_name": "nolan", -"last_name": "gautier", -"image": "https://randomuser.me/api/portraits/men/6.jpg", -"gender": "Male" -}, -{ -"first_name": "agathe", -"last_name": "menard", -"image": "https://randomuser.me/api/portraits/women/69.jpg", -"gender": "Female" -}, -{ -"first_name": "gaëtan", -"last_name": "leclerc", -"image": "https://randomuser.me/api/portraits/men/60.jpg", -"gender": "Male" -}, -{ -"first_name": "clarisse", -"last_name": "lemaire", -"image": "https://randomuser.me/api/portraits/women/21.jpg", -"gender": "Female" -}, -{ -"first_name": "samuel", -"last_name": "garnier", -"image": "https://randomuser.me/api/portraits/men/16.jpg", -"gender": "Male" -}, -{ -"first_name": "eden", -"last_name": "fontai", -"image": "https://randomuser.me/api/portraits/women/17.jpg", -"gender": "Female" -}, -{ -"first_name": "maëva", -"last_name": "pierre", -"image": "https://randomuser.me/api/portraits/women/19.jpg", -"gender": "Female" -}, -{ -"first_name": "thomas", -"last_name": "barbier", -"image": "https://randomuser.me/api/portraits/men/31.jpg", -"gender": "Male" -}, -{ -"first_name": "lily", -"last_name": "lefebvre", -"image": "https://randomuser.me/api/portraits/women/76.jpg", -"gender": "Female" -}, -{ -"first_name": "lise", -"last_name": "perez", -"image": "https://randomuser.me/api/portraits/women/74.jpg", -"gender": "Female" -}, -{ -"first_name": "mila", -"last_name": "moulin", -"image": "https://randomuser.me/api/portraits/women/43.jpg", -"gender": "Female" -}, -{ -"first_name": "dylan", -"last_name": "picard", -"image": "https://randomuser.me/api/portraits/men/37.jpg", -"gender": "Male" -}, -{ -"first_name": "amandine", -"last_name": "rodriguez", -"image": "https://randomuser.me/api/portraits/women/65.jpg", -"gender": "Female" -}, -{ -"first_name": "diego", -"last_name": "girard", -"image": "https://randomuser.me/api/portraits/men/84.jpg", -"gender": "Male" -}, -{ -"first_name": "elouan", -"last_name": "garnier", -"image": "https://randomuser.me/api/portraits/men/94.jpg", -"gender": "Male" -}, -{ -"first_name": "apolline", -"last_name": "fleury", -"image": "https://randomuser.me/api/portraits/women/65.jpg", -"gender": "Female" -}, -{ -"first_name": "coline", -"last_name": "menard", -"image": "https://randomuser.me/api/portraits/women/83.jpg", -"gender": "Female" -}, -{ -"first_name": "maëly", -"last_name": "le gall", -"image": "https://randomuser.me/api/portraits/women/60.jpg", -"gender": "Female" -}, -{ -"first_name": "justin", -"last_name": "robert", -"image": "https://randomuser.me/api/portraits/men/20.jpg", -"gender": "Male" -}, -{ -"first_name": "ryan", -"last_name": "faure", -"image": "https://randomuser.me/api/portraits/men/16.jpg", -"gender": "Male" -}, -{ -"first_name": "ninon", -"last_name": "brunet", -"image": "https://randomuser.me/api/portraits/women/68.jpg", -"gender": "Female" -}, -{ -"first_name": "tessa", -"last_name": "garnier", -"image": "https://randomuser.me/api/portraits/women/54.jpg", -"gender": "Female" -}, -{ -"first_name": "ryan", -"last_name": "bonnet", -"image": "https://randomuser.me/api/portraits/men/28.jpg", -"gender": "Male" -}, -{ -"first_name": "aurélien", -"last_name": "andre", -"image": "https://randomuser.me/api/portraits/men/29.jpg", -"gender": "Male" -}, -{ -"first_name": "clément", -"last_name": "dumas", -"image": "https://randomuser.me/api/portraits/men/10.jpg", -"gender": "Male" -}, -{ -"first_name": "alexis", -"last_name": "fournier", -"image": "https://randomuser.me/api/portraits/men/83.jpg", -"gender": "Male" -}, -{ -"first_name": "valentin", -"last_name": "lecomte", -"image": "https://randomuser.me/api/portraits/men/44.jpg", -"gender": "Male" -}, -{ -"first_name": "florian", -"last_name": "olivier", -"image": "https://randomuser.me/api/portraits/men/36.jpg", -"gender": "Male" -}, -{ -"first_name": "ewen", -"last_name": "lefebvre", -"image": "https://randomuser.me/api/portraits/men/32.jpg", -"gender": "Male" -}, -{ -"first_name": "titouan", -"last_name": "charles", -"image": "https://randomuser.me/api/portraits/men/59.jpg", -"gender": "Male" -}, -{ -"first_name": "lila", -"last_name": "aubert", -"image": "https://randomuser.me/api/portraits/women/6.jpg", -"gender": "Female" -}, -{ -"first_name": "charline", -"last_name": "caron", -"image": "https://randomuser.me/api/portraits/women/49.jpg", -"gender": "Female" -}, -{ -"first_name": "soren", -"last_name": "le gall", -"image": "https://randomuser.me/api/portraits/men/77.jpg", -"gender": "Male" -}, -{ -"first_name": "fanny", -"last_name": "louis", -"image": "https://randomuser.me/api/portraits/women/90.jpg", -"gender": "Female" -}, -{ -"first_name": "julie", -"last_name": "adam", -"image": "https://randomuser.me/api/portraits/women/34.jpg", -"gender": "Female" -}, -{ -"first_name": "louka", -"last_name": "boyer", -"image": "https://randomuser.me/api/portraits/men/98.jpg", -"gender": "Male" -} -] diff --git a/erpnext/demo/data/room.json b/erpnext/demo/data/room.json deleted file mode 100644 index 82f0868b5a0..00000000000 --- a/erpnext/demo/data/room.json +++ /dev/null @@ -1,122 +0,0 @@ -[ - { - "doctype": "Room", - "room_name": "Lecture Hall 1", - "room_number": "101", - "seating_capacity": 80 - }, - { - "doctype": "Room", - "room_name": "Lecture Hall 2", - "room_number": "102", - "seating_capacity": 80 - }, - { - "doctype": "Room", - "room_name": "Lecture Hall 3", - "room_number": "103", - "seating_capacity": 80 - }, - { - "doctype": "Room", - "room_name": "Lecture Hall 4", - "room_number": "104", - "seating_capacity": 80 - }, - { - "doctype": "Room", - "room_name": "Lecture Hall 4", - "room_number": "104", - "seating_capacity": 80 - }, - { - "doctype": "Room", - "room_name": "Lecture Hall 5", - "room_number": "201", - "seating_capacity": 120 - }, - { - "doctype": "Room", - "room_name": "Lecture Hall 6", - "room_number": "202", - "seating_capacity": 120 - }, - { - "doctype": "Room", - "room_name": "Lecture Hall 7", - "room_number": "203", - "seating_capacity": 120 - }, - { - "doctype": "Room", - "room_name": "Computer Lab 1", - "room_number": "301", - "seating_capacity": 40 - }, - { - "doctype": "Room", - "room_name": "Computer Lab 2", - "room_number": "302", - "seating_capacity": 60 - }, - { - "doctype": "Room", - "room_name": "Seminar Hall 1", - "room_number": "303", - "seating_capacity": 240 - }, - { - "doctype": "Room", - "room_name": "Auditorium", - "room_number": "400", - "seating_capacity": 450 - }, - { - "doctype": "Room", - "room_name": "Exam hall 1", - "room_number": "560", - "seating_capacity": 70 - }, - { - "doctype": "Room", - "room_name": "Exam hall 2", - "room_number": "561", - "seating_capacity": 70 - }, - { - "doctype": "Room", - "room_name": "Exam hall 2", - "room_number": "562", - "seating_capacity": 70 - }, - { - "doctype": "Room", - "room_name": "Exam hall 3", - "room_number": "563", - "seating_capacity": 70 - }, - { - "doctype": "Room", - "room_name": "Exam hall 4", - "room_number": "564", - "seating_capacity": 70 - }, - { - "doctype": "Room", - "room_name": "Exam hall 5", - "room_number": "565", - "seating_capacity": 70 - }, - { - "doctype": "Room", - "room_name": "Exam hall 6", - "room_number": "566", - "seating_capacity": 70 - }, - { - "doctype": "Room", - "room_name": "Exam hall 7", - "room_number": "567", - "seating_capacity": 70 - } -] \ No newline at end of file diff --git a/erpnext/demo/data/student_batch_name.json b/erpnext/demo/data/student_batch_name.json deleted file mode 100644 index ef3f18dcf21..00000000000 --- a/erpnext/demo/data/student_batch_name.json +++ /dev/null @@ -1,10 +0,0 @@ -[ - { - "doctype": "Student Batch Name", - "batch_name": "Section-A" - }, - { - "doctype": "Student Batch Name", - "batch_name": "Section-B" - } -] \ No newline at end of file diff --git a/erpnext/demo/data/user.json b/erpnext/demo/data/user.json deleted file mode 100644 index 9ee5e780ac1..00000000000 --- a/erpnext/demo/data/user.json +++ /dev/null @@ -1,112 +0,0 @@ -[ - { - "email": "test_demo@erpnext.com", - "first_name": "Test", - "last_name": "User" - }, - { - "email": "DianaPrince@example.com", - "first_name": "Diana", - "last_name": "Prince" - }, - { - "email": "ZatannaZatara@example.com", - "first_name": "Zatanna", - "last_name": "Zatara" - }, - { - "email": "HollyGranger@example.com", - "first_name": "Holly", - "last_name": "Granger" - }, - { - "email": "NeptuniaAquaria@example.com", - "first_name": "Neptunia", - "last_name": "Aquaria" - }, - { - "email": "ArthurCurry@example.com", - "first_name": "Arthur", - "last_name": "Curry" - }, - { - "email": "ThaliaAlGhul@example.com", - "first_name": "Thalia", - "last_name": "Al Ghul" - }, - { - "email": "MaxwellLord@example.com", - "first_name": "Maxwell", - "last_name": "Lord" - }, - { - "email": "GraceChoi@example.com", - "first_name": "Grace", - "last_name": "Choi" - }, - { - "email": "VandalSavage@example.com", - "first_name": "Vandal", - "last_name": "Savage" - }, - { - "email": "CaitlinSnow@example.com", - "first_name": "Caitlin", - "last_name": "Snow" - }, - { - "email": "RipHunter@example.com", - "first_name": "Rip", - "last_name": "Hunter" - }, - { - "email": "NicholasFury@example.com", - "first_name": "Nicholas", - "last_name": "Fury" - }, - { - "email": "PeterParker@example.com", - "first_name": "Peter", - "last_name": "Parker" - }, - { - "email": "JohnConstantine@example.com", - "first_name": "John", - "last_name": "Constantine" - }, - { - "email": "HalJordan@example.com", - "first_name": "Hal", - "last_name": "Jordan" - }, - { - "email": "VictorStone@example.com", - "first_name": "Victor", - "last_name": "Stone" - }, - { - "email": "BruceWayne@example.com", - "first_name": "Bruce", - "last_name": "Wayne" - }, - { - "email": "ClarkKent@example.com", - "first_name": "Clark", - "last_name": "Kent" - }, - { - "email": "BarryAllen@example.com", - "first_name": "Barry", - "last_name": "Allen" - }, - { - "email": "KaraZorEl@example.com", - "first_name": "Kara", - "last_name": "Zor El" - }, - { - "email": "demo@erpnext.com", - "first_name": "Demo", - "last_name": "User" - } -] \ No newline at end of file diff --git a/erpnext/demo/demo.py b/erpnext/demo/demo.py deleted file mode 100644 index 4a18a99f41f..00000000000 --- a/erpnext/demo/demo.py +++ /dev/null @@ -1,97 +0,0 @@ -import sys - -import frappe -import frappe.utils - -import erpnext -from erpnext.demo.setup import education, manufacture, retail, setup_data -from erpnext.demo.user import accounts -from erpnext.demo.user import education as edu -from erpnext.demo.user import fixed_asset, hr, manufacturing, projects, purchase, sales, stock - -""" -Make a demo - -1. Start with a fresh account - -bench --site demo.erpnext.dev reinstall - -2. Install Demo - -bench --site demo.erpnext.dev execute erpnext.demo.demo.make - -3. If Demo breaks, to continue - -bench --site demo.erpnext.dev execute erpnext.demo.demo.simulate - -""" - -def make(domain='Manufacturing', days=100): - frappe.flags.domain = domain - frappe.flags.mute_emails = True - setup_data.setup(domain) - if domain== 'Manufacturing': - manufacture.setup_data() - elif domain == "Retail": - retail.setup_data() - elif domain== 'Education': - education.setup_data() - - site = frappe.local.site - frappe.destroy() - frappe.init(site) - frappe.connect() - - simulate(domain, days) - -def simulate(domain='Manufacturing', days=100): - runs_for = frappe.flags.runs_for or days - frappe.flags.company = erpnext.get_default_company() - frappe.flags.mute_emails = True - - if not frappe.flags.start_date: - # start date = 100 days back - frappe.flags.start_date = frappe.utils.add_days(frappe.utils.nowdate(), - -1 * runs_for) - - current_date = frappe.utils.getdate(frappe.flags.start_date) - - # continue? - demo_last_date = frappe.db.get_global('demo_last_date') - if demo_last_date: - current_date = frappe.utils.add_days(frappe.utils.getdate(demo_last_date), 1) - - # run till today - if not runs_for: - runs_for = frappe.utils.date_diff(frappe.utils.nowdate(), current_date) - # runs_for = 100 - - fixed_asset.work() - for i in range(runs_for): - sys.stdout.write("\rSimulating {0}: Day {1}".format( - current_date.strftime("%Y-%m-%d"), i)) - sys.stdout.flush() - frappe.flags.current_date = current_date - if current_date.weekday() in (5, 6): - current_date = frappe.utils.add_days(current_date, 1) - continue - try: - hr.work() - purchase.work() - stock.work() - accounts.work() - projects.run_projects(current_date) - sales.work(domain) - # run_messages() - - if domain=='Manufacturing': - manufacturing.work() - elif domain=='Education': - edu.work() - - except Exception: - frappe.db.set_global('demo_last_date', current_date) - raise - finally: - current_date = frappe.utils.add_days(current_date, 1) - frappe.db.commit() diff --git a/erpnext/demo/domains.py b/erpnext/demo/domains.py deleted file mode 100644 index 346787e3c7c..00000000000 --- a/erpnext/demo/domains.py +++ /dev/null @@ -1,20 +0,0 @@ -data = { - 'Manufacturing': { - 'company_name': 'Wind Power LLC' - }, - 'Retail': { - 'company_name': 'Mobile Next', - }, - 'Distribution': { - 'company_name': 'Soltice Hardware', - }, - 'Services': { - 'company_name': 'Acme Consulting' - }, - 'Education': { - 'company_name': 'Whitmore College' - }, - 'Non Profit': { - 'company_name': 'Erpnext Foundation' - } -} diff --git a/erpnext/demo/setup/education.py b/erpnext/demo/setup/education.py deleted file mode 100644 index eb833f4e0c0..00000000000 --- a/erpnext/demo/setup/education.py +++ /dev/null @@ -1,181 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - -import json -import random -from datetime import datetime - -import frappe -from frappe.utils.make_random import get_random - -from erpnext.demo.setup.setup_data import import_json - - -def setup_data(): - frappe.flags.mute_emails = True - make_masters() - setup_item() - make_student_applicants() - make_student_group() - make_fees_category() - make_fees_structure() - make_assessment_groups() - frappe.db.commit() - frappe.clear_cache() - -def make_masters(): - import_json("Room") - import_json("Department") - import_json("Instructor") - import_json("Course") - import_json("Program") - import_json("Student Batch Name") - import_json("Assessment Criteria") - import_json("Grading Scale") - frappe.db.commit() - -def setup_item(): - items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item_education.json')).read()) - for i in items: - item = frappe.new_doc('Item') - item.update(i) - item.min_order_qty = random.randint(10, 30) - item.item_defaults[0].default_warehouse = frappe.get_all('Warehouse', - filters={'warehouse_name': item.item_defaults[0].default_warehouse}, limit=1)[0].name - item.insert() - -def make_student_applicants(): - blood_group = ["A+", "A-", "B+", "B-", "AB+", "AB-", "O+", "O-"] - male_names = [] - female_names = [] - - file_path = get_json_path("Random Student Data") - with open(file_path, "r") as open_file: - random_student_data = json.loads(open_file.read()) - count = 1 - - for d in random_student_data: - if d.get('gender') == "Male": - male_names.append(d.get('first_name').title()) - - if d.get('gender') == "Female": - female_names.append(d.get('first_name').title()) - - for idx, d in enumerate(random_student_data): - student_applicant = frappe.new_doc("Student Applicant") - student_applicant.first_name = d.get('first_name').title() - student_applicant.last_name = d.get('last_name').title() - student_applicant.image = d.get('image') - student_applicant.gender = d.get('gender') - student_applicant.program = get_random("Program") - student_applicant.blood_group = random.choice(blood_group) - year = random.randint(1990, 1998) - month = random.randint(1, 12) - day = random.randint(1, 28) - student_applicant.date_of_birth = datetime(year, month, day) - student_applicant.mother_name = random.choice(female_names) + " " + d.get('last_name').title() - student_applicant.father_name = random.choice(male_names) + " " + d.get('last_name').title() - if student_applicant.gender == "Male": - student_applicant.middle_name = random.choice(male_names) - else: - student_applicant.middle_name = random.choice(female_names) - student_applicant.student_email_id = d.get('first_name') + "_" + \ - student_applicant.middle_name + "_" + d.get('last_name') + "@example.com" - if count <5: - student_applicant.insert() - frappe.db.commit() - else: - student_applicant.submit() - frappe.db.commit() - count+=1 - -def make_student_group(): - for term in frappe.db.get_list("Academic Term"): - for program in frappe.db.get_list("Program"): - sg_tool = frappe.new_doc("Student Group Creation Tool") - sg_tool.academic_year = "2017-18" - sg_tool.academic_term = term.name - sg_tool.program = program.name - for d in sg_tool.get_courses(): - d = frappe._dict(d) - student_group = frappe.new_doc("Student Group") - student_group.student_group_name = d.student_group_name - student_group.group_based_on = d.group_based_on - student_group.program = program.name - student_group.course = d.course - student_group.batch = d.batch - student_group.academic_term = term.name - student_group.academic_year = "2017-18" - student_group.save() - frappe.db.commit() - -def make_fees_category(): - fee_type = ["Tuition Fee", "Hostel Fee", "Logistics Fee", - "Medical Fee", "Mess Fee", "Security Deposit"] - - fee_desc = {"Tuition Fee" : "Curricular activities which includes books, notebooks and faculty charges" , - "Hostel Fee" : "Stay of students in institute premises", - "Logistics Fee" : "Lodging boarding of the students" , - "Medical Fee" : "Medical welfare of the students", - "Mess Fee" : "Food and beverages for your ward", - "Security Deposit" : "In case your child is found to have damaged institutes property" - } - - for i in fee_type: - fee_category = frappe.new_doc("Fee Category") - fee_category.category_name = i - fee_category.description = fee_desc[i] - fee_category.insert() - frappe.db.commit() - -def make_fees_structure(): - for d in frappe.db.get_list("Program"): - program = frappe.get_doc("Program", d.name) - for academic_term in ["2017-18 (Semester 1)", "2017-18 (Semester 2)", "2017-18 (Semester 3)"]: - fee_structure = frappe.new_doc("Fee Structure") - fee_structure.program = d.name - fee_structure.academic_term = random.choice(frappe.db.get_list("Academic Term")).name - for j in range(1,4): - temp = {"fees_category": random.choice(frappe.db.get_list("Fee Category")).name , "amount" : random.randint(500,1000)} - fee_structure.append("components", temp) - fee_structure.insert() - program.append("fees", {"academic_term": academic_term, "fee_structure": fee_structure.name, "amount": fee_structure.total_amount}) - program.save() - frappe.db.commit() - -def make_assessment_groups(): - for year in frappe.db.get_list("Academic Year"): - ag = frappe.new_doc('Assessment Group') - ag.assessment_group_name = year.name - ag.parent_assessment_group = "All Assessment Groups" - ag.is_group = 1 - ag.insert() - for term in frappe.db.get_list("Academic Term", filters = {"academic_year": year.name}): - ag1 = frappe.new_doc('Assessment Group') - ag1.assessment_group_name = term.name - ag1.parent_assessment_group = ag.name - ag1.is_group = 1 - ag1.insert() - for assessment_group in ['Term I', 'Term II']: - ag2 = frappe.new_doc('Assessment Group') - ag2.assessment_group_name = ag1.name + " " + assessment_group - ag2.parent_assessment_group = ag1.name - ag2.insert() - frappe.db.commit() - - -def get_json_path(doctype): - return frappe.get_app_path('erpnext', 'demo', 'data', frappe.scrub(doctype) + '.json') - -def weighted_choice(weights): - totals = [] - running_total = 0 - - for w in weights: - running_total += w - totals.append(running_total) - - rnd = random.random() * running_total - for i, total in enumerate(totals): - if rnd < total: - return i diff --git a/erpnext/demo/setup/manufacture.py b/erpnext/demo/setup/manufacture.py deleted file mode 100644 index fe1a1fb2034..00000000000 --- a/erpnext/demo/setup/manufacture.py +++ /dev/null @@ -1,140 +0,0 @@ -import json -import random - -import frappe -from frappe.utils import add_days, nowdate - -from erpnext.demo.domains import data -from erpnext.demo.setup.setup_data import import_json - - -def setup_data(): - import_json("Location") - import_json("Asset Category") - setup_item() - setup_workstation() - setup_asset() - import_json('Operation') - setup_item_price() - show_item_groups_in_website() - import_json('BOM', submit=True) - frappe.db.commit() - frappe.clear_cache() - -def setup_workstation(): - workstations = [u'Drilling Machine 1', u'Lathe 1', u'Assembly Station 1', u'Assembly Station 2', u'Packing and Testing Station'] - for w in workstations: - frappe.get_doc({ - "doctype": "Workstation", - "workstation_name": w, - "holiday_list": frappe.get_all("Holiday List")[0].name, - "hour_rate_consumable": int(random.random() * 20), - "hour_rate_electricity": int(random.random() * 10), - "hour_rate_labour": int(random.random() * 40), - "hour_rate_rent": int(random.random() * 10), - "working_hours": [ - { - "enabled": 1, - "start_time": "8:00:00", - "end_time": "15:00:00" - } - ] - }).insert() - -def show_item_groups_in_website(): - """set show_in_website=1 for Item Groups""" - products = frappe.get_doc("Item Group", "Products") - products.show_in_website = 1 - products.route = 'products' - products.save() - -def setup_asset(): - assets = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'asset.json')).read()) - for d in assets: - asset = frappe.new_doc('Asset') - asset.update(d) - asset.purchase_date = add_days(nowdate(), -random.randint(20, 1500)) - asset.next_depreciation_date = add_days(asset.purchase_date, 30) - asset.warehouse = "Stores - WPL" - asset.set_missing_values() - asset.make_depreciation_schedule() - asset.flags.ignore_validate = True - asset.flags.ignore_mandatory = True - asset.save() - asset.submit() - -def setup_item(): - items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read()) - for i in items: - item = frappe.new_doc('Item') - item.update(i) - if hasattr(item, 'item_defaults') and item.item_defaults[0].default_warehouse: - item.item_defaults[0].company = data.get("Manufacturing").get('company_name') - warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.item_defaults[0].default_warehouse}, limit=1) - if warehouse: - item.item_defaults[0].default_warehouse = warehouse[0].name - item.insert() - -def setup_product_bundle(): - frappe.get_doc({ - 'doctype': 'Product Bundle', - 'new_item_code': 'Wind Mill A Series with Spare Bearing', - 'items': [ - {'item_code': 'Wind Mill A Series', 'qty': 1}, - {'item_code': 'Bearing Collar', 'qty': 1}, - {'item_code': 'Bearing Assembly', 'qty': 1}, - ] - }).insert() - -def setup_item_price(): - frappe.db.sql("delete from `tabItem Price`") - - standard_selling = { - "Base Bearing Plate": 28, - "Base Plate": 21, - "Bearing Assembly": 300, - "Bearing Block": 14, - "Bearing Collar": 103.6, - "Bearing Pipe": 63, - "Blade Rib": 46.2, - "Disc Collars": 42, - "External Disc": 56, - "Internal Disc": 70, - "Shaft": 340, - "Stand": 400, - "Upper Bearing Plate": 300, - "Wind Mill A Series": 320, - "Wind Mill A Series with Spare Bearing": 750, - "Wind MIll C Series": 400, - "Wind Turbine": 400, - "Wing Sheet": 30.8 - } - - standard_buying = { - "Base Bearing Plate": 20, - "Base Plate": 28, - "Base Plate Un Painted": 16, - "Bearing Block": 13, - "Bearing Collar": 96.4, - "Bearing Pipe": 55, - "Blade Rib": 38, - "Disc Collars": 34, - "External Disc": 50, - "Internal Disc": 60, - "Shaft": 250, - "Stand": 300, - "Upper Bearing Plate": 200, - "Wing Sheet": 25 - } - - for price_list in ("standard_buying", "standard_selling"): - for item, rate in locals().get(price_list).items(): - frappe.get_doc({ - "doctype": "Item Price", - "price_list": price_list.replace("_", " ").title(), - "item_code": item, - "selling": 1 if price_list=="standard_selling" else 0, - "buying": 1 if price_list=="standard_buying" else 0, - "price_list_rate": rate, - "currency": "USD" - }).insert() diff --git a/erpnext/demo/setup/retail.py b/erpnext/demo/setup/retail.py deleted file mode 100644 index 0469264da1e..00000000000 --- a/erpnext/demo/setup/retail.py +++ /dev/null @@ -1,62 +0,0 @@ -import json - -import frappe - -from erpnext.demo.domains import data - - -def setup_data(): - setup_item() - setup_item_price() - frappe.db.commit() - frappe.clear_cache() - -def setup_item(): - items = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'item.json')).read()) - for i in items: - if not i.get("domain") == "Retail": continue - item = frappe.new_doc('Item') - item.update(i) - if hasattr(item, 'item_defaults') and item.item_defaults[0].default_warehouse: - item.item_defaults[0].company = data.get("Retail").get('company_name') - warehouse = frappe.get_all('Warehouse', filters={'warehouse_name': item.item_defaults[0].default_warehouse}, limit=1) - if warehouse: - item.item_defaults[0].default_warehouse = warehouse[0].name - item.insert() - -def setup_item_price(): - frappe.db.sql("delete from `tabItem Price`") - - standard_selling = { - "OnePlus 6": 579, - "OnePlus 6T": 600, - "Xiaomi Poco F1": 300, - "Iphone XS": 999, - "Samsung Galaxy S9": 720, - "Sony Bluetooth Headphone": 99, - "Xiaomi Phone Repair": 10, - "Samsung Phone Repair": 20, - "OnePlus Phone Repair": 15, - "Apple Phone Repair": 30, - } - - standard_buying = { - "OnePlus 6": 300, - "OnePlus 6T": 350, - "Xiaomi Poco F1": 200, - "Iphone XS": 600, - "Samsung Galaxy S9": 500, - "Sony Bluetooth Headphone": 69 - } - - for price_list in ("standard_buying", "standard_selling"): - for item, rate in locals().get(price_list).items(): - frappe.get_doc({ - "doctype": "Item Price", - "price_list": price_list.replace("_", " ").title(), - "item_code": item, - "selling": 1 if price_list=="standard_selling" else 0, - "buying": 1 if price_list=="standard_buying" else 0, - "price_list_rate": rate, - "currency": "USD" - }).insert() diff --git a/erpnext/demo/setup/setup_data.py b/erpnext/demo/setup/setup_data.py deleted file mode 100644 index 7137c6ef564..00000000000 --- a/erpnext/demo/setup/setup_data.py +++ /dev/null @@ -1,447 +0,0 @@ -import json -import random - -import frappe -from frappe import _ -from frappe.custom.doctype.custom_field.custom_field import create_custom_fields -from frappe.utils import cstr, flt, now_datetime, random_string -from frappe.utils.make_random import add_random_children, get_random -from frappe.utils.nestedset import get_root_of - -import erpnext -from erpnext.demo.domains import data - - -def setup(domain): - frappe.flags.in_demo = 1 - complete_setup(domain) - setup_demo_page() - setup_fiscal_year() - setup_holiday_list() - setup_user() - setup_employee() - setup_user_roles(domain) - setup_role_permissions() - setup_custom_field_for_domain() - - employees = frappe.get_all('Employee', fields=['name', 'date_of_joining']) - - # monthly salary - setup_salary_structure(employees[:5], 0) - - # based on timesheet - setup_salary_structure(employees[5:], 1) - - setup_leave_allocation() - setup_customer() - setup_supplier() - setup_warehouse() - import_json('Address') - import_json('Contact') - import_json('Lead') - setup_currency_exchange() - #setup_mode_of_payment() - setup_account_to_expense_type() - setup_budget() - setup_pos_profile() - - frappe.db.commit() - frappe.clear_cache() - -def complete_setup(domain='Manufacturing'): - print("Complete Setup...") - from frappe.desk.page.setup_wizard.setup_wizard import setup_complete - - if not frappe.get_all('Company', limit=1): - setup_complete({ - "full_name": "Test User", - "email": "test_demo@erpnext.com", - "company_tagline": 'Awesome Products and Services', - "password": "demo", - "fy_start_date": "2015-01-01", - "fy_end_date": "2015-12-31", - "bank_account": "National Bank", - "domains": [domain], - "company_name": data.get(domain).get('company_name'), - "chart_of_accounts": "Standard", - "company_abbr": ''.join([d[0] for d in data.get(domain).get('company_name').split()]).upper(), - "currency": 'USD', - "timezone": 'America/New_York', - "country": 'United States', - "language": "english" - }) - - company = erpnext.get_default_company() - - if company: - company_doc = frappe.get_doc("Company", company) - company_doc.db_set('default_payroll_payable_account', - frappe.db.get_value('Account', dict(account_name='Payroll Payable'))) - -def setup_demo_page(): - # home page should always be "start" - website_settings = frappe.get_doc("Website Settings", "Website Settings") - website_settings.home_page = "demo" - website_settings.save() - -def setup_fiscal_year(): - fiscal_year = None - for year in range(2010, now_datetime().year + 1, 1): - try: - fiscal_year = frappe.get_doc({ - "doctype": "Fiscal Year", - "year": cstr(year), - "year_start_date": "{0}-01-01".format(year), - "year_end_date": "{0}-12-31".format(year) - }).insert() - except frappe.DuplicateEntryError: - pass - - # set the last fiscal year (current year) as default - if fiscal_year: - fiscal_year.set_as_default() - -def setup_holiday_list(): - """Setup Holiday List for the current year""" - year = now_datetime().year - holiday_list = frappe.get_doc({ - "doctype": "Holiday List", - "holiday_list_name": str(year), - "from_date": "{0}-01-01".format(year), - "to_date": "{0}-12-31".format(year), - }) - holiday_list.insert() - holiday_list.weekly_off = "Saturday" - holiday_list.get_weekly_off_dates() - holiday_list.weekly_off = "Sunday" - holiday_list.get_weekly_off_dates() - holiday_list.save() - - frappe.set_value("Company", erpnext.get_default_company(), "default_holiday_list", holiday_list.name) - - -def setup_user(): - frappe.db.sql('delete from tabUser where name not in ("Guest", "Administrator")') - for u in json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', 'user.json')).read()): - user = frappe.new_doc("User") - user.update(u) - user.flags.no_welcome_mail = True - user.new_password = 'Demo1234567!!!' - user.insert() - -def setup_employee(): - frappe.db.set_value("HR Settings", None, "emp_created_by", "Naming Series") - frappe.db.commit() - - for d in frappe.get_all('Salary Component'): - salary_component = frappe.get_doc('Salary Component', d.name) - salary_component.append('accounts', dict( - company=erpnext.get_default_company(), - account=frappe.get_value('Account', dict(account_name=('like', 'Salary%'))) - )) - salary_component.save() - - import_json('Employee') - holiday_list = frappe.db.get_value("Holiday List", {"holiday_list_name": str(now_datetime().year)}, 'name') - frappe.db.sql('''update tabEmployee set holiday_list={0}'''.format(holiday_list)) - -def setup_salary_structure(employees, salary_slip_based_on_timesheet=0): - ss = frappe.new_doc('Salary Structure') - ss.name = "Sample Salary Structure - " + random_string(5) - ss.salary_slip_based_on_timesheet = salary_slip_based_on_timesheet - - if salary_slip_based_on_timesheet: - ss.salary_component = 'Basic' - ss.hour_rate = flt(random.random() * 10, 2) - else: - ss.payroll_frequency = 'Monthly' - - ss.payment_account = frappe.get_value('Account', - {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name") - - ss.append('earnings', { - 'salary_component': 'Basic', - "abbr":'B', - 'formula': 'base*.2', - 'amount_based_on_formula': 1, - "idx": 1 - }) - ss.append('deductions', { - 'salary_component': 'Income Tax', - "abbr":'IT', - 'condition': 'base > 10000', - 'formula': 'base*.1', - "idx": 1 - }) - ss.insert() - ss.submit() - - for e in employees: - sa = frappe.new_doc("Salary Structure Assignment") - sa.employee = e.name - sa.salary_structure = ss.name - sa.from_date = "2015-01-01" - sa.base = random.random() * 10000 - sa.insert() - sa.submit() - - return ss - -def setup_user_roles(domain): - user = frappe.get_doc('User', 'demo@erpnext.com') - user.add_roles('HR User', 'HR Manager', 'Accounts User', 'Accounts Manager', - 'Stock User', 'Stock Manager', 'Sales User', 'Sales Manager', 'Purchase User', - 'Purchase Manager', 'Projects User', 'Manufacturing User', 'Manufacturing Manager', - 'Support Team') - - if domain == "Education": - user.add_roles('Academics User') - - if not frappe.db.get_global('demo_hr_user'): - user = frappe.get_doc('User', 'CaitlinSnow@example.com') - user.add_roles('HR User', 'HR Manager', 'Accounts User') - frappe.db.set_global('demo_hr_user', user.name) - update_employee_department(user.name, 'Human Resources') - for d in frappe.get_all('User Permission', filters={"user": "CaitlinSnow@example.com"}): - frappe.delete_doc('User Permission', d.name) - - if not frappe.db.get_global('demo_sales_user_1'): - user = frappe.get_doc('User', 'VandalSavage@example.com') - user.add_roles('Sales User') - update_employee_department(user.name, 'Sales') - frappe.db.set_global('demo_sales_user_1', user.name) - - if not frappe.db.get_global('demo_sales_user_2'): - user = frappe.get_doc('User', 'GraceChoi@example.com') - user.add_roles('Sales User', 'Sales Manager', 'Accounts User') - update_employee_department(user.name, 'Sales') - frappe.db.set_global('demo_sales_user_2', user.name) - - if not frappe.db.get_global('demo_purchase_user'): - user = frappe.get_doc('User', 'MaxwellLord@example.com') - user.add_roles('Purchase User', 'Purchase Manager', 'Accounts User', 'Stock User') - update_employee_department(user.name, 'Purchase') - frappe.db.set_global('demo_purchase_user', user.name) - - if not frappe.db.get_global('demo_manufacturing_user'): - user = frappe.get_doc('User', 'NeptuniaAquaria@example.com') - user.add_roles('Manufacturing User', 'Stock Manager', 'Stock User', 'Purchase User', 'Accounts User') - update_employee_department(user.name, 'Production') - frappe.db.set_global('demo_manufacturing_user', user.name) - - if not frappe.db.get_global('demo_stock_user'): - user = frappe.get_doc('User', 'HollyGranger@example.com') - user.add_roles('Manufacturing User', 'Stock User', 'Purchase User', 'Accounts User') - update_employee_department(user.name, 'Production') - frappe.db.set_global('demo_stock_user', user.name) - - if not frappe.db.get_global('demo_accounts_user'): - user = frappe.get_doc('User', 'BarryAllen@example.com') - user.add_roles('Accounts User', 'Accounts Manager', 'Sales User', 'Purchase User') - update_employee_department(user.name, 'Accounts') - frappe.db.set_global('demo_accounts_user', user.name) - - if not frappe.db.get_global('demo_projects_user'): - user = frappe.get_doc('User', 'PeterParker@example.com') - user.add_roles('HR User', 'Projects User') - update_employee_department(user.name, 'Management') - frappe.db.set_global('demo_projects_user', user.name) - - if domain == "Education": - if not frappe.db.get_global('demo_education_user'): - user = frappe.get_doc('User', 'ArthurCurry@example.com') - user.add_roles('Academics User') - update_employee_department(user.name, 'Management') - frappe.db.set_global('demo_education_user', user.name) - - #Add Expense Approver - user = frappe.get_doc('User', 'ClarkKent@example.com') - user.add_roles('Expense Approver') - -def setup_leave_allocation(): - year = now_datetime().year - for employee in frappe.get_all('Employee', fields=['name']): - leave_types = frappe.get_all("Leave Type", fields=['name', 'max_continuous_days_allowed']) - for leave_type in leave_types: - if not leave_type.max_continuous_days_allowed: - leave_type.max_continuous_days_allowed = 10 - - leave_allocation = frappe.get_doc({ - "doctype": "Leave Allocation", - "employee": employee.name, - "from_date": "{0}-01-01".format(year), - "to_date": "{0}-12-31".format(year), - "leave_type": leave_type.name, - "new_leaves_allocated": random.randint(1, int(leave_type.max_continuous_days_allowed)) - }) - leave_allocation.insert() - leave_allocation.submit() - frappe.db.commit() - -def setup_customer(): - customers = [u'Asian Junction', u'Life Plan Counselling', u'Two Pesos', u'Mr Fables', u'Intelacard', u'Big D Supermarkets', u'Adaptas', u'Nelson Brothers', u'Landskip Yard Care', u'Buttrey Food & Drug', u'Fayva', u'Asian Fusion', u'Crafts Canada', u'Consumers and Consumers Express', u'Netobill', u'Choices', u'Chi-Chis', u'Red Food', u'Endicott Shoes', u'Hind Enterprises'] - for c in customers: - frappe.get_doc({ - "doctype": "Customer", - "customer_name": c, - "customer_group": "Commercial", - "customer_type": random.choice(["Company", "Individual"]), - "territory": "Rest Of The World" - }).insert() - -def setup_supplier(): - suppliers = [u'Helios Air', u'Ks Merchandise', u'HomeBase', u'Scott Ties', u'Reliable Investments', u'Nan Duskin', u'Rainbow Records', u'New World Realty', u'Asiatic Solutions', u'Eagle Hardware', u'Modern Electricals'] - for s in suppliers: - frappe.get_doc({ - "doctype": "Supplier", - "supplier_name": s, - "supplier_group": random.choice(["Services", "Raw Material"]), - }).insert() - -def setup_warehouse(): - w = frappe.new_doc('Warehouse') - w.warehouse_name = 'Supplier' - w.insert() - -def setup_currency_exchange(): - frappe.get_doc({ - 'doctype': 'Currency Exchange', - 'from_currency': 'EUR', - 'to_currency': 'USD', - 'exchange_rate': 1.13 - }).insert() - - frappe.get_doc({ - 'doctype': 'Currency Exchange', - 'from_currency': 'CNY', - 'to_currency': 'USD', - 'exchange_rate': 0.16 - }).insert() - -def setup_mode_of_payment(): - company_abbr = frappe.get_cached_value('Company', erpnext.get_default_company(), "abbr") - account_dict = {'Cash': 'Cash - '+ company_abbr , 'Bank': 'National Bank - '+ company_abbr} - for payment_mode in frappe.get_all('Mode of Payment', fields = ["name", "type"]): - if payment_mode.type: - mop = frappe.get_doc('Mode of Payment', payment_mode.name) - mop.append('accounts', { - 'company': erpnext.get_default_company(), - 'default_account': account_dict.get(payment_mode.type) - }) - mop.save(ignore_permissions=True) - -def setup_account(): - frappe.flags.in_import = True - data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', - 'account.json')).read()) - for d in data: - doc = frappe.new_doc('Account') - doc.update(d) - doc.parent_account = frappe.db.get_value('Account', {'account_name': doc.parent_account}) - doc.insert() - - frappe.flags.in_import = False - -def setup_account_to_expense_type(): - company_abbr = frappe.get_cached_value('Company', erpnext.get_default_company(), "abbr") - expense_types = [{'name': _('Calls'), "account": "Sales Expenses - "+ company_abbr}, - {'name': _('Food'), "account": "Entertainment Expenses - "+ company_abbr}, - {'name': _('Medical'), "account": "Utility Expenses - "+ company_abbr}, - {'name': _('Others'), "account": "Miscellaneous Expenses - "+ company_abbr}, - {'name': _('Travel'), "account": "Travel Expenses - "+ company_abbr}] - - for expense_type in expense_types: - doc = frappe.get_doc("Expense Claim Type", expense_type["name"]) - doc.append("accounts", { - "company" : erpnext.get_default_company(), - "default_account" : expense_type["account"] - }) - doc.save(ignore_permissions=True) - -def setup_budget(): - fiscal_years = frappe.get_all("Fiscal Year", order_by="year_start_date")[-2:] - - for fy in fiscal_years: - budget = frappe.new_doc("Budget") - budget.cost_center = get_random("Cost Center") - budget.fiscal_year = fy.name - budget.action_if_annual_budget_exceeded = "Warn" - expense_ledger_count = frappe.db.count("Account", {"is_group": "0", "root_type": "Expense"}) - - add_random_children(budget, "accounts", rows=random.randint(10, expense_ledger_count), - randomize = { - "account": ("Account", {"is_group": "0", "root_type": "Expense"}) - }, unique="account") - - for d in budget.accounts: - d.budget_amount = random.randint(5, 100) * 10000 - - budget.save() - budget.submit() - -def setup_pos_profile(): - company_abbr = frappe.get_cached_value('Company', erpnext.get_default_company(), "abbr") - pos = frappe.new_doc('POS Profile') - pos.user = frappe.db.get_global('demo_accounts_user') - pos.name = "Demo POS Profile" - pos.naming_series = 'SINV-' - pos.update_stock = 0 - pos.write_off_account = 'Cost of Goods Sold - '+ company_abbr - pos.write_off_cost_center = 'Main - '+ company_abbr - pos.customer_group = get_root_of('Customer Group') - pos.territory = get_root_of('Territory') - - pos.append('payments', { - 'mode_of_payment': frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'), - 'amount': 0.0, - 'default': 1 - }) - - pos.insert() - -def setup_role_permissions(): - role_permissions = {'Batch': ['Accounts User', 'Item Manager']} - for doctype, roles in role_permissions.items(): - for role in roles: - if not frappe.db.get_value('Custom DocPerm', - {'parent': doctype, 'role': role}): - frappe.get_doc({ - 'doctype': 'Custom DocPerm', - 'role': role, - 'read': 1, - 'write': 1, - 'create': 1, - 'delete': 1, - 'parent': doctype - }).insert(ignore_permissions=True) - -def import_json(doctype, submit=False, values=None): - frappe.flags.in_import = True - data = json.loads(open(frappe.get_app_path('erpnext', 'demo', 'data', - frappe.scrub(doctype) + '.json')).read()) - for d in data: - doc = frappe.new_doc(doctype) - doc.update(d) - doc.insert() - if submit: - doc.submit() - - frappe.db.commit() - - frappe.flags.in_import = False - -def update_employee_department(user_id, department): - employee = frappe.db.get_value('Employee', {"user_id": user_id}, 'name') - department = frappe.db.get_value('Department', {'department_name': department}, 'name') - frappe.db.set_value('Employee', employee, 'department', department) - -def setup_custom_field_for_domain(): - field = { - "Item": [ - dict(fieldname='domain', label='Domain', - fieldtype='Select', hidden=1, default="Manufacturing", - options="Manufacturing\nService\nDistribution\nRetail" - ) - ] - } - create_custom_fields(field) diff --git a/erpnext/demo/user/accounts.py b/erpnext/demo/user/accounts.py deleted file mode 100644 index 273a3f92f3b..00000000000 --- a/erpnext/demo/user/accounts.py +++ /dev/null @@ -1,127 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import random - -import frappe -from frappe.desk import query_report -from frappe.utils import random_string -from frappe.utils.make_random import get_random - -import erpnext -from erpnext.accounts.doctype.journal_entry.journal_entry import get_payment_entry_against_invoice -from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry -from erpnext.accounts.doctype.payment_request.payment_request import ( - make_payment_entry, - make_payment_request, -) -from erpnext.demo.user.sales import make_sales_order -from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice -from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice - - -def work(): - frappe.set_user(frappe.db.get_global('demo_accounts_user')) - - if random.random() <= 0.6: - report = "Ordered Items to be Billed" - for so in list(set([r[0] for r in query_report.run(report)["result"] - if r[0]!="Total"]))[:random.randint(1, 5)]: - try: - si = frappe.get_doc(make_sales_invoice(so)) - si.posting_date = frappe.flags.current_date - for d in si.get("items"): - if not d.income_account: - d.income_account = "Sales - {}".format(frappe.get_cached_value('Company', si.company, 'abbr')) - si.insert() - si.submit() - frappe.db.commit() - except frappe.ValidationError: - pass - - if random.random() <= 0.6: - report = "Received Items to be Billed" - for pr in list(set([r[0] for r in query_report.run(report)["result"] - if r[0]!="Total"]))[:random.randint(1, 5)]: - try: - pi = frappe.get_doc(make_purchase_invoice(pr)) - pi.posting_date = frappe.flags.current_date - pi.bill_no = random_string(6) - pi.insert() - pi.submit() - frappe.db.commit() - except frappe.ValidationError: - pass - - - if random.random() < 0.5: - make_payment_entries("Sales Invoice", "Accounts Receivable") - - if random.random() < 0.5: - make_payment_entries("Purchase Invoice", "Accounts Payable") - - if random.random() < 0.4: - #make payment request against sales invoice - sales_invoice_name = get_random("Sales Invoice", filters={"docstatus": 1}) - if sales_invoice_name: - si = frappe.get_doc("Sales Invoice", sales_invoice_name) - if si.outstanding_amount > 0: - payment_request = make_payment_request(dt="Sales Invoice", dn=si.name, recipient_id=si.contact_email, - submit_doc=True, mute_email=True, use_dummy_message=True) - - payment_entry = frappe.get_doc(make_payment_entry(payment_request.name)) - payment_entry.posting_date = frappe.flags.current_date - payment_entry.submit() - - make_pos_invoice() - -def make_payment_entries(ref_doctype, report): - - outstanding_invoices = frappe.get_all(ref_doctype, fields=["name"], - filters={ - "company": erpnext.get_default_company(), - "outstanding_amount": (">", 0.0) - }) - - # make Payment Entry - for inv in outstanding_invoices[:random.randint(1, 2)]: - pe = get_payment_entry(ref_doctype, inv.name) - pe.posting_date = frappe.flags.current_date - pe.reference_no = random_string(6) - pe.reference_date = frappe.flags.current_date - pe.insert() - pe.submit() - frappe.db.commit() - outstanding_invoices.remove(inv) - - # make payment via JV - for inv in outstanding_invoices[:1]: - jv = frappe.get_doc(get_payment_entry_against_invoice(ref_doctype, inv.name)) - jv.posting_date = frappe.flags.current_date - jv.cheque_no = random_string(6) - jv.cheque_date = frappe.flags.current_date - jv.insert() - jv.submit() - frappe.db.commit() - -def make_pos_invoice(): - make_sales_order() - - for data in frappe.get_all('Sales Order', fields=["name"], - filters = [["per_billed", "<", "100"]]): - si = frappe.get_doc(make_sales_invoice(data.name)) - si.is_pos =1 - si.posting_date = frappe.flags.current_date - for d in si.get("items"): - if not d.income_account: - d.income_account = "Sales - {}".format(frappe.get_cached_value('Company', si.company, 'abbr')) - si.set_missing_values() - make_payment_entries_for_pos_invoice(si) - si.insert() - si.submit() - -def make_payment_entries_for_pos_invoice(si): - for data in si.payments: - data.amount = si.outstanding_amount - return diff --git a/erpnext/demo/user/education.py b/erpnext/demo/user/education.py deleted file mode 100644 index 47519c16642..00000000000 --- a/erpnext/demo/user/education.py +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import random -from datetime import timedelta - -import frappe -from frappe.utils import cstr -from frappe.utils.make_random import get_random - -from erpnext.education.api import ( - collect_fees, - enroll_student, - get_course, - get_fee_schedule, - get_student_group_students, - make_attendance_records, -) - - -def work(): - frappe.set_user(frappe.db.get_global('demo_education_user')) - for d in range(20): - approve_random_student_applicant() - enroll_random_student(frappe.flags.current_date) - # if frappe.flags.current_date.weekday()== 0: - # make_course_schedule(frappe.flags.current_date, frappe.utils.add_days(frappe.flags.current_date, 5)) - mark_student_attendance(frappe.flags.current_date) - # make_assessment_plan() - make_fees() - -def approve_random_student_applicant(): - random_student = get_random("Student Applicant", {"application_status": "Applied"}) - if random_student: - status = ["Approved", "Rejected"] - frappe.db.set_value("Student Applicant", random_student, "application_status", status[weighted_choice([9,3])]) - -def enroll_random_student(current_date): - batch = ["Section-A", "Section-B"] - random_student = get_random("Student Applicant", {"application_status": "Approved"}) - if random_student: - enrollment = enroll_student(random_student) - enrollment.academic_year = get_random("Academic Year") - enrollment.enrollment_date = current_date - enrollment.student_batch_name = batch[weighted_choice([9,3])] - fee_schedule = get_fee_schedule(enrollment.program) - for fee in fee_schedule: - enrollment.append("fees", fee) - enrolled_courses = get_course(enrollment.program) - for course in enrolled_courses: - enrollment.append("courses", course) - enrollment.submit() - frappe.db.commit() - assign_student_group(enrollment.student, enrollment.student_name, enrollment.program, - enrolled_courses, enrollment.student_batch_name) - -def assign_student_group(student, student_name, program, courses, batch): - course_list = [d["course"] for d in courses] - for d in frappe.get_list("Student Group", fields=("name"), filters={"program": program, "course":("in", course_list), "disabled": 0}): - student_group = frappe.get_doc("Student Group", d.name) - student_group.append("students", {"student": student, "student_name": student_name, - "group_roll_number":len(student_group.students)+1, "active":1}) - student_group.save() - student_batch = frappe.get_list("Student Group", fields=("name"), filters={"program": program, "group_based_on":"Batch", "batch":batch, "disabled": 0})[0] - student_batch_doc = frappe.get_doc("Student Group", student_batch.name) - student_batch_doc.append("students", {"student": student, "student_name": student_name, - "group_roll_number":len(student_batch_doc.students)+1, "active":1}) - student_batch_doc.save() - frappe.db.commit() - -def mark_student_attendance(current_date): - status = ["Present", "Absent"] - for d in frappe.db.get_list("Student Group", filters={"group_based_on": "Batch", "disabled": 0}): - students = get_student_group_students(d.name) - for stud in students: - make_attendance_records(stud.student, stud.student_name, status[weighted_choice([9,4])], None, d.name, current_date) - -def make_fees(): - for d in range(1,10): - random_fee = get_random("Fees", {"paid_amount": 0}) - collect_fees(random_fee, frappe.db.get_value("Fees", random_fee, "outstanding_amount")) - -def make_assessment_plan(date): - for d in range(1,4): - random_group = get_random("Student Group", {"group_based_on": "Course", "disabled": 0}, True) - doc = frappe.new_doc("Assessment Plan") - doc.student_group = random_group.name - doc.course = random_group.course - doc.assessment_group = get_random("Assessment Group", {"is_group": 0, "parent": "2017-18 (Semester 2)"}) - doc.grading_scale = get_random("Grading Scale") - doc.maximum_assessment_score = 100 - -def make_course_schedule(start_date, end_date): - for d in frappe.db.get_list("Student Group"): - cs = frappe.new_doc("Scheduling Tool") - cs.student_group = d.name - cs.room = get_random("Room") - cs.instructor = get_random("Instructor") - cs.course_start_date = cstr(start_date) - cs.course_end_date = cstr(end_date) - day = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] - for x in range(3): - random_day = random.choice(day) - cs.day = random_day - cs.from_time = timedelta(hours=(random.randrange(7, 17,1))) - cs.to_time = cs.from_time + timedelta(hours=1) - cs.schedule_course() - day.remove(random_day) - - -def weighted_choice(weights): - totals = [] - running_total = 0 - - for w in weights: - running_total += w - totals.append(running_total) - - rnd = random.random() * running_total - for i, total in enumerate(totals): - if rnd < total: - return i diff --git a/erpnext/demo/user/fixed_asset.py b/erpnext/demo/user/fixed_asset.py deleted file mode 100644 index 72cd420550a..00000000000 --- a/erpnext/demo/user/fixed_asset.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import frappe -from frappe.utils.make_random import get_random - -from erpnext.assets.doctype.asset.asset import make_sales_invoice -from erpnext.assets.doctype.asset.depreciation import post_depreciation_entries, scrap_asset - - -def work(): - frappe.set_user(frappe.db.get_global('demo_accounts_user')) - - # Enable booking asset depreciation entry automatically - frappe.db.set_value("Accounts Settings", None, "book_asset_depreciation_entry_automatically", 1) - - # post depreciation entries as on today - post_depreciation_entries() - - # scrap a random asset - frappe.db.set_value("Company", "Wind Power LLC", "disposal_account", "Gain/Loss on Asset Disposal - WPL") - - asset = get_random_asset() - scrap_asset(asset.name) - - # Sell a random asset - sell_an_asset() - - -def sell_an_asset(): - asset = get_random_asset() - si = make_sales_invoice(asset.name, asset.item_code, "Wind Power LLC") - si.customer = get_random("Customer") - si.get("items")[0].rate = asset.value_after_depreciation * 0.8 \ - if asset.value_after_depreciation else asset.gross_purchase_amount * 0.9 - si.save() - si.submit() - - -def get_random_asset(): - return frappe.db.sql(""" select name, item_code, value_after_depreciation, gross_purchase_amount - from `tabAsset` - where docstatus=1 and status not in ("Scrapped", "Sold") order by rand() limit 1""", as_dict=1)[0] diff --git a/erpnext/demo/user/hr.py b/erpnext/demo/user/hr.py deleted file mode 100644 index f84a853a791..00000000000 --- a/erpnext/demo/user/hr.py +++ /dev/null @@ -1,223 +0,0 @@ -import datetime -import random - -import frappe -from frappe.utils import add_days, get_last_day, getdate, random_string -from frappe.utils.make_random import get_random - -import erpnext -from erpnext.hr.doctype.expense_claim.expense_claim import make_bank_entry -from erpnext.hr.doctype.expense_claim.test_expense_claim import get_payable_account -from erpnext.hr.doctype.leave_application.leave_application import ( - AttendanceAlreadyMarkedError, - OverlapError, - get_leave_balance_on, -) -from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet -from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice - - -def work(): - frappe.set_user(frappe.db.get_global('demo_hr_user')) - year, month = frappe.flags.current_date.strftime("%Y-%m").split("-") - setup_department_approvers() - mark_attendance() - make_leave_application() - - # payroll entry - if not frappe.db.sql('select name from `tabSalary Slip` where month(adddate(start_date, interval 1 month))=month(curdate())'): - # based on frequency - payroll_entry = get_payroll_entry() - payroll_entry.salary_slip_based_on_timesheet = 0 - payroll_entry.save() - payroll_entry.create_salary_slips() - payroll_entry.submit_salary_slips() - payroll_entry.make_accrual_jv_entry() - payroll_entry.submit() - # payroll_entry.make_journal_entry(reference_date=frappe.flags.current_date, - # reference_number=random_string(10)) - - # based on timesheet - payroll_entry = get_payroll_entry() - payroll_entry.salary_slip_based_on_timesheet = 1 - payroll_entry.save() - payroll_entry.create_salary_slips() - payroll_entry.submit_salary_slips() - payroll_entry.make_accrual_jv_entry() - payroll_entry.submit() - # payroll_entry.make_journal_entry(reference_date=frappe.flags.current_date, - # reference_number=random_string(10)) - - if frappe.db.get_global('demo_hr_user'): - make_timesheet_records() - - #expense claim - expense_claim = frappe.new_doc("Expense Claim") - expense_claim.extend('expenses', get_expenses()) - expense_claim.employee = get_random("Employee") - expense_claim.company = frappe.flags.company - expense_claim.payable_account = get_payable_account(expense_claim.company) - expense_claim.posting_date = frappe.flags.current_date - expense_claim.expense_approver = frappe.db.get_global('demo_hr_user') - expense_claim.save() - - rand = random.random() - - if rand < 0.4: - update_sanctioned_amount(expense_claim) - expense_claim.approval_status = 'Approved' - expense_claim.submit() - - if random.randint(0, 1): - #make journal entry against expense claim - je = frappe.get_doc(make_bank_entry("Expense Claim", expense_claim.name)) - je.posting_date = frappe.flags.current_date - je.cheque_no = random_string(10) - je.cheque_date = frappe.flags.current_date - je.flags.ignore_permissions = 1 - je.submit() - -def get_payroll_entry(): - # process payroll for previous month - payroll_entry = frappe.new_doc("Payroll Entry") - payroll_entry.company = frappe.flags.company - payroll_entry.payroll_frequency = 'Monthly' - - # select a posting date from the previous month - payroll_entry.posting_date = get_last_day(getdate(frappe.flags.current_date) - datetime.timedelta(days=10)) - payroll_entry.payment_account = frappe.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name") - - payroll_entry.set_start_end_dates() - return payroll_entry - -def get_expenses(): - expenses = [] - expese_types = frappe.db.sql("""select ect.name, eca.default_account from `tabExpense Claim Type` ect, - `tabExpense Claim Account` eca where eca.parent=ect.name - and eca.company=%s """, frappe.flags.company,as_dict=1) - - for expense_type in expese_types[:random.randint(1,4)]: - claim_amount = random.randint(1,20)*10 - - expenses.append({ - "expense_date": frappe.flags.current_date, - "expense_type": expense_type.name, - "default_account": expense_type.default_account or "Miscellaneous Expenses - WPL", - "amount": claim_amount, - "sanctioned_amount": claim_amount - }) - - return expenses - -def update_sanctioned_amount(expense_claim): - for expense in expense_claim.expenses: - sanctioned_amount = random.randint(1,20)*10 - - if sanctioned_amount < expense.amount: - expense.sanctioned_amount = sanctioned_amount - -def get_timesheet_based_salary_slip_employee(): - sal_struct = frappe.db.sql(""" - select name from `tabSalary Structure` - where salary_slip_based_on_timesheet = 1 - and docstatus != 2""") - if sal_struct: - employees = frappe.db.sql(""" - select employee from `tabSalary Structure Assignment` - where salary_structure IN %(sal_struct)s""", {"sal_struct": sal_struct}, as_dict=True) - return employees - else: - return [] - -def make_timesheet_records(): - employees = get_timesheet_based_salary_slip_employee() - for e in employees: - ts = make_timesheet(e.employee, simulate = True, billable = 1, activity_type=get_random("Activity Type"), company=frappe.flags.company) - frappe.db.commit() - - rand = random.random() - if rand >= 0.3: - make_salary_slip_for_timesheet(ts.name) - - rand = random.random() - if rand >= 0.2: - make_sales_invoice_for_timesheet(ts.name) - -def make_salary_slip_for_timesheet(name): - salary_slip = make_salary_slip(name) - salary_slip.insert() - salary_slip.submit() - frappe.db.commit() - -def make_sales_invoice_for_timesheet(name): - sales_invoice = make_sales_invoice(name) - sales_invoice.customer = get_random("Customer") - sales_invoice.append('items', { - 'item_code': get_random("Item", {"has_variants": 0, "is_stock_item": 0, - "is_fixed_asset": 0}), - 'qty': 1, - 'rate': 1000 - }) - sales_invoice.flags.ignore_permissions = 1 - sales_invoice.set_missing_values() - sales_invoice.calculate_taxes_and_totals() - sales_invoice.insert() - sales_invoice.submit() - frappe.db.commit() - -def make_leave_application(): - allocated_leaves = frappe.get_all("Leave Allocation", fields=['employee', 'leave_type']) - - for allocated_leave in allocated_leaves: - leave_balance = get_leave_balance_on(allocated_leave.employee, allocated_leave.leave_type, frappe.flags.current_date, - consider_all_leaves_in_the_allocation_period=True) - if leave_balance != 0: - if leave_balance == 1: - to_date = frappe.flags.current_date - else: - to_date = add_days(frappe.flags.current_date, random.randint(0, leave_balance-1)) - - leave_application = frappe.get_doc({ - "doctype": "Leave Application", - "employee": allocated_leave.employee, - "from_date": frappe.flags.current_date, - "to_date": to_date, - "leave_type": allocated_leave.leave_type, - }) - try: - leave_application.insert() - leave_application.submit() - frappe.db.commit() - except (OverlapError, AttendanceAlreadyMarkedError): - frappe.db.rollback() - -def mark_attendance(): - attendance_date = frappe.flags.current_date - for employee in frappe.get_all('Employee', fields=['name'], filters = {'status': 'Active'}): - - if not frappe.db.get_value("Attendance", {"employee": employee.name, "attendance_date": attendance_date}): - attendance = frappe.get_doc({ - "doctype": "Attendance", - "employee": employee.name, - "attendance_date": attendance_date - }) - - leave = frappe.db.sql("""select name from `tabLeave Application` - where employee = %s and %s between from_date and to_date - and docstatus = 1""", (employee.name, attendance_date)) - - if leave: - attendance.status = "Absent" - else: - attendance.status = "Present" - attendance.save() - attendance.submit() - frappe.db.commit() - -def setup_department_approvers(): - for d in frappe.get_all('Department', filters={'department_name': ['!=', 'All Departments']}): - doc = frappe.get_doc('Department', d.name) - doc.append("leave_approvers", {'approver': frappe.session.user}) - doc.append("expense_approvers", {'approver': frappe.session.user}) - doc.flags.ignore_mandatory = True - doc.save() diff --git a/erpnext/demo/user/manufacturing.py b/erpnext/demo/user/manufacturing.py deleted file mode 100644 index 6b617761719..00000000000 --- a/erpnext/demo/user/manufacturing.py +++ /dev/null @@ -1,123 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import random -from datetime import timedelta - -import frappe -from frappe.desk import query_report -from frappe.utils.make_random import how_many - -import erpnext -from erpnext.manufacturing.doctype.work_order.test_work_order import make_wo_order_test_record - - -def work(): - if random.random() < 0.3: return - - frappe.set_user(frappe.db.get_global('demo_manufacturing_user')) - if not frappe.get_all('Sales Order'): return - - ppt = frappe.new_doc("Production Plan") - ppt.company = erpnext.get_default_company() - # ppt.use_multi_level_bom = 1 #refactored - ppt.get_items_from = "Sales Order" - # ppt.purchase_request_for_warehouse = "Stores - WPL" # refactored - ppt.run_method("get_open_sales_orders") - if not ppt.get("sales_orders"): return - ppt.run_method("get_items") - ppt.run_method("raise_material_requests") - ppt.save() - ppt.submit() - ppt.run_method("raise_work_orders") - frappe.db.commit() - - # submit work orders - for pro in frappe.db.get_values("Work Order", {"docstatus": 0}, "name"): - b = frappe.get_doc("Work Order", pro[0]) - b.wip_warehouse = "Work in Progress - WPL" - b.submit() - frappe.db.commit() - - # submit material requests - for pro in frappe.db.get_values("Material Request", {"docstatus": 0}, "name"): - b = frappe.get_doc("Material Request", pro[0]) - b.submit() - frappe.db.commit() - - # stores -> wip - if random.random() < 0.4: - for pro in query_report.run("Open Work Orders")["result"][:how_many("Stock Entry for WIP")]: - make_stock_entry_from_pro(pro[0], "Material Transfer for Manufacture") - - # wip -> fg - if random.random() < 0.4: - for pro in query_report.run("Work Orders in Progress")["result"][:how_many("Stock Entry for FG")]: - make_stock_entry_from_pro(pro[0], "Manufacture") - - for bom in frappe.get_all('BOM', fields=['item'], filters = {'with_operations': 1}): - pro_order = make_wo_order_test_record(item=bom.item, qty=2, - source_warehouse="Stores - WPL", wip_warehouse = "Work in Progress - WPL", - fg_warehouse = "Stores - WPL", company = erpnext.get_default_company(), - stock_uom = frappe.db.get_value('Item', bom.item, 'stock_uom'), - planned_start_date = frappe.flags.current_date) - - # submit job card - if random.random() < 0.4: - submit_job_cards() - -def make_stock_entry_from_pro(pro_id, purpose): - from erpnext.manufacturing.doctype.work_order.work_order import make_stock_entry - from erpnext.stock.doctype.stock_entry.stock_entry import ( - DuplicateEntryForWorkOrderError, - IncorrectValuationRateError, - OperationsNotCompleteError, - ) - from erpnext.stock.stock_ledger import NegativeStockError - - try: - st = frappe.get_doc(make_stock_entry(pro_id, purpose)) - st.posting_date = frappe.flags.current_date - st.fiscal_year = str(frappe.flags.current_date.year) - for d in st.get("items"): - d.cost_center = "Main - " + frappe.get_cached_value('Company', st.company, 'abbr') - st.insert() - frappe.db.commit() - st.submit() - frappe.db.commit() - except (NegativeStockError, IncorrectValuationRateError, DuplicateEntryForWorkOrderError, - OperationsNotCompleteError): - frappe.db.rollback() - -def submit_job_cards(): - work_orders = frappe.get_all("Work Order", ["name", "creation"], {"docstatus": 1, "status": "Not Started"}) - work_order = random.choice(work_orders) - # for work_order in work_orders: - start_date = work_order.creation - work_order = frappe.get_doc("Work Order", work_order.name) - job = frappe.get_all("Job Card", ["name", "operation", "work_order"], - {"docstatus": 0, "work_order": work_order.name}) - - if not job: return - job_map = {} - for d in job: - job_map[d.operation] = frappe.get_doc("Job Card", d.name) - - for operation in work_order.operations: - job = job_map[operation.operation] - job_time_log = frappe.new_doc("Job Card Time Log") - job_time_log.from_time = start_date - minutes = operation.get("time_in_mins") - job_time_log.time_in_mins = random.randint(int(minutes/2), minutes) - job_time_log.to_time = job_time_log.from_time + \ - timedelta(minutes=job_time_log.time_in_mins) - job_time_log.parent = job.name - job_time_log.parenttype = 'Job Card' - job_time_log.parentfield = 'time_logs' - job_time_log.completed_qty = work_order.qty - job_time_log.save(ignore_permissions=True) - job.time_logs.append(job_time_log) - job.save(ignore_permissions=True) - job.submit() - start_date = job_time_log.to_time diff --git a/erpnext/demo/user/projects.py b/erpnext/demo/user/projects.py deleted file mode 100644 index 1203be44084..00000000000 --- a/erpnext/demo/user/projects.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import frappe -from frappe.utils import flt -from frappe.utils.make_random import get_random - -import erpnext -from erpnext.demo.user.hr import make_sales_invoice_for_timesheet -from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet - - -def run_projects(current_date): - frappe.set_user(frappe.db.get_global('demo_projects_user')) - if frappe.db.get_global('demo_projects_user'): - make_project(current_date) - make_timesheet_for_projects(current_date) - close_tasks(current_date) - -def make_timesheet_for_projects(current_date ): - for data in frappe.get_all("Task", ["name", "project"], {"status": "Open", "exp_end_date": ("<", current_date)}): - employee = get_random("Employee") - ts = make_timesheet(employee, simulate = True, billable = 1, company = erpnext.get_default_company(), - activity_type=get_random("Activity Type"), project=data.project, task =data.name) - - if flt(ts.total_billable_amount) > 0.0: - make_sales_invoice_for_timesheet(ts.name) - frappe.db.commit() - -def close_tasks(current_date): - for task in frappe.get_all("Task", ["name"], {"status": "Open", "exp_end_date": ("<", current_date)}): - task = frappe.get_doc("Task", task.name) - task.status = "Completed" - task.save() - -def make_project(current_date): - if not frappe.db.exists('Project', - "New Product Development " + current_date.strftime("%Y-%m-%d")): - project = frappe.get_doc({ - "doctype": "Project", - "project_name": "New Product Development " + current_date.strftime("%Y-%m-%d"), - }) - project.insert() diff --git a/erpnext/demo/user/purchase.py b/erpnext/demo/user/purchase.py deleted file mode 100644 index 61f081c26f9..00000000000 --- a/erpnext/demo/user/purchase.py +++ /dev/null @@ -1,180 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import json -import random - -import frappe -from frappe.desk import query_report -from frappe.utils.make_random import get_random, how_many - -import erpnext -from erpnext.accounts.party import get_party_account_currency -from erpnext.buying.doctype.request_for_quotation.request_for_quotation import ( - make_supplier_quotation_from_rfq, -) -from erpnext.exceptions import InvalidCurrency -from erpnext.setup.utils import get_exchange_rate -from erpnext.stock.doctype.material_request.material_request import make_request_for_quotation - - -def work(): - frappe.set_user(frappe.db.get_global('demo_purchase_user')) - - if random.random() < 0.6: - report = "Items To Be Requested" - for row in query_report.run(report)["result"][:random.randint(1, 5)]: - item_code, qty = row[0], abs(row[-1]) - - mr = make_material_request(item_code, qty) - - if random.random() < 0.6: - for mr in frappe.get_all('Material Request', - filters={'material_request_type': 'Purchase', 'status': 'Open'}, - limit=random.randint(1,6)): - if not frappe.get_all('Request for Quotation', - filters={'material_request': mr.name}, limit=1): - rfq = make_request_for_quotation(mr.name) - rfq.transaction_date = frappe.flags.current_date - add_suppliers(rfq) - rfq.save() - rfq.submit() - - # Make suppier quotation from RFQ against each supplier. - if random.random() < 0.6: - for rfq in frappe.get_all('Request for Quotation', - filters={'status': 'Open'}, limit=random.randint(1, 6)): - if not frappe.get_all('Supplier Quotation', - filters={'request_for_quotation': rfq.name}, limit=1): - rfq = frappe.get_doc('Request for Quotation', rfq.name) - - for supplier in rfq.suppliers: - supplier_quotation = make_supplier_quotation_from_rfq(rfq.name, for_supplier=supplier.supplier) - supplier_quotation.save() - supplier_quotation.submit() - - # get supplier details - supplier = get_random("Supplier") - - company_currency = frappe.get_cached_value('Company', erpnext.get_default_company(), "default_currency") - party_account_currency = get_party_account_currency("Supplier", supplier, erpnext.get_default_company()) - if company_currency == party_account_currency: - exchange_rate = 1 - else: - exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_buying") - - # make supplier quotations - if random.random() < 0.5: - from erpnext.stock.doctype.material_request.material_request import make_supplier_quotation - - report = "Material Requests for which Supplier Quotations are not created" - for row in query_report.run(report)["result"][:random.randint(1, 3)]: - if row[0] != "Total": - sq = frappe.get_doc(make_supplier_quotation(row[0])) - sq.transaction_date = frappe.flags.current_date - sq.supplier = supplier - sq.currency = party_account_currency or company_currency - sq.conversion_rate = exchange_rate - sq.insert() - sq.submit() - frappe.db.commit() - - # make purchase orders - if random.random() < 0.5: - from erpnext.stock.doctype.material_request.material_request import make_purchase_order - report = "Requested Items To Be Ordered" - for row in query_report.run(report)["result"][:how_many("Purchase Order")]: - if row[0] != "Total": - try: - po = frappe.get_doc(make_purchase_order(row[0])) - po.supplier = supplier - po.currency = party_account_currency or company_currency - po.conversion_rate = exchange_rate - po.transaction_date = frappe.flags.current_date - po.insert() - po.submit() - except Exception: - pass - else: - frappe.db.commit() - - if random.random() < 0.5: - make_subcontract() - -def make_material_request(item_code, qty): - mr = frappe.new_doc("Material Request") - - variant_of = frappe.db.get_value('Item', item_code, 'variant_of') or item_code - - if frappe.db.get_value('BOM', {'item': variant_of, 'is_default': 1, 'is_active': 1}): - mr.material_request_type = 'Manufacture' - else: - mr.material_request_type = "Purchase" - - mr.transaction_date = frappe.flags.current_date - mr.schedule_date = frappe.utils.add_days(mr.transaction_date, 7) - - mr.append("items", { - "doctype": "Material Request Item", - "schedule_date": frappe.utils.add_days(mr.transaction_date, 7), - "item_code": item_code, - "qty": qty - }) - mr.insert() - mr.submit() - return mr - -def add_suppliers(rfq): - for i in range(2): - supplier = get_random("Supplier") - if supplier not in [d.supplier for d in rfq.get('suppliers')]: - rfq.append("suppliers", { "supplier": supplier }) - -def make_subcontract(): - from erpnext.buying.doctype.purchase_order.purchase_order import make_rm_stock_entry - item_code = get_random("Item", {"is_sub_contracted_item": 1}) - if item_code: - # make sub-contract PO - po = frappe.new_doc("Purchase Order") - po.is_subcontracted = "Yes" - po.supplier = get_random("Supplier") - po.transaction_date = frappe.flags.current_date # added - po.schedule_date = frappe.utils.add_days(frappe.flags.current_date, 7) - - item_code = get_random("Item", {"is_sub_contracted_item": 1}) - - po.append("items", { - "item_code": item_code, - "schedule_date": frappe.utils.add_days(frappe.flags.current_date, 7), - "qty": random.randint(10, 30) - }) - po.set_missing_values() - try: - po.insert() - except InvalidCurrency: - return - - po.submit() - - # make material request for - make_material_request(po.items[0].item_code, po.items[0].qty) - - # transfer material for sub-contract - rm_items = get_rm_item(po.items[0], po.supplied_items[0]) - stock_entry = frappe.get_doc(make_rm_stock_entry(po.name, json.dumps([rm_items]))) - stock_entry.from_warehouse = "Stores - WPL" - stock_entry.to_warehouse = "Supplier - WPL" - stock_entry.insert() - -def get_rm_item(items, supplied_items): - return { - "item_code": items.get("item_code"), - "rm_item_code": supplied_items.get("rm_item_code"), - "item_name": supplied_items.get("rm_item_code"), - "qty": supplied_items.get("required_qty") + random.randint(3,10), - "amount": supplied_items.get("amount"), - "warehouse": supplied_items.get("reserve_warehouse"), - "rate": supplied_items.get("rate"), - "stock_uom": supplied_items.get("stock_uom") - } diff --git a/erpnext/demo/user/sales.py b/erpnext/demo/user/sales.py deleted file mode 100644 index ef6e4c42cd8..00000000000 --- a/erpnext/demo/user/sales.py +++ /dev/null @@ -1,145 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import random - -import frappe -from frappe.utils import flt -from frappe.utils.make_random import add_random_children, get_random - -import erpnext -from erpnext.accounts.doctype.payment_request.payment_request import ( - make_payment_entry, - make_payment_request, -) -from erpnext.accounts.party import get_party_account_currency -from erpnext.setup.utils import get_exchange_rate - - -def work(domain="Manufacturing"): - frappe.set_user(frappe.db.get_global('demo_sales_user_2')) - - for i in range(random.randint(1,7)): - if random.random() < 0.5: - make_opportunity(domain) - - for i in range(random.randint(1,3)): - if random.random() < 0.5: - make_quotation(domain) - - try: - lost_reason = frappe.get_doc({ - "doctype": "Opportunity Lost Reason", - "lost_reason": "Did not ask" - }) - lost_reason.save(ignore_permissions=True) - except frappe.exceptions.DuplicateEntryError: - pass - - # lost quotations / inquiries - if random.random() < 0.3: - for i in range(random.randint(1,3)): - quotation = get_random('Quotation', doc=True) - if quotation and quotation.status == 'Submitted': - quotation.declare_order_lost([{'lost_reason': 'Did not ask'}]) - - for i in range(random.randint(1,3)): - opportunity = get_random('Opportunity', doc=True) - if opportunity and opportunity.status in ('Open', 'Replied'): - opportunity.declare_enquiry_lost([{'lost_reason': 'Did not ask'}]) - - for i in range(random.randint(1,3)): - if random.random() < 0.6: - make_sales_order() - - if random.random() < 0.5: - #make payment request against Sales Order - sales_order_name = get_random("Sales Order", filters={"docstatus": 1}) - try: - if sales_order_name: - so = frappe.get_doc("Sales Order", sales_order_name) - if flt(so.per_billed) != 100: - payment_request = make_payment_request(dt="Sales Order", dn=so.name, recipient_id=so.contact_email, - submit_doc=True, mute_email=True, use_dummy_message=True) - - payment_entry = frappe.get_doc(make_payment_entry(payment_request.name)) - payment_entry.posting_date = frappe.flags.current_date - payment_entry.submit() - except Exception: - pass - -def make_opportunity(domain): - b = frappe.get_doc({ - "doctype": "Opportunity", - "opportunity_from": "Customer", - "party_name": frappe.get_value("Customer", get_random("Customer"), 'name'), - "opportunity_type": "Sales", - "with_items": 1, - "transaction_date": frappe.flags.current_date, - }) - - add_random_children(b, "items", rows=4, randomize = { - "qty": (1, 5), - "item_code": ("Item", {"has_variants": 0, "is_fixed_asset": 0, "domain": domain}) - }, unique="item_code") - - b.insert() - frappe.db.commit() - -def make_quotation(domain): - # get open opportunites - opportunity = get_random("Opportunity", {"status": "Open", "with_items": 1}) - - if opportunity: - from erpnext.crm.doctype.opportunity.opportunity import make_quotation - qtn = frappe.get_doc(make_quotation(opportunity)) - qtn.insert() - frappe.db.commit() - qtn.submit() - frappe.db.commit() - else: - # make new directly - - # get customer, currency and exchange_rate - customer = get_random("Customer") - - company_currency = frappe.get_cached_value('Company', erpnext.get_default_company(), "default_currency") - party_account_currency = get_party_account_currency("Customer", customer, erpnext.get_default_company()) - if company_currency == party_account_currency: - exchange_rate = 1 - else: - exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_selling") - - qtn = frappe.get_doc({ - "creation": frappe.flags.current_date, - "doctype": "Quotation", - "quotation_to": "Customer", - "party_name": customer, - "currency": party_account_currency or company_currency, - "conversion_rate": exchange_rate, - "order_type": "Sales", - "transaction_date": frappe.flags.current_date, - }) - - add_random_children(qtn, "items", rows=3, randomize = { - "qty": (1, 5), - "item_code": ("Item", {"has_variants": "0", "is_fixed_asset": 0, "domain": domain}) - }, unique="item_code") - - qtn.insert() - frappe.db.commit() - qtn.submit() - frappe.db.commit() - -def make_sales_order(): - q = get_random("Quotation", {"status": "Submitted"}) - if q: - from erpnext.selling.doctype.quotation.quotation import make_sales_order as mso - so = frappe.get_doc(mso(q)) - so.transaction_date = frappe.flags.current_date - so.delivery_date = frappe.utils.add_days(frappe.flags.current_date, 10) - so.insert() - frappe.db.commit() - so.submit() - frappe.db.commit() diff --git a/erpnext/demo/user/stock.py b/erpnext/demo/user/stock.py deleted file mode 100644 index de379753b3d..00000000000 --- a/erpnext/demo/user/stock.py +++ /dev/null @@ -1,138 +0,0 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - - -import random - -import frappe -from frappe.desk import query_report - -import erpnext -from erpnext.stock.doctype.batch.batch import UnableToSelectBatchError -from erpnext.stock.doctype.delivery_note.delivery_note import make_sales_return -from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_return -from erpnext.stock.doctype.serial_no.serial_no import SerialNoQtyError, SerialNoRequiredError -from erpnext.stock.stock_ledger import NegativeStockError - - -def work(): - frappe.set_user(frappe.db.get_global('demo_manufacturing_user')) - - make_purchase_receipt() - make_delivery_note() - make_stock_reconciliation() - submit_draft_stock_entries() - make_sales_return_records() - make_purchase_return_records() - -def make_purchase_receipt(): - if random.random() < 0.6: - from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt - report = "Purchase Order Items To Be Received" - po_list =list(set([r[0] for r in query_report.run(report)["result"] if r[0]!="Total"]))[:random.randint(1, 10)] - for po in po_list: - pr = frappe.get_doc(make_purchase_receipt(po)) - - if pr.is_subcontracted=="Yes": - pr.supplier_warehouse = "Supplier - WPL" - - pr.posting_date = frappe.flags.current_date - pr.insert() - try: - pr.submit() - except NegativeStockError: - print('Negative stock for {0}'.format(po)) - pass - frappe.db.commit() - -def make_delivery_note(): - # make purchase requests - - # make delivery notes (if possible) - if random.random() < 0.6: - from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note - report = "Ordered Items To Be Delivered" - for so in list(set([r[0] for r in query_report.run(report)["result"] - if r[0]!="Total"]))[:random.randint(1, 3)]: - dn = frappe.get_doc(make_delivery_note(so)) - dn.posting_date = frappe.flags.current_date - for d in dn.get("items"): - if not d.expense_account: - d.expense_account = ("Cost of Goods Sold - {0}".format( - frappe.get_cached_value('Company', dn.company, 'abbr'))) - - try: - dn.insert() - dn.submit() - frappe.db.commit() - except (NegativeStockError, SerialNoRequiredError, SerialNoQtyError, UnableToSelectBatchError): - frappe.db.rollback() - -def make_stock_reconciliation(): - # random set some items as damaged - from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import ( - EmptyStockReconciliationItemsError, - OpeningEntryAccountError, - ) - - if random.random() < 0.4: - stock_reco = frappe.new_doc("Stock Reconciliation") - stock_reco.posting_date = frappe.flags.current_date - stock_reco.company = erpnext.get_default_company() - stock_reco.get_items_for("Stores - WPL") - if stock_reco.items: - for item in stock_reco.items: - if item.qty: - item.qty = item.qty - round(random.randint(1, item.qty)) - try: - stock_reco.insert(ignore_permissions=True, ignore_mandatory=True) - stock_reco.submit() - frappe.db.commit() - except OpeningEntryAccountError: - frappe.db.rollback() - except EmptyStockReconciliationItemsError: - frappe.db.rollback() - -def submit_draft_stock_entries(): - from erpnext.stock.doctype.stock_entry.stock_entry import ( - DuplicateEntryForWorkOrderError, - IncorrectValuationRateError, - OperationsNotCompleteError, - ) - - # try posting older drafts (if exists) - frappe.db.commit() - for st in frappe.db.get_values("Stock Entry", {"docstatus":0}, "name"): - try: - ste = frappe.get_doc("Stock Entry", st[0]) - ste.posting_date = frappe.flags.current_date - ste.save() - ste.submit() - frappe.db.commit() - except (NegativeStockError, IncorrectValuationRateError, DuplicateEntryForWorkOrderError, - OperationsNotCompleteError): - frappe.db.rollback() - -def make_sales_return_records(): - if random.random() < 0.1: - for data in frappe.get_all('Delivery Note', fields=["name"], filters={"docstatus": 1}): - if random.random() < 0.1: - try: - dn = make_sales_return(data.name) - dn.insert() - dn.submit() - frappe.db.commit() - except Exception: - frappe.db.rollback() - -def make_purchase_return_records(): - if random.random() < 0.1: - for data in frappe.get_all('Purchase Receipt', fields=["name"], filters={"docstatus": 1}): - if random.random() < 0.1: - try: - pr = make_purchase_return(data.name) - pr.insert() - pr.submit() - frappe.db.commit() - except Exception: - frappe.db.rollback() diff --git a/erpnext/domains/hospitality.py b/erpnext/domains/hospitality.py deleted file mode 100644 index 09b98c288bf..00000000000 --- a/erpnext/domains/hospitality.py +++ /dev/null @@ -1,35 +0,0 @@ -data = { - 'desktop_icons': [ - 'Restaurant', - 'Hotels', - 'Accounts', - 'Buying', - 'Stock', - 'HR', - 'Project', - 'ToDo' - ], - 'restricted_roles': [ - 'Restaurant Manager', - 'Hotel Manager', - 'Hotel Reservation User' - ], - 'custom_fields': { - 'Sales Invoice': [ - { - 'fieldname': 'restaurant', 'fieldtype': 'Link', 'options': 'Restaurant', - 'insert_after': 'customer_name', 'label': 'Restaurant', - }, - { - 'fieldname': 'restaurant_table', 'fieldtype': 'Link', 'options': 'Restaurant Table', - 'insert_after': 'restaurant', 'label': 'Restaurant Table', - } - ], - 'Price List': [ - { - 'fieldname':'restaurant_menu', 'fieldtype':'Link', 'options':'Restaurant Menu', 'label':'Restaurant Menu', - 'insert_after':'currency' - } - ] - } -} diff --git a/erpnext/domains/non_profit.py b/erpnext/domains/non_profit.py deleted file mode 100644 index d9fc5e5df01..00000000000 --- a/erpnext/domains/non_profit.py +++ /dev/null @@ -1,22 +0,0 @@ -data = { - 'desktop_icons': [ - 'Non Profit', - 'Member', - 'Donor', - 'Volunteer', - 'Grant Application', - 'Accounts', - 'Buying', - 'HR', - 'ToDo' - ], - 'restricted_roles': [ - 'Non Profit Manager', - 'Non Profit Member', - 'Non Profit Portal User' - ], - 'modules': [ - 'Non Profit' - ], - 'default_portal_role': 'Non Profit Manager' -} diff --git a/erpnext/hotels/doctype/__init__.py b/erpnext/e_commerce/__init__.py similarity index 100% rename from erpnext/hotels/doctype/__init__.py rename to erpnext/e_commerce/__init__.py diff --git a/erpnext/e_commerce/api.py b/erpnext/e_commerce/api.py new file mode 100644 index 00000000000..43cb36ca2e2 --- /dev/null +++ b/erpnext/e_commerce/api.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +import json + +import frappe +from frappe.utils import cint + +from erpnext.e_commerce.product_data_engine.filters import ProductFiltersBuilder +from erpnext.e_commerce.product_data_engine.query import ProductQuery +from erpnext.setup.doctype.item_group.item_group import get_child_groups_for_website + + +@frappe.whitelist(allow_guest=True) +def get_product_filter_data(query_args=None): + """ + Returns filtered products and discount filters. + :param query_args (dict): contains filters to get products list + + Query Args filters: + search (str): Search Term. + field_filters (dict): Keys include item_group, brand, etc. + attribute_filters(dict): Keys include Color, Size, etc. + start (int): Offset items by + item_group (str): Valid Item Group + from_filters (bool): Set as True to jump to page 1 + """ + if isinstance(query_args, str): + query_args = json.loads(query_args) + + query_args = frappe._dict(query_args) + if query_args: + search = query_args.get("search") + field_filters = query_args.get("field_filters", {}) + attribute_filters = query_args.get("attribute_filters", {}) + start = cint(query_args.start) if query_args.get("start") else 0 + item_group = query_args.get("item_group") + from_filters = query_args.get("from_filters") + else: + search, attribute_filters, item_group, from_filters = None, None, None, None + field_filters = {} + start = 0 + + # if new filter is checked, reset start to show filtered items from page 1 + if from_filters: + start = 0 + + sub_categories = [] + if item_group: + field_filters['item_group'] = item_group + sub_categories = get_child_groups_for_website(item_group, immediate=True) + + engine = ProductQuery() + try: + result = engine.query( + attribute_filters, + field_filters, + search_term=search, + start=start, + item_group=item_group + ) + except Exception: + traceback = frappe.get_traceback() + frappe.log_error(traceback, frappe._("Product Engine Error")) + return {"exc": "Something went wrong!"} + + # discount filter data + filters = {} + discounts = result["discounts"] + + if discounts: + filter_engine = ProductFiltersBuilder() + filters["discount_filters"] = filter_engine.get_discount_filters(discounts) + + return { + "items": result["items"] or [], + "filters": filters, + "settings": engine.settings, + "sub_categories": sub_categories, + "items_count": result["items_count"] + } + +@frappe.whitelist(allow_guest=True) +def get_guest_redirect_on_action(): + return frappe.db.get_single_value("E Commerce Settings", "redirect_on_action") \ No newline at end of file diff --git a/erpnext/hotels/doctype/hotel_room/__init__.py b/erpnext/e_commerce/doctype/__init__.py similarity index 100% rename from erpnext/hotels/doctype/hotel_room/__init__.py rename to erpnext/e_commerce/doctype/__init__.py diff --git a/erpnext/hotels/doctype/hotel_room_amenity/__init__.py b/erpnext/e_commerce/doctype/e_commerce_settings/__init__.py similarity index 100% rename from erpnext/hotels/doctype/hotel_room_amenity/__init__.py rename to erpnext/e_commerce/doctype/e_commerce_settings/__init__.py diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js similarity index 60% rename from erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js rename to erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js index b38828e0d75..6302d260e0a 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.js +++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.js @@ -1,7 +1,7 @@ -// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt +// Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt -frappe.ui.form.on("Shopping Cart Settings", { +frappe.ui.form.on("E Commerce Settings", { onload: function(frm) { if(frm.doc.__onload && frm.doc.__onload.quotation_series) { frm.fields_dict.quotation_series.df.options = frm.doc.__onload.quotation_series; @@ -23,6 +23,21 @@ frappe.ui.form.on("Shopping Cart Settings", { ` ); } + + frappe.model.with_doctype("Item", () => { + const web_item_meta = frappe.get_meta('Website Item'); + + const valid_fields = web_item_meta.fields.filter( + df => ["Link", "Table MultiSelect"].includes(df.fieldtype) && !df.hidden + ).map(df => ({ label: df.label, value: df.fieldname })); + + frm.fields_dict.filter_fields.grid.update_docfield_property( + 'fieldname', 'fieldtype', 'Select' + ); + frm.fields_dict.filter_fields.grid.update_docfield_property( + 'fieldname', 'options', valid_fields + ); + }); }, enabled: function(frm) { if (frm.doc.enabled === 1) { diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.json b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.json new file mode 100644 index 00000000000..d5fb9697f89 --- /dev/null +++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.json @@ -0,0 +1,393 @@ +{ + "actions": [], + "creation": "2021-02-10 17:13:39.139103", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "products_per_page", + "filter_categories_section", + "enable_field_filters", + "filter_fields", + "enable_attribute_filters", + "filter_attributes", + "display_settings_section", + "hide_variants", + "enable_variants", + "show_price", + "column_break_9", + "show_stock_availability", + "show_quantity_in_website", + "allow_items_not_in_stock", + "column_break_13", + "show_apply_coupon_code_in_website", + "show_contact_us_button", + "show_attachments", + "section_break_18", + "company", + "price_list", + "enabled", + "store_page_docs", + "column_break_21", + "default_customer_group", + "quotation_series", + "checkout_settings_section", + "enable_checkout", + "show_price_in_quotation", + "column_break_27", + "save_quotations_as_draft", + "payment_gateway_account", + "payment_success_url", + "add_ons_section", + "enable_wishlist", + "column_break_22", + "enable_reviews", + "column_break_23", + "enable_recommendations", + "item_search_settings_section", + "redisearch_warning", + "search_index_fields", + "show_categories_in_search_autocomplete", + "is_redisearch_loaded", + "shop_by_category_section", + "slideshow", + "guest_display_settings_section", + "hide_price_for_guest", + "redirect_on_action" + ], + "fields": [ + { + "default": "6", + "fieldname": "products_per_page", + "fieldtype": "Int", + "label": "Products per Page" + }, + { + "collapsible": 1, + "fieldname": "filter_categories_section", + "fieldtype": "Section Break", + "label": "Filters and Categories" + }, + { + "default": "0", + "fieldname": "hide_variants", + "fieldtype": "Check", + "label": "Hide Variants" + }, + { + "default": "0", + "description": "The field filters will also work as categories in the Shop by Category page.", + "fieldname": "enable_field_filters", + "fieldtype": "Check", + "label": "Enable Field Filters (Categories)" + }, + { + "default": "0", + "fieldname": "enable_attribute_filters", + "fieldtype": "Check", + "label": "Enable Attribute Filters" + }, + { + "depends_on": "enable_field_filters", + "fieldname": "filter_fields", + "fieldtype": "Table", + "label": "Website Item Fields", + "options": "Website Filter Field" + }, + { + "depends_on": "enable_attribute_filters", + "fieldname": "filter_attributes", + "fieldtype": "Table", + "label": "Attributes", + "options": "Website Attribute" + }, + { + "default": "0", + "fieldname": "enabled", + "fieldtype": "Check", + "in_list_view": 1, + "label": "Enable Shopping Cart" + }, + { + "depends_on": "doc.enabled", + "fieldname": "store_page_docs", + "fieldtype": "HTML" + }, + { + "fieldname": "display_settings_section", + "fieldtype": "Section Break", + "label": "Display Settings" + }, + { + "default": "0", + "fieldname": "show_attachments", + "fieldtype": "Check", + "label": "Show Public Attachments" + }, + { + "default": "0", + "fieldname": "show_price", + "fieldtype": "Check", + "label": "Show Price" + }, + { + "default": "0", + "fieldname": "show_stock_availability", + "fieldtype": "Check", + "label": "Show Stock Availability" + }, + { + "default": "0", + "fieldname": "enable_variants", + "fieldtype": "Check", + "label": "Enable Variant Selection" + }, + { + "fieldname": "column_break_13", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "show_contact_us_button", + "fieldtype": "Check", + "label": "Show Contact Us Button" + }, + { + "default": "0", + "depends_on": "show_stock_availability", + "fieldname": "show_quantity_in_website", + "fieldtype": "Check", + "label": "Show Stock Quantity" + }, + { + "default": "0", + "fieldname": "show_apply_coupon_code_in_website", + "fieldtype": "Check", + "label": "Show Apply Coupon Code" + }, + { + "default": "0", + "fieldname": "allow_items_not_in_stock", + "fieldtype": "Check", + "label": "Allow items not in stock to be added to cart" + }, + { + "fieldname": "section_break_18", + "fieldtype": "Section Break", + "label": "Shopping Cart" + }, + { + "depends_on": "enabled", + "fieldname": "company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "mandatory_depends_on": "eval: doc.enabled === 1", + "options": "Company", + "remember_last_selected_value": 1 + }, + { + "depends_on": "enabled", + "description": "Prices will not be shown if Price List is not set", + "fieldname": "price_list", + "fieldtype": "Link", + "label": "Price List", + "mandatory_depends_on": "eval: doc.enabled === 1", + "options": "Price List" + }, + { + "fieldname": "column_break_21", + "fieldtype": "Column Break" + }, + { + "depends_on": "enabled", + "fieldname": "default_customer_group", + "fieldtype": "Link", + "ignore_user_permissions": 1, + "label": "Default Customer Group", + "mandatory_depends_on": "eval: doc.enabled === 1", + "options": "Customer Group" + }, + { + "depends_on": "enabled", + "fieldname": "quotation_series", + "fieldtype": "Select", + "label": "Quotation Series", + "mandatory_depends_on": "eval: doc.enabled === 1" + }, + { + "collapsible": 1, + "collapsible_depends_on": "eval:doc.enable_checkout", + "depends_on": "enabled", + "fieldname": "checkout_settings_section", + "fieldtype": "Section Break", + "label": "Checkout Settings" + }, + { + "default": "0", + "fieldname": "enable_checkout", + "fieldtype": "Check", + "label": "Enable Checkout" + }, + { + "default": "Orders", + "depends_on": "enable_checkout", + "description": "After payment completion redirect user to selected page.", + "fieldname": "payment_success_url", + "fieldtype": "Select", + "label": "Payment Success Url", + "mandatory_depends_on": "enable_checkout", + "options": "\nOrders\nInvoices\nMy Account" + }, + { + "fieldname": "column_break_27", + "fieldtype": "Column Break" + }, + { + "default": "0", + "depends_on": "eval: doc.enable_checkout == 0", + "fieldname": "save_quotations_as_draft", + "fieldtype": "Check", + "label": "Save Quotations as Draft" + }, + { + "depends_on": "enable_checkout", + "fieldname": "payment_gateway_account", + "fieldtype": "Link", + "label": "Payment Gateway Account", + "mandatory_depends_on": "enable_checkout", + "options": "Payment Gateway Account" + }, + { + "collapsible": 1, + "depends_on": "enable_field_filters", + "fieldname": "shop_by_category_section", + "fieldtype": "Section Break", + "label": "Shop by Category" + }, + { + "fieldname": "slideshow", + "fieldtype": "Link", + "label": "Slideshow", + "options": "Website Slideshow" + }, + { + "collapsible": 1, + "fieldname": "add_ons_section", + "fieldtype": "Section Break", + "label": "Add-ons" + }, + { + "default": "0", + "fieldname": "enable_wishlist", + "fieldtype": "Check", + "label": "Enable Wishlist" + }, + { + "default": "0", + "fieldname": "enable_reviews", + "fieldtype": "Check", + "label": "Enable Reviews and Ratings" + }, + { + "fieldname": "search_index_fields", + "fieldtype": "Small Text", + "label": "Search Index Fields", + "read_only_depends_on": "eval:!doc.is_redisearch_loaded" + }, + { + "collapsible": 1, + "fieldname": "item_search_settings_section", + "fieldtype": "Section Break", + "label": "Item Search Settings" + }, + { + "default": "1", + "fieldname": "show_categories_in_search_autocomplete", + "fieldtype": "Check", + "label": "Show Categories in Search Autocomplete", + "read_only_depends_on": "eval:!doc.is_redisearch_loaded" + }, + { + "default": "0", + "fieldname": "is_redisearch_loaded", + "fieldtype": "Check", + "hidden": 1, + "label": "Is Redisearch Loaded" + }, + { + "depends_on": "eval:!doc.is_redisearch_loaded", + "fieldname": "redisearch_warning", + "fieldtype": "HTML", + "label": "Redisearch Warning", + "options": "Redisearch is not loaded. If you want to use the advanced product search feature, refer here.
" + }, + { + "default": "0", + "depends_on": "eval:doc.show_price", + "fieldname": "hide_price_for_guest", + "fieldtype": "Check", + "label": "Hide Price for Guest" + }, + { + "fieldname": "column_break_9", + "fieldtype": "Column Break" + }, + { + "collapsible": 1, + "fieldname": "guest_display_settings_section", + "fieldtype": "Section Break", + "label": "Guest Display Settings" + }, + { + "description": "Link to redirect Guest on actions that need login such as add to cart, wishlist, etc. E.g.: /login", + "fieldname": "redirect_on_action", + "fieldtype": "Data", + "label": "Redirect on Action" + }, + { + "fieldname": "column_break_22", + "fieldtype": "Column Break" + }, + { + "fieldname": "column_break_23", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "enable_recommendations", + "fieldtype": "Check", + "label": "Enable Recommendations" + }, + { + "default": "0", + "depends_on": "eval: doc.enable_checkout == 0", + "fieldname": "show_price_in_quotation", + "fieldtype": "Check", + "label": "Show Price in Quotation" + } + ], + "index_web_pages_for_search": 1, + "issingle": 1, + "links": [], + "modified": "2021-09-02 14:02:44.785824", + "modified_by": "Administrator", + "module": "E-commerce", + "name": "E Commerce Settings", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "print": 1, + "read": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py similarity index 52% rename from erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py rename to erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py index 4a755998dd4..dd7b114289d 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.py +++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py @@ -1,25 +1,81 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt - import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import flt +from frappe.utils import comma_and, flt, unique + +from erpnext.e_commerce.redisearch_utils import ( + create_website_items_index, + get_indexable_web_fields, + is_search_module_loaded, +) class ShoppingCartSetupError(frappe.ValidationError): pass -class ShoppingCartSettings(Document): +class ECommerceSettings(Document): def onload(self): self.get("__onload").quotation_series = frappe.get_meta("Quotation").get_options("naming_series") + self.is_redisearch_loaded = is_search_module_loaded() def validate(self): + self.validate_field_filters() + self.validate_attribute_filters() + self.validate_checkout() + self.validate_search_index_fields() + if self.enabled: self.validate_price_list_exchange_rate() + frappe.clear_document_cache("E Commerce Settings", "E Commerce Settings") + + def validate_field_filters(self): + if not (self.enable_field_filters and self.filter_fields): + return + + item_meta = frappe.get_meta("Item") + valid_fields = [df.fieldname for df in item_meta.fields if df.fieldtype in ["Link", "Table MultiSelect"]] + + for f in self.filter_fields: + if f.fieldname not in valid_fields: + frappe.throw(_("Filter Fields Row #{0}: Fieldname {1} must be of type 'Link' or 'Table MultiSelect'").format(f.idx, f.fieldname)) + + def validate_attribute_filters(self): + if not (self.enable_attribute_filters and self.filter_attributes): + return + + # if attribute filters are enabled, hide_variants should be disabled + self.hide_variants = 0 + + def validate_checkout(self): + if self.enable_checkout and not self.payment_gateway_account: + self.enable_checkout = 0 + + def validate_search_index_fields(self): + if not self.search_index_fields: + return + + fields = self.search_index_fields.replace(' ', '') + fields = unique(fields.strip(',').split(',')) # Remove extra ',' and remove duplicates + + # All fields should be indexable + allowed_indexable_fields = get_indexable_web_fields() + + if not (set(fields).issubset(allowed_indexable_fields)): + invalid_fields = list(set(fields).difference(allowed_indexable_fields)) + num_invalid_fields = len(invalid_fields) + invalid_fields = comma_and(invalid_fields) + + if num_invalid_fields > 1: + frappe.throw(_("{0} are not valid options for Search Index Field.").format(frappe.bold(invalid_fields))) + else: + frappe.throw(_("{0} is not a valid option for Search Index Field.").format(frappe.bold(invalid_fields))) + + self.search_index_fields = ','.join(fields) + def validate_price_list_exchange_rate(self): "Check if exchange rate exists for Price List currency (to Company's currency)." from erpnext.setup.utils import get_exchange_rate @@ -60,12 +116,23 @@ class ShoppingCartSettings(Document): def get_shipping_rules(self, shipping_territory): return self.get_name_from_territory(shipping_territory, "shipping_rules", "shipping_rule") + def on_change(self): + old_doc = self.get_doc_before_save() + + if old_doc: + old_fields = old_doc.search_index_fields + new_fields = self.search_index_fields + + # if search index fields get changed + if not (new_fields == old_fields): + create_website_items_index() + def validate_cart_settings(doc=None, method=None): - frappe.get_doc("Shopping Cart Settings", "Shopping Cart Settings").run_method("validate") + frappe.get_doc("E Commerce Settings", "E Commerce Settings").run_method("validate") def get_shopping_cart_settings(): if not getattr(frappe.local, "shopping_cart_settings", None): - frappe.local.shopping_cart_settings = frappe.get_doc("Shopping Cart Settings", "Shopping Cart Settings") + frappe.local.shopping_cart_settings = frappe.get_doc("E Commerce Settings", "E Commerce Settings") return frappe.local.shopping_cart_settings diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.py b/erpnext/e_commerce/doctype/e_commerce_settings/test_e_commerce_settings.py similarity index 67% rename from erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.py rename to erpnext/e_commerce/doctype/e_commerce_settings/test_e_commerce_settings.py index c3809b30b0f..86cef30d985 100644 --- a/erpnext/shopping_cart/doctype/shopping_cart_settings/test_shopping_cart_settings.py +++ b/erpnext/e_commerce/doctype/e_commerce_settings/test_e_commerce_settings.py @@ -1,24 +1,21 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors -# License: GNU General Public License v3. See license.txt - -# For license information, please see license.txt - - +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt import unittest import frappe -from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import ( +from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import ( ShoppingCartSetupError, ) -class TestShoppingCartSettings(unittest.TestCase): +class TestECommerceSettings(unittest.TestCase): def setUp(self): frappe.db.sql("""delete from `tabSingles` where doctype="Shipping Cart Settings" """) def get_cart_settings(self): - return frappe.get_doc({"doctype": "Shopping Cart Settings", + return frappe.get_doc({"doctype": "E Commerce Settings", "company": "_Test Company"}) # NOTE: Exchangrate API has all enabled currencies that ERPNext supports. @@ -34,15 +31,17 @@ class TestShoppingCartSettings(unittest.TestCase): # cart_settings = self.get_cart_settings() # cart_settings.price_list = "_Test Price List Rest of the World" - # self.assertRaises(ShoppingCartSetupError, cart_settings.validate_price_list_exchange_rate) + # self.assertRaises(ShoppingCartSetupError, cart_settings.validate_exchange_rates_exist) - # from erpnext.setup.doctype.currency_exchange.test_currency_exchange import test_records as \ - # currency_exchange_records + # from erpnext.setup.doctype.currency_exchange.test_currency_exchange import ( + # test_records as currency_exchange_records, + # ) # frappe.get_doc(currency_exchange_records[0]).insert() - # cart_settings.validate_price_list_exchange_rate() + # cart_settings.validate_exchange_rates_exist() def test_tax_rule_validation(self): frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 0") + frappe.db.commit() # nosemgrep cart_settings = self.get_cart_settings() cart_settings.enabled = 1 @@ -51,4 +50,13 @@ class TestShoppingCartSettings(unittest.TestCase): frappe.db.sql("update `tabTax Rule` set use_for_shopping_cart = 1") +def setup_e_commerce_settings(values_dict): + "Accepts a dict of values that updates E Commerce Settings." + if not values_dict: + return + + doc = frappe.get_doc("E Commerce Settings", "E Commerce Settings") + doc.update(values_dict) + doc.save() + test_dependencies = ["Tax Rule"] diff --git a/erpnext/hotels/doctype/hotel_room_package/__init__.py b/erpnext/e_commerce/doctype/item_review/__init__.py similarity index 100% rename from erpnext/hotels/doctype/hotel_room_package/__init__.py rename to erpnext/e_commerce/doctype/item_review/__init__.py diff --git a/erpnext/e_commerce/doctype/item_review/item_review.js b/erpnext/e_commerce/doctype/item_review/item_review.js new file mode 100644 index 00000000000..a57c370287b --- /dev/null +++ b/erpnext/e_commerce/doctype/item_review/item_review.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('Item Review', { + // refresh: function(frm) { + + // } +}); diff --git a/erpnext/e_commerce/doctype/item_review/item_review.json b/erpnext/e_commerce/doctype/item_review/item_review.json new file mode 100644 index 00000000000..57f719fc3c4 --- /dev/null +++ b/erpnext/e_commerce/doctype/item_review/item_review.json @@ -0,0 +1,134 @@ +{ + "actions": [], + "beta": 1, + "creation": "2021-03-23 16:47:26.542226", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "website_item", + "user", + "customer", + "column_break_3", + "item", + "published_on", + "reviews_section", + "review_title", + "rating", + "comment" + ], + "fields": [ + { + "fieldname": "website_item", + "fieldtype": "Link", + "label": "Website Item", + "options": "Website Item", + "read_only": 1, + "reqd": 1 + }, + { + "fieldname": "user", + "fieldtype": "Link", + "in_list_view": 1, + "label": "User", + "options": "User", + "read_only": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "fetch_from": "website_item.item_code", + "fieldname": "item", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Item", + "options": "Item", + "read_only": 1 + }, + { + "fieldname": "reviews_section", + "fieldtype": "Section Break", + "label": "Reviews" + }, + { + "fieldname": "rating", + "fieldtype": "Rating", + "in_list_view": 1, + "label": "Rating", + "read_only": 1 + }, + { + "fieldname": "comment", + "fieldtype": "Small Text", + "label": "Comment", + "read_only": 1 + }, + { + "fieldname": "review_title", + "fieldtype": "Data", + "label": "Review Title", + "read_only": 1 + }, + { + "fieldname": "customer", + "fieldtype": "Link", + "label": "Customer", + "options": "Customer", + "read_only": 1 + }, + { + "fieldname": "published_on", + "fieldtype": "Data", + "label": "Published on", + "read_only": 1 + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2021-08-10 12:08:58.119691", + "modified_by": "Administrator", + "module": "E-commerce", + "name": "Item Review", + "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": "Website Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "report": 1, + "role": "Customer", + "share": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/e_commerce/doctype/item_review/item_review.py b/erpnext/e_commerce/doctype/item_review/item_review.py new file mode 100644 index 00000000000..966ec350e75 --- /dev/null +++ b/erpnext/e_commerce/doctype/item_review/item_review.py @@ -0,0 +1,147 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from datetime import datetime + +import frappe +from frappe import _ +from frappe.contacts.doctype.contact.contact import get_contact_name +from frappe.model.document import Document +from frappe.utils import cint, flt + +from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import ( + get_shopping_cart_settings, +) + + +class UnverifiedReviewer(frappe.ValidationError): + pass + +class ItemReview(Document): + def after_insert(self): + # regenerate cache on review creation + reviews_dict = get_queried_reviews(self.website_item) + set_reviews_in_cache(self.website_item, reviews_dict) + + def after_delete(self): + # regenerate cache on review deletion + reviews_dict = get_queried_reviews(self.website_item) + set_reviews_in_cache(self.website_item, reviews_dict) + + +@frappe.whitelist() +def get_item_reviews(web_item, start=0, end=10, data=None): + "Get Website Item Review Data." + start, end = cint(start), cint(end) + settings = get_shopping_cart_settings() + + # Get cached reviews for first page (start=0) + # avoid cache when page is different + from_cache = not bool(start) + + if not data: + data = frappe._dict() + + if settings and settings.get("enable_reviews"): + reviews_cache = frappe.cache().hget("item_reviews", web_item) + if from_cache and reviews_cache: + data = reviews_cache + else: + data = get_queried_reviews(web_item, start, end, data) + if from_cache: + set_reviews_in_cache(web_item, data) + + return data + +def get_queried_reviews(web_item, start=0, end=10, data=None): + """ + Query Website Item wise reviews and cache if needed. + Cache stores only first page of reviews i.e. 10 reviews maximum. + Returns: + dict: Containing reviews, average ratings, % of reviews per rating and total reviews. + """ + if not data: + data = frappe._dict() + + data.reviews = frappe.db.get_all( + "Item Review", + filters={"website_item": web_item}, + fields=["*"], + limit_start=start, + limit_page_length=end + ) + + rating_data = frappe.db.get_all( + "Item Review", + filters={"website_item": web_item}, + fields=["avg(rating) as average, count(*) as total"] + )[0] + + data.average_rating = flt(rating_data.average, 1) + data.average_whole_rating = flt(data.average_rating, 0) + + # get % of reviews per rating + reviews_per_rating = [] + for i in range(1,6): + count = frappe.db.get_all( + "Item Review", + filters={"website_item": web_item, "rating": i}, + fields=["count(*) as count"] + )[0].count + + percent = flt((count / rating_data.total or 1) * 100, 0) if count else 0 + reviews_per_rating.append(percent) + + data.reviews_per_rating = reviews_per_rating + data.total_reviews = rating_data.total + + return data + +def set_reviews_in_cache(web_item, reviews_dict): + frappe.cache().hset("item_reviews", web_item, reviews_dict) + +@frappe.whitelist() +def add_item_review(web_item, title, rating, comment=None): + """ Add an Item Review by a user if non-existent. """ + if frappe.session.user == "Guest": + # guest user should not reach here ideally in the case they do via an API, throw error + frappe.throw(_("You are not verified to write a review yet."), exc=UnverifiedReviewer) + + if not frappe.db.exists("Item Review", {"user": frappe.session.user, "website_item": web_item}): + doc = frappe.get_doc({ + "doctype": "Item Review", + "user": frappe.session.user, + "customer": get_customer(), + "website_item": web_item, + "item": frappe.db.get_value("Website Item", web_item, "item_code"), + "review_title": title, + "rating": rating, + "comment": comment + }) + doc.published_on = datetime.today().strftime("%d %B %Y") + doc.insert() + +def get_customer(silent=False): + """ + silent: Return customer if exists else return nothing. Dont throw error. + """ + user = frappe.session.user + contact_name = get_contact_name(user) + customer = None + + if contact_name: + contact = frappe.get_doc('Contact', contact_name) + for link in contact.links: + if link.link_doctype == "Customer": + customer = link.link_name + break + + if customer: + return frappe.db.get_value("Customer", customer) + elif silent: + return None + else: + # should not reach here unless via an API + frappe.throw(_("You are not a verified customer yet. Please contact us to proceed."), + exc=UnverifiedReviewer) diff --git a/erpnext/e_commerce/doctype/item_review/test_item_review.py b/erpnext/e_commerce/doctype/item_review/test_item_review.py new file mode 100644 index 00000000000..8a4befc800a --- /dev/null +++ b/erpnext/e_commerce/doctype/item_review/test_item_review.py @@ -0,0 +1,84 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +import unittest + +import frappe +from frappe.core.doctype.user_permission.test_user_permission import create_user + +from erpnext.e_commerce.doctype.e_commerce_settings.test_e_commerce_settings import ( + setup_e_commerce_settings, +) +from erpnext.e_commerce.doctype.item_review.item_review import ( + UnverifiedReviewer, + add_item_review, + get_item_reviews, +) +from erpnext.e_commerce.doctype.website_item.website_item import make_website_item +from erpnext.e_commerce.shopping_cart.cart import get_party +from erpnext.stock.doctype.item.test_item import make_item + + +class TestItemReview(unittest.TestCase): + def setUp(self): + item = make_item("Test Mobile Phone") + if not frappe.db.exists("Website Item", {"item_code": "Test Mobile Phone"}): + make_website_item(item, save=True) + + setup_e_commerce_settings({"enable_reviews": 1}) + frappe.local.shopping_cart_settings = None + + def tearDown(self): + frappe.get_cached_doc("Website Item", {"item_code": "Test Mobile Phone"}).delete() + setup_e_commerce_settings({"enable_reviews": 0}) + + def test_add_and_get_item_reviews_from_customer(self): + "Add / Get Reviews from a User that is a valid customer (has added to cart or purchased in the past)" + # create user + web_item = frappe.db.get_value("Website Item", {"item_code": "Test Mobile Phone"}) + test_user = create_user("test_reviewer@example.com", "Customer") + frappe.set_user(test_user.name) + + # create customer and contact against user + customer = get_party() + + # post review on "Test Mobile Phone" + try: + add_item_review(web_item, "Great Product", 3, "Would recommend this product") + review_name = frappe.db.get_value("Item Review", {"website_item": web_item}) + except Exception: + self.fail(f"Error while publishing review for {web_item}") + + review_data = get_item_reviews(web_item, 0, 10) + + self.assertEqual(len(review_data.reviews), 1) + self.assertEqual(review_data.average_rating, 3) + self.assertEqual(review_data.reviews_per_rating[2], 100) + + # tear down + frappe.set_user("Administrator") + frappe.delete_doc("Item Review", review_name) + customer.delete() + + def test_add_item_review_from_non_customer(self): + "Check if logged in user (who is not a customer yet) is blocked from posting reviews." + web_item = frappe.db.get_value("Website Item", {"item_code": "Test Mobile Phone"}) + test_user = create_user("test_reviewer@example.com", "Customer") + frappe.set_user(test_user.name) + + with self.assertRaises(UnverifiedReviewer): + add_item_review(web_item, "Great Product", 3, "Would recommend this product") + + # tear down + frappe.set_user("Administrator") + + def test_add_item_reviews_from_guest_user(self): + "Check if Guest user is blocked from posting reviews." + web_item = frappe.db.get_value("Website Item", {"item_code": "Test Mobile Phone"}) + frappe.set_user("Guest") + + with self.assertRaises(UnverifiedReviewer): + add_item_review(web_item, "Great Product", 3, "Would recommend this product") + + # tear down + frappe.set_user("Administrator") diff --git a/erpnext/hotels/doctype/hotel_room_pricing/__init__.py b/erpnext/e_commerce/doctype/recommended_items/__init__.py similarity index 100% rename from erpnext/hotels/doctype/hotel_room_pricing/__init__.py rename to erpnext/e_commerce/doctype/recommended_items/__init__.py diff --git a/erpnext/e_commerce/doctype/recommended_items/recommended_items.json b/erpnext/e_commerce/doctype/recommended_items/recommended_items.json new file mode 100644 index 00000000000..06ac3dc03b7 --- /dev/null +++ b/erpnext/e_commerce/doctype/recommended_items/recommended_items.json @@ -0,0 +1,87 @@ +{ + "actions": [], + "creation": "2021-07-12 20:52:12.503470", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "website_item", + "website_item_name", + "column_break_2", + "item_code", + "more_information_section", + "route", + "column_break_6", + "website_item_image", + "website_item_thumbnail" + ], + "fields": [ + { + "fieldname": "website_item", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Website Item", + "options": "Website Item" + }, + { + "fetch_from": "website_item.web_item_name", + "fieldname": "website_item_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Website Item Name", + "read_only": 1 + }, + { + "fieldname": "column_break_2", + "fieldtype": "Column Break" + }, + { + "fieldname": "more_information_section", + "fieldtype": "Section Break", + "label": "More Information" + }, + { + "fetch_from": "website_item.route", + "fieldname": "route", + "fieldtype": "Small Text", + "label": "Route", + "read_only": 1 + }, + { + "fetch_from": "website_item.image", + "fieldname": "website_item_image", + "fieldtype": "Attach", + "label": "Website Item Image", + "read_only": 1 + }, + { + "fieldname": "column_break_6", + "fieldtype": "Column Break" + }, + { + "fetch_from": "website_item.thumbnail", + "fieldname": "website_item_thumbnail", + "fieldtype": "Data", + "label": "Website Item Thumbnail", + "read_only": 1 + }, + { + "fetch_from": "website_item.item_code", + "fieldname": "item_code", + "fieldtype": "Data", + "label": "Item Code" + } + ], + "index_web_pages_for_search": 1, + "istable": 1, + "links": [], + "modified": "2021-07-13 21:02:19.031652", + "modified_by": "Administrator", + "module": "E-commerce", + "name": "Recommended Items", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/e_commerce/doctype/recommended_items/recommended_items.py b/erpnext/e_commerce/doctype/recommended_items/recommended_items.py new file mode 100644 index 00000000000..16b6e52047f --- /dev/null +++ b/erpnext/e_commerce/doctype/recommended_items/recommended_items.py @@ -0,0 +1,9 @@ +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class RecommendedItems(Document): + pass diff --git a/erpnext/hotels/doctype/hotel_room_pricing_item/__init__.py b/erpnext/e_commerce/doctype/website_item/__init__.py similarity index 100% rename from erpnext/hotels/doctype/hotel_room_pricing_item/__init__.py rename to erpnext/e_commerce/doctype/website_item/__init__.py diff --git a/erpnext/e_commerce/doctype/website_item/templates/website_item.html b/erpnext/e_commerce/doctype/website_item/templates/website_item.html new file mode 100644 index 00000000000..db123090aae --- /dev/null +++ b/erpnext/e_commerce/doctype/website_item/templates/website_item.html @@ -0,0 +1,7 @@ +{% extends "templates/web.html" %} + +{% block page_content %} ++ ${ item.item_group } | Item Code : ${ item.item_code } +
+
+ {{ introduction }}
-{% if meetup_embed_html %} - {{ meetup_embed_html }} -{% endif %} -|
-
-
-
-
-
-
-
-
- {{ index|length }}. {{ frappe.db.get_value('User', user.user, 'full_name') }}
-
- {% if user.website_url %}
- {{ user.website_url | truncate (50) or '' }}
- {% endif %}
-
-
- -
- {% if user.introduction %}
- {{ user.introduction }}
- {% endif %}
-
- |
-
No member yet.
-{% endif %} - -| Name | -{{ doc.member_name }} | -
| {{ frappe.db.get_value('User', doc.email, 'email') or '' }} | -|
| Phone | -{{ frappe.db.get_value('User', doc.email, 'phone') or '' }} | -
{{ address or ''}}
-Please Review this grant application
| Organization/Indvidual | -{{ applicant_type }} | -
| Grant Applicant Name | -{{ applicant_name}} | -
| Date | -{{ frappe.format_date(creation) }} | -
| Status | -{{ status }} | -
| {{ email }} | -
{{ grant_description }}
-{{ amount }}
-{{ has_any_past_grant_record }}
-| Contact Person | -{{ contact_person }} | -
| {{ email }} | -
You must register and login to view contact details
- {% endif %} -Assessment Review done
- {% endif %} - {% else %} - - {% endif %} -{% endblock %} -{% block style %} - - -{% endblock %} diff --git a/erpnext/non_profit/doctype/grant_application/templates/grant_application_row.html b/erpnext/non_profit/doctype/grant_application/templates/grant_application_row.html deleted file mode 100644 index e375b16154d..00000000000 --- a/erpnext/non_profit/doctype/grant_application/templates/grant_application_row.html +++ /dev/null @@ -1,11 +0,0 @@ -{% if doc.published %} - -{% endif %} diff --git a/erpnext/non_profit/doctype/grant_application/test_grant_application.py b/erpnext/non_profit/doctype/grant_application/test_grant_application.py deleted file mode 100644 index ef267d7af86..00000000000 --- a/erpnext/non_profit/doctype/grant_application/test_grant_application.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - - -class TestGrantApplication(unittest.TestCase): - pass diff --git a/erpnext/non_profit/doctype/member/member.js b/erpnext/non_profit/doctype/member/member.js deleted file mode 100644 index e58ec0f5eea..00000000000 --- a/erpnext/non_profit/doctype/member/member.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Member', { - setup: function(frm) { - frappe.db.get_single_value('Non Profit Settings', 'enable_razorpay_for_memberships').then(val => { - if (val && (frm.doc.subscription_id || frm.doc.customer_id)) { - frm.set_df_property('razorpay_details_section', 'hidden', false); - } - }) - }, - - refresh: function(frm) { - - frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Member'}; - - frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal); - - if(!frm.doc.__islocal) { - 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:'Member', party:frm.doc.name}); - }); - - frm.add_custom_button(__('Accounts Receivable'), function() { - frappe.set_route('query-report', 'Accounts Receivable', {member:frm.doc.name}); - }); - - if (!frm.doc.customer) { - frm.add_custom_button(__('Create Customer'), () => { - frm.call('make_customer_and_link').then(() => { - frm.reload_doc(); - }); - }); - } - - // indicator - erpnext.utils.set_party_dashboard_indicators(frm); - - } else { - frappe.contacts.clear_address_and_contact(frm); - } - - frappe.call({ - method:"frappe.client.get_value", - args:{ - 'doctype':"Membership", - 'filters':{'member': frm.doc.name}, - 'fieldname':[ - 'to_date' - ] - }, - callback: function (data) { - if(data.message) { - frappe.model.set_value(frm.doctype,frm.docname, - "membership_expiry_date", data.message.to_date); - } - } - }); - } -}); diff --git a/erpnext/non_profit/doctype/member/member.json b/erpnext/non_profit/doctype/member/member.json deleted file mode 100644 index 7c1baf1a8d1..00000000000 --- a/erpnext/non_profit/doctype/member/member.json +++ /dev/null @@ -1,210 +0,0 @@ -{ - "actions": [], - "allow_rename": 1, - "autoname": "naming_series:", - "creation": "2017-09-11 09:24:52.898356", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "naming_series", - "member_name", - "membership_expiry_date", - "column_break_5", - "membership_type", - "email_id", - "image", - "customer_section", - "customer", - "customer_name", - "supplier_section", - "supplier", - "address_contacts", - "address_html", - "column_break_9", - "contact_html", - "razorpay_details_section", - "subscription_id", - "customer_id", - "subscription_status", - "column_break_21", - "subscription_start", - "subscription_end" - ], - "fields": [ - { - "fieldname": "naming_series", - "fieldtype": "Select", - "label": "Series", - "options": "NPO-MEM-.YYYY.-", - "reqd": 1 - }, - { - "fieldname": "member_name", - "fieldtype": "Data", - "in_list_view": 1, - "label": "Member Name", - "reqd": 1 - }, - { - "fieldname": "membership_expiry_date", - "fieldtype": "Date", - "label": "Membership Expiry Date" - }, - { - "fieldname": "column_break_5", - "fieldtype": "Column Break" - }, - { - "fieldname": "membership_type", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Membership Type", - "options": "Membership Type", - "reqd": 1 - }, - { - "fieldname": "image", - "fieldtype": "Attach Image", - "hidden": 1, - "label": "Image", - "no_copy": 1, - "print_hide": 1 - }, - { - "collapsible": 1, - "fieldname": "customer_section", - "fieldtype": "Section Break", - "label": "Customer" - }, - { - "fieldname": "customer", - "fieldtype": "Link", - "label": "Customer", - "options": "Customer" - }, - { - "fetch_from": "customer.customer_name", - "fieldname": "customer_name", - "fieldtype": "Data", - "label": "Customer Name", - "read_only": 1 - }, - { - "collapsible": 1, - "fieldname": "supplier_section", - "fieldtype": "Section Break", - "label": "Supplier" - }, - { - "fieldname": "supplier", - "fieldtype": "Link", - "label": "Supplier", - "options": "Supplier" - }, - { - "depends_on": "eval:!doc.__islocal;", - "fieldname": "address_contacts", - "fieldtype": "Section Break", - "label": "Address and Contact", - "options": "fa fa-map-marker" - }, - { - "fieldname": "address_html", - "fieldtype": "HTML", - "label": "Address HTML" - }, - { - "fieldname": "column_break_9", - "fieldtype": "Column Break" - }, - { - "fieldname": "contact_html", - "fieldtype": "HTML", - "label": "Contact HTML" - }, - { - "fieldname": "email_id", - "fieldtype": "Data", - "label": "Email Address", - "options": "Email" - }, - { - "fieldname": "subscription_id", - "fieldtype": "Data", - "label": "Subscription ID", - "read_only": 1 - }, - { - "fieldname": "customer_id", - "fieldtype": "Data", - "label": "Customer ID", - "read_only": 1 - }, - { - "fieldname": "razorpay_details_section", - "fieldtype": "Section Break", - "hidden": 1, - "label": "Razorpay Details" - }, - { - "fieldname": "column_break_21", - "fieldtype": "Column Break" - }, - { - "fieldname": "subscription_start", - "fieldtype": "Date", - "label": "Subscription Start " - }, - { - "fieldname": "subscription_end", - "fieldtype": "Date", - "label": "Subscription End" - }, - { - "fieldname": "subscription_status", - "fieldtype": "Select", - "label": "Subscription Status", - "options": "\nActive\nHalted" - } - ], - "image_field": "image", - "links": [], - "modified": "2021-07-11 14:27:26.368039", - "modified_by": "Administrator", - "module": "Non Profit", - "name": "Member", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Non Profit Manager", - "share": 1, - "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Non Profit Member", - "share": 1, - "write": 1 - } - ], - "quick_entry": 1, - "restrict_to_domain": "Non Profit", - "sort_field": "modified", - "sort_order": "DESC", - "title_field": "member_name", - "track_changes": 1 -} \ No newline at end of file diff --git a/erpnext/non_profit/doctype/member/member.py b/erpnext/non_profit/doctype/member/member.py deleted file mode 100644 index 4d80e57eccf..00000000000 --- a/erpnext/non_profit/doctype/member/member.py +++ /dev/null @@ -1,185 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -import frappe -from frappe import _ -from frappe.contacts.address_and_contact import load_address_and_contact -from frappe.integrations.utils import get_payment_gateway_controller -from frappe.model.document import Document -from frappe.utils import cint, get_link_to_form - -from erpnext.non_profit.doctype.membership_type.membership_type import get_membership_type - - -class Member(Document): - def onload(self): - """Load address and contacts in `__onload`""" - load_address_and_contact(self) - - - def validate(self): - if self.email_id: - self.validate_email_type(self.email_id) - - def validate_email_type(self, email): - from frappe.utils import validate_email_address - validate_email_address(email.strip(), True) - - def setup_subscription(self): - non_profit_settings = frappe.get_doc('Non Profit Settings') - if not non_profit_settings.enable_razorpay_for_memberships: - frappe.throw(_('Please check Enable Razorpay for Memberships in {0} to setup subscription')).format( - get_link_to_form('Non Profit Settings', 'Non Profit Settings')) - - controller = get_payment_gateway_controller("Razorpay") - settings = controller.get_settings({}) - - plan_id = frappe.get_value("Membership Type", self.membership_type, "razorpay_plan_id") - - if not plan_id: - frappe.throw(_("Please setup Razorpay Plan ID")) - - subscription_details = { - "plan_id": plan_id, - "billing_frequency": cint(non_profit_settings.billing_frequency), - "customer_notify": 1 - } - - args = { - 'subscription_details': subscription_details - } - - subscription = controller.setup_subscription(settings, **args) - - return subscription - - @frappe.whitelist() - def make_customer_and_link(self): - if self.customer: - frappe.msgprint(_("A customer is already linked to this Member")) - - customer = create_customer(frappe._dict({ - 'fullname': self.member_name, - 'email': self.email_id, - 'phone': None - })) - - self.customer = customer - self.save() - frappe.msgprint(_("Customer {0} has been created succesfully.").format(self.customer)) - - -def get_or_create_member(user_details): - member_list = frappe.get_all("Member", filters={'email': user_details.email, 'membership_type': user_details.plan_id}) - if member_list and member_list[0]: - return member_list[0]['name'] - else: - return create_member(user_details) - -def create_member(user_details): - user_details = frappe._dict(user_details) - member = frappe.new_doc("Member") - member.update({ - "member_name": user_details.fullname, - "email_id": user_details.email, - "pan_number": user_details.pan or None, - "membership_type": user_details.plan_id, - "customer_id": user_details.customer_id or None, - "subscription_id": user_details.subscription_id or None, - "subscription_status": user_details.subscription_status or "" - }) - - member.insert(ignore_permissions=True) - member.customer = create_customer(user_details, member.name) - member.save(ignore_permissions=True) - - return member - -def create_customer(user_details, member=None): - customer = frappe.new_doc("Customer") - customer.customer_name = user_details.fullname - customer.customer_type = "Individual" - customer.flags.ignore_mandatory = True - customer.insert(ignore_permissions=True) - - try: - contact = frappe.new_doc("Contact") - contact.first_name = user_details.fullname - if user_details.mobile: - contact.add_phone(user_details.mobile, is_primary_phone=1, is_primary_mobile_no=1) - if user_details.email: - contact.add_email(user_details.email, is_primary=1) - contact.insert(ignore_permissions=True) - - contact.append("links", { - "link_doctype": "Customer", - "link_name": customer.name - }) - - if member: - contact.append("links", { - "link_doctype": "Member", - "link_name": member - }) - - contact.save(ignore_permissions=True) - - except frappe.DuplicateEntryError: - return customer.name - - except Exception as e: - frappe.log_error(frappe.get_traceback(), _("Contact Creation Failed")) - pass - - return customer.name - -@frappe.whitelist(allow_guest=True) -def create_member_subscription_order(user_details): - """Create Member subscription and order for payment - - Args: - user_details (TYPE): Description - - Returns: - Dictionary: Dictionary with subscription details - { - 'subscription_details': { - 'plan_id': 'plan_EXwyxDYDCj3X4v', - 'billing_frequency': 24, - 'customer_notify': 1 - }, - 'subscription_id': 'sub_EZycCvXFvqnC6p' - } - """ - - user_details = frappe._dict(user_details) - member = get_or_create_member(user_details) - - subscription = member.setup_subscription() - - member.subscription_id = subscription.get('subscription_id') - member.save(ignore_permissions=True) - - return subscription - -@frappe.whitelist() -def register_member(fullname, email, rzpay_plan_id, subscription_id, pan=None, mobile=None): - plan = get_membership_type(rzpay_plan_id) - if not plan: - raise frappe.DoesNotExistError - - member = frappe.db.exists("Member", {'email': email, 'subscription_id': subscription_id }) - if member: - return member - else: - member = create_member(dict( - fullname=fullname, - email=email, - plan_id=plan, - subscription_id=subscription_id, - pan=pan, - mobile=mobile - )) - - return member.name diff --git a/erpnext/non_profit/doctype/member/member_dashboard.py b/erpnext/non_profit/doctype/member/member_dashboard.py deleted file mode 100644 index 0e31e3ceb83..00000000000 --- a/erpnext/non_profit/doctype/member/member_dashboard.py +++ /dev/null @@ -1,22 +0,0 @@ -from frappe import _ - - -def get_data(): - return { - 'heatmap': True, - 'heatmap_message': _('Member Activity'), - 'fieldname': 'member', - 'non_standard_fieldnames': { - 'Bank Account': 'party' - }, - 'transactions': [ - { - 'label': _('Membership Details'), - 'items': ['Membership'] - }, - { - 'label': _('Fee'), - 'items': ['Bank Account'] - } - ] - } diff --git a/erpnext/non_profit/doctype/member/member_list.js b/erpnext/non_profit/doctype/member/member_list.js deleted file mode 100644 index 8e41e7fdde8..00000000000 --- a/erpnext/non_profit/doctype/member/member_list.js +++ /dev/null @@ -1,3 +0,0 @@ -frappe.listview_settings['Member'] = { - add_fields: ["member_name", "membership_type", "image"], -}; diff --git a/erpnext/non_profit/doctype/member/test_member.py b/erpnext/non_profit/doctype/member/test_member.py deleted file mode 100644 index 46f14ed1312..00000000000 --- a/erpnext/non_profit/doctype/member/test_member.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - - -class TestMember(unittest.TestCase): - pass diff --git a/erpnext/non_profit/doctype/membership/__init__.py b/erpnext/non_profit/doctype/membership/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/non_profit/doctype/membership/membership.js b/erpnext/non_profit/doctype/membership/membership.js deleted file mode 100644 index 31872048a06..00000000000 --- a/erpnext/non_profit/doctype/membership/membership.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Membership', { - setup: function(frm) { - frappe.db.get_single_value("Non Profit Settings", "enable_razorpay_for_memberships").then(val => { - if (val) frm.set_df_property("razorpay_details_section", "hidden", false); - }) - }, - - refresh: function(frm) { - if (frm.doc.__islocal) - return; - - !frm.doc.invoice && frm.add_custom_button("Generate Invoice", () => { - frm.call({ - doc: frm.doc, - method: "generate_invoice", - args: {save: true}, - freeze: true, - freeze_message: __("Creating Membership Invoice"), - callback: function(r) { - if (r.invoice) - frm.reload_doc(); - } - }); - }); - - frappe.db.get_single_value("Non Profit Settings", "send_email").then(val => { - if (val) frm.add_custom_button("Send Acknowledgement", () => { - frm.call("send_acknowlement").then(() => { - frm.reload_doc(); - }); - }); - }) - }, - - onload: function(frm) { - frm.add_fetch("membership_type", "amount", "amount"); - } -}); diff --git a/erpnext/non_profit/doctype/membership/membership.json b/erpnext/non_profit/doctype/membership/membership.json deleted file mode 100644 index 11d32f9c2b4..00000000000 --- a/erpnext/non_profit/doctype/membership/membership.json +++ /dev/null @@ -1,184 +0,0 @@ -{ - "actions": [], - "autoname": "NPO-MSH-.YYYY.-.#####", - "creation": "2017-09-11 11:39:18.492184", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "member", - "member_name", - "membership_type", - "column_break_3", - "company", - "membership_status", - "membership_validity_section", - "from_date", - "to_date", - "column_break_8", - "member_since_date", - "payment_details", - "paid", - "currency", - "amount", - "invoice", - "razorpay_details_section", - "subscription_id", - "payment_id" - ], - "fields": [ - { - "fieldname": "member", - "fieldtype": "Link", - "label": "Member", - "options": "Member" - }, - { - "fieldname": "membership_type", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Membership Type", - "options": "Membership Type", - "reqd": 1 - }, - { - "fieldname": "column_break_3", - "fieldtype": "Column Break" - }, - { - "fieldname": "membership_status", - "fieldtype": "Select", - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Membership Status", - "options": "New\nCurrent\nExpired\nPending\nCancelled" - }, - { - "fieldname": "membership_validity_section", - "fieldtype": "Section Break", - "label": "Validity" - }, - { - "fieldname": "from_date", - "fieldtype": "Date", - "in_list_view": 1, - "label": "From", - "reqd": 1 - }, - { - "fieldname": "to_date", - "fieldtype": "Date", - "in_list_view": 1, - "label": "To", - "reqd": 1 - }, - { - "fieldname": "column_break_8", - "fieldtype": "Column Break" - }, - { - "fieldname": "member_since_date", - "fieldtype": "Date", - "label": "Member Since" - }, - { - "fieldname": "payment_details", - "fieldtype": "Section Break", - "label": "Payment Details" - }, - { - "default": "0", - "fieldname": "paid", - "fieldtype": "Check", - "label": "Paid" - }, - { - "fieldname": "currency", - "fieldtype": "Link", - "label": "Currency", - "options": "Currency" - }, - { - "fieldname": "amount", - "fieldtype": "Float", - "label": "Amount" - }, - { - "fieldname": "razorpay_details_section", - "fieldtype": "Section Break", - "hidden": 1, - "label": "Razorpay Details" - }, - { - "fieldname": "subscription_id", - "fieldtype": "Data", - "label": "Subscription ID", - "read_only": 1 - }, - { - "fieldname": "payment_id", - "fieldtype": "Data", - "label": "Payment ID", - "read_only": 1 - }, - { - "fieldname": "invoice", - "fieldtype": "Link", - "label": "Invoice", - "options": "Sales Invoice" - }, - { - "fetch_from": "member.member_name", - "fieldname": "member_name", - "fieldtype": "Data", - "label": "Member Name", - "read_only": 1 - }, - { - "fieldname": "company", - "fieldtype": "Link", - "label": "Company", - "options": "Company", - "reqd": 1 - } - ], - "index_web_pages_for_search": 1, - "links": [], - "modified": "2021-02-19 14:33:44.925122", - "modified_by": "Administrator", - "module": "Non Profit", - "name": "Membership", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Non Profit Manager", - "share": 1, - "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Non Profit Member", - "share": 1, - "write": 1 - } - ], - "restrict_to_domain": "Non Profit", - "search_fields": "member, member_name", - "sort_field": "modified", - "sort_order": "DESC", - "title_field": "member_name", - "track_changes": 1 -} \ No newline at end of file diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py deleted file mode 100644 index f9b295a223d..00000000000 --- a/erpnext/non_profit/doctype/membership/membership.py +++ /dev/null @@ -1,415 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -import json -from datetime import datetime - -import frappe -from frappe import _ -from frappe.email import sendmail_to_system_managers -from frappe.model.document import Document -from frappe.utils import add_days, add_months, add_years, get_link_to_form, getdate, nowdate - -import erpnext -from erpnext.non_profit.doctype.member.member import create_member - - -class Membership(Document): - def validate(self): - if not self.member or not frappe.db.exists("Member", self.member): - # for web forms - user_type = frappe.db.get_value("User", frappe.session.user, "user_type") - if user_type == "Website User": - self.create_member_from_website_user() - else: - frappe.throw(_("Please select a Member")) - - self.validate_membership_period() - - def create_member_from_website_user(self): - member_name = frappe.get_value("Member", dict(email_id=frappe.session.user)) - - if not member_name: - user = frappe.get_doc("User", frappe.session.user) - member = frappe.get_doc(dict( - doctype="Member", - email_id=frappe.session.user, - membership_type=self.membership_type, - member_name=user.get_fullname() - )).insert(ignore_permissions=True) - member_name = member.name - - if self.get("__islocal"): - self.member = member_name - - def validate_membership_period(self): - # get last membership (if active) - last_membership = erpnext.get_last_membership(self.member) - - # if person applied for offline membership - if last_membership and last_membership.name != self.name and not frappe.session.user == "Administrator": - # if last membership does not expire in 30 days, then do not allow to renew - if getdate(add_days(last_membership.to_date, -30)) > getdate(nowdate()) : - frappe.throw(_("You can only renew if your membership expires within 30 days")) - - self.from_date = add_days(last_membership.to_date, 1) - elif frappe.session.user == "Administrator": - self.from_date = self.from_date - else: - self.from_date = nowdate() - - if frappe.db.get_single_value("Non Profit Settings", "billing_cycle") == "Yearly": - self.to_date = add_years(self.from_date, 1) - else: - self.to_date = add_months(self.from_date, 1) - - def on_payment_authorized(self, status_changed_to=None): - if status_changed_to not in ("Completed", "Authorized"): - return - self.load_from_db() - self.db_set("paid", 1) - settings = frappe.get_doc("Non Profit Settings") - if settings.allow_invoicing and settings.automate_membership_invoicing: - self.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) - - - @frappe.whitelist() - def generate_invoice(self, save=True, with_payment_entry=False): - if not (self.paid or self.currency or self.amount): - frappe.throw(_("The payment for this membership is not paid. To generate invoice fill the payment details")) - - if self.invoice: - frappe.throw(_("An invoice is already linked to this document")) - - member = frappe.get_doc("Member", self.member) - if not member.customer: - frappe.throw(_("No customer linked to member {0}").format(frappe.bold(self.member))) - - plan = frappe.get_doc("Membership Type", self.membership_type) - settings = frappe.get_doc("Non Profit Settings") - self.validate_membership_type_and_settings(plan, settings) - - invoice = make_invoice(self, member, plan, settings) - self.reload() - self.invoice = invoice.name - - if with_payment_entry: - self.make_payment_entry(settings, invoice) - - if save: - self.save() - - return invoice - - def validate_membership_type_and_settings(self, plan, settings): - settings_link = get_link_to_form("Membership Type", self.membership_type) - - if not settings.membership_debit_account: - frappe.throw(_("You need to set Debit Account in {0}").format(settings_link)) - - if not settings.company: - frappe.throw(_("You need to set Default Company for invoicing in {0}").format(settings_link)) - - if not plan.linked_item: - frappe.throw(_("Please set a Linked Item for the Membership Type {0}").format( - get_link_to_form("Membership Type", self.membership_type))) - - def make_payment_entry(self, settings, invoice): - if not settings.membership_payment_account: - frappe.throw(_("You need to set Payment Account for Membership in {0}").format( - get_link_to_form("Non Profit Settings", "Non Profit Settings"))) - - from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry - frappe.flags.ignore_account_permission = True - pe = get_payment_entry(dt="Sales Invoice", dn=invoice.name, bank_amount=invoice.grand_total) - frappe.flags.ignore_account_permission=False - pe.paid_to = settings.membership_payment_account - pe.reference_no = self.name - pe.reference_date = getdate() - pe.flags.ignore_mandatory = True - pe.save() - pe.submit() - - @frappe.whitelist() - def send_acknowlement(self): - settings = frappe.get_doc("Non Profit Settings") - if not settings.send_email: - frappe.throw(_("You need to enable Send Acknowledge Email in {0}").format( - get_link_to_form("Non Profit Settings", "Non Profit Settings"))) - - member = frappe.get_doc("Member", self.member) - if not member.email_id: - frappe.throw(_("Email address of member {0} is missing").format(frappe.utils.get_link_to_form("Member", self.member))) - - plan = frappe.get_doc("Membership Type", self.membership_type) - email = member.email_id - attachments = [frappe.attach_print("Membership", self.name, print_format=settings.membership_print_format)] - - if self.invoice and settings.send_invoice: - attachments.append(frappe.attach_print("Sales Invoice", self.invoice, print_format=settings.inv_print_format)) - - email_template = frappe.get_doc("Email Template", settings.email_template) - context = { "doc": self, "member": member} - - email_args = { - "recipients": [email], - "message": frappe.render_template(email_template.get("response"), context), - "subject": frappe.render_template(email_template.get("subject"), context), - "attachments": attachments, - "reference_doctype": self.doctype, - "reference_name": self.name - } - - if not frappe.flags.in_test: - frappe.enqueue(method=frappe.sendmail, queue="short", timeout=300, is_async=True, **email_args) - else: - frappe.sendmail(**email_args) - - def generate_and_send_invoice(self): - self.generate_invoice(save=False) - self.send_acknowlement() - - -def make_invoice(membership, member, plan, settings): - invoice = frappe.get_doc({ - "doctype": "Sales Invoice", - "customer": member.customer, - "debit_to": settings.membership_debit_account, - "currency": membership.currency, - "company": settings.company, - "is_pos": 0, - "items": [ - { - "item_code": plan.linked_item, - "rate": membership.amount, - "qty": 1 - } - ] - }) - invoice.set_missing_values() - invoice.insert() - invoice.submit() - - frappe.msgprint(_("Sales Invoice created successfully")) - - return invoice - - -def get_member_based_on_subscription(subscription_id, email=None, customer_id=None): - filters = {"subscription_id": subscription_id} - if email: - filters.update({"email_id": email}) - if customer_id: - filters.update({"customer_id": customer_id}) - - members = frappe.get_all("Member", filters=filters, order_by="creation desc") - - try: - return frappe.get_doc("Member", members[0]["name"]) - except Exception: - return None - - -def verify_signature(data, endpoint="Membership"): - signature = frappe.request.headers.get("X-Razorpay-Signature") - - settings = frappe.get_doc("Non Profit Settings") - key = settings.get_webhook_secret(endpoint) - - controller = frappe.get_doc("Razorpay Settings") - - controller.verify_signature(data, signature, key) - frappe.set_user(settings.creation_user) - - -@frappe.whitelist(allow_guest=True) -def trigger_razorpay_subscription(*args, **kwargs): - data = frappe.request.get_data(as_text=True) - data = process_request_data(data) - - subscription = data.payload.get("subscription", {}).get("entity", {}) - subscription = frappe._dict(subscription) - - payment = data.payload.get("payment", {}).get("entity", {}) - payment = frappe._dict(payment) - - try: - if not data.event == "subscription.charged": - return - - member = get_member_based_on_subscription(subscription.id, payment.email) - if not member: - member = create_member(frappe._dict({ - "fullname": payment.email, - "email": payment.email, - "plan_id": get_plan_from_razorpay_id(subscription.plan_id) - })) - - member.subscription_id = subscription.id - member.customer_id = payment.customer_id - - if subscription.get("notes"): - member = get_additional_notes(member, subscription) - - company = get_company_for_memberships() - # Update Membership - membership = frappe.new_doc("Membership") - membership.update({ - "company": company, - "member": member.name, - "membership_status": "Current", - "membership_type": member.membership_type, - "currency": "INR", - "paid": 1, - "payment_id": payment.id, - "from_date": datetime.fromtimestamp(subscription.current_start), - "to_date": datetime.fromtimestamp(subscription.current_end), - "amount": payment.amount / 100 # Convert to rupees from paise - }) - membership.flags.ignore_mandatory = True - membership.insert() - - # Update membership values - member.subscription_start = datetime.fromtimestamp(subscription.start_at) - member.subscription_end = datetime.fromtimestamp(subscription.end_at) - member.subscription_status = "Active" - member.flags.ignore_mandatory = True - member.save() - - settings = frappe.get_doc("Non Profit Settings") - if settings.allow_invoicing and settings.automate_membership_invoicing: - membership.reload() - membership.generate_invoice(with_payment_entry=settings.automate_membership_payment_entries, save=True) - - except Exception as e: - message = "{0}\n\n{1}\n\n{2}: {3}".format(e, frappe.get_traceback(), _("Payment ID"), payment.id) - log = frappe.log_error(message, _("Error creating membership entry for {0}").format(member.name)) - notify_failure(log) - return {"status": "Failed", "reason": e} - - return {"status": "Success"} - - -@frappe.whitelist(allow_guest=True) -def update_halted_razorpay_subscription(*args, **kwargs): - """ - When all retries have been exhausted, Razorpay moves the subscription to the halted state. - The customer has to manually retry the charge or change the card linked to the subscription, - for the subscription to move back to the active state. - """ - if frappe.request: - data = frappe.request.get_data(as_text=True) - data = process_request_data(data) - elif frappe.flags.in_test: - data = kwargs.get("data") - data = frappe._dict(data) - else: - return - - if not data.event == "subscription.halted": - return - - subscription = data.payload.get("subscription", {}).get("entity", {}) - subscription = frappe._dict(subscription) - - try: - member = get_member_based_on_subscription(subscription.id, customer_id=subscription.customer_id) - if not member: - frappe.throw(_("Member with Razorpay Subscription ID {0} not found").format(subscription.id)) - - member.subscription_status = "Halted" - member.flags.ignore_mandatory = True - member.save() - - if subscription.get("notes"): - member = get_additional_notes(member, subscription) - - except Exception as e: - message = "{0}\n\n{1}".format(e, frappe.get_traceback()) - log = frappe.log_error(message, _("Error updating halted status for member {0}").format(member.name)) - notify_failure(log) - return {"status": "Failed", "reason": e} - - return {"status": "Success"} - - -def process_request_data(data): - try: - verify_signature(data) - except Exception as e: - log = frappe.log_error(e, "Membership Webhook Verification Error") - notify_failure(log) - return {"status": "Failed", "reason": e} - - if isinstance(data, str): - data = json.loads(data) - data = frappe._dict(data) - - return data - - -def get_company_for_memberships(): - company = frappe.db.get_single_value("Non Profit Settings", "company") - if not company: - from erpnext.non_profit.utils import get_company - company = get_company() - return company - - -def get_additional_notes(member, subscription): - if type(subscription.notes) == dict: - for k, v in subscription.notes.items(): - notes = "\n".join("{}: {}".format(k, v)) - - # extract member name from notes - if "name" in k.lower(): - member.update({ - "member_name": subscription.notes.get(k) - }) - - # extract pan number from notes - if "pan" in k.lower(): - member.update({ - "pan_number": subscription.notes.get(k) - }) - - member.add_comment("Comment", notes) - - elif type(subscription.notes) == str: - member.add_comment("Comment", subscription.notes) - - return member - - -def notify_failure(log): - try: - content = """ - Dear System Manager, - Razorpay webhook for creating renewing membership subscription failed due to some reason. - Please check the following error log linked below - Error Log: {0} - Regards, Administrator - """.format(get_link_to_form("Error Log", log.name)) - - sendmail_to_system_managers("[Important] [ERPNext] Razorpay membership webhook failed , please check.", content) - except Exception: - pass - - -def get_plan_from_razorpay_id(plan_id): - plan = frappe.get_all("Membership Type", filters={"razorpay_plan_id": plan_id}, order_by="creation desc") - - try: - return plan[0]["name"] - except Exception: - return None - - -def set_expired_status(): - frappe.db.sql(""" - UPDATE - `tabMembership` SET `membership_status` = 'Expired' - WHERE - `membership_status` not in ('Cancelled') AND `to_date` < %s - """, (nowdate())) diff --git a/erpnext/non_profit/doctype/membership/membership_list.js b/erpnext/non_profit/doctype/membership/membership_list.js deleted file mode 100644 index a959159899d..00000000000 --- a/erpnext/non_profit/doctype/membership/membership_list.js +++ /dev/null @@ -1,15 +0,0 @@ -frappe.listview_settings['Membership'] = { - get_indicator: function(doc) { - if (doc.membership_status == 'New') { - return [__('New'), 'blue', 'membership_status,=,New']; - } else if (doc.membership_status === 'Current') { - return [__('Current'), 'green', 'membership_status,=,Current']; - } else if (doc.membership_status === 'Pending') { - return [__('Pending'), 'yellow', 'membership_status,=,Pending']; - } else if (doc.membership_status === 'Expired') { - return [__('Expired'), 'grey', 'membership_status,=,Expired']; - } else { - return [__('Cancelled'), 'red', 'membership_status,=,Cancelled']; - } - } -}; diff --git a/erpnext/non_profit/doctype/membership/test_membership.py b/erpnext/non_profit/doctype/membership/test_membership.py deleted file mode 100644 index fbe344c6a15..00000000000 --- a/erpnext/non_profit/doctype/membership/test_membership.py +++ /dev/null @@ -1,164 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - -import frappe -from frappe.utils import add_months, nowdate - -import erpnext -from erpnext.non_profit.doctype.member.member import create_member -from erpnext.non_profit.doctype.membership.membership import update_halted_razorpay_subscription - - -class TestMembership(unittest.TestCase): - def setUp(self): - plan = setup_membership() - - # make test member - self.member_doc = create_member( - frappe._dict({ - "fullname": "_Test_Member", - "email": "_test_member_erpnext@example.com", - "plan_id": plan.name, - "subscription_id": "sub_DEX6xcJ1HSW4CR", - "customer_id": "cust_C0WlbKhp3aLA7W", - "subscription_status": "Active" - }) - ) - self.member_doc.make_customer_and_link() - self.member = self.member_doc.name - - def test_auto_generate_invoice_and_payment_entry(self): - entry = make_membership(self.member) - - # Naive test to see if at all invoice was generated and attached to member - # In any case if details were missing, the invoicing would throw an error - invoice = entry.generate_invoice(save=True) - self.assertEqual(invoice.name, entry.invoice) - - def test_renew_within_30_days(self): - # create a membership for two months - # Should work fine - make_membership(self.member, { "from_date": nowdate() }) - make_membership(self.member, { "from_date": add_months(nowdate(), 1) }) - - from frappe.utils.user import add_role - add_role("test@example.com", "Non Profit Manager") - frappe.set_user("test@example.com") - - # create next membership with expiry not within 30 days - self.assertRaises(frappe.ValidationError, make_membership, self.member, { - "from_date": add_months(nowdate(), 2), - }) - - frappe.set_user("Administrator") - # create the same membership but as administrator - make_membership(self.member, { - "from_date": add_months(nowdate(), 2), - "to_date": add_months(nowdate(), 3), - }) - - def test_halted_memberships(self): - make_membership(self.member, { - "from_date": add_months(nowdate(), 2), - "to_date": add_months(nowdate(), 3) - }) - - self.assertEqual(frappe.db.get_value("Member", self.member, "subscription_status"), "Active") - payload = get_subscription_payload() - update_halted_razorpay_subscription(data=payload) - self.assertEqual(frappe.db.get_value("Member", self.member, "subscription_status"), "Halted") - - def tearDown(self): - frappe.db.rollback() - -def set_config(key, value): - frappe.db.set_value("Non Profit Settings", None, key, value) - -def make_membership(member, payload={}): - data = { - "doctype": "Membership", - "member": member, - "membership_status": "Current", - "membership_type": "_rzpy_test_milythm", - "currency": "INR", - "paid": 1, - "from_date": nowdate(), - "amount": 100 - } - data.update(payload) - membership = frappe.get_doc(data) - membership.insert(ignore_permissions=True, ignore_if_duplicate=True) - return membership - -def create_item(item_code): - if not frappe.db.exists("Item", item_code): - item = frappe.new_doc("Item") - item.item_code = item_code - item.item_name = item_code - item.stock_uom = "Nos" - item.description = item_code - item.item_group = "All Item Groups" - item.is_stock_item = 0 - item.save() - else: - item = frappe.get_doc("Item", item_code) - return item - -def setup_membership(): - # Get default company - company = frappe.get_doc("Company", erpnext.get_default_company()) - - # update non profit settings - settings = frappe.get_doc("Non Profit Settings") - # Enable razorpay - settings.enable_razorpay_for_memberships = 1 - settings.billing_cycle = "Monthly" - settings.billing_frequency = 24 - # Enable invoicing - settings.allow_invoicing = 1 - settings.automate_membership_payment_entries = 1 - settings.company = company.name - settings.donation_company = company.name - settings.membership_payment_account = company.default_cash_account - settings.membership_debit_account = company.default_receivable_account - settings.flags.ignore_mandatory = True - settings.save() - - # make test plan - if not frappe.db.exists("Membership Type", "_rzpy_test_milythm"): - plan = frappe.new_doc("Membership Type") - plan.membership_type = "_rzpy_test_milythm" - plan.amount = 100 - plan.razorpay_plan_id = "_rzpy_test_milythm" - plan.linked_item = create_item("_Test Item for Non Profit Membership").name - plan.insert() - else: - plan = frappe.get_doc("Membership Type", "_rzpy_test_milythm") - - return plan - -def get_subscription_payload(): - return { - "entity": "event", - "account_id": "acc_BFQ7uQEaa7j2z7", - "event": "subscription.halted", - "contains": [ - "subscription" - ], - "payload": { - "subscription": { - "entity": { - "id": "sub_DEX6xcJ1HSW4CR", - "entity": "subscription", - "plan_id": "_rzpy_test_milythm", - "customer_id": "cust_C0WlbKhp3aLA7W", - "status": "halted", - "notes": { - "Important": "Notes for Internal Reference" - }, - } - } - } - } diff --git a/erpnext/non_profit/doctype/membership_type/__init__.py b/erpnext/non_profit/doctype/membership_type/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/non_profit/doctype/membership_type/membership_type.js b/erpnext/non_profit/doctype/membership_type/membership_type.js deleted file mode 100644 index 2f2427629c3..00000000000 --- a/erpnext/non_profit/doctype/membership_type/membership_type.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Membership Type', { - refresh: function (frm) { - frappe.db.get_single_value('Non Profit Settings', 'enable_razorpay_for_memberships').then(val => { - if (val) frm.set_df_property('razorpay_plan_id', 'hidden', false); - }); - - frappe.db.get_single_value('Non Profit Settings', 'allow_invoicing').then(val => { - if (val) frm.set_df_property('linked_item', 'hidden', false); - }); - - frm.set_query('linked_item', () => { - return { - filters: { - is_stock_item: 0 - } - }; - }); - } -}); diff --git a/erpnext/non_profit/doctype/membership_type/membership_type.json b/erpnext/non_profit/doctype/membership_type/membership_type.json deleted file mode 100644 index 6ce1ecde123..00000000000 --- a/erpnext/non_profit/doctype/membership_type/membership_type.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "actions": [], - "autoname": "field:membership_type", - "creation": "2017-09-18 12:56:56.343999", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "membership_type", - "amount", - "razorpay_plan_id", - "linked_item" - ], - "fields": [ - { - "fieldname": "membership_type", - "fieldtype": "Data", - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Membership Type", - "reqd": 1, - "unique": 1 - }, - { - "fieldname": "amount", - "fieldtype": "Float", - "in_list_view": 1, - "label": "Amount", - "reqd": 1 - }, - { - "fieldname": "razorpay_plan_id", - "fieldtype": "Data", - "hidden": 1, - "label": "Razorpay Plan ID", - "unique": 1 - }, - { - "fieldname": "linked_item", - "fieldtype": "Link", - "label": "Linked Item", - "options": "Item", - "unique": 1 - } - ], - "links": [], - "modified": "2020-08-05 15:21:43.595745", - "modified_by": "Administrator", - "module": "Non Profit", - "name": "Membership Type", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "Non Profit Manager", - "share": 1, - "write": 1 - } - ], - "quick_entry": 1, - "restrict_to_domain": "Non Profit", - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1 -} \ No newline at end of file diff --git a/erpnext/non_profit/doctype/membership_type/membership_type.py b/erpnext/non_profit/doctype/membership_type/membership_type.py deleted file mode 100644 index b4464215715..00000000000 --- a/erpnext/non_profit/doctype/membership_type/membership_type.py +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -import frappe -from frappe import _ -from frappe.model.document import Document - - -class MembershipType(Document): - def validate(self): - if self.linked_item: - is_stock_item = frappe.db.get_value("Item", self.linked_item, "is_stock_item") - if is_stock_item: - frappe.throw(_("The Linked Item should be a service item")) - -def get_membership_type(razorpay_id): - return frappe.db.exists("Membership Type", {"razorpay_plan_id": razorpay_id}) diff --git a/erpnext/non_profit/doctype/membership_type/test_membership_type.py b/erpnext/non_profit/doctype/membership_type/test_membership_type.py deleted file mode 100644 index 98bc087acde..00000000000 --- a/erpnext/non_profit/doctype/membership_type/test_membership_type.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - - -class TestMembershipType(unittest.TestCase): - pass diff --git a/erpnext/non_profit/doctype/non_profit_settings/__init__.py b/erpnext/non_profit/doctype/non_profit_settings/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js deleted file mode 100644 index 4c4ca9834b0..00000000000 --- a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.js +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on("Non Profit Settings", { - refresh: function(frm) { - frm.set_query("inv_print_format", function() { - return { - filters: { - "doc_type": "Sales Invoice" - } - }; - }); - - frm.set_query("membership_print_format", function() { - return { - filters: { - "doc_type": "Membership" - } - }; - }); - - frm.set_query("membership_debit_account", function() { - return { - filters: { - "account_type": "Receivable", - "is_group": 0, - "company": frm.doc.company - } - }; - }); - - frm.set_query("donation_debit_account", function() { - return { - filters: { - "account_type": "Receivable", - "is_group": 0, - "company": frm.doc.donation_company - } - }; - }); - - frm.set_query("membership_payment_account", function () { - var account_types = ["Bank", "Cash"]; - return { - filters: { - "account_type": ["in", account_types], - "is_group": 0, - "company": frm.doc.company - } - }; - }); - - frm.set_query("donation_payment_account", function () { - var account_types = ["Bank", "Cash"]; - return { - filters: { - "account_type": ["in", account_types], - "is_group": 0, - "company": frm.doc.donation_company - } - }; - }); - - let docs_url = "https://docs.erpnext.com/docs/user/manual/en/non_profit/membership"; - - frm.set_intro(__("You can learn more about memberships in the manual. ") + `${__('ERPNext Docs')}`, true); - frm.trigger("setup_buttons_for_membership"); - frm.trigger("setup_buttons_for_donation"); - }, - - setup_buttons_for_membership: function(frm) { - let label; - - if (frm.doc.membership_webhook_secret) { - - frm.add_custom_button(__("Copy Webhook URL"), () => { - frappe.utils.copy_to_clipboard(`https://${frappe.boot.sitename}/api/method/erpnext.non_profit.doctype.membership.membership.trigger_razorpay_subscription`); - }, __("Memberships")); - - frm.add_custom_button(__("Revoke Key"), () => { - frm.call("revoke_key", { - key: "membership_webhook_secret" - }).then(() => { - frm.refresh(); - }); - }, __("Memberships")); - - label = __("Regenerate Webhook Secret"); - - } else { - label = __("Generate Webhook Secret"); - } - - frm.add_custom_button(label, () => { - frm.call("generate_webhook_secret", { - field: "membership_webhook_secret" - }).then(() => { - frm.refresh(); - }); - }, __("Memberships")); - }, - - setup_buttons_for_donation: function(frm) { - let label; - - if (frm.doc.donation_webhook_secret) { - label = __("Regenerate Webhook Secret"); - - frm.add_custom_button(__("Copy Webhook URL"), () => { - frappe.utils.copy_to_clipboard(`https://${frappe.boot.sitename}/api/method/erpnext.non_profit.doctype.donation.donation.capture_razorpay_donations`); - }, __("Donations")); - - frm.add_custom_button(__("Revoke Key"), () => { - frm.call("revoke_key", { - key: "donation_webhook_secret" - }).then(() => { - frm.refresh(); - }); - }, __("Donations")); - - } else { - label = __("Generate Webhook Secret"); - } - - frm.add_custom_button(label, () => { - frm.call("generate_webhook_secret", { - field: "donation_webhook_secret" - }).then(() => { - frm.refresh(); - }); - }, __("Donations")); - } -}); diff --git a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.json b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.json deleted file mode 100644 index 25ff0c1bb02..00000000000 --- a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.json +++ /dev/null @@ -1,273 +0,0 @@ -{ - "actions": [], - "creation": "2020-03-29 12:57:03.005120", - "doctype": "DocType", - "editable_grid": 1, - "engine": "InnoDB", - "field_order": [ - "enable_razorpay_for_memberships", - "razorpay_settings_section", - "billing_cycle", - "billing_frequency", - "membership_webhook_secret", - "column_break_6", - "allow_invoicing", - "automate_membership_invoicing", - "automate_membership_payment_entries", - "company", - "membership_debit_account", - "membership_payment_account", - "column_break_9", - "send_email", - "send_invoice", - "membership_print_format", - "inv_print_format", - "email_template", - "donation_settings_section", - "donation_company", - "default_donor_type", - "donation_webhook_secret", - "column_break_22", - "automate_donation_payment_entries", - "donation_debit_account", - "donation_payment_account", - "section_break_27", - "creation_user" - ], - "fields": [ - { - "fieldname": "billing_cycle", - "fieldtype": "Select", - "label": "Billing Cycle", - "options": "Monthly\nYearly" - }, - { - "depends_on": "eval:doc.enable_razorpay_for_memberships", - "fieldname": "razorpay_settings_section", - "fieldtype": "Section Break", - "label": "RazorPay Settings for Memberships" - }, - { - "description": "The number of billing cycles for which the customer should be charged. For example, if a customer is buying a 1-year membership that should be billed on a monthly basis, this value should be 12.", - "fieldname": "billing_frequency", - "fieldtype": "Int", - "label": "Billing Frequency" - }, - { - "fieldname": "column_break_6", - "fieldtype": "Section Break", - "label": "Membership Invoicing" - }, - { - "fieldname": "column_break_9", - "fieldtype": "Column Break" - }, - { - "description": "This company will be set for the Memberships created via webhook.", - "fieldname": "company", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Company", - "options": "Company", - "reqd": 1 - }, - { - "default": "0", - "depends_on": "eval:doc.allow_invoicing && doc.send_email", - "fieldname": "send_invoice", - "fieldtype": "Check", - "label": "Send Invoice with Email" - }, - { - "default": "0", - "fieldname": "send_email", - "fieldtype": "Check", - "label": "Send Membership Acknowledgement" - }, - { - "depends_on": "eval: doc.send_invoice", - "fieldname": "inv_print_format", - "fieldtype": "Link", - "label": "Invoice Print Format", - "mandatory_depends_on": "eval: doc.send_invoice", - "options": "Print Format" - }, - { - "depends_on": "eval:doc.send_email", - "fieldname": "membership_print_format", - "fieldtype": "Link", - "label": "Membership Print Format", - "options": "Print Format" - }, - { - "depends_on": "eval:doc.send_email", - "fieldname": "email_template", - "fieldtype": "Link", - "label": "Email Template", - "mandatory_depends_on": "eval:doc.send_email", - "options": "Email Template" - }, - { - "default": "0", - "fieldname": "allow_invoicing", - "fieldtype": "Check", - "label": "Allow Invoicing for Memberships", - "mandatory_depends_on": "eval:doc.send_invoice || doc.make_payment_entry" - }, - { - "default": "0", - "depends_on": "eval:doc.allow_invoicing", - "description": "Automatically create an invoice when payment is authorized from a web form entry", - "fieldname": "automate_membership_invoicing", - "fieldtype": "Check", - "label": "Automate Invoicing for Web Forms" - }, - { - "default": "0", - "depends_on": "eval:doc.allow_invoicing", - "description": "Auto creates Payment Entry for Sales Invoices created for Membership from web forms.", - "fieldname": "automate_membership_payment_entries", - "fieldtype": "Check", - "label": "Automate Payment Entry Creation" - }, - { - "default": "0", - "fieldname": "enable_razorpay_for_memberships", - "fieldtype": "Check", - "label": "Enable RazorPay For Memberships" - }, - { - "depends_on": "eval:doc.automate_membership_payment_entries", - "description": "Account for accepting membership payments", - "fieldname": "membership_payment_account", - "fieldtype": "Link", - "label": "Membership Payment To", - "mandatory_depends_on": "eval:doc.automate_membership_payment_entries", - "options": "Account" - }, - { - "fieldname": "membership_webhook_secret", - "fieldtype": "Password", - "label": "Membership Webhook Secret", - "read_only": 1 - }, - { - "fieldname": "donation_webhook_secret", - "fieldtype": "Password", - "label": "Donation Webhook Secret", - "read_only": 1 - }, - { - "depends_on": "automate_donation_payment_entries", - "description": "Account for accepting donation payments", - "fieldname": "donation_payment_account", - "fieldtype": "Link", - "label": "Donation Payment To", - "mandatory_depends_on": "automate_donation_payment_entries", - "options": "Account" - }, - { - "default": "0", - "description": "Auto creates Payment Entry for Donations created from web forms.", - "fieldname": "automate_donation_payment_entries", - "fieldtype": "Check", - "label": "Automate Donation Payment Entries" - }, - { - "depends_on": "eval:doc.allow_invoicing", - "fieldname": "membership_debit_account", - "fieldtype": "Link", - "label": "Debit Account", - "mandatory_depends_on": "eval:doc.allow_invoicing", - "options": "Account" - }, - { - "depends_on": "automate_donation_payment_entries", - "fieldname": "donation_debit_account", - "fieldtype": "Link", - "label": "Debit Account", - "mandatory_depends_on": "automate_donation_payment_entries", - "options": "Account" - }, - { - "description": "This company will be set for the Donations created via webhook.", - "fieldname": "donation_company", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Company", - "options": "Company", - "reqd": 1 - }, - { - "fieldname": "donation_settings_section", - "fieldtype": "Section Break", - "label": "Donation Settings" - }, - { - "fieldname": "column_break_22", - "fieldtype": "Column Break" - }, - { - "description": "This Donor Type will be set for the Donor created via Donation web form entry.", - "fieldname": "default_donor_type", - "fieldtype": "Link", - "in_list_view": 1, - "label": "Default Donor Type", - "options": "Donor Type", - "reqd": 1 - }, - { - "fieldname": "section_break_27", - "fieldtype": "Section Break" - }, - { - "description": "The user that will be used to create Donations, Memberships, Invoices, and Payment Entries. This user should have the relevant permissions.", - "fieldname": "creation_user", - "fieldtype": "Link", - "label": "Creation User", - "options": "User", - "reqd": 1 - } - ], - "index_web_pages_for_search": 1, - "issingle": 1, - "links": [], - "modified": "2021-03-11 10:43:38.124240", - "modified_by": "Administrator", - "module": "Non Profit", - "name": "Non Profit Settings", - "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "print": 1, - "read": 1, - "role": "System Manager", - "share": 1, - "write": 1 - }, - { - "create": 1, - "delete": 1, - "email": 1, - "print": 1, - "read": 1, - "role": "Non Profit Manager", - "share": 1, - "write": 1 - }, - { - "email": 1, - "print": 1, - "read": 1, - "role": "Non Profit Member", - "share": 1 - } - ], - "quick_entry": 1, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1 -} \ No newline at end of file diff --git a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.py b/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.py deleted file mode 100644 index ace66055427..00000000000 --- a/erpnext/non_profit/doctype/non_profit_settings/non_profit_settings.py +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -import frappe -from frappe import _ -from frappe.integrations.utils import get_payment_gateway_controller -from frappe.model.document import Document - - -class NonProfitSettings(Document): - @frappe.whitelist() - def generate_webhook_secret(self, field="membership_webhook_secret"): - key = frappe.generate_hash(length=20) - self.set(field, key) - self.save() - - secret_for = "Membership" if field == "membership_webhook_secret" else "Donation" - - frappe.msgprint( - _("Here is your webhook secret for {0} API, this will be shown to you only once.").format(secret_for) + "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.
+ ${__(review.review_title)} +
+ ++ ${__(review.comment)} +
+
+ {{ _(\"Certificate No. : \") }} {{ doc.name }}
\n\n \t{{ _(\"Date\") }} : {{ doc.get_formatted(\"date\") }}
\n
\n We thank you for your contribution towards the corpus of the {{ doc.company }} and helping support our work.\n
\n\n{{doc.company_address_display }}
\n\n", - "idx": 0, - "line_breaks": 0, - "modified": "2021-02-22 00:20:08.516600", - "modified_by": "Administrator", - "module": "Regional", - "name": "80G Certificate for Donation", - "owner": "Administrator", - "print_format_builder": 0, - "print_format_type": "Jinja", - "raw_printing": 0, - "show_section_headings": 0, - "standard": "Yes" -} \ No newline at end of file diff --git a/erpnext/regional/print_format/80g_certificate_for_donation/__init__.py b/erpnext/regional/print_format/80g_certificate_for_donation/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/regional/print_format/80g_certificate_for_membership/80g_certificate_for_membership.json b/erpnext/regional/print_format/80g_certificate_for_membership/80g_certificate_for_membership.json deleted file mode 100644 index f1b15aab298..00000000000 --- a/erpnext/regional/print_format/80g_certificate_for_membership/80g_certificate_for_membership.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "absolute_value": 0, - "align_labels_right": 0, - "creation": "2021-02-15 16:53:55.026611", - "css": ".details {\n font-size: 15px;\n font-family: Tahoma, sans-serif;;\n line-height: 150%;\n}\n\n.certificate-footer {\n font-size: 15px;\n font-family: Tahoma, sans-serif;\n line-height: 140%;\n margin-top: 120px;\n}\n\n.company-address {\n color: #666666;\n font-size: 15px;\n font-family: Tahoma, sans-serif;;\n}", - "custom_format": 1, - "default_print_language": "en", - "disabled": 0, - "doc_type": "Tax Exemption 80G Certificate", - "docstatus": 0, - "doctype": "Print Format", - "font": "Default", - "html": "{% if letter_head and not no_letterhead -%}\n{{ _(\"Certificate No. : \") }} {{ doc.name }}
\n\n \t{{ _(\"Date\") }} : {{ doc.get_formatted(\"date\") }}
\n
| {{ _(\"Date\") }} | \n \t\t\t{{ _(\"Amount\") }} | \n \t\t\t{{ _(\"Invoice ID\") }} | \n \t\t
|---|---|---|
| {{ payment.date }} | \n \t\t\t{{ payment.get_formatted(\"amount\") }} | \n \t\t\t{{ payment.invoice_id }} | \n \t\t
\n We thank you for your contribution towards the corpus of the {{ doc.company }} and helping support our work.\n
\n\n{{doc.company_address_display }}
\n\n", - "idx": 0, - "line_breaks": 0, - "modified": "2021-02-21 23:29:00.778973", - "modified_by": "Administrator", - "module": "Regional", - "name": "80G Certificate for Membership", - "owner": "Administrator", - "print_format_builder": 0, - "print_format_type": "Jinja", - "raw_printing": 0, - "show_section_headings": 0, - "standard": "Yes" -} \ No newline at end of file diff --git a/erpnext/regional/print_format/80g_certificate_for_membership/__init__.py b/erpnext/regional/print_format/80g_certificate_for_membership/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/regional/report/datev/datev.js b/erpnext/regional/report/datev/datev.js index 4124e3df190..03c729e6df4 100644 --- a/erpnext/regional/report/datev/datev.js +++ b/erpnext/regional/report/datev/datev.js @@ -40,7 +40,11 @@ frappe.query_reports["DATEV"] = { }); query_report.page.add_menu_item(__("Download DATEV File"), () => { - const filters = JSON.stringify(query_report.get_values()); + const filters = encodeURIComponent( + JSON.stringify( + query_report.get_values() + ) + ); window.open(`/api/method/erpnext.regional.report.datev.datev.download_datev_csv?filters=${filters}`); }); diff --git a/erpnext/regional/report/datev/test_datev.py b/erpnext/regional/report/datev/test_datev.py index 14d5495eed7..052fb2a7244 100644 --- a/erpnext/regional/report/datev/test_datev.py +++ b/erpnext/regional/report/datev/test_datev.py @@ -1,9 +1,9 @@ import zipfile +from io import BytesIO from unittest import TestCase import frappe from frappe.utils import cstr, now_datetime, today -from six import BytesIO from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.regional.germany.utils.datev.datev_constants import ( diff --git a/erpnext/non_profit/doctype/donor_type/__init__.py b/erpnext/regional/report/e_invoice_summary/__init__.py similarity index 100% rename from erpnext/non_profit/doctype/donor_type/__init__.py rename to erpnext/regional/report/e_invoice_summary/__init__.py diff --git a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.js b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.js new file mode 100644 index 00000000000..4713217d83c --- /dev/null +++ b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.js @@ -0,0 +1,55 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["E-Invoice Summary"] = { + "filters": [ + { + "fieldtype": "Link", + "options": "Company", + "reqd": 1, + "fieldname": "company", + "label": __("Company"), + "default": frappe.defaults.get_user_default("Company"), + }, + { + "fieldtype": "Link", + "options": "Customer", + "fieldname": "customer", + "label": __("Customer") + }, + { + "fieldtype": "Date", + "reqd": 1, + "fieldname": "from_date", + "label": __("From Date"), + "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1), + }, + { + "fieldtype": "Date", + "reqd": 1, + "fieldname": "to_date", + "label": __("To Date"), + "default": frappe.datetime.get_today(), + }, + { + "fieldtype": "Select", + "fieldname": "status", + "label": __("Status"), + "options": "\nPending\nGenerated\nCancelled\nFailed" + } + ], + + "formatter": function (value, row, column, data, default_formatter) { + value = default_formatter(value, row, column, data); + + if (column.fieldname == "einvoice_status" && value) { + if (value == 'Pending') value = `${value}`; + else if (value == 'Generated') value = `${value}`; + else if (value == 'Cancelled') value = `${value}`; + else if (value == 'Failed') value = `${value}`; + } + + return value; + } +}; diff --git a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.json b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.json new file mode 100644 index 00000000000..d0000ad50df --- /dev/null +++ b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.json @@ -0,0 +1,28 @@ +{ + "add_total_row": 0, + "columns": [], + "creation": "2021-03-12 11:23:37.312294", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "json": "{}", + "letter_head": "Logo", + "modified": "2021-03-13 12:36:48.689413", + "modified_by": "Administrator", + "module": "Regional", + "name": "E-Invoice Summary", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Sales Invoice", + "report_name": "E-Invoice Summary", + "report_type": "Script Report", + "roles": [ + { + "role": "Administrator" + } + ] +} \ No newline at end of file diff --git a/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py new file mode 100644 index 00000000000..2110c444470 --- /dev/null +++ b/erpnext/regional/report/e_invoice_summary/e_invoice_summary.py @@ -0,0 +1,110 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +import frappe +from frappe import _ + + +def execute(filters=None): + validate_filters(filters) + + columns = get_columns() + data = get_data(filters) + + return columns, data + +def validate_filters(filters=None): + if filters is None: + filters = {} + filters = frappe._dict(filters) + + if not filters.company: + frappe.throw(_('{} is mandatory for generating E-Invoice Summary Report').format(_('Company')), title=_('Invalid Filter')) + if filters.company: + # validate if company has e-invoicing enabled + pass + if not filters.from_date or not filters.to_date: + frappe.throw(_('From Date & To Date is mandatory for generating E-Invoice Summary Report'), title=_('Invalid Filter')) + if filters.from_date > filters.to_date: + frappe.throw(_('From Date must be before To Date'), title=_('Invalid Filter')) + +def get_data(filters=None): + if filters is None: + filters = {} + query_filters = { + 'posting_date': ['between', [filters.from_date, filters.to_date]], + 'einvoice_status': ['is', 'set'], + 'company': filters.company + } + if filters.customer: + query_filters['customer'] = filters.customer + if filters.status: + query_filters['einvoice_status'] = filters.status + + data = frappe.get_all( + 'Sales Invoice', + filters=query_filters, + fields=[d.get('fieldname') for d in get_columns()] + ) + + return data + +def get_columns(): + return [ + { + "fieldtype": "Date", + "fieldname": "posting_date", + "label": _("Posting Date"), + "width": 0 + }, + { + "fieldtype": "Link", + "fieldname": "name", + "label": _("Sales Invoice"), + "options": "Sales Invoice", + "width": 140 + }, + { + "fieldtype": "Data", + "fieldname": "einvoice_status", + "label": _("Status"), + "width": 100 + }, + { + "fieldtype": "Link", + "fieldname": "customer", + "options": "Customer", + "label": _("Customer") + }, + { + "fieldtype": "Check", + "fieldname": "is_return", + "label": _("Is Return"), + "width": 85 + }, + { + "fieldtype": "Data", + "fieldname": "ack_no", + "label": "Ack. No.", + "width": 145 + }, + { + "fieldtype": "Data", + "fieldname": "ack_date", + "label": "Ack. Date", + "width": 165 + }, + { + "fieldtype": "Data", + "fieldname": "irn", + "label": _("IRN No."), + "width": 250 + }, + { + "fieldtype": "Currency", + "options": "Company:company:default_currency", + "fieldname": "base_grand_total", + "label": _("Grand Total"), + "width": 120 + } + ] diff --git a/erpnext/regional/report/gstr_1/gstr_1.js b/erpnext/regional/report/gstr_1/gstr_1.js index 4b98978f130..9999a6d167b 100644 --- a/erpnext/regional/report/gstr_1/gstr_1.js +++ b/erpnext/regional/report/gstr_1/gstr_1.js @@ -17,7 +17,7 @@ frappe.query_reports["GSTR-1"] = { "fieldtype": "Link", "options": "Address", "get_query": function () { - var company = frappe.query_report.get_filter_value('company'); + let company = frappe.query_report.get_filter_value('company'); if (company) { return { "query": 'frappe.contacts.doctype.address.address.address_query', @@ -26,6 +26,11 @@ frappe.query_reports["GSTR-1"] = { } } }, + { + "fieldname": "company_gstin", + "label": __("Company GSTIN"), + "fieldtype": "Select" + }, { "fieldname": "from_date", "label": __("From Date"), @@ -60,10 +65,21 @@ frappe.query_reports["GSTR-1"] = { } ], onload: function (report) { + let filters = report.get_values(); + + frappe.call({ + method: 'erpnext.regional.report.gstr_1.gstr_1.get_company_gstins', + args: { + company: filters.company + }, + callback: function(r) { + frappe.query_report.page.fields_dict.company_gstin.df.options = r.message; + frappe.query_report.page.fields_dict.company_gstin.refresh(); + } + }); + report.page.add_inner_button(__("Download as JSON"), function () { - var filters = report.get_values(); - frappe.call({ method: 'erpnext.regional.report.gstr_1.gstr_1.get_json', args: { diff --git a/erpnext/regional/report/gstr_1/gstr_1.py b/erpnext/regional/report/gstr_1/gstr_1.py index e50ff180328..8fcb6bb4448 100644 --- a/erpnext/regional/report/gstr_1/gstr_1.py +++ b/erpnext/regional/report/gstr_1/gstr_1.py @@ -28,7 +28,7 @@ class Gstr1Report(object): posting_date, base_grand_total, base_rounded_total, - COALESCE(NULLIF(customer_gstin,''), NULLIF(billing_address_gstin, '')) as customer_gstin, + NULLIF(billing_address_gstin, '') as billing_address_gstin, place_of_supply, ecommerce_gstin, reverse_charge, @@ -253,13 +253,14 @@ class Gstr1Report(object): for opts in (("company", " and company=%(company)s"), ("from_date", " and posting_date>=%(from_date)s"), ("to_date", " and posting_date<=%(to_date)s"), - ("company_address", " and company_address=%(company_address)s")): + ("company_address", " and company_address=%(company_address)s"), + ("company_gstin", " and company_gstin=%(company_gstin)s")): if self.filters.get(opts[0]): conditions += opts[1] if self.filters.get("type_of_business") == "B2B": - conditions += "AND IFNULL(gst_category, '') in ('Registered Regular', 'Deemed Export', 'SEZ') AND is_return != 1 AND is_debit_note !=1" + conditions += "AND IFNULL(gst_category, '') in ('Registered Regular', 'Registered Composition', 'Deemed Export', 'SEZ') AND is_return != 1 AND is_debit_note !=1" if self.filters.get("type_of_business") in ("B2C Large", "B2C Small"): b2c_limit = frappe.db.get_single_value('GST Settings', 'b2c_limit') @@ -383,7 +384,7 @@ class Gstr1Report(object): for invoice, items in self.invoice_items.items(): if invoice not in self.items_based_on_tax_rate and invoice not in unidentified_gst_accounts_invoice \ and self.invoices.get(invoice, {}).get('export_type') == "Without Payment of Tax" \ - and self.invoices.get(invoice, {}).get('gst_category') == "Overseas": + and self.invoices.get(invoice, {}).get('gst_category') in ("Overseas", "SEZ"): self.items_based_on_tax_rate.setdefault(invoice, {}).setdefault(0, items.keys()) def get_columns(self): @@ -409,7 +410,7 @@ class Gstr1Report(object): if self.filters.get("type_of_business") == "B2B": self.invoice_columns = [ { - "fieldname": "customer_gstin", + "fieldname": "billing_address_gstin", "label": "GSTIN/UIN of Recipient", "fieldtype": "Data", "width": 150 @@ -516,7 +517,7 @@ class Gstr1Report(object): elif self.filters.get("type_of_business") == "CDNR-REG": self.invoice_columns = [ { - "fieldname": "customer_gstin", + "fieldname": "billing_address_gstin", "label": "GSTIN/UIN of Recipient", "fieldtype": "Data", "width": 150 @@ -817,7 +818,7 @@ def get_json(filters, report_name, data): res = {} if filters["type_of_business"] == "B2B": for item in report_data[:-1]: - res.setdefault(item["customer_gstin"], {}).setdefault(item["invoice_number"],[]).append(item) + res.setdefault(item["billing_address_gstin"], {}).setdefault(item["invoice_number"],[]).append(item) out = get_b2b_json(res, gstin) gst_json["b2b"] = out @@ -841,7 +842,7 @@ def get_json(filters, report_name, data): gst_json["exp"] = out elif filters["type_of_business"] == "CDNR-REG": for item in report_data[:-1]: - res.setdefault(item["customer_gstin"], {}).setdefault(item["invoice_number"],[]).append(item) + res.setdefault(item["billing_address_gstin"], {}).setdefault(item["invoice_number"],[]).append(item) out = get_cdnr_reg_json(res, gstin) gst_json["cdnr"] = out @@ -875,7 +876,7 @@ def get_json(filters, report_name, data): } def get_b2b_json(res, gstin): - inv_type, out = {"Registered Regular": "R", "Deemed Export": "DE", "URD": "URD", "SEZ": "SEZ"}, [] + out = [] for gst_in in res: b2b_item, inv = {"ctin": gst_in, "inv": []}, [] if not gst_in: continue @@ -889,7 +890,7 @@ def get_b2b_json(res, gstin): inv_item = get_basic_invoice_detail(invoice[0]) inv_item["pos"] = "%02d" % int(invoice[0]["place_of_supply"].split('-')[0]) inv_item["rchrg"] = invoice[0]["reverse_charge"] - inv_item["inv_typ"] = inv_type.get(invoice[0].get("gst_category", ""),"") + inv_item["inv_typ"] = get_invoice_type(invoice[0]) if inv_item["pos"]=="00": continue inv_item["itms"] = [] @@ -1044,7 +1045,7 @@ def get_cdnr_reg_json(res, gstin): "ntty": invoice[0]["document_type"], "pos": "%02d" % int(invoice[0]["place_of_supply"].split('-')[0]), "rchrg": invoice[0]["reverse_charge"], - "inv_typ": get_invoice_type_for_cdnr(invoice[0]) + "inv_typ": get_invoice_type(invoice[0]) } inv_item["itms"] = [] @@ -1069,7 +1070,7 @@ def get_cdnr_unreg_json(res, gstin): "val": abs(flt(items[0]["invoice_value"])), "ntty": items[0]["document_type"], "pos": "%02d" % int(items[0]["place_of_supply"].split('-')[0]), - "typ": get_invoice_type_for_cdnrur(items[0]) + "typ": get_invoice_type(items[0]) } inv_item["itms"] = [] @@ -1110,29 +1111,21 @@ def get_exempted_json(data): return out -def get_invoice_type_for_cdnr(row): - if row.get('gst_category') == 'SEZ': - if row.get('export_type') == 'WPAY': - invoice_type = 'SEWP' - else: - invoice_type = 'SEWOP' - elif row.get('gst_category') == 'Deemed Export': - invoice_type = 'DE' - elif row.get('gst_category') == 'Registered Regular': - invoice_type = 'R' +def get_invoice_type(row): + gst_category = row.get('gst_category') - return invoice_type + if gst_category == 'SEZ': + return 'SEWP' if row.get('export_type') == 'WPAY' else 'SEWOP' -def get_invoice_type_for_cdnrur(row): - if row.get('gst_category') == 'Overseas': - if row.get('export_type') == 'WPAY': - invoice_type = 'EXPWP' - else: - invoice_type = 'EXPWOP' - elif row.get('gst_category') == 'Unregistered': - invoice_type = 'B2CL' + if gst_category == 'Overseas': + return 'EXPWP' if row.get('export_type') == 'WPAY' else 'EXPWOP' - return invoice_type + return ({ + 'Deemed Export': 'DE', + 'Registered Regular': 'R', + 'Registered Composition': 'R', + 'Unregistered': 'B2CL' + }).get(gst_category) def get_basic_invoice_detail(row): return { @@ -1154,7 +1147,7 @@ def get_rate_and_tax_details(row, gstin): # calculate tax amount added tax = flt((row["taxable_value"]*rate)/100.0, 2) frappe.errprint([tax, tax/2]) - if row.get("customer_gstin") and gstin[0:2] == row["customer_gstin"][0:2]: + if row.get("billing_address_gstin") and gstin[0:2] == row["billing_address_gstin"][0:2]: itm_det.update({"camt": flt(tax/2.0, 2), "samt": flt(tax/2.0, 2)}) else: itm_det.update({"iamt": tax}) @@ -1199,4 +1192,24 @@ def is_inter_state(invoice_detail): if invoice_detail.place_of_supply.split("-")[0] != invoice_detail.company_gstin[:2]: return True else: - return False \ No newline at end of file + return False + + +@frappe.whitelist() +def get_company_gstins(company): + address = frappe.qb.DocType("Address") + links = frappe.qb.DocType("Dynamic Link") + + addresses = frappe.qb.from_(address).inner_join(links).on( + address.name == links.parent + ).select( + address.gstin + ).where( + links.link_doctype == 'Company' + ).where( + links.link_name == company + ).run(as_dict=1) + + address_list = [''] + [d.gstin for d in addresses] + + return address_list \ No newline at end of file diff --git a/erpnext/regional/saudi_arabia/setup.py b/erpnext/regional/saudi_arabia/setup.py index 15d524d5b81..d2ef6f3f178 100644 --- a/erpnext/regional/saudi_arabia/setup.py +++ b/erpnext/regional/saudi_arabia/setup.py @@ -102,7 +102,7 @@ def make_custom_fields(): ] } - create_custom_fields(custom_fields, update=True) + create_custom_fields(custom_fields, ignore_validate=True, update=True) def update_regional_tax_settings(country, company): create_ksa_vat_setting(company) diff --git a/erpnext/restaurant/__init__.py b/erpnext/restaurant/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/__init__.py b/erpnext/restaurant/doctype/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant/__init__.py b/erpnext/restaurant/doctype/restaurant/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant/restaurant.js b/erpnext/restaurant/doctype/restaurant/restaurant.js deleted file mode 100644 index 13fda73922a..00000000000 --- a/erpnext/restaurant/doctype/restaurant/restaurant.js +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Restaurant', { - refresh: function(frm) { - frm.add_custom_button(__('Order Entry'), () => { - frappe.set_route('Form', 'Restaurant Order Entry'); - }); - } -}); diff --git a/erpnext/restaurant/doctype/restaurant/restaurant.json b/erpnext/restaurant/doctype/restaurant/restaurant.json deleted file mode 100644 index 85726874119..00000000000 --- a/erpnext/restaurant/doctype/restaurant/restaurant.json +++ /dev/null @@ -1,309 +0,0 @@ -{ - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "prompt", - "beta": 1, - "creation": "2017-09-15 12:40:41.546933", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "Setup", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "image", - "fieldtype": "Attach Image", - "hidden": 1, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Image", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 1, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "company", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Company", - "length": 0, - "no_copy": 0, - "options": "Company", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "default_customer", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Default Customer", - "length": 0, - "no_copy": 0, - "options": "Customer", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "invoice_series_prefix", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Invoice Series Prefix", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_4", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "active_menu", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Active Menu", - "length": 0, - "no_copy": 0, - "options": "Restaurant Menu", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "default_tax_template", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Default Tax Template", - "length": 0, - "no_copy": 0, - "options": "Sales Taxes and Charges Template", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "address", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Address", - "length": 0, - "no_copy": 0, - "options": "Address", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_field": "image", - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2017-12-09 12:13:10.185496", - "modified_by": "Administrator", - "module": "Restaurant", - "name": "Restaurant", - "name_case": "", - "owner": "Administrator", - "permissions": [ - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - } - ], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Hospitality", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} \ No newline at end of file diff --git a/erpnext/restaurant/doctype/restaurant/restaurant.py b/erpnext/restaurant/doctype/restaurant/restaurant.py deleted file mode 100644 index 67838d29a37..00000000000 --- a/erpnext/restaurant/doctype/restaurant/restaurant.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -from frappe.model.document import Document - - -class Restaurant(Document): - pass diff --git a/erpnext/restaurant/doctype/restaurant/restaurant_dashboard.py b/erpnext/restaurant/doctype/restaurant/restaurant_dashboard.py deleted file mode 100644 index bfdd052753e..00000000000 --- a/erpnext/restaurant/doctype/restaurant/restaurant_dashboard.py +++ /dev/null @@ -1,17 +0,0 @@ -from frappe import _ - - -def get_data(): - return { - 'fieldname': 'restaurant', - 'transactions': [ - { - 'label': _('Setup'), - 'items': ['Restaurant Menu', 'Restaurant Table'] - }, - { - 'label': _('Operations'), - 'items': ['Restaurant Reservation', 'Sales Invoice'] - } - ] - } diff --git a/erpnext/restaurant/doctype/restaurant/test_restaurant.py b/erpnext/restaurant/doctype/restaurant/test_restaurant.py deleted file mode 100644 index f88f9801290..00000000000 --- a/erpnext/restaurant/doctype/restaurant/test_restaurant.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - -test_records = [ - dict(doctype='Restaurant', name='Test Restaurant 1', company='_Test Company 1', - invoice_series_prefix='Test-Rest-1-Inv-', default_customer='_Test Customer 1'), - dict(doctype='Restaurant', name='Test Restaurant 2', company='_Test Company 1', - invoice_series_prefix='Test-Rest-2-Inv-', default_customer='_Test Customer 1'), -] - -class TestRestaurant(unittest.TestCase): - pass diff --git a/erpnext/restaurant/doctype/restaurant_menu/__init__.py b/erpnext/restaurant/doctype/restaurant_menu/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.js b/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.js deleted file mode 100644 index da7d43f8a3e..00000000000 --- a/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Restaurant Menu', { - setup: function(frm) { - frm.add_fetch('item', 'standard_rate', 'rate'); - }, -}); diff --git a/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.json b/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.json deleted file mode 100644 index 1b1610dbacf..00000000000 --- a/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.json +++ /dev/null @@ -1,247 +0,0 @@ -{ - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "prompt", - "beta": 1, - "creation": "2017-09-15 12:48:29.818715", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "Setup", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "restaurant", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Restaurant", - "length": 0, - "no_copy": 0, - "options": "Restaurant", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "1", - "fieldname": "enabled", - "fieldtype": "Check", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Enabled", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "price_list", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Price List (Auto created)", - "length": 0, - "no_copy": 0, - "options": "Price List", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "items_section", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Items", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "items", - "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Items", - "length": 0, - "no_copy": 0, - "options": "Restaurant Menu Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2017-12-09 12:13:13.684500", - "modified_by": "Administrator", - "module": "Restaurant", - "name": "Restaurant Menu", - "name_case": "", - "owner": "Administrator", - "permissions": [ - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Restaurant Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Hospitality", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} \ No newline at end of file diff --git a/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.py b/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.py deleted file mode 100644 index 64eb40f3645..00000000000 --- a/erpnext/restaurant/doctype/restaurant_menu/restaurant_menu.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -import frappe -from frappe.model.document import Document - - -class RestaurantMenu(Document): - def validate(self): - for d in self.items: - if not d.rate: - d.rate = frappe.db.get_value('Item', d.item, 'standard_rate') - - def on_update(self): - '''Sync Price List''' - self.make_price_list() - - def on_trash(self): - '''clear prices''' - self.clear_item_price() - - def clear_item_price(self, price_list=None): - '''clear all item prices for this menu''' - if not price_list: - price_list = self.get_price_list().name - frappe.db.sql('delete from `tabItem Price` where price_list = %s', price_list) - - def make_price_list(self): - # create price list for menu - price_list = self.get_price_list() - self.db_set('price_list', price_list.name) - - # delete old items - self.clear_item_price(price_list.name) - - for d in self.items: - frappe.get_doc(dict( - doctype = 'Item Price', - price_list = price_list.name, - item_code = d.item, - price_list_rate = d.rate - )).insert() - - def get_price_list(self): - '''Create price list for menu if missing''' - price_list_name = frappe.db.get_value('Price List', dict(restaurant_menu=self.name)) - if price_list_name: - price_list = frappe.get_doc('Price List', price_list_name) - else: - price_list = frappe.new_doc('Price List') - price_list.restaurant_menu = self.name - price_list.price_list_name = self.name - - price_list.enabled = 1 - price_list.selling = 1 - price_list.save() - - return price_list diff --git a/erpnext/restaurant/doctype/restaurant_menu/test_restaurant_menu.py b/erpnext/restaurant/doctype/restaurant_menu/test_restaurant_menu.py deleted file mode 100644 index 27020eb869f..00000000000 --- a/erpnext/restaurant/doctype/restaurant_menu/test_restaurant_menu.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - -import frappe - -test_records = [ - dict(doctype='Item', item_code='Food Item 1', - item_group='Products', is_stock_item=0), - dict(doctype='Item', item_code='Food Item 2', - item_group='Products', is_stock_item=0), - dict(doctype='Item', item_code='Food Item 3', - item_group='Products', is_stock_item=0), - dict(doctype='Item', item_code='Food Item 4', - item_group='Products', is_stock_item=0), - dict(doctype='Restaurant Menu', restaurant='Test Restaurant 1', name='Test Restaurant 1 Menu 1', - items = [ - dict(item='Food Item 1', rate=400), - dict(item='Food Item 2', rate=300), - dict(item='Food Item 3', rate=200), - dict(item='Food Item 4', rate=100), - ]), - dict(doctype='Restaurant Menu', restaurant='Test Restaurant 1', name='Test Restaurant 1 Menu 2', - items = [ - dict(item='Food Item 1', rate=450), - dict(item='Food Item 2', rate=350), - ]) -] - -class TestRestaurantMenu(unittest.TestCase): - def test_price_list_creation_and_editing(self): - menu1 = frappe.get_doc('Restaurant Menu', 'Test Restaurant 1 Menu 1') - menu1.save() - - menu2 = frappe.get_doc('Restaurant Menu', 'Test Restaurant 1 Menu 2') - menu2.save() - - self.assertTrue(frappe.db.get_value('Price List', 'Test Restaurant 1 Menu 1')) - self.assertEqual(frappe.db.get_value('Item Price', - dict(price_list = 'Test Restaurant 1 Menu 1', item_code='Food Item 1'), 'price_list_rate'), 400) - self.assertEqual(frappe.db.get_value('Item Price', - dict(price_list = 'Test Restaurant 1 Menu 2', item_code='Food Item 1'), 'price_list_rate'), 450) - - menu1.items[0].rate = 401 - menu1.save() - - self.assertEqual(frappe.db.get_value('Item Price', - dict(price_list = 'Test Restaurant 1 Menu 1', item_code='Food Item 1'), 'price_list_rate'), 401) - - menu1.items[0].rate = 400 - menu1.save() diff --git a/erpnext/restaurant/doctype/restaurant_menu_item/__init__.py b/erpnext/restaurant/doctype/restaurant_menu_item/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant_menu_item/restaurant_menu_item.json b/erpnext/restaurant/doctype/restaurant_menu_item/restaurant_menu_item.json deleted file mode 100644 index 87568bf9818..00000000000 --- a/erpnext/restaurant/doctype/restaurant_menu_item/restaurant_menu_item.json +++ /dev/null @@ -1,105 +0,0 @@ -{ - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "", - "beta": 0, - "creation": "2017-09-15 12:49:36.072636", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "Setup", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "item", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Item", - "length": 0, - "no_copy": 0, - "options": "Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "rate", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Rate", - "length": 0, - "no_copy": 0, - "options": "", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2017-09-15 14:18:55.145088", - "modified_by": "Administrator", - "module": "Restaurant", - "name": "Restaurant Menu Item", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Hospitality", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} \ No newline at end of file diff --git a/erpnext/restaurant/doctype/restaurant_menu_item/restaurant_menu_item.py b/erpnext/restaurant/doctype/restaurant_menu_item/restaurant_menu_item.py deleted file mode 100644 index 98b245edece..00000000000 --- a/erpnext/restaurant/doctype/restaurant_menu_item/restaurant_menu_item.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -from frappe.model.document import Document - - -class RestaurantMenuItem(Document): - pass diff --git a/erpnext/restaurant/doctype/restaurant_order_entry/__init__.py b/erpnext/restaurant/doctype/restaurant_order_entry/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.js b/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.js deleted file mode 100644 index 8df851c62b1..00000000000 --- a/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.js +++ /dev/null @@ -1,162 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Restaurant Order Entry', { - setup: function(frm) { - let get_item_query = () => { - return { - query: 'erpnext.restaurant.doctype.restaurant_order_entry.restaurant_order_entry.item_query_restaurant', - filters: { - 'table': frm.doc.restaurant_table - } - }; - }; - frm.set_query('item', 'items', get_item_query); - frm.set_query('add_item', get_item_query); - }, - onload_post_render: function(frm) { - if(!frm.item_selector) { - frm.item_selector = new erpnext.ItemSelector({ - frm: frm, - item_field: 'item', - item_query: 'erpnext.restaurant.doctype.restaurant_order_entry.restaurant_order_entry.item_query_restaurant', - get_filters: () => { - return {table: frm.doc.restaurant_table}; - } - }); - } - - let $input = frm.get_field('add_item').$input; - - $input.on('keyup', function(e) { - if (e.which===13) { - if (frm.clear_item_timeout) { - clearTimeout (frm.clear_item_timeout); - } - - // clear the item input so user can enter a new item - frm.clear_item_timeout = setTimeout (() => { - frm.set_value('add_item', ''); - }, 1000); - - let item = $input.val(); - - if (!item) return; - - var added = false; - (frm.doc.items || []).forEach((d) => { - if (d.item===item) { - d.qty += 1; - added = true; - } - }); - - return frappe.run_serially([ - () => { - if (!added) { - return frm.add_child('items', {item: item, qty: 1}); - } - }, - () => frm.get_field("items").refresh() - ]); - } - }); - }, - refresh: function(frm) { - frm.disable_save(); - frm.add_custom_button(__('Update'), () => { - return frm.trigger('sync'); - }); - frm.add_custom_button(__('Clear'), () => { - return frm.trigger('clear'); - }); - frm.add_custom_button(__('Bill'), () => { - return frm.trigger('make_invoice'); - }); - }, - clear: function(frm) { - frm.doc.add_item = ''; - frm.doc.grand_total = 0; - frm.doc.items = []; - frm.refresh(); - frm.get_field('add_item').$input.focus(); - }, - restaurant_table: function(frm) { - // select the open sales order items for this table - if (!frm.doc.restaurant_table) { - return; - } - return frappe.call({ - method: 'erpnext.restaurant.doctype.restaurant_order_entry.restaurant_order_entry.get_invoice', - args: { - table: frm.doc.restaurant_table - }, - callback: (r) => { - frm.events.set_invoice_items(frm, r); - } - }); - }, - sync: function(frm) { - return frappe.call({ - method: 'erpnext.restaurant.doctype.restaurant_order_entry.restaurant_order_entry.sync', - args: { - table: frm.doc.restaurant_table, - items: frm.doc.items - }, - callback: (r) => { - frm.events.set_invoice_items(frm, r); - frappe.show_alert({message: __('Saved'), indicator: 'green'}); - } - }); - - }, - make_invoice: function(frm) { - frm.trigger('sync').then(() => { - frappe.prompt([ - { - fieldname: 'customer', - label: __('Customer'), - fieldtype: 'Link', - reqd: 1, - options: 'Customer', - 'default': frm.invoice.customer - }, - { - fieldname: 'mode_of_payment', - label: __('Mode of Payment'), - fieldtype: 'Link', - reqd: 1, - options: 'Mode of Payment', - 'default': frm.mode_of_payment || '' - } - ], (data) => { - // cache this for next entry - frm.mode_of_payment = data.mode_of_payment; - return frappe.call({ - method: 'erpnext.restaurant.doctype.restaurant_order_entry.restaurant_order_entry.make_invoice', - args: { - table: frm.doc.restaurant_table, - customer: data.customer, - mode_of_payment: data.mode_of_payment - }, - callback: (r) => { - frm.set_value('last_sales_invoice', r.message); - frm.trigger('clear'); - } - }); - }, - __("Select Customer")); - }); - }, - set_invoice_items: function(frm, r) { - let invoice = r.message; - frm.doc.items = []; - (invoice.items || []).forEach((d) => { - frm.add_child('items', {item: d.item_code, qty: d.qty, rate: d.rate}); - }); - frm.set_value('grand_total', invoice.grand_total); - frm.set_value('last_sales_invoice', invoice.name); - frm.invoice = invoice; - frm.refresh(); - } -}); diff --git a/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.json b/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.json deleted file mode 100644 index 3e4d593d5b6..00000000000 --- a/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.json +++ /dev/null @@ -1,280 +0,0 @@ -{ - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 1, - "creation": "2017-09-15 15:10:24.530365", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "restaurant_table", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Restaurant Table", - "length": 0, - "no_copy": 0, - "options": "Restaurant Table", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "restaurant_table", - "description": "Click Enter To Add", - "fieldname": "add_item", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Add Item", - "length": 0, - "no_copy": 0, - "options": "Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "grand_total", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Grand Total", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "last_sales_invoice", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Last Sales Invoice", - "length": 0, - "no_copy": 0, - "options": "Sales Invoice", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "restaurant_table", - "fieldname": "current_order", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Current Order", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "depends_on": "restaurant_table", - "fieldname": "items", - "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Items", - "length": 0, - "no_copy": 0, - "options": "Restaurant Order Entry Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 1, - "istable": 0, - "max_attachments": 0, - "modified": "2017-10-04 17:06:20.926999", - "modified_by": "Administrator", - "module": "Restaurant", - "name": "Restaurant Order Entry", - "name_case": "", - "owner": "Administrator", - "permissions": [ - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 0, - "role": "Restaurant Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Hospitality", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} \ No newline at end of file diff --git a/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.py b/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.py deleted file mode 100644 index f9e75b47a0f..00000000000 --- a/erpnext/restaurant/doctype/restaurant_order_entry/restaurant_order_entry.py +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -import json - -import frappe -from frappe import _ -from frappe.model.document import Document - -from erpnext.controllers.queries import item_query - - -class RestaurantOrderEntry(Document): - pass - -@frappe.whitelist() -def get_invoice(table): - '''returns the active invoice linked to the given table''' - invoice_name = frappe.get_value('Sales Invoice', dict(restaurant_table = table, docstatus=0)) - restaurant, menu_name = get_restaurant_and_menu_name(table) - if invoice_name: - invoice = frappe.get_doc('Sales Invoice', invoice_name) - else: - invoice = frappe.new_doc('Sales Invoice') - invoice.naming_series = frappe.db.get_value('Restaurant', restaurant, 'invoice_series_prefix') - invoice.is_pos = 1 - default_customer = frappe.db.get_value('Restaurant', restaurant, 'default_customer') - if not default_customer: - frappe.throw(_('Please set default customer in Restaurant Settings')) - invoice.customer = default_customer - - invoice.taxes_and_charges = frappe.db.get_value('Restaurant', restaurant, 'default_tax_template') - invoice.selling_price_list = frappe.db.get_value('Price List', dict(restaurant_menu=menu_name, enabled=1)) - - return invoice - -@frappe.whitelist() -def sync(table, items): - '''Sync the sales order related to the table''' - invoice = get_invoice(table) - items = json.loads(items) - - invoice.items = [] - invoice.restaurant_table = table - for d in items: - invoice.append('items', dict( - item_code = d.get('item'), - qty = d.get('qty') - )) - - invoice.save() - return invoice.as_dict() - -@frappe.whitelist() -def make_invoice(table, customer, mode_of_payment): - '''Make table based on Sales Order''' - restaurant, menu = get_restaurant_and_menu_name(table) - invoice = get_invoice(table) - invoice.customer = customer - invoice.restaurant = restaurant - invoice.calculate_taxes_and_totals() - invoice.append('payments', dict(mode_of_payment=mode_of_payment, amount=invoice.grand_total)) - invoice.save() - invoice.submit() - - frappe.msgprint(_('Invoice Created'), indicator='green', alert=True) - - return invoice.name - -@frappe.whitelist() -def item_query_restaurant(doctype='Item', txt='', searchfield='name', start=0, page_len=20, filters=None, as_dict=False): - '''Return items that are selected in active menu of the restaurant''' - restaurant, menu = get_restaurant_and_menu_name(filters['table']) - items = frappe.db.get_all('Restaurant Menu Item', ['item'], dict(parent = menu)) - del filters['table'] - filters['name'] = ('in', [d.item for d in items]) - - return item_query('Item', txt, searchfield, start, page_len, filters, as_dict) - -def get_restaurant_and_menu_name(table): - if not table: - frappe.throw(_('Please select a table')) - - restaurant = frappe.db.get_value('Restaurant Table', table, 'restaurant') - menu = frappe.db.get_value('Restaurant', restaurant, 'active_menu') - - if not menu: - frappe.throw(_('Please set an active menu for Restaurant {0}').format(restaurant)) - - return restaurant, menu diff --git a/erpnext/restaurant/doctype/restaurant_order_entry_item/__init__.py b/erpnext/restaurant/doctype/restaurant_order_entry_item/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant_order_entry_item/restaurant_order_entry_item.json b/erpnext/restaurant/doctype/restaurant_order_entry_item/restaurant_order_entry_item.json deleted file mode 100644 index 0240013c784..00000000000 --- a/erpnext/restaurant/doctype/restaurant_order_entry_item/restaurant_order_entry_item.json +++ /dev/null @@ -1,163 +0,0 @@ -{ - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "beta": 0, - "creation": "2017-09-15 15:11:50.313241", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "item", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Item", - "length": 0, - "no_copy": 0, - "options": "Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "qty", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Qty", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "served", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Served", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "rate", - "fieldtype": "Currency", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Rate", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 1, - "max_attachments": 0, - "modified": "2017-09-21 08:39:27.232175", - "modified_by": "Administrator", - "module": "Restaurant", - "name": "Restaurant Order Entry Item", - "name_case": "", - "owner": "Administrator", - "permissions": [], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Hospitality", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} \ No newline at end of file diff --git a/erpnext/restaurant/doctype/restaurant_order_entry_item/restaurant_order_entry_item.py b/erpnext/restaurant/doctype/restaurant_order_entry_item/restaurant_order_entry_item.py deleted file mode 100644 index 0d9c236c0ea..00000000000 --- a/erpnext/restaurant/doctype/restaurant_order_entry_item/restaurant_order_entry_item.py +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -from frappe.model.document import Document - - -class RestaurantOrderEntryItem(Document): - pass diff --git a/erpnext/restaurant/doctype/restaurant_reservation/__init__.py b/erpnext/restaurant/doctype/restaurant_reservation/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.js b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.js deleted file mode 100644 index cebd1052a81..00000000000 --- a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.js +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Restaurant Reservation', { - setup: function(frm) { - frm.add_fetch('customer', 'customer_name', 'customer_name'); - }, - refresh: function(frm) { - - } -}); diff --git a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.json b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.json deleted file mode 100644 index 17df2b931de..00000000000 --- a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.json +++ /dev/null @@ -1,355 +0,0 @@ -{ - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "RES-RES-.YYYY.-.#####", - "beta": 1, - "creation": "2017-09-15 13:05:51.063661", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "Setup", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "status", - "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Status", - "length": 0, - "no_copy": 0, - "options": "Open\nWaitlisted\nCancelled\nNo Show\nSuccess", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "restaurant", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Restaurant", - "length": 0, - "no_copy": 0, - "options": "Restaurant", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "no_of_people", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "No of People", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "reservation_time", - "fieldtype": "Datetime", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Reservation Time", - "length": 0, - "no_copy": 0, - "options": "", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "reservation_end_time", - "fieldtype": "Datetime", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Reservation End Time", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "column_break_4", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "customer", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Customer", - "length": 0, - "no_copy": 0, - "options": "Customer", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "customer_name", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 1, - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Customer Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "contact_number", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Contact Number", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2018-08-21 16:15:38.435656", - "modified_by": "Administrator", - "module": "Restaurant", - "name": "Restaurant Reservation", - "name_case": "", - "owner": "Administrator", - "permissions": [ - { - "amend": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Restaurant Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Hospitality", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 -} \ No newline at end of file diff --git a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.py b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.py deleted file mode 100644 index 02ffaf6c20b..00000000000 --- a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -from datetime import timedelta - -from frappe.model.document import Document -from frappe.utils import get_datetime - - -class RestaurantReservation(Document): - def validate(self): - if not self.reservation_end_time: - self.reservation_end_time = get_datetime(self.reservation_time) + timedelta(hours=1) diff --git a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation_calendar.js b/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation_calendar.js deleted file mode 100644 index fe3dc57a720..00000000000 --- a/erpnext/restaurant/doctype/restaurant_reservation/restaurant_reservation_calendar.js +++ /dev/null @@ -1,18 +0,0 @@ -frappe.views.calendar["Restaurant Reservation"] = { - field_map: { - "start": "reservation_time", - "end": "reservation_end_time", - "id": "name", - "title": "customer_name", - "allDay": "allDay", - }, - gantt: true, - filters: [ - { - "fieldtype": "Data", - "fieldname": "customer_name", - "label": __("Customer Name") - } - ], - get_events_method: "frappe.desk.calendar.get_events" -}; diff --git a/erpnext/restaurant/doctype/restaurant_reservation/test_restaurant_reservation.py b/erpnext/restaurant/doctype/restaurant_reservation/test_restaurant_reservation.py deleted file mode 100644 index 11a3541bd56..00000000000 --- a/erpnext/restaurant/doctype/restaurant_reservation/test_restaurant_reservation.py +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - - -class TestRestaurantReservation(unittest.TestCase): - pass diff --git a/erpnext/restaurant/doctype/restaurant_table/__init__.py b/erpnext/restaurant/doctype/restaurant_table/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/erpnext/restaurant/doctype/restaurant_table/restaurant_table.js b/erpnext/restaurant/doctype/restaurant_table/restaurant_table.js deleted file mode 100644 index a55605c90bf..00000000000 --- a/erpnext/restaurant/doctype/restaurant_table/restaurant_table.js +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -// For license information, please see license.txt - -frappe.ui.form.on('Restaurant Table', { - refresh: function(frm) { - - } -}); diff --git a/erpnext/restaurant/doctype/restaurant_table/restaurant_table.json b/erpnext/restaurant/doctype/restaurant_table/restaurant_table.json deleted file mode 100644 index 5fc6e62ecb9..00000000000 --- a/erpnext/restaurant/doctype/restaurant_table/restaurant_table.json +++ /dev/null @@ -1,156 +0,0 @@ -{ - "allow_copy": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "", - "beta": 1, - "creation": "2017-09-15 12:45:24.717355", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "Setup", - "editable_grid": 1, - "engine": "InnoDB", - "fields": [ - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "restaurant", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Restaurant", - "length": 0, - "no_copy": 0, - "options": "Restaurant", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "no_of_seats", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "No of Seats", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - }, - { - "allow_bulk_edit": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "1", - "fieldname": "minimum_seating", - "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Minimum Seating", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "unique": 0 - } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2017-12-09 12:13:24.382345", - "modified_by": "Administrator", - "module": "Restaurant", - "name": "Restaurant Table", - "name_case": "", - "owner": "Administrator", - "permissions": [ - { - "amend": 0, - "apply_user_permissions": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Restaurant Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, - "write": 1 - } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "restrict_to_domain": "Hospitality", - "show_name_in_global_search": 0, - "sort_field": "modified", - "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0 -} \ No newline at end of file diff --git a/erpnext/restaurant/doctype/restaurant_table/restaurant_table.py b/erpnext/restaurant/doctype/restaurant_table/restaurant_table.py deleted file mode 100644 index 29f8a1a12b1..00000000000 --- a/erpnext/restaurant/doctype/restaurant_table/restaurant_table.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors -# For license information, please see license.txt - - -import re - -from frappe.model.document import Document -from frappe.model.naming import make_autoname - - -class RestaurantTable(Document): - def autoname(self): - prefix = re.sub('-+', '-', self.restaurant.replace(' ', '-')) - self.name = make_autoname(prefix + '-.##') diff --git a/erpnext/restaurant/doctype/restaurant_table/test_restaurant_table.py b/erpnext/restaurant/doctype/restaurant_table/test_restaurant_table.py deleted file mode 100644 index 00d14d2bb2a..00000000000 --- a/erpnext/restaurant/doctype/restaurant_table/test_restaurant_table.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - -import unittest - -test_records = [ - dict(restaurant='Test Restaurant 1', no_of_seats=5, minimum_seating=1), - dict(restaurant='Test Restaurant 1', no_of_seats=5, minimum_seating=1), - dict(restaurant='Test Restaurant 1', no_of_seats=5, minimum_seating=1), - dict(restaurant='Test Restaurant 1', no_of_seats=5, minimum_seating=1), -] - -class TestRestaurantTable(unittest.TestCase): - pass diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index b7f74df105d..7742f26ad11 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -142,7 +142,7 @@ class Customer(TransactionBase): self.update_lead_status() if self.flags.is_new_doc: - self.create_lead_address_contact() + self.link_lead_address_and_contact() self.update_customer_groups() @@ -176,62 +176,24 @@ class Customer(TransactionBase): if self.lead_name: frappe.db.set_value("Lead", self.lead_name, "status", "Converted") - def create_lead_address_contact(self): + def link_lead_address_and_contact(self): if self.lead_name: - # assign lead address to customer (if already not set) - address_names = frappe.get_all('Dynamic Link', filters={ - "parenttype":"Address", - "link_doctype":"Lead", - "link_name":self.lead_name - }, fields=["parent as name"]) + # assign lead address and contact to customer (if already not set) + linked_contacts_and_addresses = frappe.get_all( + "Dynamic Link", + filters=[ + ["parenttype", "in", ["Contact", "Address"]], + ["link_doctype", "=", "Lead"], + ["link_name", "=", self.lead_name], + ], + fields=["parent as name", "parenttype as doctype"], + ) - for address_name in address_names: - address = frappe.get_doc('Address', address_name.get('name')) - if not address.has_link('Customer', self.name): - address.append('links', dict(link_doctype='Customer', link_name=self.name)) - address.save(ignore_permissions=self.flags.ignore_permissions) - - lead = frappe.db.get_value("Lead", self.lead_name, ["company_name", "lead_name", "email_id", "phone", "mobile_no", "gender", "salutation"], as_dict=True) - - if not lead.lead_name: - frappe.throw(_("Please mention the Lead Name in Lead {0}").format(self.lead_name)) - - contact_names = frappe.get_all('Dynamic Link', filters={ - "parenttype":"Contact", - "link_doctype":"Lead", - "link_name":self.lead_name - }, fields=["parent as name"]) - - for contact_name in contact_names: - contact = frappe.get_doc('Contact', contact_name.get('name')) - if not contact.has_link('Customer', self.name): - contact.append('links', dict(link_doctype='Customer', link_name=self.name)) - contact.save(ignore_permissions=self.flags.ignore_permissions) - - if not contact_names: - lead.lead_name = lead.lead_name.lstrip().split(" ") - lead.first_name = lead.lead_name[0] - lead.last_name = " ".join(lead.lead_name[1:]) - - # create contact from lead - contact = frappe.new_doc('Contact') - contact.first_name = lead.first_name - contact.last_name = lead.last_name - contact.gender = lead.gender - contact.salutation = lead.salutation - contact.email_id = lead.email_id - contact.phone = lead.phone - contact.mobile_no = lead.mobile_no - contact.is_primary_contact = 1 - contact.append('links', dict(link_doctype='Customer', link_name=self.name)) - if lead.email_id: - contact.append('email_ids', dict(email_id=lead.email_id, is_primary=1)) - if lead.mobile_no: - contact.append('phone_nos', dict(phone=lead.mobile_no, is_primary_mobile_no=1)) - contact.flags.ignore_permissions = self.flags.ignore_permissions - contact.autoname() - if not frappe.db.exists("Contact", contact.name): - contact.insert() + for row in linked_contacts_and_addresses: + linked_doc = frappe.get_doc(row.doctype, row.name) + if not linked_doc.has_link('Customer', self.name): + linked_doc.append('links', dict(link_doctype='Customer', link_name=self.name)) + linked_doc.save(ignore_permissions=self.flags.ignore_permissions) def validate_name_with_customer_group(self): if frappe.db.exists("Customer Group", self.name): @@ -296,30 +258,6 @@ class Customer(TransactionBase): .format(frappe.bold(self.customer_name)) ) - def create_onboarding_docs(self, args): - defaults = frappe.defaults.get_defaults() - company = defaults.get('company') or \ - frappe.db.get_single_value('Global Defaults', 'default_company') - - for i in range(1, args.get('max_count')): - customer = args.get('customer_name_' + str(i)) - if customer: - try: - doc = frappe.get_doc({ - 'doctype': self.doctype, - 'customer_name': customer, - 'customer_type': 'Company', - 'customer_group': _('Commercial'), - 'territory': defaults.get('country'), - 'company': company - }).insert() - - if args.get('customer_email_' + str(i)): - create_contact(customer, self.doctype, - doc.name, args.get("customer_email_" + str(i))) - except frappe.NameError: - pass - def create_contact(contact, party_type, party, email): """Create contact based on given contact name""" contact = contact.split(' ') diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 5301fd0524d..165ee818729 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -4,12 +4,13 @@ import frappe from frappe.test_runner import make_test_records +from frappe.tests.utils import FrappeTestCase from frappe.utils import flt from erpnext.accounts.party import get_due_date from erpnext.exceptions import PartyDisabled, PartyFrozen from erpnext.selling.doctype.customer.customer import get_credit_limit, get_customer_outstanding -from erpnext.tests.utils import ERPNextTestCase, create_test_contact_and_address +from erpnext.tests.utils import create_test_contact_and_address test_ignore = ["Price List"] test_dependencies = ['Payment Term', 'Payment Terms Template'] @@ -17,7 +18,7 @@ test_records = frappe.get_test_records('Customer') -class TestCustomer(ERPNextTestCase): +class TestCustomer(FrappeTestCase): def setUp(self): if not frappe.get_value('Item', '_Test Item'): make_test_records('Item') diff --git a/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py b/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py index b951044f332..9b672b4b5d3 100644 --- a/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py +++ b/erpnext/selling/doctype/party_specific_item/test_party_specific_item.py @@ -1,12 +1,10 @@ # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest - import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.controllers.queries import item_query -from erpnext.tests.utils import ERPNextTestCase test_dependencies = ['Item', 'Customer', 'Supplier'] @@ -18,7 +16,7 @@ def create_party_specific_item(**args): psi.based_on_value = args.get('based_on_value') psi.insert() -class TestPartySpecificItem(ERPNextTestCase): +class TestPartySpecificItem(FrappeTestCase): def setUp(self): self.customer = frappe.get_last_doc("Customer") self.supplier = frappe.get_last_doc("Supplier") diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index daab6fbb8f9..eebde766d32 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -287,7 +287,7 @@ def _make_customer(source_name, ignore_permissions=False): customer = frappe.get_doc(customer_doclist) customer.flags.ignore_permissions = ignore_permissions if quotation.get("party_name") == "Shopping Cart": - customer.customer_group = frappe.db.get_value("Shopping Cart Settings", None, + customer.customer_group = frappe.db.get_value("E Commerce Settings", None, "default_customer_group") try: diff --git a/erpnext/selling/doctype/quotation/quotation_list.js b/erpnext/selling/doctype/quotation/quotation_list.js index b631685bd19..4c8f9c4f84c 100644 --- a/erpnext/selling/doctype/quotation/quotation_list.js +++ b/erpnext/selling/doctype/quotation/quotation_list.js @@ -12,6 +12,14 @@ frappe.listview_settings['Quotation'] = { }; }; } + + listview.page.add_action_item(__("Sales Order"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Quotation", "Sales Order"); + }); + + listview.page.add_action_item(__("Sales Invoice"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Quotation", "Sales Invoice"); + }); }, get_indicator: function(doc) { diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py index 4357201d23d..a749d9e1f1f 100644 --- a/erpnext/selling/doctype/quotation/test_quotation.py +++ b/erpnext/selling/doctype/quotation/test_quotation.py @@ -2,14 +2,13 @@ # License: GNU General Public License v3. See license.txt import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import add_days, add_months, flt, getdate, nowdate -from erpnext.tests.utils import ERPNextTestCase - test_dependencies = ["Product Bundle"] -class TestQuotation(ERPNextTestCase): +class TestQuotation(FrappeTestCase): def test_make_quotation_without_terms(self): quotation = make_quotation(do_not_save=1) self.assertFalse(quotation.get('payment_schedule')) diff --git a/erpnext/selling/doctype/quotation_item/quotation_item.json b/erpnext/selling/doctype/quotation_item/quotation_item.json index 8b53902d32f..31a95896bc1 100644 --- a/erpnext/selling/doctype/quotation_item/quotation_item.json +++ b/erpnext/selling/doctype/quotation_item/quotation_item.json @@ -649,7 +649,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-02-23 01:13:54.670763", + "modified": "2021-07-15 12:40:51.074820", "modified_by": "Administrator", "module": "Selling", "name": "Quotation Item", diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 79e9e17e414..eb98e6c0bf8 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -457,12 +457,8 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex make_delivery_note_based_on_delivery_date() { var me = this; - var delivery_dates = []; - $.each(this.frm.doc.items || [], function(i, d) { - if(!delivery_dates.includes(d.delivery_date)) { - delivery_dates.push(d.delivery_date); - } - }); + var delivery_dates = this.frm.doc.items.map(i => i.delivery_date); + delivery_dates = [ ...new Set(delivery_dates) ]; var item_grid = this.frm.fields_dict["items"].grid; if(!item_grid.get_selected().length && delivery_dates.length > 1) { @@ -500,14 +496,7 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex if(!dates) return; - $.each(dates, function(i, d) { - $.each(item_grid.grid_rows || [], function(j, row) { - if(row.doc.delivery_date == d) { - row.doc.__checked = 1; - } - }); - }) - me.make_delivery_note(); + me.make_delivery_note(dates); dialog.hide(); }); dialog.show(); @@ -516,10 +505,13 @@ erpnext.selling.SalesOrderController = class SalesOrderController extends erpnex } } - make_delivery_note() { + make_delivery_note(delivery_dates) { frappe.model.open_mapped_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note", - frm: this.frm + frm: this.frm, + args: { + delivery_dates + } }) } diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index cc951850a4a..0f5b1e3b89c 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -565,6 +565,13 @@ def make_delivery_note(source_name, target_doc=None, skip_item_mapping=False): } if not skip_item_mapping: + def condition(doc): + # make_mapped_doc sets js `args` into `frappe.flags.args` + if frappe.flags.args and frappe.flags.args.delivery_dates: + if cstr(doc.delivery_date) not in frappe.flags.args.delivery_dates: + return False + return abs(doc.delivered_qty) < abs(doc.qty) and doc.delivered_by_supplier!=1 + mapper["Sales Order Item"] = { "doctype": "Delivery Note Item", "field_map": { @@ -573,7 +580,7 @@ def make_delivery_note(source_name, target_doc=None, skip_item_mapping=False): "parent": "against_sales_order", }, "postprocess": update_item, - "condition": lambda doc: abs(doc.delivered_qty) < abs(doc.qty) and doc.delivered_by_supplier!=1 + "condition": condition } target_doc = get_mapped_doc("Sales Order", source_name, mapper, target_doc, set_missing_values) diff --git a/erpnext/selling/doctype/sales_order/sales_order_list.js b/erpnext/selling/doctype/sales_order/sales_order_list.js index 26d96d59f29..4691190d2a5 100644 --- a/erpnext/selling/doctype/sales_order/sales_order_list.js +++ b/erpnext/selling/doctype/sales_order/sales_order_list.js @@ -16,7 +16,7 @@ frappe.listview_settings['Sales Order'] = { return [__("Overdue"), "red", "per_delivered,<,100|delivery_date,<,Today|status,!=,Closed"]; } else if (flt(doc.grand_total) === 0) { - // not delivered (zero-amount order) + // not delivered (zeroount order) return [__("To Deliver"), "orange", "per_delivered,<,100|grand_total,=,0|status,!=,Closed"]; } else if (flt(doc.per_billed, 6) < 100) { @@ -48,5 +48,17 @@ frappe.listview_settings['Sales Order'] = { listview.call_for_selected_items(method, {"status": "Submitted"}); }); + listview.page.add_action_item(__("Sales Invoice"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Sales Invoice"); + }); + + listview.page.add_action_item(__("Delivery Note"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Delivery Note"); + }); + + listview.page.add_action_item(__("Advance Payment"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Sales Order", "Advance Payment"); + }); + } }; diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py index 42bc0b70f8e..f5a34c0eec3 100644 --- a/erpnext/selling/doctype/sales_order/test_sales_order.py +++ b/erpnext/selling/doctype/sales_order/test_sales_order.py @@ -6,7 +6,8 @@ import json import frappe import frappe.permissions from frappe.core.doctype.user_permission.test_user_permission import create_user -from frappe.utils import add_days, flt, getdate, nowdate +from frappe.tests.utils import FrappeTestCase +from frappe.utils import add_days, flt, getdate, nowdate, today from erpnext.controllers.accounts_controller import update_child_qty_rate from erpnext.maintenance.doctype.maintenance_schedule.test_maintenance_schedule import ( @@ -27,10 +28,9 @@ from erpnext.selling.doctype.sales_order.sales_order import ( ) from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry -from erpnext.tests.utils import ERPNextTestCase -class TestSalesOrder(ERPNextTestCase): +class TestSalesOrder(FrappeTestCase): @classmethod def setUpClass(cls): @@ -1375,6 +1375,72 @@ class TestSalesOrder(ERPNextTestCase): automatically_fetch_payment_terms(enable=0) + def test_zero_amount_sales_order_billing_status(self): + from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice + + so = make_sales_order(uom="Nos", do_not_save=1) + so.items[0].rate = 0 + so.save() + so.submit() + + self.assertEqual(so.net_total, 0) + self.assertEqual(so.billing_status, 'Not Billed') + + si = create_sales_invoice(qty=10, do_not_save=1) + si.price_list = '_Test Price List' + si.items[0].rate = 0 + si.items[0].price_list_rate = 0 + si.items[0].sales_order = so.name + si.items[0].so_detail = so.items[0].name + si.save() + si.submit() + + self.assertEqual(si.net_total, 0) + so.load_from_db() + self.assertEqual(so.billing_status, 'Fully Billed') + + def test_so_back_updated_from_wo_via_mr(self): + "SO -> MR (Manufacture) -> WO. Test if WO Qty is updated in SO." + from erpnext.manufacturing.doctype.work_order.work_order import ( + make_stock_entry as make_se_from_wo, + ) + from erpnext.stock.doctype.material_request.material_request import raise_work_orders + + so = make_sales_order(item_list=[{"item_code": "_Test FG Item","qty": 2, "rate":100}]) + + mr = make_material_request(so.name) + mr.material_request_type = "Manufacture" + mr.schedule_date = today() + mr.submit() + + # WO from MR + wo_name = raise_work_orders(mr.name)[0] + wo = frappe.get_doc("Work Order", wo_name) + wo.wip_warehouse = "Work In Progress - _TC" + wo.skip_transfer = True + + self.assertEqual(wo.sales_order, so.name) + self.assertEqual(wo.sales_order_item, so.items[0].name) + + wo.submit() + make_stock_entry(item_code="_Test Item", # Stock RM + target="Work In Progress - _TC", + qty=4, basic_rate=100 + ) + make_stock_entry(item_code="_Test Item Home Desktop 100", # Stock RM + target="Work In Progress - _TC", + qty=4, basic_rate=100 + ) + + se = frappe.get_doc(make_se_from_wo(wo.name, "Manufacture", 2)) + se.submit() # Finish WO + + mr.reload() + wo.reload() + so.reload() + self.assertEqual(so.items[0].work_order_qty, wo.produced_qty) + self.assertEqual(mr.status, "Manufactured") + def automatically_fetch_payment_terms(enable=1): accounts_settings = frappe.get_doc("Accounts Settings") accounts_settings.automatically_fetch_payment_terms = enable diff --git a/erpnext/selling/doctype/sales_order_item/sales_order_item.json b/erpnext/selling/doctype/sales_order_item/sales_order_item.json index 95f6c4e96df..7e55499533b 100644 --- a/erpnext/selling/doctype/sales_order_item/sales_order_item.json +++ b/erpnext/selling/doctype/sales_order_item/sales_order_item.json @@ -793,6 +793,7 @@ }, { "default": "0", + "fetch_from": "item_code.grant_commission", "fieldname": "grant_commission", "fieldtype": "Check", "label": "Grant Commission", @@ -802,7 +803,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-10-05 12:27:25.014789", + "modified": "2022-02-24 14:41:57.325799", "modified_by": "Administrator", "module": "Selling", "name": "Sales Order Item", @@ -811,5 +812,6 @@ "permissions": [], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.json b/erpnext/selling/doctype/selling_settings/selling_settings.json index 27bc541d62f..7c4a3f63dcc 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.json +++ b/erpnext/selling/doctype/selling_settings/selling_settings.json @@ -80,7 +80,7 @@ "description": "How often should Project and Company be updated based on Sales Transactions?", "fieldname": "sales_update_frequency", "fieldtype": "Select", - "label": "Sales Update Frequency", + "label": "Sales Update Frequency in Company and Project", "options": "Each Transaction\nDaily\nMonthly", "reqd": 1 }, @@ -171,7 +171,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-09-13 12:32:17.004404", + "modified": "2022-02-04 15:41:59.939261", "modified_by": "Administrator", "module": "Selling", "name": "Selling Settings", @@ -189,5 +189,6 @@ ], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/selling/doctype/selling_settings/selling_settings.py b/erpnext/selling/doctype/selling_settings/selling_settings.py index fb86e614b6c..e1ef63578e9 100644 --- a/erpnext/selling/doctype/selling_settings/selling_settings.py +++ b/erpnext/selling/doctype/selling_settings/selling_settings.py @@ -16,7 +16,7 @@ class SellingSettings(Document): self.toggle_editable_rate_for_bundle_items() def validate(self): - for key in ["cust_master_name", "campaign_naming_by", "customer_group", "territory", + for key in ["cust_master_name", "customer_group", "territory", "maintain_same_sales_rate", "editable_price_list_rate", "selling_price_list"]: frappe.db.set_default(key, self.get(key, "")) diff --git a/erpnext/selling/onboarding_slide/add_a_few_customers/add_a_few_customers.json b/erpnext/selling/onboarding_slide/add_a_few_customers/add_a_few_customers.json deleted file mode 100644 index 92d00bcb380..00000000000 --- a/erpnext/selling/onboarding_slide/add_a_few_customers/add_a_few_customers.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "add_more_button": 1, - "app": "ERPNext", - "creation": "2019-11-15 14:44:10.065014", - "docstatus": 0, - "doctype": "Onboarding Slide", - "domains": [], - "help_links": [ - { - "label": "Learn More", - "video_id": "zsrrVDk6VBs" - } - ], - "idx": 0, - "image_src": "", - "is_completed": 0, - "max_count": 3, - "modified": "2019-12-09 17:54:01.686006", - "modified_by": "Administrator", - "name": "Add A Few Customers", - "owner": "Administrator", - "ref_doctype": "Customer", - "slide_desc": "", - "slide_fields": [ - { - "align": "", - "fieldname": "customer_name", - "fieldtype": "Data", - "label": "Customer Name", - "placeholder": "", - "reqd": 1 - }, - { - "align": "", - "fieldtype": "Column Break", - "reqd": 0 - }, - { - "align": "", - "fieldname": "customer_email", - "fieldtype": "Data", - "label": "Email ID", - "reqd": 1 - } - ], - "slide_order": 40, - "slide_title": "Add A Few Customers", - "slide_type": "Create" -} \ No newline at end of file diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index db5b20e3e19..993c61d5639 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -24,7 +24,7 @@ def search_by_term(search_term, warehouse, price_list): ["name as item_code", "item_name", "description", "stock_uom", "image as item_image", "is_stock_item"], as_dict=1) - item_stock_qty = get_stock_availability(item_code, warehouse) + item_stock_qty, is_stock_item = get_stock_availability(item_code, warehouse) price_list_rate, currency = frappe.db.get_value('Item Price', { 'price_list': price_list, 'item_code': item_code @@ -99,7 +99,6 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te ), {'warehouse': warehouse}, as_dict=1) if items_data: - items_data = filter_service_items(items_data) items = [d.item_code for d in items_data] item_prices_data = frappe.get_all("Item Price", fields = ["item_code", "price_list_rate", "currency"], @@ -112,7 +111,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te for item in items_data: item_code = item.item_code item_price = item_prices.get(item_code) or {} - item_stock_qty = get_stock_availability(item_code, warehouse) + item_stock_qty, is_stock_item = get_stock_availability(item_code, warehouse) row = {} row.update(item) @@ -144,14 +143,6 @@ def search_for_serial_or_batch_or_barcode_number(search_value): return {} -def filter_service_items(items): - for item in items: - if not item['is_stock_item']: - if not frappe.db.exists('Product Bundle', item['item_code']): - items.remove(item) - - return items - def get_conditions(search_term): condition = "(" condition += """item.name like {search_term} diff --git a/erpnext/selling/page/point_of_sale/pos_controller.js b/erpnext/selling/page/point_of_sale/pos_controller.js index ce74f6d0a58..ea8459f970b 100644 --- a/erpnext/selling/page/point_of_sale/pos_controller.js +++ b/erpnext/selling/page/point_of_sale/pos_controller.js @@ -248,7 +248,7 @@ erpnext.PointOfSale.Controller = class { numpad_event: (value, action) => this.update_item_field(value, action), - checkout: () => this.payment.checkout(), + checkout: () => this.save_and_checkout(), edit_cart: () => this.payment.edit_cart(), @@ -630,18 +630,24 @@ erpnext.PointOfSale.Controller = class { } async check_stock_availability(item_row, qty_needed, warehouse) { - const available_qty = (await this.get_available_stock(item_row.item_code, warehouse)).message; + const resp = (await this.get_available_stock(item_row.item_code, warehouse)).message; + const available_qty = resp[0]; + const is_stock_item = resp[1]; frappe.dom.unfreeze(); const bold_item_code = item_row.item_code.bold(); const bold_warehouse = warehouse.bold(); const bold_available_qty = available_qty.toString().bold() if (!(available_qty > 0)) { - frappe.model.clear_doc(item_row.doctype, item_row.name); - frappe.throw({ - title: __("Not Available"), - message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse]) - }) + if (is_stock_item) { + frappe.model.clear_doc(item_row.doctype, item_row.name); + frappe.throw({ + title: __("Not Available"), + message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse]) + }); + } else { + return; + } } else if (available_qty < qty_needed) { frappe.throw({ message: __('Stock quantity not enough for Item Code: {0} under warehouse {1}. Available quantity {2}.', [bold_item_code, bold_warehouse, bold_available_qty]), @@ -675,8 +681,8 @@ erpnext.PointOfSale.Controller = class { }, callback(res) { if (!me.item_stock_map[item_code]) - me.item_stock_map[item_code] = {} - me.item_stock_map[item_code][warehouse] = res.message; + me.item_stock_map[item_code] = {}; + me.item_stock_map[item_code][warehouse] = res.message[0]; } }); } @@ -707,4 +713,9 @@ erpnext.PointOfSale.Controller = class { }) .catch(e => console.log(e)); } + + async save_and_checkout() { + this.frm.is_dirty() && await this.frm.save(); + this.payment.checkout(); + } }; diff --git a/erpnext/selling/page/point_of_sale/pos_item_cart.js b/erpnext/selling/page/point_of_sale/pos_item_cart.js index 4920584d95e..4a99f068cd5 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_cart.js +++ b/erpnext/selling/page/point_of_sale/pos_item_cart.js @@ -191,10 +191,10 @@ erpnext.PointOfSale.ItemCart = class { this.numpad_value = ''; }); - this.$component.on('click', '.checkout-btn', function() { + this.$component.on('click', '.checkout-btn', async function() { if ($(this).attr('style').indexOf('--blue-500') == -1) return; - me.events.checkout(); + await me.events.checkout(); me.toggle_checkout_btn(false); me.allow_discount_change && me.$add_discount_elem.removeClass("d-none"); @@ -985,6 +985,7 @@ erpnext.PointOfSale.ItemCart = class { $(frm.wrapper).off('refresh-fields'); $(frm.wrapper).on('refresh-fields', () => { if (frm.doc.items.length) { + this.$cart_items_wrapper.html(''); frm.doc.items.forEach(item => { this.update_item_html(item); }); diff --git a/erpnext/selling/page/point_of_sale/pos_item_selector.js b/erpnext/selling/page/point_of_sale/pos_item_selector.js index a30bcd7cf6d..1177615aee9 100644 --- a/erpnext/selling/page/point_of_sale/pos_item_selector.js +++ b/erpnext/selling/page/point_of_sale/pos_item_selector.js @@ -79,14 +79,20 @@ erpnext.PointOfSale.ItemSelector = class { const me = this; // eslint-disable-next-line no-unused-vars const { item_image, serial_no, batch_no, barcode, actual_qty, stock_uom, price_list_rate } = item; - const indicator_color = actual_qty > 10 ? "green" : actual_qty <= 0 ? "red" : "orange"; const precision = flt(price_list_rate, 2) % 1 != 0 ? 2 : 0; - + let indicator_color; let qty_to_display = actual_qty; - if (Math.round(qty_to_display) > 999) { - qty_to_display = Math.round(qty_to_display)/1000; - qty_to_display = qty_to_display.toFixed(1) + 'K'; + if (item.is_stock_item) { + indicator_color = (actual_qty > 10 ? "green" : actual_qty <= 0 ? "red" : "orange"); + + if (Math.round(qty_to_display) > 999) { + qty_to_display = Math.round(qty_to_display)/1000; + qty_to_display = qty_to_display.toFixed(1) + 'K'; + } + } else { + indicator_color = ''; + qty_to_display = ''; } function get_item_image_html() { diff --git a/erpnext/selling/page/point_of_sale/pos_payment.js b/erpnext/selling/page/point_of_sale/pos_payment.js index b9b65591dc7..1e9f6d7d920 100644 --- a/erpnext/selling/page/point_of_sale/pos_payment.js +++ b/erpnext/selling/page/point_of_sale/pos_payment.js @@ -169,6 +169,24 @@ erpnext.PointOfSale.Payment = class { } }); + frappe.ui.form.on('POS Invoice', 'coupon_code', (frm) => { + if (!frm.doc.ignore_pricing_rule && frm.doc.coupon_code) { + frappe.run_serially([ + () => frm.doc.ignore_pricing_rule=1, + () => frm.trigger('ignore_pricing_rule'), + () => frm.doc.ignore_pricing_rule=0, + () => frm.trigger('apply_pricing_rule'), + () => frm.save(), + () => this.update_totals_section(frm.doc) + ]); + } else if (frm.doc.ignore_pricing_rule && frm.doc.coupon_code) { + frappe.show_alert({ + message: __("Ignore Pricing Rule is enabled. Cannot apply coupon code."), + indicator: "orange" + }); + } + }); + this.setup_listener_for_payments(); this.$payment_modes.on('click', '.shortcut', function() { diff --git a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py index 777b02ca66d..dd49f1355d2 100644 --- a/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py +++ b/erpnext/selling/report/customer_credit_balance/customer_credit_balance.py @@ -23,19 +23,24 @@ def execute(filters=None): row = [] outstanding_amt = get_customer_outstanding(d.name, filters.get("company"), - ignore_outstanding_sales_order=d.bypass_credit_limit_check_at_sales_order) + ignore_outstanding_sales_order=d.bypass_credit_limit_check) credit_limit = get_credit_limit(d.name, filters.get("company")) bal = flt(credit_limit) - flt(outstanding_amt) if customer_naming_type == "Naming Series": - row = [d.name, d.customer_name, credit_limit, outstanding_amt, bal, - d.bypass_credit_limit_check, d.is_frozen, - d.disabled] + row = [ + d.name, d.customer_name, credit_limit, + outstanding_amt, bal, d.bypass_credit_limit_check, + d.is_frozen, d.disabled + ] else: - row = [d.name, credit_limit, outstanding_amt, bal, - d.bypass_credit_limit_check_at_sales_order, d.is_frozen, d.disabled] + row = [ + d.name, credit_limit, outstanding_amt, bal, + d.bypass_credit_limit_check, d.is_frozen, + d.disabled + ] if credit_limit: data.append(row) diff --git a/erpnext/non_profit/doctype/grant_application/__init__.py b/erpnext/selling/report/payment_terms_status_for_sales_order/__init__.py similarity index 100% rename from erpnext/non_profit/doctype/grant_application/__init__.py rename to erpnext/selling/report/payment_terms_status_for_sales_order/__init__.py diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js new file mode 100644 index 00000000000..0e36b3fe3d2 --- /dev/null +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.js @@ -0,0 +1,84 @@ +// Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +function get_filters() { + let filters = [ + { + "fieldname":"company", + "label": __("Company"), + "fieldtype": "Link", + "options": "Company", + "default": frappe.defaults.get_user_default("Company"), + "reqd": 1 + }, + { + "fieldname":"period_start_date", + "label": __("Start Date"), + "fieldtype": "Date", + "reqd": 1, + "default": frappe.datetime.add_months(frappe.datetime.get_today(), -1) + }, + { + "fieldname":"period_end_date", + "label": __("End Date"), + "fieldtype": "Date", + "reqd": 1, + "default": frappe.datetime.get_today() + }, + { + "fieldname":"sales_order", + "label": __("Sales Order"), + "fieldtype": "MultiSelectList", + "width": 100, + "options": "Sales Order", + "get_data": function(txt) { + return frappe.db.get_link_options("Sales Order", txt, this.filters()); + }, + "filters": () => { + return { + docstatus: 1, + payment_terms_template: ['not in', ['']], + company: frappe.query_report.get_filter_value("company"), + transaction_date: ['between', [frappe.query_report.get_filter_value("period_start_date"), frappe.query_report.get_filter_value("period_end_date")]] + } + }, + on_change: function(){ + frappe.query_report.refresh(); + } + } + ] + + return filters; +} + +frappe.query_reports["Payment Terms Status for Sales Order"] = { + "filters": get_filters(), + "formatter": function(value, row, column, data, default_formatter){ + if(column.fieldname == 'invoices' && value) { + invoices = value.split(','); + const invoice_formatter = (prev_value, curr_value) => { + if(prev_value != "") { + return prev_value + ", " + default_formatter(curr_value, row, column, data); + } + else { + return default_formatter(curr_value, row, column, data); + } + } + return invoices.reduce(invoice_formatter, "") + } + else if (column.fieldname == 'paid_amount' && value){ + formatted_value = default_formatter(value, row, column, data); + if(value > 0) { + formatted_value = "" + formatted_value + "" + } + return formatted_value; + } + else if (column.fieldname == 'status' && value == 'Completed'){ + return "" + default_formatter(value, row, column, data) + ""; + } + + return default_formatter(value, row, column, data); + }, + +}; diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.json b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.json new file mode 100644 index 00000000000..850fa4dc47a --- /dev/null +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.json @@ -0,0 +1,38 @@ +{ + "add_total_row": 1, + "columns": [], + "creation": "2021-12-28 10:39:34.533964", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "modified": "2021-12-30 10:42:06.058457", + "modified_by": "Administrator", + "module": "Selling", + "name": "Payment Terms Status for Sales Order", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Sales Order", + "report_name": "Payment Terms Status for Sales Order", + "report_type": "Script Report", + "roles": [ + { + "role": "Sales User" + }, + { + "role": "Sales Manager" + }, + { + "role": "Maintenance User" + }, + { + "role": "Accounts User" + }, + { + "role": "Stock User" + } + ] +} \ No newline at end of file diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.py b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.py new file mode 100644 index 00000000000..e6a56eea310 --- /dev/null +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/payment_terms_status_for_sales_order.py @@ -0,0 +1,205 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# License: MIT. See LICENSE + +import frappe +from frappe import _, qb, query_builder +from frappe.query_builder import functions + + +def get_columns(): + columns = [ + { + "label": _("Sales Order"), + "fieldname": "name", + "fieldtype": "Link", + "options": "Sales Order", + }, + { + "label": _("Posting Date"), + "fieldname": "submitted", + "fieldtype": "Date", + }, + { + "label": _("Payment Term"), + "fieldname": "payment_term", + "fieldtype": "Data", + }, + { + "label": _("Description"), + "fieldname": "description", + "fieldtype": "Data", + }, + { + "label": _("Due Date"), + "fieldname": "due_date", + "fieldtype": "Date", + }, + { + "label": _("Invoice Portion"), + "fieldname": "invoice_portion", + "fieldtype": "Percent", + }, + { + "label": _("Payment Amount"), + "fieldname": "base_payment_amount", + "fieldtype": "Currency", + "options": "currency", + }, + { + "label": _("Paid Amount"), + "fieldname": "paid_amount", + "fieldtype": "Currency", + "options": "currency", + }, + { + "label": _("Invoices"), + "fieldname": "invoices", + "fieldtype": "Link", + "options": "Sales Invoice", + }, + { + "label": _("Status"), + "fieldname": "status", + "fieldtype": "Data", + }, + { + "label": _("Currency"), + "fieldname": "currency", + "fieldtype": "Currency", + "hidden": 1 + } + ] + return columns + + +def get_conditions(filters): + """ + Convert filter options to conditions used in query + """ + filters = frappe._dict(filters) if filters else frappe._dict({}) + conditions = frappe._dict({}) + + conditions.company = filters.company or frappe.defaults.get_user_default("company") + conditions.end_date = filters.period_end_date or frappe.utils.today() + conditions.start_date = filters.period_start_date or frappe.utils.add_months( + conditions.end_date, -1 + ) + conditions.sales_order = filters.sales_order or [] + + return conditions + + +def get_so_with_invoices(filters): + """ + Get Sales Order with payment terms template with their associated Invoices + """ + sorders = [] + + so = qb.DocType("Sales Order") + ps = qb.DocType("Payment Schedule") + datediff = query_builder.CustomFunction("DATEDIFF", ["cur_date", "due_date"]) + ifelse = query_builder.CustomFunction("IF", ["condition", "then", "else"]) + + conditions = get_conditions(filters) + query_so = ( + qb.from_(so) + .join(ps) + .on(ps.parent == so.name) + .select( + so.name, + so.transaction_date.as_("submitted"), + ifelse(datediff(ps.due_date, functions.CurDate()) < 0, "Overdue", "Unpaid").as_("status"), + ps.payment_term, + ps.description, + ps.due_date, + ps.invoice_portion, + ps.base_payment_amount, + ps.paid_amount, + ) + .where( + (so.docstatus == 1) + & (so.payment_terms_template != "NULL") + & (so.company == conditions.company) + & (so.transaction_date[conditions.start_date : conditions.end_date]) + ) + .orderby(so.name, so.transaction_date, ps.due_date) + ) + + if conditions.sales_order != []: + query_so = query_so.where(so.name.isin(conditions.sales_order)) + + sorders = query_so.run(as_dict=True) + + invoices = [] + if sorders != []: + soi = qb.DocType("Sales Order Item") + si = qb.DocType("Sales Invoice") + sii = qb.DocType("Sales Invoice Item") + query_inv = ( + qb.from_(sii) + .right_join(si) + .on(si.name == sii.parent) + .inner_join(soi) + .on(soi.name == sii.so_detail) + .select(sii.sales_order, sii.parent.as_("invoice"), si.base_grand_total.as_("invoice_amount")) + .where((sii.sales_order.isin([x.name for x in sorders])) & (si.docstatus == 1)) + .groupby(sii.parent) + ) + invoices = query_inv.run(as_dict=True) + + return sorders, invoices + + +def set_payment_terms_statuses(sales_orders, invoices, filters): + """ + compute status for payment terms with associated sales invoice using FIFO + """ + + for so in sales_orders: + so.currency = frappe.get_cached_value('Company', filters.get('company'), 'default_currency') + so.invoices = "" + for inv in [x for x in invoices if x.sales_order == so.name and x.invoice_amount > 0]: + if so.base_payment_amount - so.paid_amount > 0: + amount = so.base_payment_amount - so.paid_amount + if inv.invoice_amount >= amount: + inv.invoice_amount -= amount + so.paid_amount += amount + so.invoices += "," + inv.invoice + so.status = "Completed" + break + else: + so.paid_amount += inv.invoice_amount + inv.invoice_amount = 0 + so.invoices += "," + inv.invoice + so.status = "Partly Paid" + + return sales_orders, invoices + + +def prepare_chart(s_orders): + if len(set([x.name for x in s_orders])) == 1: + chart = { + "data": { + "labels": [term.payment_term for term in s_orders], + "datasets": [ + {"name": "Payment Amount", "values": [x.base_payment_amount for x in s_orders],}, + {"name": "Paid Amount", "values": [x.paid_amount for x in s_orders],}, + ], + }, + "type": "bar", + } + return chart + + +def execute(filters=None): + columns = get_columns() + sales_orders, so_invoices = get_so_with_invoices(filters) + sales_orders, so_invoices = set_payment_terms_statuses(sales_orders, so_invoices, filters) + + prepare_chart(sales_orders) + + data = sales_orders + message = [] + chart = prepare_chart(sales_orders) + + return columns, data, message, chart diff --git a/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py b/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py new file mode 100644 index 00000000000..f7f8a5dbce3 --- /dev/null +++ b/erpnext/selling/report/payment_terms_status_for_sales_order/test_payment_terms_status_for_sales_order.py @@ -0,0 +1,198 @@ +import datetime + +import frappe +from frappe.tests.utils import FrappeTestCase +from frappe.utils import add_days + +from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice +from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.selling.report.payment_terms_status_for_sales_order.payment_terms_status_for_sales_order import ( + execute, +) +from erpnext.stock.doctype.item.test_item import create_item + +test_dependencies = ["Sales Order", "Item", "Sales Invoice", "Payment Terms Template"] + + +class TestPaymentTermsStatusForSalesOrder(FrappeTestCase): + def create_payment_terms_template(self): + # create template for 50-50 payments + template = None + if frappe.db.exists("Payment Terms Template", "_Test 50-50"): + template = frappe.get_doc("Payment Terms Template", "_Test 50-50") + else: + template = frappe.get_doc( + { + "doctype": "Payment Terms Template", + "template_name": "_Test 50-50", + "terms": [ + { + "doctype": "Payment Terms Template Detail", + "due_date_based_on": "Day(s) after invoice date", + "payment_term_name": "_Test 50% on 15 Days", + "description": "_Test 50-50", + "invoice_portion": 50, + "credit_days": 15, + }, + { + "doctype": "Payment Terms Template Detail", + "due_date_based_on": "Day(s) after invoice date", + "payment_term_name": "_Test 50% on 30 Days", + "description": "_Test 50-50", + "invoice_portion": 50, + "credit_days": 30, + }, + ], + } + ) + template.insert() + self.template = template + + def test_payment_terms_status(self): + self.create_payment_terms_template() + item = create_item(item_code="_Test Excavator", is_stock_item=0) + so = make_sales_order( + transaction_date="2021-06-15", + delivery_date=add_days("2021-06-15", -30), + item=item.item_code, + qty=10, + rate=100000, + do_not_save=True, + ) + so.po_no = "" + so.taxes_and_charges = "" + so.taxes = "" + so.payment_terms_template = self.template.name + so.save() + so.submit() + + # make invoice with 60% of the total sales order value + sinv = make_sales_invoice(so.name) + sinv.taxes_and_charges = "" + sinv.taxes = "" + sinv.items[0].qty = 6 + sinv.insert() + sinv.submit() + columns, data, message, chart = execute( + { + "company": "_Test Company", + "period_start_date": "2021-06-01", + "period_end_date": "2021-06-30", + "sales_order": [so.name], + } + ) + + expected_value = [ + { + "name": so.name, + "submitted": datetime.date(2021, 6, 15), + "status": "Completed", + "payment_term": None, + "description": "_Test 50-50", + "due_date": datetime.date(2021, 6, 30), + "invoice_portion": 50.0, + "currency": "INR", + "base_payment_amount": 500000.0, + "paid_amount": 500000.0, + "invoices": ","+sinv.name, + }, + { + "name": so.name, + "submitted": datetime.date(2021, 6, 15), + "status": "Partly Paid", + "payment_term": None, + "description": "_Test 50-50", + "due_date": datetime.date(2021, 7, 15), + "invoice_portion": 50.0, + "currency": "INR", + "base_payment_amount": 500000.0, + "paid_amount": 100000.0, + "invoices": ","+sinv.name, + }, + ] + self.assertEqual(data, expected_value) + + def create_exchange_rate(self, date): + # make an entry in Currency Exchange list. serves as a static exchange rate + if frappe.db.exists({'doctype': "Currency Exchange",'date': date,'from_currency': 'USD', 'to_currency':'INR'}): + return + else: + doc = frappe.get_doc({ + 'doctype': "Currency Exchange", + 'date': date, + 'from_currency': 'USD', + 'to_currency': frappe.get_cached_value("Company", '_Test Company','default_currency'), + 'exchange_rate': 70, + 'for_buying': True, + 'for_selling': True + }) + doc.insert() + + def test_alternate_currency(self): + transaction_date = "2021-06-15" + self.create_payment_terms_template() + self.create_exchange_rate(transaction_date) + item = create_item(item_code="_Test Excavator", is_stock_item=0) + so = make_sales_order( + transaction_date=transaction_date, + currency="USD", + delivery_date=add_days(transaction_date, -30), + item=item.item_code, + qty=10, + rate=10000, + do_not_save=True, + ) + so.po_no = "" + so.taxes_and_charges = "" + so.taxes = "" + so.payment_terms_template = self.template.name + so.save() + so.submit() + + # make invoice with 60% of the total sales order value + sinv = make_sales_invoice(so.name) + sinv.currency = "USD" + sinv.taxes_and_charges = "" + sinv.taxes = "" + sinv.items[0].qty = 6 + sinv.insert() + sinv.submit() + columns, data, message, chart = execute( + { + "company": "_Test Company", + "period_start_date": "2021-06-01", + "period_end_date": "2021-06-30", + "sales_order": [so.name], + } + ) + + # report defaults to company currency. + expected_value = [ + { + "name": so.name, + "submitted": datetime.date(2021, 6, 15), + "status": "Completed", + "payment_term": None, + "description": "_Test 50-50", + "due_date": datetime.date(2021, 6, 30), + "invoice_portion": 50.0, + "currency": frappe.get_cached_value("Company", '_Test Company','default_currency'), + "base_payment_amount": 3500000.0, + "paid_amount": 3500000.0, + "invoices": ","+sinv.name, + }, + { + "name": so.name, + "submitted": datetime.date(2021, 6, 15), + "status": "Partly Paid", + "payment_term": None, + "description": "_Test 50-50", + "due_date": datetime.date(2021, 7, 15), + "invoice_portion": 50.0, + "currency": frappe.get_cached_value("Company", '_Test Company','default_currency'), + "base_payment_amount": 3500000.0, + "paid_amount": 700000.0, + "invoices": ","+sinv.name, + }, + ] + self.assertEqual(data, expected_value) diff --git a/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py b/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py index d62915fc66d..16162acc8f3 100644 --- a/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py +++ b/erpnext/selling/report/pending_so_items_for_purchase_request/test_pending_so_items_for_purchase_request.py @@ -2,6 +2,7 @@ # For license information, please see license.txt +from frappe.tests.utils import FrappeTestCase from frappe.utils import add_months, nowdate from erpnext.selling.doctype.sales_order.sales_order import make_material_request @@ -9,10 +10,9 @@ from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_orde from erpnext.selling.report.pending_so_items_for_purchase_request.pending_so_items_for_purchase_request import ( execute, ) -from erpnext.tests.utils import ERPNextTestCase -class TestPendingSOItemsForPurchaseRequest(ERPNextTestCase): +class TestPendingSOItemsForPurchaseRequest(FrappeTestCase): def test_result_for_partial_material_request(self): so = make_sales_order() mr=make_material_request(so.name) diff --git a/erpnext/selling/report/sales_analytics/test_analytics.py b/erpnext/selling/report/sales_analytics/test_analytics.py index f56cce2dfdc..564f48fef3b 100644 --- a/erpnext/selling/report/sales_analytics/test_analytics.py +++ b/erpnext/selling/report/sales_analytics/test_analytics.py @@ -3,13 +3,13 @@ import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.selling.report.sales_analytics.sales_analytics import execute -from erpnext.tests.utils import ERPNextTestCase -class TestAnalytics(ERPNextTestCase): +class TestAnalytics(FrappeTestCase): def test_sales_analytics(self): frappe.db.sql("delete from `tabSales Order` where company='_Test Company 2'") 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 b2bf5464b5a..3e22d0fa8c8 100644 --- a/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py +++ b/erpnext/selling/report/sales_order_analysis/sales_order_analysis.py @@ -85,7 +85,7 @@ def get_data(conditions, filters): and so.docstatus = 1 {conditions} GROUP BY soi.name - ORDER BY so.transaction_date ASC + ORDER BY so.transaction_date ASC, soi.item_code ASC """.format(conditions=conditions), filters, as_dict=1) return data diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 540aca234bd..98131f96ed4 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -227,11 +227,11 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran }, callback:function(r){ if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { - if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; - - me.set_batch_number(cdt, cdn); - me.batch_no(doc, cdt, cdn); + if (has_batch_no) { + me.set_batch_number(cdt, cdn); + me.batch_no(doc, cdt, cdn); + } } } }); @@ -486,7 +486,7 @@ frappe.ui.form.on(cur_frm.doctype, { "options": "Competitor Detail" }, { - "fieldtype": "Text", + "fieldtype": "Small Text", "label": __("Detailed Reason"), "fieldname": "detailed_reason" }, @@ -499,7 +499,7 @@ frappe.ui.form.on(cur_frm.doctype, { method: 'declare_enquiry_lost', args: { 'lost_reasons_list': values.lost_reason, - 'competitors': values.competitors, + 'competitors': values.competitors ? values.competitors : [], 'detailed_reason': values.detailed_reason }, callback: function(r) { diff --git a/erpnext/setup/doctype/brand/brand.json b/erpnext/setup/doctype/brand/brand.json index a8f0674b1f8..45b4db81f1f 100644 --- a/erpnext/setup/doctype/brand/brand.json +++ b/erpnext/setup/doctype/brand/brand.json @@ -1,270 +1,111 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 1, - "allow_rename": 1, - "autoname": "field:brand", - "beta": 0, - "creation": "2013-02-22 01:27:54", - "custom": 0, - "docstatus": 0, - "doctype": "DocType", - "document_type": "Setup", - "editable_grid": 0, + "actions": [], + "allow_import": 1, + "allow_rename": 1, + "autoname": "field:brand", + "creation": "2013-02-22 01:27:54", + "doctype": "DocType", + "document_type": "Setup", + "engine": "InnoDB", + "field_order": [ + "brand", + "image", + "description", + "defaults", + "brand_defaults" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 1, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "brand", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Brand Name", - "length": 0, - "no_copy": 0, - "oldfieldname": "brand", - "oldfieldtype": "Data", - "permlevel": 0, - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, + "allow_in_quick_entry": 1, + "fieldname": "brand", + "fieldtype": "Data", + "label": "Brand Name", + "oldfieldname": "brand", + "oldfieldtype": "Data", + "reqd": 1, "unique": 1 - }, + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "description", - "fieldtype": "Text", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 1, - "in_standard_filter": 0, - "label": "Description", - "length": 0, - "no_copy": 0, - "oldfieldname": "description", - "oldfieldtype": "Text", - "permlevel": 0, - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0, + "fieldname": "description", + "fieldtype": "Text", + "in_list_view": 1, + "label": "Description", + "oldfieldname": "description", + "oldfieldtype": "Text", "width": "300px" - }, + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "defaults", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Defaults", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 - }, + "fieldname": "defaults", + "fieldtype": "Section Break", + "label": "Defaults" + }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "brand_defaults", - "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Brand Defaults", - "length": 0, - "no_copy": 0, - "options": "Item Default", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldname": "brand_defaults", + "fieldtype": "Table", + "label": "Brand Defaults", + "options": "Item Default" + }, + { + "fieldname": "image", + "fieldtype": "Attach Image", + "hidden": 1, + "label": "Image" } - ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "icon": "fa fa-certificate", - "idx": 1, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2018-10-23 23:18:06.067612", - "modified_by": "Administrator", - "module": "Setup", - "name": "Brand", - "owner": "Administrator", + ], + "icon": "fa fa-certificate", + "idx": 1, + "image_field": "image", + "links": [], + "modified": "2021-03-01 15:57:30.005783", + "modified_by": "Administrator", + "module": "Setup", + "name": "Brand", + "owner": "Administrator", "permissions": [ { - "amend": 0, - "cancel": 0, - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "if_owner": 0, - "import": 1, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Item Manager", - "set_user_permissions": 0, - "share": 1, - "submit": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "import": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Item Manager", + "share": 1, "write": 1 - }, + }, { - "amend": 0, - "cancel": 0, - "create": 0, - "delete": 0, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Stock User", - "set_user_permissions": 0, - "share": 0, - "submit": 0, - "write": 0 - }, + "email": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Stock User" + }, { - "amend": 0, - "cancel": 0, - "create": 0, - "delete": 0, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Sales User", - "set_user_permissions": 0, - "share": 0, - "submit": 0, - "write": 0 - }, + "email": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Sales User" + }, { - "amend": 0, - "cancel": 0, - "create": 0, - "delete": 0, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Purchase User", - "set_user_permissions": 0, - "share": 0, - "submit": 0, - "write": 0 - }, + "email": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Purchase User" + }, { - "amend": 0, - "cancel": 0, - "create": 0, - "delete": 0, - "email": 1, - "export": 0, - "if_owner": 0, - "import": 0, - "permlevel": 0, - "print": 1, - "read": 1, - "report": 1, - "role": "Accounts User", - "set_user_permissions": 0, - "share": 0, - "submit": 0, - "write": 0 + "email": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User" } - ], - "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 1, - "sort_order": "ASC", - "track_changes": 0, - "track_seen": 0, - "track_views": 0 -} + ], + "quick_entry": 1, + "show_name_in_global_search": 1, + "sort_field": "modified", + "sort_order": "ASC" +} \ No newline at end of file diff --git a/erpnext/setup/doctype/company/company.json b/erpnext/setup/doctype/company/company.json index 63d96bf85e7..370a3278a01 100644 --- a/erpnext/setup/doctype/company/company.json +++ b/erpnext/setup/doctype/company/company.json @@ -3,7 +3,7 @@ "allow_import": 1, "allow_rename": 1, "autoname": "field:company_name", - "creation": "2013-04-10 08:35:39", + "creation": "2022-01-25 10:29:55.938239", "description": "Legal Entity / Subsidiary with a separate Chart of Accounts belonging to the Organization.", "doctype": "DocType", "document_type": "Setup", @@ -77,13 +77,13 @@ "default_finance_book", "auto_accounting_for_stock_settings", "enable_perpetual_inventory", - "enable_perpetual_inventory_for_non_stock_items", + "enable_provisional_accounting_for_non_stock_items", "default_inventory_account", "stock_adjustment_account", "default_in_transit_warehouse", "column_break_32", "stock_received_but_not_billed", - "service_received_but_not_billed", + "default_provisional_account", "expenses_included_in_valuation", "fixed_asset_defaults", "accumulated_depreciation_account", @@ -684,20 +684,6 @@ "label": "Default Buying Terms", "options": "Terms and Conditions" }, - { - "fieldname": "service_received_but_not_billed", - "fieldtype": "Link", - "ignore_user_permissions": 1, - "label": "Service Received But Not Billed", - "no_copy": 1, - "options": "Account" - }, - { - "default": "0", - "fieldname": "enable_perpetual_inventory_for_non_stock_items", - "fieldtype": "Check", - "label": "Enable Perpetual Inventory For Non Stock Items" - }, { "fieldname": "default_in_transit_warehouse", "fieldtype": "Link", @@ -741,6 +727,20 @@ "fieldname": "section_break_28", "fieldtype": "Section Break", "label": "Chart of Accounts" + }, + { + "default": "0", + "fieldname": "enable_provisional_accounting_for_non_stock_items", + "fieldtype": "Check", + "label": "Enable Provisional Accounting For Non Stock Items" + }, + { + "fieldname": "default_provisional_account", + "fieldtype": "Link", + "ignore_user_permissions": 1, + "label": "Default Provisional Account", + "no_copy": 1, + "options": "Account" } ], "icon": "fa fa-building", @@ -748,7 +748,7 @@ "image_field": "company_logo", "is_tree": 1, "links": [], - "modified": "2021-10-04 12:09:25.833133", + "modified": "2022-01-25 10:33:16.826067", "modified_by": "Administrator", "module": "Setup", "name": "Company", @@ -809,5 +809,6 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "ASC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index 0a02bcd6cd9..95b1e8b9c63 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -10,6 +10,7 @@ import frappe.defaults from frappe import _ from frappe.cache_manager import clear_defaults_cache from frappe.contacts.address_and_contact import load_address_and_contact +from frappe.custom.doctype.property_setter.property_setter import make_property_setter from frappe.utils import cint, formatdate, get_timestamp, today from frappe.utils.nestedset import NestedSet @@ -45,7 +46,7 @@ class Company(NestedSet): self.validate_currency() self.validate_coa_input() self.validate_perpetual_inventory() - self.validate_perpetual_inventory_for_non_stock_items() + self.validate_provisional_account_for_non_stock_items() self.check_country_change() self.check_parent_changed() self.set_chart_of_accounts() @@ -187,11 +188,14 @@ class Company(NestedSet): frappe.msgprint(_("Set default inventory account for perpetual inventory"), alert=True, indicator='orange') - def validate_perpetual_inventory_for_non_stock_items(self): + def validate_provisional_account_for_non_stock_items(self): if not self.get("__islocal"): - if cint(self.enable_perpetual_inventory_for_non_stock_items) == 1 and not self.service_received_but_not_billed: - frappe.throw(_("Set default {0} account for perpetual inventory for non stock items").format( - frappe.bold('Service Received But Not Billed'))) + if cint(self.enable_provisional_accounting_for_non_stock_items) == 1 and not self.default_provisional_account: + frappe.throw(_("Set default {0} account for non stock items").format( + frappe.bold('Provisional Account'))) + + make_property_setter("Purchase Receipt", "provisional_expense_account", "hidden", + not self.enable_provisional_accounting_for_non_stock_items, "Check", validate_fields_for_doctype=False) def check_country_change(self): frappe.flags.country_change = False diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index c94b3463fc8..4f92240c84f 100644 --- a/erpnext/setup/doctype/item_group/item_group.py +++ b/erpnext/setup/doctype/item_group/item_group.py @@ -1,21 +1,17 @@ -# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt - import copy +from urllib.parse import quote import frappe from frappe import _ -from frappe.utils import cint, cstr, nowdate +from frappe.utils import cint from frappe.utils.nestedset import NestedSet from frappe.website.utils import clear_cache from frappe.website.website_generator import WebsiteGenerator -from six.moves.urllib.parse import quote -from erpnext.shopping_cart.filters import ProductFiltersBuilder -from erpnext.shopping_cart.product_info import set_product_info_for_website -from erpnext.shopping_cart.product_query import ProductQuery -from erpnext.utilities.product import get_qty_in_stock +from erpnext.e_commerce.product_data_engine.filters import ProductFiltersBuilder class ItemGroup(NestedSet, WebsiteGenerator): @@ -67,30 +63,11 @@ class ItemGroup(NestedSet, WebsiteGenerator): self.delete_child_item_groups_key() def get_context(self, context): - context.show_search=True - context.page_length = cint(frappe.db.get_single_value('Products Settings', 'products_per_page')) or 6 + context.show_search = True + context.body_class = "product-page" + context.page_length = cint(frappe.db.get_single_value('E Commerce Settings', 'products_per_page')) or 6 context.search_link = '/product_search' - if frappe.form_dict: - search = frappe.form_dict.search - field_filters = frappe.parse_json(frappe.form_dict.field_filters) - attribute_filters = frappe.parse_json(frappe.form_dict.attribute_filters) - start = frappe.parse_json(frappe.form_dict.start) - else: - search = None - attribute_filters = None - field_filters = {} - start = 0 - - if not field_filters: - field_filters = {} - - # Ensure the query remains within current item group & sub group - field_filters['item_group'] = [ig[0] for ig in get_child_groups(self.name)] - - engine = ProductQuery() - context.items = engine.query(attribute_filters, field_filters, search, start, item_group=self.name) - filter_engine = ProductFiltersBuilder(self.name) context.field_filters = filter_engine.get_field_filters() @@ -114,15 +91,16 @@ class ItemGroup(NestedSet, WebsiteGenerator): values[f"slide_{index + 1}_image"] = slide.image values[f"slide_{index + 1}_title"] = slide.heading values[f"slide_{index + 1}_subtitle"] = slide.description - values[f"slide_{index + 1}_theme"] = slide.theme or "Light" - values[f"slide_{index + 1}_content_align"] = slide.content_align or "Centre" - values[f"slide_{index + 1}_primary_action_label"] = slide.label + values[f"slide_{index + 1}_theme"] = slide.get("theme") or "Light" + values[f"slide_{index + 1}_content_align"] = slide.get("content_align") or "Centre" values[f"slide_{index + 1}_primary_action"] = slide.url context.slideshow = values - context.breadcrumbs = 0 + context.no_breadcrumbs = False context.title = self.website_title or self.name + context.name = self.name + context.item_group_name = self.item_group_name return context @@ -133,91 +111,24 @@ class ItemGroup(NestedSet, WebsiteGenerator): from erpnext.stock.doctype.item.item import validate_item_default_company_links validate_item_default_company_links(self.item_group_defaults) -@frappe.whitelist(allow_guest=True) -def get_product_list_for_group(product_group=None, start=0, limit=10, search=None): - if product_group: - item_group = frappe.get_cached_doc('Item Group', product_group) - if item_group.is_group: - # return child item groups if the type is of "Is Group" - return get_child_groups_for_list_in_html(item_group, start, limit, search) +def get_child_groups_for_website(item_group_name, immediate=False): + """Returns child item groups *excluding* passed group.""" + item_group = frappe.get_cached_value("Item Group", item_group_name, ["lft", "rgt"], as_dict=1) + filters = { + "lft": [">", item_group.lft], + "rgt": ["<", item_group.rgt], + "show_in_website": 1 + } - child_groups = ", ".join(frappe.db.escape(i[0]) for i in get_child_groups(product_group)) + if immediate: + filters["parent_item_group"] = item_group_name - # base query - query = """select I.name, I.item_name, I.item_code, I.route, I.image, I.website_image, I.thumbnail, I.item_group, - I.description, I.web_long_description as website_description, I.is_stock_item, - case when (S.actual_qty - S.reserved_qty) > 0 then 1 else 0 end as in_stock, I.website_warehouse, - I.has_batch_no - from `tabItem` I - left join tabBin S on I.item_code = S.item_code and I.website_warehouse = S.warehouse - where I.show_in_website = 1 - and I.disabled = 0 - and (I.end_of_life is null or I.end_of_life='0000-00-00' or I.end_of_life > %(today)s) - and (I.variant_of = '' or I.variant_of is null) - and (I.item_group in ({child_groups}) - or I.name in (select parent from `tabWebsite Item Group` where item_group in ({child_groups}))) - """.format(child_groups=child_groups) - # search term condition - if search: - query += """ and (I.web_long_description like %(search)s - or I.item_name like %(search)s - or I.name like %(search)s)""" - search = "%" + cstr(search) + "%" - - query += """order by I.weightage desc, in_stock desc, I.modified desc limit %s, %s""" % (cint(start), cint(limit)) - - data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1) - data = adjust_qty_for_expired_items(data) - - if cint(frappe.db.get_single_value("Shopping Cart Settings", "enabled")): - for item in data: - set_product_info_for_website(item) - - return data - -def get_child_groups_for_list_in_html(item_group, start, limit, search): - search_filters = None - if search_filters: - search_filters = [ - dict(name = ('like', '%{}%'.format(search))), - dict(description = ('like', '%{}%'.format(search))) - ] - data = frappe.db.get_all('Item Group', - fields = ['name', 'route', 'description', 'image'], - filters = dict( - show_in_website = 1, - parent_item_group = item_group.name, - lft = ('>', item_group.lft), - rgt = ('<', item_group.rgt), - ), - or_filters = search_filters, - order_by = 'weightage desc, name asc', - start = start, - limit = limit + return frappe.get_all( + "Item Group", + filters=filters, + fields=["name", "route"] ) - return data - -def adjust_qty_for_expired_items(data): - adjusted_data = [] - - for item in data: - if item.get('has_batch_no') and item.get('website_warehouse'): - stock_qty_dict = get_qty_in_stock( - item.get('name'), 'website_warehouse', item.get('website_warehouse')) - qty = stock_qty_dict.stock_qty[0][0] if stock_qty_dict.stock_qty else 0 - item['in_stock'] = 1 if qty else 0 - adjusted_data.append(item) - - return adjusted_data - - -def get_child_groups(item_group_name): - item_group = frappe.get_doc("Item Group", item_group_name) - return frappe.db.sql("""select name - from `tabItem Group` where lft>=%(lft)s and rgt<=%(rgt)s - and show_in_website = 1""", {"lft": item_group.lft, "rgt": item_group.rgt}) - def get_child_item_groups(item_group_name): item_group = frappe.get_cached_value("Item Group", item_group_name, ["lft", "rgt"], as_dict=1) @@ -233,31 +144,33 @@ def get_item_for_list_in_html(context): if (context.get("website_image") or "").startswith("files/"): context["website_image"] = "/" + quote(context["website_image"]) - context["show_availability_status"] = cint(frappe.db.get_single_value('Products Settings', + context["show_availability_status"] = cint(frappe.db.get_single_value('E Commerce Settings', 'show_availability_status')) products_template = 'templates/includes/products_as_list.html' return frappe.get_template(products_template).render(context) -def get_group_item_count(item_group): - child_groups = ", ".join('"' + i[0] + '"' for i in get_child_groups(item_group)) - return frappe.db.sql("""select count(*) from `tabItem` - where docstatus = 0 and show_in_website = 1 - and (item_group in (%s) - or name in (select parent from `tabWebsite Item Group` - where item_group in (%s))) """ % (child_groups, child_groups))[0][0] +def get_parent_item_groups(item_group_name, from_item=False): + base_nav_page = {"name": _("Shop by Category"), "route":"/shop-by-category"} + + if from_item and frappe.request.environ.get("HTTP_REFERER"): + # base page after 'Home' will vary on Item page + last_page = frappe.request.environ["HTTP_REFERER"].split('/')[-1] + if last_page and last_page in ("shop-by-category", "all-products"): + base_nav_page_title = " ".join(last_page.split("-")).title() + base_nav_page = {"name": _(base_nav_page_title), "route":"/"+last_page} -def get_parent_item_groups(item_group_name): base_parents = [ - {"name": frappe._("Home"), "route":"/"}, - {"name": frappe._("All Products"), "route":"/all-products"}, + {"name": _("Home"), "route":"/"}, + base_nav_page, ] + if not item_group_name: return base_parents - item_group = frappe.get_doc("Item Group", item_group_name) + item_group = frappe.db.get_value("Item Group", item_group_name, ["lft", "rgt"], as_dict=1) parent_groups = frappe.db.sql("""select name, route from `tabItem Group` where lft <= %s and rgt >= %s and show_in_website=1 diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index bafaab814b4..1d7bad2686a 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -189,7 +189,7 @@ def add_non_standard_user_types(): user_type_limit = {} for user_type, data in user_types.items(): - user_type_limit.setdefault(frappe.scrub(user_type), 10) + user_type_limit.setdefault(frappe.scrub(user_type), 20) update_site_config('user_type_doctype_limit', user_type_limit) @@ -204,15 +204,33 @@ def get_user_types_data(): 'apply_user_permission_on': 'Employee', 'user_id_field': 'user_id', 'doctypes': { - 'Salary Slip': ['read'], + # masters + 'Holiday List': ['read'], 'Employee': ['read', 'write'], + # payroll + 'Salary Slip': ['read'], + 'Employee Benefit Application': ['read', 'write', 'create', 'delete'], + # expenses 'Expense Claim': ['read', 'write', 'create', 'delete'], + 'Employee Advance': ['read', 'write', 'create', 'delete'], + # leave and attendance 'Leave Application': ['read', 'write', 'create', 'delete'], 'Attendance Request': ['read', 'write', 'create', 'delete'], 'Compensatory Leave Request': ['read', 'write', 'create', 'delete'], + # tax 'Employee Tax Exemption Declaration': ['read', 'write', 'create', 'delete'], 'Employee Tax Exemption Proof Submission': ['read', 'write', 'create', 'delete'], - 'Timesheet': ['read', 'write', 'create', 'delete', 'submit', 'cancel', 'amend'] + # projects + 'Timesheet': ['read', 'write', 'create', 'delete', 'submit', 'cancel', 'amend'], + # trainings + 'Training Program': ['read'], + 'Training Feedback': ['read', 'write', 'create', 'delete', 'submit', 'cancel', 'amend'], + # shifts + 'Shift Request': ['read', 'write', 'create', 'delete', 'submit', 'cancel', 'amend'], + # misc + 'Employee Grievance': ['read', 'write', 'create', 'delete'], + 'Employee Referral': ['read', 'write', 'create', 'delete'], + 'Travel Request': ['read', 'write', 'create', 'delete'] } } } diff --git a/erpnext/setup/onboarding_slide/welcome_back_to_erpnext!/welcome_back_to_erpnext!.json b/erpnext/setup/onboarding_slide/welcome_back_to_erpnext!/welcome_back_to_erpnext!.json deleted file mode 100644 index f00dc947d2c..00000000000 --- a/erpnext/setup/onboarding_slide/welcome_back_to_erpnext!/welcome_back_to_erpnext!.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "add_more_button": 0, - "app": "ERPNext", - "creation": "2019-12-04 19:21:39.995776", - "docstatus": 0, - "doctype": "Onboarding Slide", - "domains": [], - "help_links": [], - "idx": 0, - "image_src": "", - "is_completed": 0, - "max_count": 3, - "modified": "2019-12-09 17:53:53.849953", - "modified_by": "Administrator", - "name": "Welcome back to ERPNext!", - "owner": "Administrator", - "slide_desc": "Let's continue where you left from!
", - "slide_fields": [], - "slide_module": "Setup", - "slide_order": 0, - "slide_title": "Welcome back to ERPNext!", - "slide_type": "Continue" -} \ No newline at end of file diff --git a/erpnext/setup/onboarding_slide/welcome_to_erpnext!/welcome_to_erpnext!.json b/erpnext/setup/onboarding_slide/welcome_to_erpnext!/welcome_to_erpnext!.json deleted file mode 100644 index 37eb67b1d7e..00000000000 --- a/erpnext/setup/onboarding_slide/welcome_to_erpnext!/welcome_to_erpnext!.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "add_more_button": 0, - "app": "ERPNext", - "creation": "2019-11-26 17:01:26.671859", - "docstatus": 0, - "doctype": "Onboarding Slide", - "domains": [], - "help_links": [], - "idx": 0, - "image_src": "", - "is_completed": 0, - "max_count": 0, - "modified": "2019-12-22 21:26:28.414597", - "modified_by": "Administrator", - "name": "Welcome to ERPNext!", - "owner": "Administrator", - "slide_desc": "' + - __("Add more items or open full form") + '
') - .appendTo(dialog.body) - .find('.link-open') - .on('click', function () { - frappe.model.with_doctype('Stock Entry', function () { - var doc = frappe.model.get_new_doc('Stock Entry'); - doc.from_warehouse = dialog.get_value('source'); - doc.to_warehouse = dialog.get_value('target'); - var row = frappe.model.add_child(doc, 'items'); - row.item_code = dialog.get_value('item_code'); - row.f_warehouse = dialog.get_value('target'); - row.t_warehouse = dialog.get_value('target'); - row.qty = dialog.get_value('qty'); - row.conversion_factor = 1; - row.transfer_qty = dialog.get_value('qty'); - row.basic_rate = dialog.get_value('rate'); - frappe.set_route('Form', doc.doctype, doc.name); - }); - }); }; diff --git a/erpnext/stock/doctype/batch/batch.json b/erpnext/stock/doctype/batch/batch.json index fc4cf1dbdb8..967c5729bf4 100644 --- a/erpnext/stock/doctype/batch/batch.json +++ b/erpnext/stock/doctype/batch/batch.json @@ -9,6 +9,8 @@ "field_order": [ "sb_disabled", "disabled", + "column_break_24", + "use_batchwise_valuation", "sb_batch", "batch_id", "item", @@ -186,6 +188,18 @@ "fieldtype": "Float", "label": "Produced Qty", "read_only": 1 + }, + { + "fieldname": "column_break_24", + "fieldtype": "Column Break" + }, + { + "default": "0", + "fieldname": "use_batchwise_valuation", + "fieldtype": "Check", + "label": "Use Batch-wise Valuation", + "read_only": 1, + "set_only_once": 1 } ], "icon": "fa fa-archive", @@ -193,10 +207,11 @@ "image_field": "image", "links": [], "max_attachments": 5, - "modified": "2021-07-08 16:22:01.343105", + "modified": "2022-02-21 08:08:23.999236", "modified_by": "Administrator", "module": "Stock", "name": "Batch", + "naming_rule": "By fieldname", "owner": "Administrator", "permissions": [ { @@ -217,6 +232,7 @@ "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "title_field": "batch_id", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 96751d6eae5..c9b4c147f1d 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -110,11 +110,18 @@ class Batch(Document): def validate(self): self.item_has_batch_enabled() + self.set_batchwise_valuation() def item_has_batch_enabled(self): if frappe.db.get_value("Item", self.item, "has_batch_no") == 0: frappe.throw(_("The selected item cannot have Batch")) + def set_batchwise_valuation(self): + from erpnext.stock.stock_ledger import get_valuation_method + + if self.is_new() and get_valuation_method(self.item) != "Moving Average": + self.use_batchwise_valuation = 1 + def before_save(self): has_expiry_date, shelf_life_in_days = frappe.db.get_value('Item', self.item, ['has_expiry_date', 'shelf_life_in_days']) if not self.expiry_date and has_expiry_date and shelf_life_in_days: diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index 0a663c2a188..57637538531 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -1,17 +1,25 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt +import json + import frappe from frappe.exceptions import ValidationError +from frappe.tests.utils import FrappeTestCase from frappe.utils import cint, flt +from frappe.utils.data import add_to_date, getdate 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.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import ( + create_stock_reconciliation, +) from erpnext.stock.get_item_details import get_item_details -from erpnext.tests.utils import ERPNextTestCase +from erpnext.stock.stock_ledger import get_valuation_rate -class TestBatch(ERPNextTestCase): +class TestBatch(FrappeTestCase): def test_item_has_batch_enabled(self): self.assertRaises(ValidationError, frappe.get_doc({ "doctype": "Batch", @@ -300,6 +308,105 @@ class TestBatch(ERPNextTestCase): details = get_item_details(args) self.assertEqual(details.get('price_list_rate'), 400) + + def test_basic_batch_wise_valuation(self, batch_qty = 100): + item_code = "_TestBatchWiseVal" + warehouse = "_Test Warehouse - _TC" + self.make_batch_item(item_code) + + rates = [42, 420] + + batches = {} + for rate in rates: + se = make_stock_entry(item_code=item_code, qty=10, rate=rate, target=warehouse) + batches[se.items[0].batch_no] = rate + + LOW, HIGH = list(batches.keys()) + + # consume things out of order + consumption_plan = [ + (HIGH, 1), + (LOW, 2), + (HIGH, 2), + (HIGH, 4), + (LOW, 6), + ] + + stock_value = sum(rates) * 10 + qty_after_transaction = 20 + for batch, qty in consumption_plan: + # consume out of order + se = make_stock_entry(item_code=item_code, source=warehouse, qty=qty, batch_no=batch) + + sle = frappe.get_last_doc("Stock Ledger Entry", {"is_cancelled": 0, "voucher_no": se.name}) + + stock_value_difference = sle.actual_qty * batches[sle.batch_no] + self.assertAlmostEqual(sle.stock_value_difference, stock_value_difference) + + stock_value += stock_value_difference + self.assertAlmostEqual(sle.stock_value, stock_value) + + qty_after_transaction += sle.actual_qty + self.assertAlmostEqual(sle.qty_after_transaction, qty_after_transaction) + self.assertAlmostEqual(sle.valuation_rate, stock_value / qty_after_transaction) + + self.assertEqual(json.loads(sle.stock_queue), []) # queues don't apply on batched items + + def test_moving_batch_valuation_rates(self): + item_code = "_TestBatchWiseVal" + warehouse = "_Test Warehouse - _TC" + self.make_batch_item(item_code) + + def assertValuation(expected): + actual = get_valuation_rate(item_code, warehouse, "voucher_type", "voucher_no", batch_no=batch_no) + self.assertAlmostEqual(actual, expected) + + se = make_stock_entry(item_code=item_code, qty=100, rate=10, target=warehouse) + batch_no = se.items[0].batch_no + assertValuation(10) + + # consumption should never affect current valuation rate + make_stock_entry(item_code=item_code, qty=20, source=warehouse) + assertValuation(10) + + make_stock_entry(item_code=item_code, qty=30, source=warehouse) + assertValuation(10) + + # 50 * 10 = 500 current value, add more item with higher valuation + make_stock_entry(item_code=item_code, qty=50, rate=20, target=warehouse, batch_no=batch_no) + assertValuation(15) + + # consuming again shouldn't do anything + make_stock_entry(item_code=item_code, qty=20, source=warehouse) + assertValuation(15) + + # reset rate with stock reconiliation + create_stock_reconciliation(item_code=item_code, warehouse=warehouse, qty=10, rate=25, batch_no=batch_no) + assertValuation(25) + + make_stock_entry(item_code=item_code, qty=20, rate=20, target=warehouse, batch_no=batch_no) + assertValuation((20 * 20 + 10 * 25) / (10 + 20)) + + + def test_update_batch_properties(self): + item_code = "_TestBatchWiseVal" + self.make_batch_item(item_code) + + se = make_stock_entry(item_code=item_code, qty=100, rate=10, target="_Test Warehouse - _TC") + batch_no = se.items[0].batch_no + batch = frappe.get_doc("Batch", batch_no) + + expiry_date = add_to_date(batch.manufacturing_date, days=30) + + batch.expiry_date = expiry_date + batch.save() + + batch.reload() + + self.assertEqual(getdate(batch.expiry_date), getdate(expiry_date)) + + + def create_batch(item_code, rate, create_item_price_for_batch): pi = make_purchase_invoice(company="_Test Company", warehouse= "Stores - _TC", cost_center = "Main - _TC", update_stock=1, @@ -326,14 +433,13 @@ def create_price_list_for_batch(item_code, batch, rate): def make_new_batch(**args): args = frappe._dict(args) - try: + if frappe.db.exists("Batch", args.batch_id): + batch = frappe.get_doc("Batch", args.batch_id) + else: batch = frappe.get_doc({ "doctype": "Batch", "batch_id": args.batch_id, "item": args.item_code, }).insert() - except frappe.DuplicateEntryError: - batch = frappe.get_doc("Batch", args.batch_id) - return batch diff --git a/erpnext/stock/doctype/bin/bin.json b/erpnext/stock/doctype/bin/bin.json index 8e79f0e5552..56dc71c57e1 100644 --- a/erpnext/stock/doctype/bin/bin.json +++ b/erpnext/stock/doctype/bin/bin.json @@ -33,6 +33,7 @@ "oldfieldtype": "Link", "options": "Warehouse", "read_only": 1, + "reqd": 1, "search_index": 1 }, { @@ -46,6 +47,7 @@ "oldfieldtype": "Link", "options": "Item", "read_only": 1, + "reqd": 1, "search_index": 1 }, { @@ -169,10 +171,11 @@ "idx": 1, "in_create": 1, "links": [], - "modified": "2021-03-30 23:09:39.572776", + "modified": "2022-01-30 17:04:54.715288", "modified_by": "Administrator", "module": "Stock", "name": "Bin", + "naming_rule": "Expression (old style)", "owner": "Administrator", "permissions": [ { @@ -200,5 +203,6 @@ "quick_entry": 1, "search_fields": "item_code,warehouse", "sort_field": "modified", - "sort_order": "ASC" + "sort_order": "ASC", + "states": [] } \ No newline at end of file diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 0ef7ce29230..3bc15a80250 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -20,43 +20,12 @@ class Bin(Document): + flt(self.indented_qty) + flt(self.planned_qty) - flt(self.reserved_qty) - flt(self.reserved_qty_for_production) - flt(self.reserved_qty_for_sub_contract)) - def get_first_sle(self): - sle = frappe.qb.DocType("Stock Ledger Entry") - first_sle = ( - frappe.qb.from_(sle) - .select("*") - .where((sle.item_code == self.item_code) & (sle.warehouse == self.warehouse)) - .orderby(sle.posting_date, sle.posting_time, sle.creation) - .limit(1) - ).run(as_dict=True) - - return first_sle and first_sle[0] or None - def update_reserved_qty_for_production(self): '''Update qty reserved for production from Production Item tables in open work orders''' + from erpnext.manufacturing.doctype.work_order.work_order import get_reserved_qty_for_production - wo = frappe.qb.DocType("Work Order") - wo_item = frappe.qb.DocType("Work Order Item") - - self.reserved_qty_for_production = ( - frappe.qb - .from_(wo) - .from_(wo_item) - .select(Sum(Case() - .when(wo.skip_transfer == 0, wo_item.required_qty - wo_item.transferred_qty) - .else_(wo_item.required_qty - wo_item.consumed_qty)) - ) - .where( - (wo_item.item_code == self.item_code) - & (wo_item.parent == wo.name) - & (wo.docstatus == 1) - & (wo_item.source_warehouse == self.warehouse) - & (wo.status.notin(["Stopped", "Completed"])) - & ((wo_item.required_qty > wo_item.transferred_qty) - | (wo_item.required_qty > wo_item.consumed_qty)) - ) - ).run()[0][0] or 0.0 + self.reserved_qty_for_production = get_reserved_qty_for_production(self.item_code, self.warehouse) self.set_projected_qty() @@ -123,16 +92,9 @@ class Bin(Document): self.db_set('projected_qty', self.projected_qty) def on_doctype_update(): - frappe.db.add_index("Bin", ["item_code", "warehouse"]) + frappe.db.add_unique("Bin", ["item_code", "warehouse"], constraint_name="unique_item_warehouse") -def update_stock(bin_name, args, allow_negative_stock=False, via_landed_cost_voucher=False): - """WARNING: This function is deprecated. Inline this function instead of using it.""" - from erpnext.stock.stock_ledger import repost_current_voucher - - repost_current_voucher(args, allow_negative_stock, via_landed_cost_voucher) - update_qty(bin_name, args) - 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', diff --git a/erpnext/stock/doctype/bin/test_bin.py b/erpnext/stock/doctype/bin/test_bin.py index 9c390d94b4e..ec0d8a88e3f 100644 --- a/erpnext/stock/doctype/bin/test_bin.py +++ b/erpnext/stock/doctype/bin/test_bin.py @@ -1,9 +1,36 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest +import frappe +from frappe.tests.utils import FrappeTestCase -# test_records = frappe.get_test_records('Bin') +from erpnext.stock.doctype.item.test_item import make_item +from erpnext.stock.utils import _create_bin -class TestBin(unittest.TestCase): - pass + +class TestBin(FrappeTestCase): + + + def test_concurrent_inserts(self): + """ Ensure no duplicates are possible in case of concurrent inserts""" + item_code = "_TestConcurrentBin" + make_item(item_code) + warehouse = "_Test Warehouse - _TC" + + bin1 = frappe.get_doc(doctype="Bin", item_code=item_code, warehouse=warehouse) + bin1.insert() + + bin2 = frappe.get_doc(doctype="Bin", item_code=item_code, warehouse=warehouse) + with self.assertRaises(frappe.UniqueValidationError): + bin2.insert() + + # util method should handle it + bin = _create_bin(item_code, warehouse) + self.assertEqual(bin.item_code, item_code) + + frappe.db.rollback() + + def test_index_exists(self): + indexes = frappe.db.sql("show index from tabBin where Non_unique = 0", as_dict=1) + if not any(index.get("Key_name") == "unique_item_warehouse" for index in indexes): + self.fail(f"Expected unique index on item-warehouse") diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 70d48a42d72..2a4d63954a7 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -14,6 +14,7 @@ from erpnext.controllers.accounts_controller import get_taxes_and_charges from erpnext.controllers.selling_controller import SellingController from erpnext.stock.doctype.batch.batch import set_batch_nos from erpnext.stock.doctype.serial_no.serial_no import get_delivery_note_serial_no +from erpnext.stock.utils import calculate_mapped_packed_items_return form_grid_templates = { "items": "templates/form_grid/item_grid.html" @@ -128,8 +129,12 @@ class DeliveryNote(SellingController): self.validate_uom_is_integer("uom", "qty") self.validate_with_previous_doc() - from erpnext.stock.doctype.packed_item.packed_item import make_packing_list - make_packing_list(self) + # Keeps mapped packed_items in case product bundle is updated. + if self.is_return and self.return_against: + calculate_mapped_packed_items_return(self) + else: + from erpnext.stock.doctype.packed_item.packed_item import make_packing_list + make_packing_list(self) if self._action != 'submit' and not self.is_return: set_batch_nos(self, 'warehouse', throw=True) @@ -334,17 +339,35 @@ class DeliveryNote(SellingController): frappe.throw(_("Could not create Credit Note automatically, please uncheck 'Issue Credit Note' and submit again")) def update_billed_amount_based_on_so(so_detail, update_modified=True): + from frappe.query_builder.functions import Sum + # Billed against Sales Order directly - billed_against_so = frappe.db.sql("""select sum(amount) from `tabSales Invoice Item` - where so_detail=%s and (dn_detail is null or dn_detail = '') and docstatus=1""", so_detail) + si = frappe.qb.DocType("Sales Invoice").as_("si") + si_item = frappe.qb.DocType("Sales Invoice Item").as_("si_item") + sum_amount = Sum(si_item.amount).as_("amount") + + billed_against_so = frappe.qb.from_(si).from_(si_item).select(sum_amount).where( + (si_item.parent == si.name) & + (si_item.so_detail == so_detail) & + ((si_item.dn_detail.isnull()) | (si_item.dn_detail == '')) & + (si_item.docstatus == 1) & + (si.update_stock == 0) + ).run() billed_against_so = billed_against_so and billed_against_so[0][0] or 0 # Get all Delivery Note Item rows against the Sales Order Item row - dn_details = frappe.db.sql("""select dn_item.name, dn_item.amount, dn_item.si_detail, dn_item.parent - from `tabDelivery Note Item` dn_item, `tabDelivery Note` dn - where dn.name=dn_item.parent and dn_item.so_detail=%s - and dn.docstatus=1 and dn.is_return = 0 - order by dn.posting_date asc, dn.posting_time asc, dn.name asc""", so_detail, as_dict=1) + + dn = frappe.qb.DocType("Delivery Note").as_("dn") + dn_item = frappe.qb.DocType("Delivery Note Item").as_("dn_item") + + dn_details = frappe.qb.from_(dn).from_(dn_item).select(dn_item.name, dn_item.amount, dn_item.si_detail, dn_item.parent, dn_item.stock_qty, dn_item.returned_qty).where( + (dn.name == dn_item.parent) & + (dn_item.so_detail == so_detail) & + (dn.docstatus == 1) & + (dn.is_return == 0) + ).orderby( + dn.posting_date, dn.posting_time, dn.name + ).run(as_dict=True) updated_dn = [] for dnd in dn_details: @@ -362,7 +385,11 @@ def update_billed_amount_based_on_so(so_detail, update_modified=True): # Distribute billed amount directly against SO between DNs based on FIFO if billed_against_so and billed_amt_agianst_dn < dnd.amount: - pending_to_bill = flt(dnd.amount) - billed_amt_agianst_dn + if dnd.returned_qty: + pending_to_bill = flt(dnd.amount) * (dnd.stock_qty - dnd.returned_qty) / dnd.stock_qty + else: + pending_to_bill = flt(dnd.amount) + pending_to_bill -= billed_amt_agianst_dn if pending_to_bill <= billed_against_so: billed_amt_agianst_dn += pending_to_bill billed_against_so -= pending_to_bill @@ -581,7 +608,18 @@ def make_packing_slip(source_name, target_doc=None): "validation": { "docstatus": ["=", 0] } + }, + + "Delivery Note Item": { + "doctype": "Packing Slip Item", + "field_map": { + "item_code": "item_code", + "item_name": "item_name", + "description": "description", + "qty": "qty", + } } + }, target_doc) return doclist diff --git a/erpnext/stock/doctype/delivery_note/delivery_note_list.js b/erpnext/stock/doctype/delivery_note/delivery_note_list.js index 04028980473..9e6f3bc9321 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note_list.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note_list.js @@ -14,7 +14,7 @@ frappe.listview_settings['Delivery Note'] = { return [__("Completed"), "green", "per_billed,=,100"]; } }, - onload: function (doclist) { + onload: function (listview) { const action = () => { const selected_docs = doclist.get_checked_items(); const docnames = doclist.get_checked_items(true); @@ -54,6 +54,16 @@ frappe.listview_settings['Delivery Note'] = { }; }; - doclist.page.add_actions_menu_item(__('Create Delivery Trip'), action, false); + // doclist.page.add_actions_menu_item(__('Create Delivery Trip'), action, false); + + listview.page.add_action_item(__('Create Delivery Trip'), action); + + listview.page.add_action_item(__("Sales Invoice"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Delivery Note", "Sales Invoice"); + }); + + listview.page.add_action_item(__("Packaging Slip From Delivery Note"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Delivery Note", "Packing Slip"); + }); } }; diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.py b/erpnext/stock/doctype/delivery_note/test_delivery_note.py index 4f89a19f3c7..16c892128a6 100644 --- a/erpnext/stock/doctype/delivery_note/test_delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.py @@ -6,6 +6,7 @@ import json import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import cstr, flt, nowdate, nowtime from erpnext.accounts.doctype.account.test_account import get_inventory_account @@ -35,10 +36,9 @@ 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(ERPNextTestCase): +class TestDeliveryNote(FrappeTestCase): def test_over_billing_against_dn(self): frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) @@ -386,8 +386,7 @@ class TestDeliveryNote(ERPNextTestCase): self.assertEqual(actual_qty, 25) # return bundled item - dn1 = create_delivery_note(item_code='_Test Product Bundle Item', is_return=1, - return_against=dn.name, qty=-2, rate=500, company=company, warehouse="Stores - TCP1", expense_account="Cost of Goods Sold - TCP1", cost_center="Main - TCP1") + dn1 = create_return_delivery_note(source_name=dn.name, rate=500, qty=-2) # qty after return actual_qty = get_qty_after_transaction(warehouse="Stores - TCP1") @@ -823,6 +822,15 @@ class TestDeliveryNote(ERPNextTestCase): automatically_fetch_payment_terms(enable=0) +def create_return_delivery_note(**args): + args = frappe._dict(args) + from erpnext.controllers.sales_and_purchase_return import make_return_doc + doc = make_return_doc("Delivery Note", args.source_name, None) + doc.items[0].rate = args.rate + doc.items[0].qty = args.qty + doc.submit() + return doc + def create_delivery_note(**args): dn = frappe.new_doc("Delivery Note") args = frappe._dict(args) diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 51c88bed61d..f1f5d96e628 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -757,6 +757,7 @@ }, { "default": "0", + "fetch_from": "item_code.grant_commission", "fieldname": "grant_commission", "fieldtype": "Check", "label": "Grant Commission", @@ -767,12 +768,14 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-10-06 12:12:44.018872", + "modified": "2022-02-24 14:42:20.211085", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", - "sort_order": "DESC" -} + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py index 321f48b2c59..dcdff4a0f1e 100644 --- a/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py +++ b/erpnext/stock/doctype/delivery_trip/test_delivery_trip.py @@ -4,6 +4,7 @@ import unittest import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import add_days, flt, now_datetime, nowdate import erpnext @@ -12,10 +13,10 @@ from erpnext.stock.doctype.delivery_trip.delivery_trip import ( make_expense_claim, notify_customers, ) -from erpnext.tests.utils import ERPNextTestCase, create_test_contact_and_address +from erpnext.tests.utils import create_test_contact_and_address -class TestDeliveryTrip(ERPNextTestCase): +class TestDeliveryTrip(FrappeTestCase): def setUp(self): super().setUp() driver = create_driver() diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 752a1fe732b..ffea9c2d6e0 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -17,8 +17,6 @@ frappe.ui.form.on("Item", { frm.fields_dict["attributes"].grid.set_column_disp("attribute_value", true); } - // should never check Private - frm.fields_dict["website_image"].df.is_private = 0; if (frm.doc.is_fixed_asset) { frm.trigger("set_asset_naming_series"); } @@ -91,6 +89,29 @@ frappe.ui.form.on("Item", { erpnext.toggle_naming_series(); } + if (!frm.doc.published_in_website) { + frm.add_custom_button(__("Publish in Website"), function() { + frappe.call({ + method: "erpnext.e_commerce.doctype.website_item.website_item.make_website_item", + args: {doc: frm.doc}, + freeze: true, + freeze_message: __("Publishing Item ..."), + callback: function(result) { + frappe.msgprint({ + message: __("Website Item {0} has been created.", + [repl('%(item)s', { + item_encoded: encodeURIComponent(result.message[0]), + item: result.message[1] + })] + ), + title: __("Published"), + indicator: "green" + }); + } + }); + }, __('Actions')); + } + erpnext.item.edit_prices_button(frm); erpnext.item.toggle_attributes(frm); @@ -182,25 +203,8 @@ frappe.ui.form.on("Item", { } }, - copy_from_item_group: function(frm) { - return frm.call({ - doc: frm.doc, - method: "copy_specification_from_item_group" - }); - }, - has_variants: function(frm) { erpnext.item.toggle_attributes(frm); - }, - - show_in_website: function(frm) { - if (frm.doc.default_warehouse && !frm.doc.website_warehouse){ - frm.set_value("website_warehouse", frm.doc.default_warehouse); - } - }, - - set_meta_tags(frm) { - frappe.utils.set_meta_tag(frm.doc.route); } }); @@ -376,8 +380,7 @@ $.extend(erpnext.item, { // Show Stock Levels only if is_stock_item if (frm.doc.is_stock_item) { frappe.require('item-dashboard.bundle.js', function() { - frm.dashboard.parent.find('.stock-levels').remove(); - const section = frm.dashboard.add_section('', __("Stock Levels"), 'stock-levels'); + const section = frm.dashboard.add_section('', __("Stock Levels")); erpnext.item.item_dashboard = new erpnext.stock.ItemDashboard({ parent: section, item_code: frm.doc.name, @@ -393,13 +396,15 @@ $.extend(erpnext.item, { edit_prices_button: function(frm) { frm.add_custom_button(__("Add / Edit Prices"), function() { frappe.set_route("List", "Item Price", {"item_code": frm.doc.name}); - }, __("View")); + }, __("Actions")); }, - weight_to_validate: function(frm){ - if((frm.doc.nett_weight || frm.doc.gross_weight) && !frm.doc.weight_uom) { - frappe.msgprint(__('Weight is mentioned,\nPlease mention "Weight UOM" too')); - frappe.validated = 0; + weight_to_validate: function(frm) { + if (frm.doc.weight_per_unit && !frm.doc.weight_uom) { + frappe.msgprint({ + message: __("Please mention 'Weight UOM' along with Weight."), + title: __("Note") + }); } }, @@ -540,7 +545,7 @@ $.extend(erpnext.item, { let selected_attributes = {}; me.multiple_variant_dialog.$wrapper.find('.form-column').each((i, col) => { if(i===0) return; - let attribute_name = $(col).find('label').html(); + let attribute_name = $(col).find('label').html().trim(); selected_attributes[attribute_name] = []; let checked_opts = $(col).find('.checkbox input'); checked_opts.each((i, opt) => { @@ -589,7 +594,7 @@ $.extend(erpnext.item, { const increment = r.message.increment; let values = []; - for(var i = from; i <= to; i += increment) { + for(var i = from; i <= to; i = flt(i + increment, 6)) { values.push(i); } attr_val_fields[d.attribute] = values; diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json index 29abd45fcc8..c7971878506 100644 --- a/erpnext/stock/doctype/item/item.json +++ b/erpnext/stock/doctype/item/item.json @@ -28,6 +28,7 @@ "standard_rate", "is_fixed_asset", "auto_create_assets", + "is_grouped_asset", "asset_category", "asset_naming_series", "over_delivery_receipt_allowance", @@ -47,6 +48,7 @@ "warranty_period", "weight_per_unit", "weight_uom", + "allow_negative_stock", "reorder_section", "reorder_levels", "unit_of_measure_conversion", @@ -116,24 +118,8 @@ "customer_code", "default_item_manufacturer", "default_manufacturer_part_no", - "website_section", - "show_in_website", - "show_variant_in_website", - "route", - "weightage", - "slideshow", - "website_image", - "website_image_alt", - "thumbnail", - "cb72", - "website_warehouse", - "website_item_groups", - "set_meta_tags", - "sb72", - "copy_from_item_group", - "website_specifications", - "web_long_description", - "website_content", + "more_information_section", + "published_in_website", "total_projected_qty" ], "fields": [ @@ -361,7 +347,7 @@ "fieldname": "valuation_method", "fieldtype": "Select", "label": "Valuation Method", - "options": "\nFIFO\nMoving Average" + "options": "\nFIFO\nMoving Average\nLIFO" }, { "depends_on": "is_stock_item", @@ -855,125 +841,6 @@ "no_copy": 1, "print_hide": 1 }, - { - "collapsible": 1, - "depends_on": "eval:!doc.is_fixed_asset", - "fieldname": "website_section", - "fieldtype": "Section Break", - "label": "Website", - "options": "fa fa-globe" - }, - { - "default": "0", - "depends_on": "eval:!doc.variant_of", - "fieldname": "show_in_website", - "fieldtype": "Check", - "label": "Show in Website", - "search_index": 1 - }, - { - "default": "0", - "depends_on": "variant_of", - "fieldname": "show_variant_in_website", - "fieldtype": "Check", - "label": "Show in Website (Variant)", - "search_index": 1 - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "fieldname": "route", - "fieldtype": "Small Text", - "label": "Route", - "no_copy": 1 - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "description": "Items with higher weightage will be shown higher", - "fieldname": "weightage", - "fieldtype": "Int", - "label": "Weightage" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "description": "Show a slideshow at the top of the page", - "fieldname": "slideshow", - "fieldtype": "Link", - "label": "Slideshow", - "options": "Website Slideshow" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "description": "Item Image (if not slideshow)", - "fieldname": "website_image", - "fieldtype": "Attach", - "label": "Website Image" - }, - { - "fieldname": "thumbnail", - "fieldtype": "Data", - "label": "Thumbnail", - "read_only": 1 - }, - { - "fieldname": "cb72", - "fieldtype": "Column Break" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "description": "Show \"In Stock\" or \"Not in Stock\" based on stock available in this warehouse.", - "fieldname": "website_warehouse", - "fieldtype": "Link", - "ignore_user_permissions": 1, - "label": "Website Warehouse", - "options": "Warehouse" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "description": "List this Item in multiple groups on the website.", - "fieldname": "website_item_groups", - "fieldtype": "Table", - "label": "Website Item Groups", - "options": "Website Item Group" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "fieldname": "set_meta_tags", - "fieldtype": "Button", - "label": "Set Meta Tags" - }, - { - "collapsible": 1, - "collapsible_depends_on": "website_specifications", - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "fieldname": "sb72", - "fieldtype": "Section Break", - "label": "Website Specifications" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "fieldname": "copy_from_item_group", - "fieldtype": "Button", - "label": "Copy From Item Group" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "fieldname": "website_specifications", - "fieldtype": "Table", - "label": "Website Specifications", - "options": "Item Website Specification" - }, - { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "fieldname": "web_long_description", - "fieldtype": "Text Editor", - "label": "Website Description" - }, - { - "description": "You can use any valid Bootstrap 4 markup in this field. It will be shown on your Item Page.", - "fieldname": "website_content", - "fieldtype": "HTML Editor", - "label": "Website Content" - }, { "fieldname": "total_projected_qty", "fieldtype": "Float", @@ -1016,25 +883,45 @@ "read_only": 1 }, { - "depends_on": "eval: doc.show_in_website || doc.show_variant_in_website", - "fieldname": "website_image_alt", - "fieldtype": "Data", - "label": "Image Description" + "collapsible": 1, + "fieldname": "more_information_section", + "fieldtype": "Section Break", + "label": "More Information" + }, + { + "default": "0", + "depends_on": "published_in_website", + "fieldname": "published_in_website", + "fieldtype": "Check", + "label": "Published in Website", + "read_only": 1 }, { "default": "1", "fieldname": "grant_commission", "fieldtype": "Check", "label": "Grant Commission" + }, + { + "default": "0", + "depends_on": "auto_create_assets", + "fieldname": "is_grouped_asset", + "fieldtype": "Check", + "label": "Create Grouped Asset" + }, + { + "default": "0", + "fieldname": "allow_negative_stock", + "fieldtype": "Check", + "label": "Allow Negative Stock" } ], - "has_web_view": 1, "icon": "fa fa-tag", "idx": 2, "image_field": "image", "index_web_pages_for_search": 1, "links": [], - "modified": "2021-12-14 04:13:16.857534", + "modified": "2022-02-11 08:07:46.663220", "modified_by": "Administrator", "module": "Stock", "name": "Item", @@ -1104,6 +991,7 @@ "show_preview_popup": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "title_field": "item_name", "track_changes": 1 -} \ No newline at end of file +} diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index 281e8818759..494fb3b8bb2 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -2,12 +2,12 @@ # License: GNU General Public License v3. See license.txt import copy -import itertools import json from typing import List import frappe from frappe import _ +from frappe.model.document import Document from frappe.utils import ( cint, cstr, @@ -17,13 +17,9 @@ from frappe.utils import ( getdate, now_datetime, nowtime, - random_string, strip, ) from frappe.utils.html_utils import clean_html -from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow -from frappe.website.utils import clear_cache -from frappe.website.website_generator import WebsiteGenerator import erpnext from erpnext.controllers.item_variant import ( @@ -33,10 +29,7 @@ from erpnext.controllers.item_variant import ( make_variant_item_code, validate_item_variant_attributes, ) -from erpnext.setup.doctype.item_group.item_group import ( - get_parent_item_groups, - invalidate_cache_for, -) +from erpnext.setup.doctype.item_group.item_group import invalidate_cache_for from erpnext.stock.doctype.item_default.item_default import ItemDefault @@ -51,18 +44,11 @@ class StockExistsForTemplate(frappe.ValidationError): class InvalidBarcode(frappe.ValidationError): pass +class DataValidationError(frappe.ValidationError): + pass -class Item(WebsiteGenerator): - website = frappe._dict( - page_title_field="item_name", - condition_field="show_in_website", - template="templates/generators/item/item.html", - no_cache=1 - ) - +class Item(Document): def onload(self): - super(Item, self).onload() - self.set_onload('stock_exists', self.stock_ledger_created()) self.set_asset_naming_series() @@ -103,8 +89,6 @@ class Item(WebsiteGenerator): self.set_opening_stock() def validate(self): - super(Item, self).validate() - if not self.item_name: self.item_name = self.item_code @@ -130,8 +114,6 @@ class Item(WebsiteGenerator): self.validate_attributes() self.validate_variant_attributes() self.validate_variant_based_on_change() - self.validate_website_image() - self.make_thumbnail() self.validate_fixed_asset() self.validate_retain_sample() self.validate_uom_conversion_factor() @@ -140,21 +122,17 @@ class Item(WebsiteGenerator): self.validate_item_defaults() self.validate_auto_reorder_enabled_in_stock_settings() self.cant_change() - self.update_show_in_website() self.validate_item_tax_net_rate_range() set_item_tax_from_hsn_code(self) if not self.is_new(): self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group") - self.old_website_item_groups = frappe.db.sql_list("""select item_group - from `tabWebsite Item Group` - where parentfield='website_item_groups' and parenttype='Item' and parent=%s""", self.name) def on_update(self): invalidate_cache_for_item(self) self.update_variants() self.update_item_price() - self.update_template_item() + self.update_website_item() def validate_description(self): '''Clean HTML description if set''' @@ -216,97 +194,6 @@ class Item(WebsiteGenerator): stock_entry.add_comment("Comment", _("Opening Stock")) - def make_route(self): - if not self.route: - return cstr(frappe.db.get_value('Item Group', self.item_group, - 'route')) + '/' + self.scrub((self.item_name or self.item_code) + '-' + random_string(5)) - - def validate_website_image(self): - """Validate if the website image is a public file""" - - if frappe.flags.in_import: - return - - auto_set_website_image = False - if not self.website_image and self.image: - auto_set_website_image = True - self.website_image = self.image - - if not self.website_image: - return - - # find if website image url exists as public - file_doc = frappe.get_all("File", filters={ - "file_url": self.website_image - }, fields=["name", "is_private"], order_by="is_private asc", limit_page_length=1) - - if file_doc: - file_doc = file_doc[0] - - if not file_doc: - if not auto_set_website_image: - frappe.msgprint(_("Website Image {0} attached to Item {1} cannot be found").format(self.website_image, self.name)) - - self.website_image = None - - elif file_doc.is_private: - if not auto_set_website_image: - frappe.msgprint(_("Website Image should be a public file or website URL")) - - self.website_image = None - - def make_thumbnail(self): - """Make a thumbnail of `website_image`""" - - if frappe.flags.in_import: - return - - import requests.exceptions - - if not self.is_new() and self.website_image != frappe.db.get_value(self.doctype, self.name, "website_image"): - self.thumbnail = None - - if self.website_image and not self.thumbnail: - file_doc = None - - try: - file_doc = frappe.get_doc("File", { - "file_url": self.website_image, - "attached_to_doctype": "Item", - "attached_to_name": self.name - }) - except frappe.DoesNotExistError: - # cleanup - frappe.local.message_log.pop() - - except requests.exceptions.HTTPError: - frappe.msgprint(_("Warning: Invalid attachment {0}").format(self.website_image)) - self.website_image = None - - except requests.exceptions.SSLError: - frappe.msgprint( - _("Warning: Invalid SSL certificate on attachment {0}").format(self.website_image)) - self.website_image = None - - # for CSV import - if self.website_image and not file_doc: - try: - file_doc = frappe.get_doc({ - "doctype": "File", - "file_url": self.website_image, - "attached_to_doctype": "Item", - "attached_to_name": self.name - }).save() - - except IOError: - self.website_image = None - - if file_doc: - if not file_doc.thumbnail_url: - file_doc.make_thumbnail() - - self.thumbnail = file_doc.thumbnail_url - def validate_fixed_asset(self): if self.is_fixed_asset: if self.is_stock_item: @@ -330,167 +217,6 @@ class Item(WebsiteGenerator): frappe.throw(_("{0} Retain Sample is based on batch, please check Has Batch No to retain sample of item").format( self.item_code)) - def get_context(self, context): - context.show_search = True - context.search_link = '/product_search' - - context.parents = get_parent_item_groups(self.item_group) - context.body_class = "product-page" - - self.set_variant_context(context) - self.set_attribute_context(context) - self.set_disabled_attributes(context) - self.set_metatags(context) - self.set_shopping_cart_data(context) - - return context - - def set_variant_context(self, context): - if self.has_variants: - context.no_cache = True - - # load variants - # also used in set_attribute_context - context.variants = frappe.get_all("Item", - filters={"variant_of": self.name, "show_variant_in_website": 1}, - order_by="name asc") - - variant = frappe.form_dict.variant - if not variant and context.variants: - # the case when the item is opened for the first time from its list - variant = context.variants[0] - - if variant: - context.variant = frappe.get_doc("Item", variant) - - for fieldname in ("website_image", "website_image_alt", "web_long_description", "description", - "website_specifications"): - if context.variant.get(fieldname): - value = context.variant.get(fieldname) - if isinstance(value, list): - value = [d.as_dict() for d in value] - - context[fieldname] = value - - if self.slideshow: - if context.variant and context.variant.slideshow: - context.update(get_slideshow(context.variant)) - else: - context.update(get_slideshow(self)) - - def set_attribute_context(self, context): - if not self.has_variants: - return - - attribute_values_available = {} - context.attribute_values = {} - context.selected_attributes = {} - - # load attributes - for v in context.variants: - v.attributes = frappe.get_all("Item Variant Attribute", - fields=["attribute", "attribute_value"], - filters={"parent": v.name}) - # make a map for easier access in templates - v.attribute_map = frappe._dict({}) - for attr in v.attributes: - v.attribute_map[attr.attribute] = attr.attribute_value - - for attr in v.attributes: - values = attribute_values_available.setdefault(attr.attribute, []) - if attr.attribute_value not in values: - values.append(attr.attribute_value) - - if v.name == context.variant.name: - context.selected_attributes[attr.attribute] = attr.attribute_value - - # filter attributes, order based on attribute table - for attr in self.attributes: - values = context.attribute_values.setdefault(attr.attribute, []) - - if cint(frappe.db.get_value("Item Attribute", attr.attribute, "numeric_values")): - for val in sorted(attribute_values_available.get(attr.attribute, []), key=flt): - values.append(val) - - else: - # get list of values defined (for sequence) - for attr_value in frappe.db.get_all("Item Attribute Value", - fields=["attribute_value"], - filters={"parent": attr.attribute}, order_by="idx asc"): - - if attr_value.attribute_value in attribute_values_available.get(attr.attribute, []): - values.append(attr_value.attribute_value) - - context.variant_info = json.dumps(context.variants) - - def set_disabled_attributes(self, context): - """Disable selection options of attribute combinations that do not result in a variant""" - if not self.attributes or not self.has_variants: - return - - context.disabled_attributes = {} - attributes = [attr.attribute for attr in self.attributes] - - def find_variant(combination): - for variant in context.variants: - if len(variant.attributes) < len(attributes): - continue - - if "combination" not in variant: - ref_combination = [] - - for attr in variant.attributes: - idx = attributes.index(attr.attribute) - ref_combination.insert(idx, attr.attribute_value) - - variant["combination"] = ref_combination - - if not (set(combination) - set(variant["combination"])): - # check if the combination is a subset of a variant combination - # eg. [Blue, 0.5] is a possible combination if exists [Blue, Large, 0.5] - return True - - for i, attr in enumerate(self.attributes): - if i == 0: - continue - - combination_source = [] - - # loop through previous attributes - for prev_attr in self.attributes[:i]: - combination_source.append([context.selected_attributes.get(prev_attr.attribute)]) - - combination_source.append(context.attribute_values[attr.attribute]) - - for combination in itertools.product(*combination_source): - if not find_variant(combination): - context.disabled_attributes.setdefault(attr.attribute, []).append(combination[-1]) - - def set_metatags(self, context): - context.metatags = frappe._dict({}) - - safe_description = frappe.utils.to_markdown(self.description) - - context.metatags.url = frappe.utils.get_url() + '/' + context.route - - if context.website_image: - if context.website_image.startswith('http'): - url = context.website_image - else: - url = frappe.utils.get_url() + context.website_image - context.metatags.image = url - - context.metatags.description = safe_description[:300] - - context.metatags.title = self.item_name or self.item_code - - context.metatags['og:type'] = 'product' - context.metatags['og:site_name'] = 'ERPNext' - - def set_shopping_cart_data(self, context): - from erpnext.shopping_cart.product_info import get_product_info_for_website - context.shopping_cart = get_product_info_for_website(self.name, skip_quotation_creation=True) - def add_default_uom_in_conversion_factor_table(self): if not self.is_new() and self.has_value_changed("stock_uom"): self.uoms = [] @@ -507,9 +233,29 @@ class Item(WebsiteGenerator): "conversion_factor": 1 }) - def update_show_in_website(self): - if self.disabled: - self.show_in_website = False + def update_website_item(self): + """Update Website Item if change in Item impacts it.""" + web_item = frappe.db.exists("Website Item", {"item_code": self.item_code}) + + if web_item: + changed = {} + editable_fields = ["item_name", "item_group", "stock_uom", "brand", "description", + "disabled"] + doc_before_save = self.get_doc_before_save() + + for field in editable_fields: + if doc_before_save.get(field) != self.get(field): + if field == "disabled": + changed["published"] = not self.get(field) + else: + changed[field] = self.get(field) + + if not changed: + return + + web_item_doc = frappe.get_doc("Website Item", web_item) + web_item_doc.update(changed) + web_item_doc.save() def validate_item_tax_net_rate_range(self): for tax in self.get('taxes'): @@ -602,14 +348,6 @@ class Item(WebsiteGenerator): frappe.throw(_("Barcode {0} is not a valid {1} code").format( item_barcode.barcode, item_barcode.barcode_type), InvalidBarcode) - if item_barcode.barcode != item_barcode.name: - # if barcode is getting updated , the row name has to reset. - # Delete previous old row doc and re-enter row as if new to reset name in db. - item_barcode.set("__islocal", True) - item_barcode_entry_name = item_barcode.name - item_barcode.name = None - frappe.delete_doc("Item Barcode", item_barcode_entry_name) - def validate_warehouse_for_reorder(self): '''Validate Reorder level table for duplicate and conditional mandatory''' warehouse = [] @@ -649,7 +387,6 @@ class Item(WebsiteGenerator): ) def on_trash(self): - super(Item, self).on_trash() frappe.db.sql("""delete from tabBin where item_code=%s""", self.name) frappe.db.sql("delete from `tabItem Price` where item_code=%s", self.name) for variant_of in frappe.get_all("Item", filters={"variant_of": self.name}): @@ -660,15 +397,9 @@ class Item(WebsiteGenerator): frappe.db.set_value("Item", old_name, "item_name", new_name) if merge: - # Validate properties before merging - if not frappe.db.exists("Item", new_name): - frappe.throw(_("Item {0} does not exist").format(new_name)) - - field_list = ["stock_uom", "is_stock_item", "has_serial_no", "has_batch_no"] - new_properties = [cstr(d) for d in frappe.db.get_value("Item", new_name, field_list)] - if new_properties != [cstr(self.get(fld)) for fld in field_list]: - frappe.throw(_("To merge, following properties must be same for both items") - + ": \n" + ", ".join([self.meta.get_label(fld) for fld in field_list])) + self.validate_properties_before_merge(new_name) + self.validate_duplicate_product_bundles_before_merge(old_name, new_name) + self.validate_duplicate_website_item_before_merge(old_name, new_name) def after_rename(self, old_name, new_name, merge): if merge: @@ -676,9 +407,8 @@ class Item(WebsiteGenerator): frappe.msgprint(_("It can take upto few hours for accurate stock values to be visible after merging items."), indicator="orange", title="Note") - if self.route: + if self.published_in_website: invalidate_cache_for_item(self) - clear_cache(self.route) frappe.db.set_value("Item", new_name, "item_code", new_name) @@ -718,7 +448,56 @@ class Item(WebsiteGenerator): msg += _("Note: To merge the items, create a separate Stock Reconciliation for the old item {0}").format( frappe.bold(old_name)) - frappe.throw(_(msg), title=_("Merge not allowed")) + frappe.throw(_(msg), title=_("Cannot Merge"), exc=DataValidationError) + + def validate_properties_before_merge(self, new_name): + # Validate properties before merging + if not frappe.db.exists("Item", new_name): + frappe.throw(_("Item {0} does not exist").format(new_name)) + + field_list = ["stock_uom", "is_stock_item", "has_serial_no", "has_batch_no"] + new_properties = [cstr(d) for d in frappe.db.get_value("Item", new_name, field_list)] + + if new_properties != [cstr(self.get(field)) for field in field_list]: + msg = _("To merge, following properties must be same for both items") + msg += ": \n" + ", ".join([self.meta.get_label(fld) for fld in field_list]) + frappe.throw(msg, title=_("Cannot Merge"), exc=DataValidationError) + + def validate_duplicate_product_bundles_before_merge(self, old_name, new_name): + "Block merge if both old and new items have product bundles." + old_bundle = frappe.get_value("Product Bundle",filters={"new_item_code": old_name}) + new_bundle = frappe.get_value("Product Bundle",filters={"new_item_code": new_name}) + + if old_bundle and new_bundle: + bundle_link = get_link_to_form("Product Bundle", old_bundle) + old_name, new_name = frappe.bold(old_name), frappe.bold(new_name) + + msg = _("Please delete Product Bundle {0}, before merging {1} into {2}").format( + bundle_link, old_name, new_name + ) + frappe.throw(msg, title=_("Cannot Merge"), exc=DataValidationError) + + def validate_duplicate_website_item_before_merge(self, old_name, new_name): + """ + Block merge if both old and new items have website items against them. + This is to avoid duplicate website items after merging. + """ + web_items = frappe.get_all( + "Website Item", + filters={ + "item_code": ["in", [old_name, new_name]] + }, + fields=["item_code", "name"]) + + if len(web_items) <= 1: + return + + old_web_item = [d.get("name") for d in web_items if d.get("item_code") == old_name][0] + web_item_link = get_link_to_form("Website Item", old_web_item) + old_name, new_name = frappe.bold(old_name), frappe.bold(new_name) + + msg = f"Please delete linked Website Item {frappe.bold(web_item_link)} before merging {old_name} into {new_name}" + frappe.throw(_(msg), title=_("Cannot Merge"), exc=DataValidationError) def set_last_purchase_rate(self, new_name): last_purchase_rate = get_last_purchase_details(new_name).get("base_net_rate", 0) @@ -740,16 +519,6 @@ class Item(WebsiteGenerator): frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock) - @frappe.whitelist() - def copy_specification_from_item_group(self): - self.set("website_specifications", []) - if self.item_group: - for label, desc in frappe.db.get_values("Item Website Specification", - {"parent": self.item_group}, ["label", "description"]): - row = self.append("website_specifications") - row.label = label - row.description = desc - def update_bom_item_desc(self): if self.is_new(): return @@ -773,25 +542,6 @@ class Item(WebsiteGenerator): where item_code = %s and docstatus < 2 """, (self.description, self.name)) - def update_template_item(self): - """Set Show in Website for Template Item if True for its Variant""" - if not self.variant_of: - return - - if self.show_in_website: - self.show_variant_in_website = 1 - self.show_in_website = 0 - - if self.show_variant_in_website: - # show template - template_item = frappe.get_doc("Item", self.variant_of) - - if not template_item.show_in_website: - template_item.show_in_website = 1 - template_item.flags.dont_update_variants = True - template_item.flags.ignore_permissions = True - template_item.save() - def validate_item_defaults(self): companies = {row.company for row in self.item_defaults} @@ -1042,47 +792,6 @@ class Item(WebsiteGenerator): if not enabled: frappe.msgprint(msg=_("You have to enable auto re-order in Stock Settings to maintain re-order levels."), title=_("Enable Auto Re-Order"), indicator="orange") - def create_onboarding_docs(self, args): - company = frappe.defaults.get_defaults().get('company') or \ - frappe.db.get_single_value('Global Defaults', 'default_company') - - for i in range(1, args.get('max_count')): - item = args.get('item_' + str(i)) - if item: - default_warehouse = '' - default_warehouse = frappe.db.get_value('Warehouse', filters={ - 'warehouse_name': _('Finished Goods'), - 'company': company - }) - - try: - frappe.get_doc({ - 'doctype': self.doctype, - 'item_code': item, - 'item_name': item, - 'description': item, - 'show_in_website': 1, - 'is_sales_item': 1, - 'is_purchase_item': 1, - 'is_stock_item': 1, - 'item_group': _('Products'), - 'stock_uom': _(args.get('item_uom_' + str(i))), - 'item_defaults': [{ - 'default_warehouse': default_warehouse, - 'company': company - }] - }).insert() - - except frappe.NameError: - pass - else: - if args.get('item_price_' + str(i)): - item_price = flt(args.get('item_price_' + str(i))) - - price_list_name = frappe.db.get_value('Price List', {'selling': 1}) - make_item_price(item, price_list_name, item_price) - price_list_name = frappe.db.get_value('Price List', {'buying': 1}) - make_item_price(item, price_list_name, item_price) def make_item_price(item, price_list_name, item_price): frappe.get_doc({ @@ -1197,14 +906,9 @@ def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0): def invalidate_cache_for_item(doc): + """Invalidate Item Group cache and rebuild ItemVariantsCacheManager.""" invalidate_cache_for(doc, doc.item_group) - website_item_groups = list(set((doc.get("old_website_item_groups") or []) - + [d.item_group for d in doc.get({"doctype": "Website Item Group"}) if d.item_group])) - - for item_group in website_item_groups: - invalidate_cache_for(doc, item_group) - if doc.get("old_item_group") and doc.get("old_item_group") != doc.item_group: invalidate_cache_for(doc, doc.old_item_group) @@ -1212,12 +916,14 @@ def invalidate_cache_for_item(doc): def invalidate_item_variants_cache_for_website(doc): - from erpnext.portal.product_configurator.item_variants_cache import ItemVariantsCacheManager + """Rebuild ItemVariantsCacheManager via Item or Website Item.""" + from erpnext.e_commerce.variant_selector.item_variants_cache import ItemVariantsCacheManager item_code = None - if doc.has_variants and doc.show_in_website: - item_code = doc.name - elif doc.variant_of and frappe.db.get_value('Item', doc.variant_of, 'show_in_website'): + is_web_item = doc.get("published_in_website") or doc.get("published") + if doc.has_variants and is_web_item: + item_code = doc.item_code + elif doc.variant_of and frappe.db.get_value('Item', doc.variant_of, 'published_in_website'): item_code = doc.variant_of if item_code: @@ -1341,10 +1047,6 @@ def update_variants(variants, template, publish_progress=True): if publish_progress: frappe.publish_progress(count / total * 100, title=_("Updating Variants...")) -def on_doctype_update(): - # since route is a Text column, it needs a length for indexing - frappe.db.add_index("Item", ["route(500)"]) - @erpnext.allow_regional def set_item_tax_from_hsn_code(item): pass diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py index 0957ce06159..d7671b1d714 100644 --- a/erpnext/stock/doctype/item/test_item.py +++ b/erpnext/stock/doctype/item/test_item.py @@ -6,6 +6,8 @@ import json import frappe from frappe.test_runner import make_test_objects +from frappe.tests.utils import FrappeTestCase, change_settings +from frappe.utils import add_days, today from erpnext.controllers.item_variant import ( InvalidItemAttributeValueError, @@ -14,6 +16,7 @@ from erpnext.controllers.item_variant import ( get_variant, ) from erpnext.stock.doctype.item.item import ( + DataValidationError, InvalidBarcode, StockExistsForTemplate, get_item_attribute, @@ -23,7 +26,6 @@ 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 ERPNextTestCase, change_settings test_ignore = ["BOM"] test_dependencies = ["Warehouse", "Item Group", "Item Tax Template", "Brand", "Item Attribute"] @@ -51,7 +53,7 @@ def make_item(item_code, properties=None): return item -class TestItem(ERPNextTestCase): +class TestItem(FrappeTestCase): def setUp(self): super().setUp() frappe.flags.attribute_values = None @@ -387,6 +389,26 @@ class TestItem(ERPNextTestCase): self.assertTrue(frappe.db.get_value("Bin", {"item_code": "Test Item for Merging 2", "warehouse": "_Test Warehouse 1 - _TC"})) + def test_item_merging_with_product_bundle(self): + from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle + + create_item("Test Item Bundle Item 1", is_stock_item=False) + create_item("Test Item Bundle Item 2", is_stock_item=False) + create_item("Test Item inside Bundle") + bundle_items = ["Test Item inside Bundle"] + + # make bundles for both items + bundle1 = make_product_bundle("Test Item Bundle Item 1", bundle_items, qty=2) + make_product_bundle("Test Item Bundle Item 2", bundle_items, qty=2) + + with self.assertRaises(DataValidationError): + frappe.rename_doc("Item", "Test Item Bundle Item 1", "Test Item Bundle Item 2", merge=True) + + bundle1.delete() + frappe.rename_doc("Item", "Test Item Bundle Item 1", "Test Item Bundle Item 2", merge=True) + + self.assertFalse(frappe.db.exists("Item", "Test Item Bundle Item 1")) + def test_uom_conversion_factor(self): if frappe.db.exists('Item', 'Test Item UOM'): frappe.delete_doc('Item', 'Test Item UOM') @@ -536,7 +558,7 @@ class TestItem(ERPNextTestCase): "check if index is getting created in db" indices = frappe.db.sql("show index from tabItem", as_dict=1) - expected_columns = {"item_code", "item_name", "item_group", "route"} + expected_columns = {"item_code", "item_name", "item_group"} for index in indices: expected_columns.discard(index.get("Column_name")) @@ -608,6 +630,45 @@ class TestItem(ERPNextTestCase): item.item_group = "All Item Groups" item.save() # if item code saved without item_code then series worked + @change_settings("Stock Settings", {"allow_negative_stock": 0}) + def test_item_wise_negative_stock(self): + """ When global settings are disabled check that item that allows + negative stock can still consume material in all known stock + transactions that consume inventory.""" + from erpnext.stock.stock_ledger import is_negative_stock_allowed + + item = make_item("_TestNegativeItemSetting", {"allow_negative_stock": 1, "valuation_rate": 100}) + self.assertTrue(is_negative_stock_allowed(item_code=item.name)) + + self.consume_item_code_with_differet_stock_transactions(item_code=item.name) + + @change_settings("Stock Settings", {"allow_negative_stock": 0}) + def test_backdated_negative_stock(self): + """ same as test above but backdated entries """ + from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry + item = make_item("_TestNegativeItemSetting", {"allow_negative_stock": 1, "valuation_rate": 100}) + + # create a future entry so all new entries are backdated + make_stock_entry(qty=1, item_code=item.name, target="_Test Warehouse - _TC", posting_date = add_days(today(), 5)) + self.consume_item_code_with_differet_stock_transactions(item_code=item.name) + + + def consume_item_code_with_differet_stock_transactions(self, item_code, warehouse="_Test Warehouse - _TC"): + from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice + from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note + from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt + from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry + + typical_args = {"item_code": item_code, "warehouse": warehouse} + + create_delivery_note(**typical_args) + create_sales_invoice(update_stock=1, **typical_args) + make_stock_entry(item_code=item_code, source=warehouse, qty=1, purpose="Material Issue") + make_stock_entry(item_code=item_code, source=warehouse, target="Stores - _TC", qty=1) + # standalone return + make_purchase_receipt(is_return=True, qty=-1, **typical_args) + + def set_item_variant_settings(fields): doc = frappe.get_doc('Item Variant Settings') diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json index 6cec85288fe..91c77d51529 100644 --- a/erpnext/stock/doctype/item/test_records.json +++ b/erpnext/stock/doctype/item/test_records.json @@ -40,9 +40,7 @@ "conversion_factor": 10.0 } ], - "stock_uom": "_Test UOM", - "show_in_website": 1, - "website_warehouse": "_Test Warehouse - _TC" + "stock_uom": "_Test UOM" }, { "description": "_Test Item 2", @@ -56,8 +54,6 @@ "item_group": "_Test Item Group", "item_name": "_Test Item 2", "stock_uom": "_Test UOM", - "show_in_website": 1, - "website_warehouse": "_Test Warehouse - _TC", "gst_hsn_code": "999800", "opening_stock": 10, "valuation_rate": 100, @@ -311,8 +307,7 @@ "warehouse_reorder_level": 20, "warehouse_reorder_qty": 20 } - ], - "show_in_website": 1 + ] }, { "description": "_Test Item 1", @@ -344,9 +339,7 @@ "warehouse_reorder_qty": 20 } ], - "stock_uom": "_Test UOM", - "show_in_website": 1, - "website_warehouse": "_Test Warehouse Group-C1 - _TC" + "stock_uom": "_Test UOM" }, { "description": "_Test Item With Item Tax Template", diff --git a/erpnext/stock/doctype/item_alternative/test_item_alternative.py b/erpnext/stock/doctype/item_alternative/test_item_alternative.py index 3976af4e88c..501c1c1ad3c 100644 --- a/erpnext/stock/doctype/item_alternative/test_item_alternative.py +++ b/erpnext/stock/doctype/item_alternative/test_item_alternative.py @@ -4,6 +4,7 @@ import json import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import flt from erpnext.buying.doctype.purchase_order.purchase_order import ( @@ -18,10 +19,9 @@ 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(ERPNextTestCase): +class TestItemAlternative(FrappeTestCase): def setUp(self): super().setUp() make_items() diff --git a/erpnext/stock/doctype/item_attribute/test_item_attribute.py b/erpnext/stock/doctype/item_attribute/test_item_attribute.py index 0b7ca257151..055c22e0c5d 100644 --- a/erpnext/stock/doctype/item_attribute/test_item_attribute.py +++ b/erpnext/stock/doctype/item_attribute/test_item_attribute.py @@ -6,11 +6,12 @@ import frappe test_records = frappe.get_test_records('Item Attribute') +from frappe.tests.utils import FrappeTestCase + from erpnext.stock.doctype.item_attribute.item_attribute import ItemAttributeIncrementError -from erpnext.tests.utils import ERPNextTestCase -class TestItemAttribute(ERPNextTestCase): +class TestItemAttribute(FrappeTestCase): def setUp(self): super().setUp() if frappe.db.exists("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 f81770e487d..6ceba3f8d3f 100644 --- a/erpnext/stock/doctype/item_price/test_item_price.py +++ b/erpnext/stock/doctype/item_price/test_item_price.py @@ -4,13 +4,13 @@ import frappe from frappe.test_runner import make_test_records_for_doctype +from frappe.tests.utils import FrappeTestCase 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(ERPNextTestCase): +class TestItemPrice(FrappeTestCase): def setUp(self): super().setUp() frappe.db.sql("delete from `tabItem Price`") diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js index 488920aadbc..5e1f7d53221 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.js @@ -7,9 +7,8 @@ frappe.ui.form.on('Item Variant Settings', { const existing_fields = frm.doc.fields.map(row => row.field_name); const exclude_fields = [...existing_fields, "naming_series", "item_code", "item_name", - "show_in_website", "show_variant_in_website", "standard_rate", "opening_stock", "image", - "variant_of", "valuation_rate", "barcodes", "website_image", "thumbnail", - "website_specifiations", "web_long_description", "has_variants", "attributes"]; + "published_in_website", "standard_rate", "opening_stock", "image", + "variant_of", "valuation_rate", "barcodes", "has_variants", "attributes"]; const exclude_field_types = ['HTML', 'Section Break', 'Column Break', 'Button', 'Read Only']; diff --git a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py index f63498b9ac6..be1517eb587 100644 --- a/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py +++ b/erpnext/stock/doctype/item_variant_settings/item_variant_settings.py @@ -1,4 +1,4 @@ -# Copyright (c) 2017, Frappe Technologies Pvt. Ltd. and contributors +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt @@ -13,10 +13,9 @@ class ItemVariantSettings(Document): def set_default_fields(self): self.fields = [] fields = frappe.get_meta('Item').fields - exclude_fields = {"naming_series", "item_code", "item_name", "show_in_website", - "show_variant_in_website", "standard_rate", "opening_stock", "image", "description", + exclude_fields = {"naming_series", "item_code", "item_name", "published_in_website", + "standard_rate", "opening_stock", "image", "description", "variant_of", "valuation_rate", "description", "barcodes", - "website_image", "thumbnail", "website_specifiations", "web_long_description", "has_variants", "attributes"} for d in fields: 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 9204842b8f6..dbaefc1e113 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,19 +4,20 @@ import frappe -from frappe.utils import flt +from frappe.tests.utils import FrappeTestCase +from frappe.utils import add_to_date, flt, now from erpnext.accounts.doctype.account.test_account import create_account, get_inventory_account from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice +from erpnext.accounts.utils import update_gl_entries_after from erpnext.assets.doctype.asset.test_asset import create_asset_category, create_fixed_asset_item from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import ( get_gl_entries, make_purchase_receipt, ) -from erpnext.tests.utils import ERPNextTestCase -class TestLandedCostVoucher(ERPNextTestCase): +class TestLandedCostVoucher(FrappeTestCase): def test_landed_cost_voucher(self): frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) @@ -28,7 +29,8 @@ class TestLandedCostVoucher(ERPNextTestCase): "voucher_type": pr.doctype, "voucher_no": pr.name, "item_code": "_Test Item", - "warehouse": "Stores - TCP1" + "warehouse": "Stores - TCP1", + "is_cancelled": 0, }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1) @@ -41,14 +43,39 @@ class TestLandedCostVoucher(ERPNextTestCase): "voucher_type": pr.doctype, "voucher_no": pr.name, "item_code": "_Test Item", - "warehouse": "Stores - TCP1" + "warehouse": "Stores - TCP1", + "is_cancelled": 0, }, fieldname=["qty_after_transaction", "stock_value"], as_dict=1) self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction) - self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 25.0) + # assert after submit + self.assertPurchaseReceiptLCVGLEntries(pr) + + # Mess up cancelled SLE modified timestamp to check + # if they aren't effective in any business logic. + frappe.db.set_value("Stock Ledger Entry", + { + "is_cancelled": 1, + "voucher_type": pr.doctype, + "voucher_no": pr.name + }, + "is_cancelled", 1, + modified=add_to_date(now(), hours=1, as_datetime=True, as_string=True) + ) + + items, warehouses = pr.get_items_and_warehouses() + update_gl_entries_after(pr.posting_date, pr.posting_time, + warehouses, items, company=pr.company) + + # reassert after reposting + self.assertPurchaseReceiptLCVGLEntries(pr) + + + def assertPurchaseReceiptLCVGLEntries(self, pr): + gl_entries = get_gl_entries("Purchase Receipt", pr.name) self.assertTrue(gl_entries) @@ -74,8 +101,8 @@ class TestLandedCostVoucher(ERPNextTestCase): for gle in gl_entries: if not gle.get('is_cancelled'): - self.assertEqual(expected_values[gle.account][0], gle.debit) - self.assertEqual(expected_values[gle.account][1], gle.credit) + self.assertEqual(expected_values[gle.account][0], gle.debit, msg=f"incorrect debit for {gle.account}") + self.assertEqual(expected_values[gle.account][1], gle.credit, msg=f"incorrect credit for {gle.account}") def test_landed_cost_voucher_against_purchase_invoice(self): diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index 103e8d6a88c..51209acb275 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -56,14 +56,13 @@ class MaterialRequest(BuyingController): if actual_so_qty and (flt(so_items[so_no][item]) + already_indented > actual_so_qty): frappe.throw(_("Material Request of maximum {0} can be made for Item {1} against Sales Order {2}").format(actual_so_qty - already_indented, item, so_no)) - # Validate - # --------------------- def validate(self): super(MaterialRequest, self).validate() self.validate_schedule_date() self.check_for_on_hold_or_closed_status('Sales Order', 'sales_order') self.validate_uom_is_integer("uom", "qty") + self.validate_material_request_type() if not self.status: self.status = "Draft" @@ -83,6 +82,12 @@ class MaterialRequest(BuyingController): self.reset_default_field_value("set_warehouse", "items", "warehouse") self.reset_default_field_value("set_from_warehouse", "items", "from_warehouse") + def validate_material_request_type(self): + """ Validate fields in accordance with selected type """ + + if self.material_request_type != "Customer Provided": + self.customer = None + def set_title(self): '''Set title as comma separated list of items''' if not self.title: @@ -533,6 +538,7 @@ def raise_work_orders(material_request): "stock_uom": d.stock_uom, "expected_delivery_date": d.schedule_date, "sales_order": d.sales_order, + "sales_order_item": d.get("sales_order_item"), "bom_no": get_item_details(d.item_code).bom_no, "material_request": mr.name, "material_request_item": d.name, diff --git a/erpnext/stock/doctype/material_request/test_material_request.py b/erpnext/stock/doctype/material_request/test_material_request.py index 383b0ae806e..1cda7816170 100644 --- a/erpnext/stock/doctype/material_request/test_material_request.py +++ b/erpnext/stock/doctype/material_request/test_material_request.py @@ -6,6 +6,7 @@ import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import flt, today from erpnext.stock.doctype.item.test_item import create_item @@ -15,10 +16,9 @@ from erpnext.stock.doctype.material_request.material_request import ( make_supplier_quotation, raise_work_orders, ) -from erpnext.tests.utils import ERPNextTestCase -class TestMaterialRequest(ERPNextTestCase): +class TestMaterialRequest(FrappeTestCase): def test_make_purchase_order(self): mr = frappe.copy_doc(test_records[0]).insert() diff --git a/erpnext/stock/doctype/packed_item/packed_item.json b/erpnext/stock/doctype/packed_item/packed_item.json index 830d5469bf0..d2d47897658 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.json +++ b/erpnext/stock/doctype/packed_item/packed_item.json @@ -218,8 +218,6 @@ "label": "Conversion Factor" }, { - "fetch_from": "item_code.valuation_rate", - "fetch_if_empty": 1, "fieldname": "rate", "fieldtype": "Currency", "in_list_view": 1, @@ -232,7 +230,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-09-01 15:10:29.646399", + "modified": "2022-01-28 16:03:30.780111", "modified_by": "Administrator", "module": "Stock", "name": "Packed Item", @@ -240,5 +238,6 @@ "permissions": [], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py index e4091c40dc4..07c2f1f0dd3 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -8,187 +8,253 @@ import json import frappe from frappe.model.document import Document -from frappe.utils import cstr, flt +from frappe.utils import flt -from erpnext.stock.get_item_details import get_item_details +from erpnext.stock.get_item_details import get_item_details, get_price_list_rate class PackedItem(Document): pass -def get_product_bundle_items(item_code): - return frappe.db.sql("""select t1.item_code, t1.qty, t1.uom, t1.description - from `tabProduct Bundle Item` t1, `tabProduct Bundle` t2 - where t2.new_item_code=%s and t1.parent = t2.name order by t1.idx""", item_code, as_dict=1) - -def get_packing_item_details(item, company): - return frappe.db.sql(""" - select i.item_name, i.is_stock_item, i.description, i.stock_uom, id.default_warehouse - from `tabItem` i LEFT JOIN `tabItem Default` id ON id.parent=i.name and id.company=%s - where i.name = %s""", - (company, item), as_dict = 1)[0] - -def get_bin_qty(item, warehouse): - det = frappe.db.sql("""select actual_qty, projected_qty from `tabBin` - where item_code = %s and warehouse = %s""", (item, warehouse), as_dict = 1) - return det and det[0] or frappe._dict() - -def update_packing_list_item(doc, packing_item_code, qty, main_item_row, description): - if doc.amended_from: - old_packed_items_map = get_old_packed_item_details(doc.packed_items) - else: - old_packed_items_map = False - item = get_packing_item_details(packing_item_code, doc.company) - - # check if exists - exists = 0 - for d in doc.get("packed_items"): - if d.parent_item == main_item_row.item_code and d.item_code == packing_item_code: - if d.parent_detail_docname != main_item_row.name: - d.parent_detail_docname = main_item_row.name - - pi, exists = d, 1 - break - - if not exists: - pi = doc.append('packed_items', {}) - - pi.parent_item = main_item_row.item_code - pi.item_code = packing_item_code - pi.item_name = item.item_name - pi.parent_detail_docname = main_item_row.name - pi.uom = item.stock_uom - pi.qty = flt(qty) - pi.conversion_factor = main_item_row.conversion_factor - if description and not pi.description: - pi.description = description - if not pi.warehouse and not doc.amended_from: - pi.warehouse = (main_item_row.warehouse if ((doc.get('is_pos') or item.is_stock_item \ - or not item.default_warehouse) and main_item_row.warehouse) else item.default_warehouse) - if not pi.batch_no and not doc.amended_from: - pi.batch_no = cstr(main_item_row.get("batch_no")) - if not pi.target_warehouse: - pi.target_warehouse = main_item_row.get("target_warehouse") - bin = get_bin_qty(packing_item_code, pi.warehouse) - pi.actual_qty = flt(bin.get("actual_qty")) - pi.projected_qty = flt(bin.get("projected_qty")) - if old_packed_items_map and old_packed_items_map.get((packing_item_code, main_item_row.item_code)): - pi.batch_no = old_packed_items_map.get((packing_item_code, main_item_row.item_code))[0].batch_no - pi.serial_no = old_packed_items_map.get((packing_item_code, main_item_row.item_code))[0].serial_no - pi.warehouse = old_packed_items_map.get((packing_item_code, main_item_row.item_code))[0].warehouse def make_packing_list(doc): - """make packing list for Product Bundle item""" - if doc.get("_action") and doc._action == "update_after_submit": return - - parent_items = [] - for d in doc.get("items"): - if frappe.db.get_value("Product Bundle", {"new_item_code": d.item_code}): - for i in get_product_bundle_items(d.item_code): - update_packing_list_item(doc, i.item_code, flt(i.qty)*flt(d.stock_qty), d, i.description) - - if [d.item_code, d.name] not in parent_items: - parent_items.append([d.item_code, d.name]) - - cleanup_packing_list(doc, parent_items) - - if frappe.db.get_single_value("Selling Settings", "editable_bundle_item_rates"): - update_product_bundle_price(doc, parent_items) - -def cleanup_packing_list(doc, parent_items): - """Remove all those child items which are no longer present in main item table""" - delete_list = [] - for d in doc.get("packed_items"): - if [d.parent_item, d.parent_detail_docname] not in parent_items: - # mark for deletion from doclist - delete_list.append(d) - - if not delete_list: - return doc - - packed_items = doc.get("packed_items") - doc.set("packed_items", []) - - for d in packed_items: - if d not in delete_list: - add_item_to_packing_list(doc, d) - -def add_item_to_packing_list(doc, packed_item): - doc.append("packed_items", { - 'parent_item': packed_item.parent_item, - 'item_code': packed_item.item_code, - 'item_name': packed_item.item_name, - 'uom': packed_item.uom, - 'qty': packed_item.qty, - 'rate': packed_item.rate, - 'conversion_factor': packed_item.conversion_factor, - 'description': packed_item.description, - 'warehouse': packed_item.warehouse, - 'batch_no': packed_item.batch_no, - 'actual_batch_qty': packed_item.actual_batch_qty, - 'serial_no': packed_item.serial_no, - 'target_warehouse': packed_item.target_warehouse, - 'actual_qty': packed_item.actual_qty, - 'projected_qty': packed_item.projected_qty, - 'incoming_rate': packed_item.incoming_rate, - 'prevdoc_doctype': packed_item.prevdoc_doctype, - 'parent_detail_docname': packed_item.parent_detail_docname - }) - -def update_product_bundle_price(doc, parent_items): - """Updates the prices of Product Bundles based on the rates of the Items in the bundle.""" - - if not doc.get('items'): + "Make/Update packing list for Product Bundle Item." + if doc.get("_action") and doc._action == "update_after_submit": return - parent_items_index = 0 - bundle_price = 0 + parent_items_price, reset = {}, False + set_price_from_children = frappe.db.get_single_value("Selling Settings", "editable_bundle_item_rates") - for bundle_item in doc.get("packed_items"): - if parent_items[parent_items_index][0] == bundle_item.parent_item: - bundle_item_rate = bundle_item.rate if bundle_item.rate else 0 - bundle_price += bundle_item.qty * bundle_item_rate - else: - update_parent_item_price(doc, parent_items[parent_items_index][0], bundle_price) + stale_packed_items_table = get_indexed_packed_items_table(doc) - bundle_item_rate = bundle_item.rate if bundle_item.rate else 0 - bundle_price = bundle_item.qty * bundle_item_rate - parent_items_index += 1 + reset = reset_packing_list(doc) - # for the last product bundle - if doc.get("packed_items"): - update_parent_item_price(doc, parent_items[parent_items_index][0], bundle_price) + for item_row in doc.get("items"): + if frappe.db.exists("Product Bundle", {"new_item_code": item_row.item_code}): + for bundle_item in get_product_bundle_items(item_row.item_code): + pi_row = add_packed_item_row( + doc=doc, packing_item=bundle_item, + main_item_row=item_row, packed_items_table=stale_packed_items_table, + reset=reset + ) + item_data = get_packed_item_details(bundle_item.item_code, doc.company) + update_packed_item_basic_data(item_row, pi_row, bundle_item, item_data) + update_packed_item_stock_data(item_row, pi_row, bundle_item, item_data, doc) + update_packed_item_price_data(pi_row, item_data, doc) + update_packed_item_from_cancelled_doc(item_row, bundle_item, pi_row, doc) -def update_parent_item_price(doc, parent_item_code, bundle_price): - parent_item_doc = doc.get('items', {'item_code': parent_item_code})[0] + if set_price_from_children: # create/update bundle item wise price dict + update_product_bundle_rate(parent_items_price, pi_row) - current_parent_item_price = parent_item_doc.amount - if current_parent_item_price != bundle_price: - parent_item_doc.amount = bundle_price - update_parent_item_rate(parent_item_doc, bundle_price) + if parent_items_price: + set_product_bundle_rate_amount(doc, parent_items_price) # set price in bundle item -def update_parent_item_rate(parent_item_doc, bundle_price): - parent_item_doc.rate = bundle_price/parent_item_doc.qty +def get_indexed_packed_items_table(doc): + """ + Create dict from stale packed items table like: + {(Parent Item 1, Bundle Item 1, ae4b5678): {...}, (key): {value}} -@frappe.whitelist() -def get_items_from_product_bundle(args): - args = json.loads(args) - items = [] - bundled_items = get_product_bundle_items(args["item_code"]) - for item in bundled_items: - args.update({ - "item_code": item.item_code, - "qty": flt(args["quantity"]) * flt(item.qty) - }) - items.append(get_item_details(args)) + Use: to quickly retrieve/check if row existed in table instead of looping n times + """ + indexed_table = {} + for packed_item in doc.get("packed_items"): + key = (packed_item.parent_item, packed_item.item_code, packed_item.parent_detail_docname) + indexed_table[key] = packed_item - return items + return indexed_table + +def reset_packing_list(doc): + "Conditionally reset the table and return if it was reset or not." + reset_table = False + doc_before_save = doc.get_doc_before_save() + + if doc_before_save: + # reset table if: + # 1. items were deleted + # 2. if bundle item replaced by another item (same no. of items but different items) + # we maintain list to track recurring item rows as well + items_before_save = [item.item_code for item in doc_before_save.get("items")] + items_after_save = [item.item_code for item in doc.get("items")] + reset_table = items_before_save != items_after_save + else: + # reset: if via Update Items OR + # if new mapped doc with packed items set (SO -> DN) + # (cannot determine action) + reset_table = True + + if reset_table: + doc.set("packed_items", []) + return reset_table + +def get_product_bundle_items(item_code): + product_bundle = frappe.qb.DocType("Product Bundle") + product_bundle_item = frappe.qb.DocType("Product Bundle Item") + + query = ( + frappe.qb.from_(product_bundle_item) + .join(product_bundle).on(product_bundle_item.parent == product_bundle.name) + .select( + product_bundle_item.item_code, + product_bundle_item.qty, + product_bundle_item.uom, + product_bundle_item.description + ).where( + product_bundle.new_item_code == item_code + ).orderby( + product_bundle_item.idx + ) + ) + return query.run(as_dict=True) + +def add_packed_item_row(doc, packing_item, main_item_row, packed_items_table, reset): + """Add and return packed item row. + doc: Transaction document + packing_item (dict): Packed Item details + main_item_row (dict): Items table row corresponding to packed item + packed_items_table (dict): Packed Items table before save (indexed) + reset (bool): State if table is reset or preserved as is + """ + exists, pi_row = False, {} + + # check if row already exists in packed items table + key = (main_item_row.item_code, packing_item.item_code, main_item_row.name) + if packed_items_table.get(key): + pi_row, exists = packed_items_table.get(key), True + + if not exists: + pi_row = doc.append('packed_items', {}) + elif reset: # add row if row exists but table is reset + pi_row.idx, pi_row.name = None, None + pi_row = doc.append('packed_items', pi_row) + + return pi_row + +def get_packed_item_details(item_code, company): + item = frappe.qb.DocType("Item") + item_default = frappe.qb.DocType("Item Default") + query = ( + frappe.qb.from_(item) + .left_join(item_default) + .on( + (item_default.parent == item.name) + & (item_default.company == company) + ).select( + item.item_name, item.is_stock_item, + item.description, item.stock_uom, + item.valuation_rate, + item_default.default_warehouse + ).where( + item.name == item_code + ) + ) + return query.run(as_dict=True)[0] + +def update_packed_item_basic_data(main_item_row, pi_row, packing_item, item_data): + pi_row.parent_item = main_item_row.item_code + pi_row.parent_detail_docname = main_item_row.name + pi_row.item_code = packing_item.item_code + pi_row.item_name = item_data.item_name + pi_row.uom = item_data.stock_uom + pi_row.qty = flt(packing_item.qty) * flt(main_item_row.stock_qty) + pi_row.conversion_factor = main_item_row.conversion_factor + + if not pi_row.description: + pi_row.description = packing_item.get("description") + +def update_packed_item_stock_data(main_item_row, pi_row, packing_item, item_data, doc): + # TODO batch_no, actual_batch_qty, incoming_rate + if not pi_row.warehouse and not doc.amended_from: + fetch_warehouse = (doc.get('is_pos') or item_data.is_stock_item or not item_data.default_warehouse) + pi_row.warehouse = (main_item_row.warehouse if (fetch_warehouse and main_item_row.warehouse) + else item_data.default_warehouse) + + if not pi_row.target_warehouse: + pi_row.target_warehouse = main_item_row.get("target_warehouse") + + bin = get_packed_item_bin_qty(packing_item.item_code, pi_row.warehouse) + pi_row.actual_qty = flt(bin.get("actual_qty")) + pi_row.projected_qty = flt(bin.get("projected_qty")) + +def update_packed_item_price_data(pi_row, item_data, doc): + "Set price as per price list or from the Item master." + if pi_row.rate: + return + + item_doc = frappe.get_cached_doc("Item", pi_row.item_code) + row_data = pi_row.as_dict().copy() + row_data.update({ + "company": doc.get("company"), + "price_list": doc.get("selling_price_list"), + "currency": doc.get("currency") + }) + rate = get_price_list_rate(row_data, item_doc).get("price_list_rate") + + pi_row.rate = rate or item_data.get("valuation_rate") or 0.0 + +def update_packed_item_from_cancelled_doc(main_item_row, packing_item, pi_row, doc): + "Update packed item row details from cancelled doc into amended doc." + prev_doc_packed_items_map = None + if doc.amended_from: + prev_doc_packed_items_map = get_cancelled_doc_packed_item_details(doc.packed_items) + + if prev_doc_packed_items_map and prev_doc_packed_items_map.get((packing_item.item_code, main_item_row.item_code)): + prev_doc_row = prev_doc_packed_items_map.get((packing_item.item_code, main_item_row.item_code)) + pi_row.batch_no = prev_doc_row[0].batch_no + pi_row.serial_no = prev_doc_row[0].serial_no + pi_row.warehouse = prev_doc_row[0].warehouse + +def get_packed_item_bin_qty(item, warehouse): + bin_data = frappe.db.get_values( + "Bin", + fieldname=["actual_qty", "projected_qty"], + filters={"item_code": item, "warehouse": warehouse}, + as_dict=True + ) + + return bin_data[0] if bin_data else {} + +def get_cancelled_doc_packed_item_details(old_packed_items): + prev_doc_packed_items_map = {} + for items in old_packed_items: + prev_doc_packed_items_map.setdefault((items.item_code ,items.parent_item), []).append(items.as_dict()) + return prev_doc_packed_items_map + +def update_product_bundle_rate(parent_items_price, pi_row): + """ + Update the price dict of Product Bundles based on the rates of the Items in the bundle. + + Stucture: + {(Bundle Item 1, ae56fgji): 150.0, (Bundle Item 2, bc78fkjo): 200.0} + """ + key = (pi_row.parent_item, pi_row.parent_detail_docname) + rate = parent_items_price.get(key) + if not rate: + parent_items_price[key] = 0.0 + + parent_items_price[key] += flt(pi_row.rate) + +def set_product_bundle_rate_amount(doc, parent_items_price): + "Set cumulative rate and amount in bundle item." + for item in doc.get("items"): + bundle_rate = parent_items_price.get((item.item_code, item.name)) + if bundle_rate and bundle_rate != item.rate: + item.rate = bundle_rate + item.amount = flt(bundle_rate * item.qty) def on_doctype_update(): frappe.db.add_index("Packed Item", ["item_code", "warehouse"]) -def get_old_packed_item_details(old_packed_items): - old_packed_items_map = {} - for items in old_packed_items: - old_packed_items_map.setdefault((items.item_code ,items.parent_item), []).append(items.as_dict()) - return old_packed_items_map + +@frappe.whitelist() +def get_items_from_product_bundle(row): + row, items = json.loads(row), [] + + bundled_items = get_product_bundle_items(row["item_code"]) + for item in bundled_items: + row.update({ + "item_code": item.item_code, + "qty": flt(row["quantity"]) * flt(item.qty) + }) + items.append(get_item_details(row)) + + return items diff --git a/erpnext/stock/doctype/packed_item/test_packed_item.py b/erpnext/stock/doctype/packed_item/test_packed_item.py new file mode 100644 index 00000000000..94268a8ef37 --- /dev/null +++ b/erpnext/stock/doctype/packed_item/test_packed_item.py @@ -0,0 +1,158 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from frappe.tests.utils import FrappeTestCase, change_settings +from frappe.utils import add_to_date, nowdate + +from erpnext.selling.doctype.product_bundle.test_product_bundle import make_product_bundle +from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note +from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order +from erpnext.stock.doctype.item.test_item import make_item +from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries +from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry + + +class TestPackedItem(FrappeTestCase): + "Test impact on Packed Items table in various scenarios." + @classmethod + def setUpClass(cls) -> None: + super().setUpClass() + cls.bundle = "_Test Product Bundle X" + cls.bundle_items = ["_Test Bundle Item 1", "_Test Bundle Item 2"] + make_item(cls.bundle, {"is_stock_item": 0}) + for item in cls.bundle_items: + make_item(item, {"is_stock_item": 1}) + + make_item("_Test Normal Stock Item", {"is_stock_item": 1}) + + make_product_bundle(cls.bundle, cls.bundle_items, qty=2) + + def test_adding_bundle_item(self): + "Test impact on packed items if bundle item row is added." + so = make_sales_order(item_code = self.bundle, qty=1, + do_not_submit=True) + + self.assertEqual(so.items[0].qty, 1) + self.assertEqual(len(so.packed_items), 2) + self.assertEqual(so.packed_items[0].item_code, self.bundle_items[0]) + self.assertEqual(so.packed_items[0].qty, 2) + + def test_updating_bundle_item(self): + "Test impact on packed items if bundle item row is updated." + so = make_sales_order(item_code=self.bundle, qty=1, do_not_submit=True) + + so.items[0].qty = 2 # change qty + so.save() + + self.assertEqual(so.packed_items[0].qty, 4) + self.assertEqual(so.packed_items[1].qty, 4) + + # change item code to non bundle item + so.items[0].item_code = "_Test Normal Stock Item" + so.save() + + self.assertEqual(len(so.packed_items), 0) + + def test_recurring_bundle_item(self): + "Test impact on packed items if same bundle item is added and removed." + so_items = [] + for qty in [2, 4, 6, 8]: + so_items.append({ + "item_code": self.bundle, + "qty": qty, + "rate": 400, + "warehouse": "_Test Warehouse - _TC" + }) + + # create SO with recurring bundle item + so = make_sales_order(item_list=so_items, do_not_submit=True) + + # check alternate rows for qty + self.assertEqual(len(so.packed_items), 8) + self.assertEqual(so.packed_items[1].item_code, self.bundle_items[1]) + self.assertEqual(so.packed_items[1].qty, 4) + self.assertEqual(so.packed_items[3].qty, 8) + self.assertEqual(so.packed_items[5].qty, 12) + self.assertEqual(so.packed_items[7].qty, 16) + + # delete intermediate row (2nd) + del so.items[1] + so.save() + + # check alternate rows for qty + self.assertEqual(len(so.packed_items), 6) + self.assertEqual(so.packed_items[1].qty, 4) + self.assertEqual(so.packed_items[3].qty, 12) + self.assertEqual(so.packed_items[5].qty, 16) + + # delete last row + del so.items[2] + so.save() + + # check alternate rows for qty + self.assertEqual(len(so.packed_items), 4) + self.assertEqual(so.packed_items[1].qty, 4) + self.assertEqual(so.packed_items[3].qty, 12) + + @change_settings("Selling Settings", {"editable_bundle_item_rates": 1}) + def test_bundle_item_cumulative_price(self): + "Test if Bundle Item rate is cumulative from packed items." + so = make_sales_order(item_code=self.bundle, qty=2, do_not_submit=True) + + so.packed_items[0].rate = 150 + so.packed_items[1].rate = 200 + so.save() + + self.assertEqual(so.items[0].rate, 350) + self.assertEqual(so.items[0].amount, 700) + + def test_newly_mapped_doc_packed_items(self): + "Test impact on packed items in newly mapped DN from SO." + so_items = [] + for qty in [2, 4]: + so_items.append({ + "item_code": self.bundle, + "qty": qty, + "rate": 400, + "warehouse": "_Test Warehouse - _TC" + }) + + # create SO with recurring bundle item + so = make_sales_order(item_list=so_items) + + dn = make_delivery_note(so.name) + dn.items[1].qty = 3 # change second row qty for inserting doc + dn.save() + + self.assertEqual(len(dn.packed_items), 4) + self.assertEqual(dn.packed_items[2].qty, 6) + self.assertEqual(dn.packed_items[3].qty, 6) + + def test_reposting_packed_items(self): + warehouse = "Stores - TCP1" + company = "_Test Company with perpetual inventory" + + today = nowdate() + yesterday = add_to_date(today, days=-1, as_string=True) + + for item in self.bundle_items: + make_stock_entry(item_code=item, to_warehouse=warehouse, qty=10, rate=100, posting_date=today) + + so = make_sales_order(item_code = self.bundle, qty=1, company=company, warehouse=warehouse) + + dn = make_delivery_note(so.name) + dn.save() + dn.submit() + + gles = get_gl_entries(dn.doctype, dn.name) + credit_before_repost = sum(gle.credit for gle in gles) + + # backdated stock entry + for item in self.bundle_items: + make_stock_entry(item_code=item, to_warehouse=warehouse, qty=10, rate=200, posting_date=yesterday) + + # assert correct reposting + gles = get_gl_entries(dn.doctype, dn.name) + credit_after_reposting = sum(gle.credit for gle in gles) + self.assertNotEqual(credit_before_repost, credit_after_reposting) + self.assertAlmostEqual(credit_after_reposting, 2 * credit_before_repost) diff --git a/erpnext/stock/doctype/packing_slip/test_packing_slip.py b/erpnext/stock/doctype/packing_slip/test_packing_slip.py index 5eb6b7399ae..bc405b20995 100644 --- a/erpnext/stock/doctype/packing_slip/test_packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/test_packing_slip.py @@ -4,7 +4,7 @@ import unittest # test_records = frappe.get_test_records('Packing Slip') -from erpnext.tests.utils import ERPNextTestCase +from frappe.tests.utils import FrappeTestCase class TestPackingSlip(unittest.TestCase): diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 41e3150f0d7..f3b6b89784a 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -6,16 +6,17 @@ from frappe import _dict test_dependencies = ['Item', 'Sales Invoice', 'Stock Entry', 'Batch'] +from frappe.tests.utils import FrappeTestCase + from erpnext.stock.doctype.item.test_item import create_item from erpnext.stock.doctype.pick_list.pick_list import create_delivery_note from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import ( EmptyStockReconciliationItemsError, ) -from erpnext.tests.utils import ERPNextTestCase -class TestPickList(ERPNextTestCase): +class TestPickList(FrappeTestCase): def test_pick_list_picks_warehouse_for_each_item(self): try: diff --git a/erpnext/stock/doctype/price_list/price_list.py b/erpnext/stock/doctype/price_list/price_list.py index 74b823ada3e..8a3172e9e22 100644 --- a/erpnext/stock/doctype/price_list/price_list.py +++ b/erpnext/stock/doctype/price_list/price_list.py @@ -36,14 +36,14 @@ class PriceList(Document): (self.currency, cint(self.buying), cint(self.selling), self.name)) def check_impact_on_shopping_cart(self): - "Check if Price List currency change impacts Shopping Cart." - from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import ( + "Check if Price List currency change impacts E Commerce Cart." + from erpnext.e_commerce.doctype.e_commerce_settings.e_commerce_settings import ( validate_cart_settings, ) doc_before_save = self.get_doc_before_save() currency_changed = self.currency != doc_before_save.currency - affects_cart = self.name == frappe.get_cached_value("Shopping Cart Settings", None, "price_list") + affects_cart = self.name == frappe.get_cached_value("E Commerce Settings", None, "price_list") if currency_changed and affects_cart: validate_cart_settings() diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json index 112ddedac29..b54a90eed35 100755 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.json @@ -106,6 +106,8 @@ "terms", "bill_no", "bill_date", + "accounting_details_section", + "provisional_expense_account", "more_info", "project", "status", @@ -1144,16 +1146,30 @@ "label": "Represents Company", "options": "Company", "read_only": 1 + }, + { + "collapsible": 1, + "fieldname": "accounting_details_section", + "fieldtype": "Section Break", + "label": "Accounting Details" + }, + { + "fieldname": "provisional_expense_account", + "fieldtype": "Link", + "hidden": 1, + "label": "Provisional Expense Account", + "options": "Account" } ], "icon": "fa fa-truck", "idx": 261, "is_submittable": 1, "links": [], - "modified": "2021-09-28 13:11:10.181328", + "modified": "2022-02-01 11:40:52.690984", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt", + "naming_rule": "By \"Naming Series\" field", "owner": "Administrator", "permissions": [ { @@ -1214,6 +1230,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "timeline_field": "supplier", "title_field": "title", "track_changes": 1 diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index c97b306c4e6..33e40c85f1a 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -8,6 +8,7 @@ from frappe.desk.notifications import clear_doctype_notifications from frappe.model.mapper import get_mapped_doc from frappe.utils import cint, flt, getdate, nowdate +import erpnext from erpnext.accounts.utils import get_account_currency from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accounting_enabled from erpnext.assets.doctype.asset_category.asset_category import get_asset_category_account @@ -112,6 +113,7 @@ class PurchaseReceipt(BuyingController): self.validate_uom_is_integer("uom", ["qty", "received_qty"]) self.validate_uom_is_integer("stock_uom", "stock_qty") self.validate_cwip_accounts() + self.validate_provisional_expense_account() self.check_on_hold_or_closed_status() @@ -133,6 +135,15 @@ class PurchaseReceipt(BuyingController): company = self.company) break + def validate_provisional_expense_account(self): + provisional_accounting_for_non_stock_items = \ + cint(frappe.db.get_value('Company', self.company, 'enable_provisional_accounting_for_non_stock_items')) + + if provisional_accounting_for_non_stock_items: + default_provisional_account = self.get_company_default("default_provisional_account") + if not self.provisional_expense_account: + self.provisional_expense_account = default_provisional_account + def validate_with_previous_doc(self): super(PurchaseReceipt, self).validate_with_previous_doc({ "Purchase Order": { @@ -258,13 +269,15 @@ class PurchaseReceipt(BuyingController): get_purchase_document_details, ) - stock_rbnb = self.get_company_default("stock_received_but_not_billed") - landed_cost_entries = get_item_account_wise_additional_cost(self.name) - expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") - auto_accounting_for_non_stock_items = cint(frappe.db.get_value('Company', self.company, 'enable_perpetual_inventory_for_non_stock_items')) + if erpnext.is_perpetual_inventory_enabled(self.company): + stock_rbnb = self.get_company_default("stock_received_but_not_billed") + landed_cost_entries = get_item_account_wise_additional_cost(self.name) + expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") warehouse_with_no_account = [] stock_items = self.get_stock_items() + provisional_accounting_for_non_stock_items = \ + cint(frappe.db.get_value('Company', self.company, 'enable_provisional_accounting_for_non_stock_items')) exchange_rate_map, net_rate_map = get_purchase_document_details(self) @@ -273,10 +286,7 @@ class PurchaseReceipt(BuyingController): if warehouse_account.get(d.warehouse): stock_value_diff = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", "voucher_no": self.name, - "voucher_detail_no": d.name, "warehouse": d.warehouse}, "stock_value_difference") - - if not stock_value_diff: - continue + "voucher_detail_no": d.name, "warehouse": d.warehouse, "is_cancelled": 0}, "stock_value_difference") warehouse_account_name = warehouse_account[d.warehouse]["account"] warehouse_account_currency = warehouse_account[d.warehouse]["account_currency"] @@ -422,43 +432,58 @@ class PurchaseReceipt(BuyingController): elif d.warehouse not in warehouse_with_no_account or \ d.rejected_warehouse not in warehouse_with_no_account: warehouse_with_no_account.append(d.warehouse) - elif d.item_code not in stock_items and not d.is_fixed_asset and flt(d.qty) and auto_accounting_for_non_stock_items: - service_received_but_not_billed_account = self.get_company_default("service_received_but_not_billed") - credit_currency = get_account_currency(service_received_but_not_billed_account) - debit_currency = get_account_currency(d.expense_account) - remarks = self.get("remarks") or _("Accounting Entry for Service") - - self.add_gl_entry( - gl_entries=gl_entries, - account=service_received_but_not_billed_account, - cost_center=d.cost_center, - debit=0.0, - credit=d.amount, - remarks=remarks, - against_account=d.expense_account, - account_currency=credit_currency, - project=d.project, - voucher_detail_no=d.name, item=d) - - self.add_gl_entry( - gl_entries=gl_entries, - account=d.expense_account, - cost_center=d.cost_center, - debit=d.amount, - credit=0.0, - remarks=remarks, - against_account=service_received_but_not_billed_account, - account_currency = debit_currency, - project=d.project, - voucher_detail_no=d.name, - item=d) + elif d.item_code not in stock_items and not d.is_fixed_asset and flt(d.qty) and provisional_accounting_for_non_stock_items: + self.add_provisional_gl_entry(d, gl_entries, self.posting_date) if warehouse_with_no_account: frappe.msgprint(_("No accounting entries for the following warehouses") + ": \n" + "\n".join(warehouse_with_no_account)) + def add_provisional_gl_entry(self, item, gl_entries, posting_date, reverse=0): + provisional_expense_account = self.get('provisional_expense_account') + credit_currency = get_account_currency(provisional_expense_account) + debit_currency = get_account_currency(item.expense_account) + expense_account = item.expense_account + remarks = self.get("remarks") or _("Accounting Entry for Service") + multiplication_factor = 1 + + if reverse: + multiplication_factor = -1 + expense_account = frappe.db.get_value('Purchase Receipt Item', {'name': item.get('pr_detail')}, ['expense_account']) + + self.add_gl_entry( + gl_entries=gl_entries, + account=provisional_expense_account, + cost_center=item.cost_center, + debit=0.0, + credit=multiplication_factor * item.amount, + remarks=remarks, + against_account=expense_account, + account_currency=credit_currency, + project=item.project, + voucher_detail_no=item.name, + item=item, + posting_date=posting_date) + + self.add_gl_entry( + gl_entries=gl_entries, + account=expense_account, + cost_center=item.cost_center, + debit=multiplication_factor * item.amount, + credit=0.0, + remarks=remarks, + against_account=provisional_expense_account, + account_currency = debit_currency, + project=item.project, + voucher_detail_no=item.name, + item=item, + posting_date=posting_date) + def make_tax_gl_entries(self, gl_entries): - expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") + + if erpnext.is_perpetual_inventory_enabled(self.company): + expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") + negative_expense_to_be_booked = sum([flt(d.item_tax_amount) for d in self.get('items')]) # Cost center-wise amount breakup for other charges included for valuation valuation_tax = {} @@ -515,7 +540,8 @@ class PurchaseReceipt(BuyingController): def add_gl_entry(self, gl_entries, account, cost_center, debit, credit, remarks, against_account, debit_in_account_currency=None, credit_in_account_currency=None, account_currency=None, - project=None, voucher_detail_no=None, item=None): + project=None, voucher_detail_no=None, item=None, posting_date=None): + gl_entry = { "account": account, "cost_center": cost_center, @@ -534,6 +560,9 @@ class PurchaseReceipt(BuyingController): if credit_in_account_currency: gl_entry.update({"credit_in_account_currency": credit_in_account_currency}) + if posting_date: + gl_entry.update({"posting_date": posting_date}) + gl_entries.append(self.get_gl_dict(gl_entry, item=item)) def get_asset_gl_entry(self, gl_entries): @@ -562,6 +591,7 @@ class PurchaseReceipt(BuyingController): # debit cwip account debit_in_account_currency = (base_asset_amount if cwip_account_currency == self.company_currency else asset_amount) + self.add_gl_entry( gl_entries=gl_entries, account=cwip_account, @@ -577,6 +607,7 @@ class PurchaseReceipt(BuyingController): # credit arbnb account credit_in_account_currency = (base_asset_amount if asset_rbnb_currency == self.company_currency else asset_amount) + self.add_gl_entry( gl_entries=gl_entries, account=arbnb_account, diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js index 77711de93f7..4029f0c127b 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt_list.js @@ -13,5 +13,13 @@ frappe.listview_settings['Purchase Receipt'] = { } else if (flt(doc.grand_total) === 0 || flt(doc.per_billed, 2) === 100) { return [__("Completed"), "green", "per_billed,=,100"]; } + }, + + onload: function(listview) { + + listview.page.add_action_item(__("Purchase Invoice"), ()=>{ + erpnext.bulk_transaction_processing.create(listview, "Purchase Receipt", "Purchase Invoice"); + }); } + }; diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 2909a2d2e74..a24acb1bd83 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4,8 +4,10 @@ import json import unittest +from collections import defaultdict import frappe +from frappe.tests.utils import FrappeTestCase, change_settings from frappe.utils import add_days, cint, cstr, flt, today import erpnext @@ -16,10 +18,9 @@ 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(ERPNextTestCase): +class TestPurchaseReceipt(FrappeTestCase): def setUp(self): frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1) @@ -1312,58 +1313,6 @@ class TestPurchaseReceipt(ERPNextTestCase): self.assertEqual(pr.status, "To Bill") self.assertAlmostEqual(pr.per_billed, 50.0, places=2) - def test_service_item_purchase_with_perpetual_inventory(self): - company = '_Test Company with perpetual inventory' - service_item = '_Test Non Stock Item' - - before_test_value = frappe.db.get_value( - 'Company', company, 'enable_perpetual_inventory_for_non_stock_items' - ) - frappe.db.set_value( - 'Company', company, - 'enable_perpetual_inventory_for_non_stock_items', 1 - ) - srbnb_account = 'Stock Received But Not Billed - TCP1' - frappe.db.set_value( - 'Company', company, - 'service_received_but_not_billed', srbnb_account - ) - - pr = make_purchase_receipt( - company=company, item=service_item, - warehouse='Finished Goods - TCP1', do_not_save=1 - ) - item_row_with_diff_rate = frappe.copy_doc(pr.items[0]) - item_row_with_diff_rate.rate = 100 - pr.append('items', item_row_with_diff_rate) - - pr.save() - pr.submit() - - item_one_gl_entry = frappe.db.get_all("GL Entry", { - 'voucher_type': pr.doctype, - 'voucher_no': pr.name, - 'account': srbnb_account, - 'voucher_detail_no': pr.items[0].name - }, pluck="name") - - item_two_gl_entry = frappe.db.get_all("GL Entry", { - 'voucher_type': pr.doctype, - 'voucher_no': pr.name, - 'account': srbnb_account, - 'voucher_detail_no': pr.items[1].name - }, pluck="name") - - # check if the entries are not merged into one - # seperate entries should be made since voucher_detail_no is different - self.assertEqual(len(item_one_gl_entry), 1) - self.assertEqual(len(item_two_gl_entry), 1) - - frappe.db.set_value( - 'Company', company, - 'enable_perpetual_inventory_for_non_stock_items', before_test_value - ) - def test_purchase_receipt_with_exchange_rate_difference(self): from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import ( make_purchase_receipt as create_purchase_receipt, @@ -1439,6 +1388,36 @@ class TestPurchaseReceipt(ERPNextTestCase): automatically_fetch_payment_terms(enable=0) + @change_settings("Stock Settings", {"allow_negative_stock": 1}) + def test_neg_to_positive(self): + from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry + + item_code = "_TestNegToPosItem" + warehouse = "Stores - TCP1" + company = "_Test Company with perpetual inventory" + account = "Stock Received But Not Billed - TCP1" + + make_item(item_code) + se = make_stock_entry(item_code=item_code, from_warehouse=warehouse, qty=50, do_not_save=True, rate=0) + se.items[0].allow_zero_valuation_rate = 1 + se.save() + se.submit() + + pr = make_purchase_receipt( + qty=50, + rate=1, + item_code=item_code, + warehouse=warehouse, + get_taxes_and_charges=True, + company=company, + ) + gles = get_gl_entries(pr.doctype, pr.name) + + for gle in gles: + if gle.account == account: + self.assertEqual(gle.credit, 50) + + def get_sl_entries(voucher_type, voucher_no): return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s @@ -1561,6 +1540,7 @@ def make_purchase_receipt(**args): "conversion_factor": args.conversion_factor or 1.0, "stock_qty": flt(qty) * (flt(args.conversion_factor) or 1.0), "serial_no": args.serial_no, + "batch_no": args.batch_no, "stock_uom": args.stock_uom or "_Test UOM", "uom": uom, "cost_center": args.cost_center or frappe.get_cached_value('Company', pr.company, 'cost_center'), diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 30ea1c3cadc..e5994b2dd48 100644 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -976,7 +976,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2021-11-15 15:46:10.591600", + "modified": "2022-02-01 11:32:27.980524", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", @@ -985,5 +985,6 @@ "permissions": [], "quick_entry": 1, "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "states": [] } \ No newline at end of file diff --git a/erpnext/stock/doctype/putaway_rule/putaway_rule.py b/erpnext/stock/doctype/putaway_rule/putaway_rule.py index 523ba120de8..4e472a92dc1 100644 --- a/erpnext/stock/doctype/putaway_rule/putaway_rule.py +++ b/erpnext/stock/doctype/putaway_rule/putaway_rule.py @@ -9,7 +9,7 @@ from collections import defaultdict import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import cint, floor, flt, nowdate +from frappe.utils import cint, cstr, floor, flt, nowdate from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos from erpnext.stock.utils import get_stock_balance @@ -142,11 +142,44 @@ def apply_putaway_rule(doctype, items, company, sync=None, purpose=None): if items_not_accomodated: show_unassigned_items_message(items_not_accomodated) - items[:] = updated_table if updated_table else items # modify items table + if updated_table and _items_changed(items, updated_table, doctype): + items[:] = updated_table + frappe.msgprint(_("Applied putaway rules."), alert=True) if sync and json.loads(sync): # sync with client side return items +def _items_changed(old, new, doctype: str) -> bool: + """ Check if any items changed by application of putaway rules. + + If not, changing item table can have side effects since `name` items also changes. + """ + if len(old) != len(new): + return True + + old = [frappe._dict(item) if isinstance(item, dict) else item for item in old] + + if doctype == "Stock Entry": + compare_keys = ("item_code", "t_warehouse", "transfer_qty", "serial_no") + sort_key = lambda item: (item.item_code, cstr(item.t_warehouse), # noqa + flt(item.transfer_qty), cstr(item.serial_no)) + else: + # purchase receipt / invoice + compare_keys = ("item_code", "warehouse", "stock_qty", "received_qty", "serial_no") + sort_key = lambda item: (item.item_code, cstr(item.warehouse), # noqa + flt(item.stock_qty), flt(item.received_qty), cstr(item.serial_no)) + + old_sorted = sorted(old, key=sort_key) + new_sorted = sorted(new, key=sort_key) + + # Once sorted by all relevant keys both tables should align if they are same. + for old_item, new_item in zip(old_sorted, new_sorted): + for key in compare_keys: + if old_item.get(key) != new_item.get(key): + return True + return False + + def get_ordered_putaway_rules(item_code, company, source_warehouse=None): """Returns an ordered list of putaway rules to apply on an item.""" filters = { diff --git a/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py b/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py index bd4d811e76c..4e8d71fe5e4 100644 --- a/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py +++ b/erpnext/stock/doctype/putaway_rule/test_putaway_rule.py @@ -2,6 +2,7 @@ # See license.txt import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.stock.doctype.batch.test_batch import make_new_batch from erpnext.stock.doctype.item.test_item import make_item @@ -9,10 +10,9 @@ 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(ERPNextTestCase): +class TestPutawayRule(FrappeTestCase): def setUp(self): if not frappe.db.exists("Item", "_Rice"): make_item("_Rice", { @@ -35,6 +35,18 @@ class TestPutawayRule(ERPNextTestCase): new_uom.uom_name = "Bag" new_uom.save() + def assertUnchangedItemsOnResave(self, doc): + """ Check if same items remain even after reapplication of rules. + + This is required since some business logic like subcontracting + depends on `name` of items to be same if item isn't changed. + """ + doc.reload() + old_items = {d.name for d in doc.items} + doc.save() + new_items = {d.name for d in doc.items} + self.assertSetEqual(old_items, new_items) + def test_putaway_rules_priority(self): """Test if rule is applied by priority, irrespective of free space.""" rule_1 = create_putaway_rule(item_code="_Rice", warehouse=self.warehouse_1, capacity=200, @@ -50,6 +62,8 @@ class TestPutawayRule(ERPNextTestCase): self.assertEqual(pr.items[1].qty, 100) self.assertEqual(pr.items[1].warehouse, self.warehouse_2) + self.assertUnchangedItemsOnResave(pr) + pr.delete() rule_1.delete() rule_2.delete() @@ -162,6 +176,8 @@ class TestPutawayRule(ERPNextTestCase): # leftover space was for 500 kg (0.5 Bag) # Since Bag is a whole UOM, 1(out of 2) Bag will be unassigned + self.assertUnchangedItemsOnResave(pr) + pr.delete() rule_1.delete() rule_2.delete() @@ -196,6 +212,8 @@ class TestPutawayRule(ERPNextTestCase): self.assertEqual(pr.items[1].warehouse, self.warehouse_1) self.assertEqual(pr.items[1].putaway_rule, rule_1.name) + self.assertUnchangedItemsOnResave(pr) + pr.delete() rule_1.delete() @@ -239,6 +257,8 @@ class TestPutawayRule(ERPNextTestCase): self.assertEqual(stock_entry_item.qty, 100) # unassigned 100 out of 200 Kg self.assertEqual(stock_entry_item.putaway_rule, rule_2.name) + self.assertUnchangedItemsOnResave(stock_entry) + stock_entry.delete() rule_1.delete() rule_2.delete() @@ -294,6 +314,8 @@ class TestPutawayRule(ERPNextTestCase): self.assertEqual(stock_entry.items[2].qty, 200) self.assertEqual(stock_entry.items[2].putaway_rule, rule_2.name) + self.assertUnchangedItemsOnResave(stock_entry) + stock_entry.delete() rule_1.delete() rule_2.delete() @@ -344,6 +366,8 @@ class TestPutawayRule(ERPNextTestCase): self.assertEqual(stock_entry.items[1].serial_no, "\n".join(serial_nos[3:])) self.assertEqual(stock_entry.items[1].batch_no, "BOTTL-BATCH-1") + self.assertUnchangedItemsOnResave(stock_entry) + stock_entry.delete() pr.cancel() rule_1.delete() @@ -366,6 +390,8 @@ class TestPutawayRule(ERPNextTestCase): self.assertEqual(stock_entry_item.qty, 100) self.assertEqual(stock_entry_item.putaway_rule, rule_1.name) + self.assertUnchangedItemsOnResave(stock_entry) + stock_entry.delete() rule_1.delete() rule_2.delete() diff --git a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py index 308c62875d5..601ca054b53 100644 --- a/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/test_quality_inspection.py @@ -2,6 +2,7 @@ # See license.txt import frappe +from frappe.tests.utils import FrappeTestCase from frappe.utils import nowdate from erpnext.controllers.stock_controller import ( @@ -13,12 +14,11 @@ 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(ERPNextTestCase): +class TestQualityInspection(FrappeTestCase): def setUp(self): super().setUp() create_item("_Test Item with QA") diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json index cd7e63b18b2..0ba97d59a14 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.json @@ -1,7 +1,7 @@ { "actions": [], "autoname": "REPOST-ITEM-VAL-.######", - "creation": "2020-10-22 22:27:07.742161", + "creation": "2022-01-11 15:03:38.273179", "doctype": "DocType", "editable_grid": 1, "engine": "InnoDB", @@ -129,7 +129,7 @@ "reqd": 1 }, { - "default": "0", + "default": "1", "fieldname": "allow_negative_stock", "fieldtype": "Check", "label": "Allow Negative Stock" @@ -177,7 +177,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-11-24 02:18:10.524560", + "modified": "2022-01-18 10:57:33.450907", "modified_by": "Administrator", "module": "Stock", "name": "Repost Item Valuation", @@ -227,5 +227,6 @@ } ], "sort_field": "modified", - "sort_order": "DESC" -} + "sort_order": "DESC", + "states": [] +} \ No newline at end of file diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index fb3b355fb74..977d470995e 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -13,7 +13,7 @@ from erpnext.accounts.utils import ( check_if_stock_and_account_balance_synced, update_gl_entries_after, ) -from erpnext.stock.stock_ledger import repost_future_sle +from erpnext.stock.stock_ledger import get_items_to_be_repost, repost_future_sle class RepostItemValuation(Document): @@ -27,8 +27,7 @@ class RepostItemValuation(Document): self.item_code = None self.warehouse = None - self.allow_negative_stock = self.allow_negative_stock or \ - cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock")) + self.allow_negative_stock = 1 def set_company(self): if self.based_on == "Transaction": @@ -139,13 +138,20 @@ def repost_gl_entries(doc): if doc.based_on == 'Transaction': ref_doc = frappe.get_doc(doc.voucher_type, doc.voucher_no) - items, warehouses = ref_doc.get_items_and_warehouses() + doc_items, doc_warehouses = ref_doc.get_items_and_warehouses() + + sles = get_items_to_be_repost(doc.voucher_type, doc.voucher_no) + sle_items = [sle.item_code for sle in sles] + sle_warehouse = [sle.warehouse for sle in sles] + + items = list(set(doc_items).union(set(sle_items))) + warehouses = list(set(doc_warehouses).union(set(sle_warehouse))) else: items = [doc.item_code] warehouses = [doc.warehouse] update_gl_entries_after(doc.posting_date, doc.posting_time, - warehouses, items, company=doc.company) + for_warehouses=warehouses, for_items=items, company=doc.company) def notify_error_to_stock_managers(doc, traceback): recipients = get_users_with_role("Stock Manager") diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index ee55af34753..ee08e38f33c 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -465,6 +465,13 @@ def get_serial_nos(serial_no): return [s.strip() for s in cstr(serial_no).strip().upper().replace(',', '\n').split('\n') if s.strip()] +def clean_serial_no_string(serial_no: str) -> str: + if not serial_no: + return "" + + serial_no_list = get_serial_nos(serial_no) + return "\n".join(serial_no_list) + def update_args_for_serial_no(serial_no_doc, serial_no, args, is_new=False): for field in ["item_code", "work_order", "company", "batch_no", "supplier", "location"]: if args.get(field): diff --git a/erpnext/stock/doctype/serial_no/test_serial_no.py b/erpnext/stock/doctype/serial_no/test_serial_no.py index f8cea717251..057a7d4c01f 100644 --- a/erpnext/stock/doctype/serial_no/test_serial_no.py +++ b/erpnext/stock/doctype/serial_no/test_serial_no.py @@ -18,11 +18,12 @@ from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse test_dependencies = ["Item"] test_records = frappe.get_test_records('Serial No') +from frappe.tests.utils import FrappeTestCase + from erpnext.stock.doctype.serial_no.serial_no import * -from erpnext.tests.utils import ERPNextTestCase -class TestSerialNo(ERPNextTestCase): +class TestSerialNo(FrappeTestCase): def tearDown(self): frappe.db.rollback() diff --git a/erpnext/stock/doctype/shipment/test_shipment.py b/erpnext/stock/doctype/shipment/test_shipment.py index afe821845ae..317abb6d03e 100644 --- a/erpnext/stock/doctype/shipment/test_shipment.py +++ b/erpnext/stock/doctype/shipment/test_shipment.py @@ -4,12 +4,12 @@ from datetime import date, timedelta import frappe +from frappe.tests.utils import FrappeTestCase from erpnext.stock.doctype.delivery_note.delivery_note import make_shipment -from erpnext.tests.utils import ERPNextTestCase -class TestShipment(ERPNextTestCase): +class TestShipment(FrappeTestCase): def test_shipment_from_delivery_note(self): delivery_note = create_test_delivery_note() delivery_note.submit() diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index c4b8131305e..324ca7ac599 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -425,6 +425,7 @@ frappe.ui.form.on('Stock Entry', { 'posting_time' : frm.doc.posting_time, 'warehouse' : cstr(item.s_warehouse) || cstr(item.t_warehouse), 'serial_no' : item.serial_no, + 'batch_no' : item.batch_no, 'company' : frm.doc.company, 'qty' : item.s_warehouse ? -1*flt(item.transfer_qty) : flt(item.transfer_qty), 'voucher_type' : frm.doc.doctype, @@ -457,6 +458,7 @@ frappe.ui.form.on('Stock Entry', { 'warehouse': cstr(child.s_warehouse) || cstr(child.t_warehouse), 'transfer_qty': child.transfer_qty, 'serial_no': child.serial_no, + 'batch_no': child.batch_no, 'qty': child.s_warehouse ? -1* child.transfer_qty : child.transfer_qty, 'posting_date': frm.doc.posting_date, 'posting_time': frm.doc.posting_time, @@ -627,6 +629,12 @@ frappe.ui.form.on('Stock Entry Detail', { frm.events.set_serial_no(frm, cdt, cdn, () => { frm.events.get_warehouse_details(frm, cdt, cdn); }); + + // set allow_zero_valuation_rate to 0 if s_warehouse is selected. + let item = frappe.get_doc(cdt, cdn); + if (item.s_warehouse) { + item.allow_zero_valuation_rate = 0; + } }, t_warehouse: function(frm, cdt, cdn) { @@ -680,6 +688,7 @@ frappe.ui.form.on('Stock Entry Detail', { 'warehouse' : cstr(d.s_warehouse) || cstr(d.t_warehouse), 'transfer_qty' : d.transfer_qty, 'serial_no' : d.serial_no, + 'batch_no' : d.batch_no, 'bom_no' : d.bom_no, 'expense_account' : d.expense_account, 'cost_center' : d.cost_center, diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.json b/erpnext/stock/doctype/stock_entry/stock_entry.json index 2f377788961..c38dfaa1c84 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.json +++ b/erpnext/stock/doctype/stock_entry/stock_entry.json @@ -8,7 +8,6 @@ "engine": "InnoDB", "field_order": [ "items_section", - "title", "naming_series", "stock_entry_type", "outgoing_stock_entry", @@ -83,14 +82,6 @@ "fieldtype": "Section Break", "oldfieldtype": "Section Break" }, - { - "fieldname": "title", - "fieldtype": "Data", - "hidden": 1, - "label": "Title", - "no_copy": 1, - "print_hide": 1 - }, { "fieldname": "naming_series", "fieldtype": "Select", @@ -353,9 +344,9 @@ }, { "fieldname": "scan_barcode", - "options": "Barcode", "fieldtype": "Data", - "label": "Scan Barcode" + "label": "Scan Barcode", + "options": "Barcode" }, { "allow_bulk_edit": 1, @@ -628,10 +619,11 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2021-08-20 19:19:31.514846", + "modified": "2022-02-07 12:55:14.614077", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry", + "naming_rule": "By \"Naming Series\" field", "owner": "Administrator", "permissions": [ { @@ -698,6 +690,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", - "title_field": "title", + "states": [], + "title_field": "stock_entry_type", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index a61b3199c0e..99cf4de5de7 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -76,7 +76,6 @@ class StockEntry(StockController): self.validate_posting_time() self.validate_purpose() - self.set_title() self.validate_item() self.validate_customer_provided_item() self.validate_qty() @@ -434,9 +433,10 @@ class StockEntry(StockController): ) def set_actual_qty(self): - allow_negative_stock = cint(frappe.db.get_value("Stock Settings", None, "allow_negative_stock")) + from erpnext.stock.stock_ledger import is_negative_stock_allowed for d in self.get('items'): + allow_negative_stock = is_negative_stock_allowed(item_code=d.item_code) previous_sle = get_previous_sle({ "item_code": d.item_code, "warehouse": d.s_warehouse or d.t_warehouse, @@ -510,7 +510,7 @@ class StockEntry(StockController): d.basic_rate = get_valuation_rate(d.item_code, d.t_warehouse, self.doctype, self.name, d.allow_zero_valuation_rate, currency=erpnext.get_company_currency(self.company), company=self.company, - raise_error_if_no_rate=raise_error_if_no_rate) + raise_error_if_no_rate=raise_error_if_no_rate, batch_no=d.batch_no) d.basic_rate = flt(d.basic_rate, d.precision("basic_rate")) if d.is_process_loss: @@ -541,6 +541,7 @@ class StockEntry(StockController): "posting_time": self.posting_time, "qty": item.s_warehouse and -1*flt(item.transfer_qty) or flt(item.transfer_qty), "serial_no": item.serial_no, + "batch_no": item.batch_no, "voucher_type": self.doctype, "voucher_no": self.name, "company": self.company, @@ -1116,7 +1117,7 @@ class StockEntry(StockController): self.set_actual_qty() self.update_items_for_process_loss() self.validate_customer_provided_item() - self.calculate_rate_and_amount() + self.calculate_rate_and_amount(raise_error_if_no_rate=False) def set_scrap_items(self): if self.purpose != "Send to Subcontractor" and self.purpose in ["Manufacture", "Repack"]: @@ -1445,14 +1446,15 @@ class StockEntry(StockController): qty = req_qty_each * flt(self.fg_completed_qty) elif backflushed_materials.get(item.item_code): + precision = frappe.get_precision("Stock Entry Detail", "qty") for d in backflushed_materials.get(item.item_code): - if d.get(item.warehouse): + if d.get(item.warehouse) > 0: if (qty > req_qty): - qty = (qty/trans_qty) * flt(self.fg_completed_qty) + qty = ((flt(qty, precision) - flt(d.get(item.warehouse), precision)) + / (flt(trans_qty, precision) - flt(produced_qty, precision)) + ) * flt(self.fg_completed_qty) - if consumed_qty and frappe.db.get_single_value("Manufacturing Settings", - "material_consumption"): - qty -= consumed_qty + d[item.warehouse] -= qty if cint(frappe.get_cached_value('UOM', item.stock_uom, 'must_be_whole_number')): qty = frappe.utils.ceil(qty) @@ -1672,6 +1674,8 @@ class StockEntry(StockController): for d in self.get("items"): item_code = d.get('original_item') or d.get('item_code') reserve_warehouse = item_wh.get(item_code) + if not (reserve_warehouse and item_code): + continue stock_bin = get_bin(item_code, reserve_warehouse) stock_bin.update_reserved_qty_for_sub_contracting() @@ -1832,14 +1836,6 @@ class StockEntry(StockController): return sorted(list(set(get_serial_nos(self.pro_doc.serial_no)) - set(used_serial_nos))) - def set_title(self): - if frappe.flags.in_import and self.title: - # Allow updating title during data import/update - return - - self.title = self.purpose - - @frappe.whitelist() def move_sample_to_retention_warehouse(company, items): if isinstance(items, str): diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 306f2c3e69f..54c0e43c5ed 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -6,6 +6,7 @@ import unittest import frappe from frappe.permissions import add_user_permission, remove_user_permission +from frappe.tests.utils import FrappeTestCase, change_settings from frappe.utils import flt, nowdate, nowtime from erpnext.accounts.doctype.account.test_account import get_inventory_account @@ -28,7 +29,6 @@ from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import create_stock_reconciliation, ) from erpnext.stock.stock_ledger import NegativeStockError, get_previous_sle -from erpnext.tests.utils import ERPNextTestCase, change_settings def get_sle(**args): @@ -42,8 +42,9 @@ def get_sle(**args): order by timestamp(posting_date, posting_time) desc, creation desc limit 1"""% condition, values, as_dict=1) -class TestStockEntry(ERPNextTestCase): +class TestStockEntry(FrappeTestCase): def tearDown(self): + frappe.db.rollback() frappe.set_user("Administrator") frappe.db.set_value("Manufacturing Settings", None, "material_consumption", "0") @@ -565,6 +566,7 @@ class TestStockEntry(ERPNextTestCase): st1.set_stock_entry_type() st1.insert() st1.submit() + st1.cancel() frappe.set_user("Administrator") remove_user_permission("Warehouse", "_Test Warehouse 1 - _TC", "test@example.com") @@ -689,6 +691,8 @@ class TestStockEntry(ERPNextTestCase): bom_no = frappe.db.get_value("BOM", {"item": "_Test Variant Item", "is_default": 1, "docstatus": 1}) + make_item_variant() # make variant of _Test Variant Item if absent + work_order = frappe.new_doc("Work Order") work_order.update({ "company": "_Test Company", @@ -1023,13 +1027,10 @@ class TestStockEntry(ERPNextTestCase): # Check if FG cost is calculated based on RM total cost # RM total cost = 200, FG rate = 200/4(FG qty) = 50 - self.assertEqual(se.items[1].basic_rate, 50) + self.assertEqual(se.items[1].basic_rate, flt(se.items[0].basic_rate/4)) self.assertEqual(se.value_difference, 0.0) self.assertEqual(se.total_incoming_value, se.total_outgoing_value) - # teardown - se.delete() - @change_settings("Stock Settings", {"allow_negative_stock": 0}) def test_future_negative_sle(self): # Initialize item, batch, warehouse, opening qty @@ -1107,6 +1108,52 @@ class TestStockEntry(ERPNextTestCase): posting_date='2021-09-02', # backdated consumption of 2nd batch purpose='Material Issue') + def test_multi_batch_value_diff(self): + """ Test value difference on stock entry in case of multi-batch. + | Stock entry | batch | qty | rate | value diff on SE | + | --- | --- | --- | --- | --- | + | receipt | A | 1 | 10 | 30 | + | receipt | B | 1 | 20 | | + | issue | A | -1 | 10 | -30 (to assert after submit) | + | issue | B | -1 | 20 | | + """ + from erpnext.stock.doctype.batch.test_batch import TestBatch + + batch_nos = [] + + item_code = '_TestMultibatchFifo' + TestBatch.make_batch_item(item_code) + warehouse = '_Test Warehouse - _TC' + receipt = make_stock_entry( + item_code=item_code, + qty=1, + rate=10, + to_warehouse=warehouse, + purpose='Material Receipt', + do_not_save=True + ) + receipt.append("items", frappe.copy_doc(receipt.items[0], ignore_no_copy=False).update({"basic_rate": 20}) ) + receipt.save() + receipt.submit() + batch_nos.extend(row.batch_no for row in receipt.items) + self.assertEqual(receipt.value_difference, 30) + + issue = make_stock_entry( + item_code=item_code, + qty=1, + from_warehouse=warehouse, + purpose='Material Issue', + do_not_save=True + ) + issue.append("items", frappe.copy_doc(issue.items[0], ignore_no_copy=False)) + for row, batch_no in zip(issue.items, batch_nos): + row.batch_no = batch_no + issue.save() + issue.submit() + + issue.reload() # reload because reposting current voucher updates rate + self.assertEqual(issue.value_difference, -30) + def make_serialized_item(**args): args = frappe._dict(args) se = frappe.copy_doc(test_records[0]) diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index df65706c39d..83aed904ddd 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -1,7 +1,7 @@ { "actions": [], "autoname": "hash", - "creation": "2013-03-29 18:22:12", + "creation": "2022-02-05 00:17:49.860824", "doctype": "DocType", "document_type": "Other", "editable_grid": 1, @@ -340,13 +340,13 @@ "label": "More Information" }, { - "allow_on_submit": 1, "default": "0", "fieldname": "allow_zero_valuation_rate", "fieldtype": "Check", "label": "Allow Zero Valuation Rate", "no_copy": 1, - "print_hide": 1 + "print_hide": 1, + "read_only_depends_on": "eval:doc.s_warehouse" }, { "allow_on_submit": 1, @@ -556,12 +556,14 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2021-06-22 16:47:11.268975", + "modified": "2022-02-26 00:51:24.963653", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry Detail", + "naming_rule": "Random", "owner": "Administrator", "permissions": [], "sort_field": "modified", - "sort_order": "ASC" + "sort_order": "ASC", + "states": [] } \ No newline at end of file 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 cafbd7581ce..01d25b2e864 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 @@ -1,11 +1,19 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt +import json +from operator import itemgetter +from uuid import uuid4 + import frappe from frappe.core.page.permission_manager.permission_manager import reset +from frappe.tests.utils import FrappeTestCase from frappe.utils import add_days, today -from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note +from erpnext.stock.doctype.delivery_note.test_delivery_note import ( + create_delivery_note, + create_return_delivery_note, +) from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.landed_cost_voucher.test_landed_cost_voucher import ( create_landed_cost_voucher, @@ -17,10 +25,9 @@ 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(ERPNextTestCase): +class TestStockLedgerEntry(FrappeTestCase): def setUp(self): items = create_items() reset('Stock Entry') @@ -232,8 +239,7 @@ class TestStockLedgerEntry(ERPNextTestCase): self.assertEqual(outgoing_rate, 100) # Return Entry: Qty = -2, Rate = 150 - return_dn = create_delivery_note(is_return=1, return_against=dn.name, item_code=bundled_item, qty=-2, rate=150, - company=company, warehouse="Stores - _TC", expense_account="Cost of Goods Sold - _TC", cost_center="Main - _TC") + return_dn = create_return_delivery_note(source_name=dn.name, rate=150, qty=-2) # check incoming rate for Return entry incoming_rate, stock_value_difference = frappe.db.get_value("Stock Ledger Entry", @@ -347,6 +353,317 @@ class TestStockLedgerEntry(ERPNextTestCase): frappe.set_user("Administrator") user.remove_roles("Stock Manager") + def test_batchwise_item_valuation_moving_average(self): + item, warehouses, batches = setup_item_valuation_test(valuation_method="Moving Average") + + # Incoming Entries for Stock Value check + pr_entry_list = [ + (item, warehouses[0], batches[0], 1, 100), + (item, warehouses[0], batches[1], 1, 50), + (item, warehouses[0], batches[0], 1, 150), + (item, warehouses[0], batches[1], 1, 100), + ] + prs = create_purchase_receipt_entries_for_batchwise_item_valuation_test(pr_entry_list) + sle_details = fetch_sle_details_for_doc_list(prs, ['stock_value']) + sv_list = [d['stock_value'] for d in sle_details] + expected_sv = [100, 150, 300, 400] + self.assertEqual(expected_sv, sv_list, "Incorrect 'Stock Value' values") + + # Outgoing Entries for Stock Value Difference check + dn_entry_list = [ + (item, warehouses[0], batches[1], 1, 200), + (item, warehouses[0], batches[0], 1, 200), + (item, warehouses[0], batches[1], 1, 200), + (item, warehouses[0], batches[0], 1, 200) + ] + dns = create_delivery_note_entries_for_batchwise_item_valuation_test(dn_entry_list) + sle_details = fetch_sle_details_for_doc_list(dns, ['stock_value_difference']) + svd_list = [-1 * d['stock_value_difference'] for d in sle_details] + expected_incoming_rates = expected_abs_svd = [75, 125, 75, 125] + + self.assertEqual(expected_abs_svd, svd_list, "Incorrect 'Stock Value Difference' values") + for dn, incoming_rate in zip(dns, expected_incoming_rates): + self.assertEqual( + dn.items[0].incoming_rate, incoming_rate, + "Incorrect 'Incoming Rate' values fetched for DN items" + ) + + + def assertSLEs(self, doc, expected_sles): + """ Compare sorted SLEs, useful for vouchers that create multiple SLEs for same line""" + sles = frappe.get_all("Stock Ledger Entry", fields=["*"], + filters={"voucher_no": doc.name, "voucher_type": doc.doctype, "is_cancelled":0}, + order_by="timestamp(posting_date, posting_time), creation") + + for exp_sle, act_sle in zip(expected_sles, sles): + for k, v in exp_sle.items(): + act_value = act_sle[k] + if k == "stock_queue": + act_value = json.loads(act_value) + if act_value and act_value[0][0] == 0: + # ignore empty fifo bins + continue + + self.assertEqual(v, act_value, msg=f"{k} doesn't match \n{exp_sle}\n{act_sle}") + + + def test_batchwise_item_valuation_stock_reco(self): + item, warehouses, batches = setup_item_valuation_test() + state = { + "stock_value" : 0.0, + "qty": 0.0 + } + def update_invariants(exp_sles): + for sle in exp_sles: + state["stock_value"] += sle["stock_value_difference"] + state["qty"] += sle["actual_qty"] + sle["stock_value"] = state["stock_value"] + sle["qty_after_transaction"] = state["qty"] + + osr1 = create_stock_reconciliation(warehouse=warehouses[0], item_code=item, qty=10, rate=100, batch_no=batches[1]) + expected_sles = [ + {"actual_qty": 10, "stock_value_difference": 1000}, + ] + update_invariants(expected_sles) + self.assertSLEs(osr1, expected_sles) + + osr2 = create_stock_reconciliation(warehouse=warehouses[0], item_code=item, qty=13, rate=200, batch_no=batches[0]) + expected_sles = [ + {"actual_qty": 13, "stock_value_difference": 200*13}, + ] + update_invariants(expected_sles) + self.assertSLEs(osr2, expected_sles) + + sr1 = create_stock_reconciliation(warehouse=warehouses[0], item_code=item, qty=5, rate=50, batch_no=batches[1]) + + expected_sles = [ + {"actual_qty": -10, "stock_value_difference": -10 * 100}, + {"actual_qty": 5, "stock_value_difference": 250} + ] + update_invariants(expected_sles) + self.assertSLEs(sr1, expected_sles) + + sr2 = create_stock_reconciliation(warehouse=warehouses[0], item_code=item, qty=20, rate=75, batch_no=batches[0]) + expected_sles = [ + {"actual_qty": -13, "stock_value_difference": -13 * 200}, + {"actual_qty": 20, "stock_value_difference": 20 * 75} + ] + update_invariants(expected_sles) + self.assertSLEs(sr2, expected_sles) + + def test_batch_wise_valuation_across_warehouse(self): + item_code, warehouses, batches = setup_item_valuation_test() + source = warehouses[0] + target = warehouses[1] + + unrelated_batch = make_stock_entry(item_code=item_code, target=source, batch_no=batches[1], + qty=5, rate=10) + self.assertSLEs(unrelated_batch, [ + {"actual_qty": 5, "stock_value_difference": 10 * 5}, + ]) + + reciept = make_stock_entry(item_code=item_code, target=source, batch_no=batches[0], qty=5, rate=10) + self.assertSLEs(reciept, [ + {"actual_qty": 5, "stock_value_difference": 10 * 5}, + ]) + + transfer = make_stock_entry(item_code=item_code, source=source, target=target, batch_no=batches[0], qty=5) + self.assertSLEs(transfer, [ + {"actual_qty": -5, "stock_value_difference": -10 * 5, "warehouse": source}, + {"actual_qty": 5, "stock_value_difference": 10 * 5, "warehouse": target} + ]) + + backdated_receipt = make_stock_entry(item_code=item_code, target=source, batch_no=batches[0], + qty=5, rate=20, posting_date=add_days(today(), -1)) + self.assertSLEs(backdated_receipt, [ + {"actual_qty": 5, "stock_value_difference": 20 * 5}, + ]) + + # check reposted average rate in *future* transfer + self.assertSLEs(transfer, [ + {"actual_qty": -5, "stock_value_difference": -15 * 5, "warehouse": source, "stock_value": 15 * 5 + 10 * 5}, + {"actual_qty": 5, "stock_value_difference": 15 * 5, "warehouse": target, "stock_value": 15 * 5} + ]) + + transfer_unrelated = make_stock_entry(item_code=item_code, source=source, + target=target, batch_no=batches[1], qty=5) + self.assertSLEs(transfer_unrelated, [ + {"actual_qty": -5, "stock_value_difference": -10 * 5, "warehouse": source, "stock_value": 15 * 5}, + {"actual_qty": 5, "stock_value_difference": 10 * 5, "warehouse": target, "stock_value": 15 * 5 + 10 * 5} + ]) + + def test_intermediate_average_batch_wise_valuation(self): + """ A batch has moving average up until posting time, + check if same is respected when backdated entry is inserted in middle""" + item_code, warehouses, batches = setup_item_valuation_test() + warehouse = warehouses[0] + + batch = batches[0] + + yesterday = make_stock_entry(item_code=item_code, target=warehouse, batch_no=batch, + qty=1, rate=10, posting_date=add_days(today(), -1)) + self.assertSLEs(yesterday, [ + {"actual_qty": 1, "stock_value_difference": 10}, + ]) + + tomorrow = make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[0], + qty=1, rate=30, posting_date=add_days(today(), 1)) + self.assertSLEs(tomorrow, [ + {"actual_qty": 1, "stock_value_difference": 30}, + ]) + + create_today = make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[0], + qty=1, rate=20) + self.assertSLEs(create_today, [ + {"actual_qty": 1, "stock_value_difference": 20}, + ]) + + consume_today = make_stock_entry(item_code=item_code, source=warehouse, batch_no=batches[0], + qty=1) + self.assertSLEs(consume_today, [ + {"actual_qty": -1, "stock_value_difference": -15}, + ]) + + consume_tomorrow = make_stock_entry(item_code=item_code, source=warehouse, batch_no=batches[0], + qty=2, posting_date=add_days(today(), 2)) + self.assertSLEs(consume_tomorrow, [ + {"stock_value_difference": -(30 + 15), "stock_value": 0, "qty_after_transaction": 0}, + ]) + + def test_legacy_item_valuation_stock_entry(self): + columns = [ + 'stock_value_difference', + 'stock_value', + 'actual_qty', + 'qty_after_transaction', + 'stock_queue', + ] + item, warehouses, batches = setup_item_valuation_test(use_batchwise_valuation=0) + + def check_sle_details_against_expected(sle_details, expected_sle_details, detail, columns): + for i, (sle_vals, ex_sle_vals) in enumerate(zip(sle_details, expected_sle_details)): + for col, sle_val, ex_sle_val in zip(columns, sle_vals, ex_sle_vals): + if col == 'stock_queue': + sle_val = get_stock_value_from_q(sle_val) + ex_sle_val = get_stock_value_from_q(ex_sle_val) + self.assertEqual( + sle_val, ex_sle_val, + f"Incorrect {col} value on transaction #: {i} in {detail}" + ) + + # List used to defer assertions to prevent commits cause of error skipped rollback + details_list = [] + + + # Test Material Receipt Entries + se_entry_list_mr = [ + (item, None, warehouses[0], batches[0], 1, 50, "2021-01-21"), + (item, None, warehouses[0], batches[1], 1, 100, "2021-01-23"), + ] + ses = create_stock_entry_entries_for_batchwise_item_valuation_test( + se_entry_list_mr, "Material Receipt" + ) + sle_details = fetch_sle_details_for_doc_list(ses, columns=columns, as_dict=0) + expected_sle_details = [ + (50.0, 50.0, 1.0, 1.0, '[[1.0, 50.0]]'), + (100.0, 150.0, 1.0, 2.0, '[[1.0, 50.0], [1.0, 100.0]]'), + ] + details_list.append(( + sle_details, expected_sle_details, + "Material Receipt Entries", columns + )) + + + # Test Material Issue Entries + se_entry_list_mi = [ + (item, warehouses[0], None, batches[1], 1, None, "2021-01-29"), + ] + ses = create_stock_entry_entries_for_batchwise_item_valuation_test( + se_entry_list_mi, "Material Issue" + ) + sle_details = fetch_sle_details_for_doc_list(ses, columns=columns, as_dict=0) + expected_sle_details = [ + (-50.0, 100.0, -1.0, 1.0, '[[1, 100.0]]') + ] + details_list.append(( + sle_details, expected_sle_details, + "Material Issue Entries", columns + )) + + + # Run assertions + for details in details_list: + check_sle_details_against_expected(*details) + + def test_mixed_valuation_batches_fifo(self): + item_code, warehouses, batches = setup_item_valuation_test(use_batchwise_valuation=0) + warehouse = warehouses[0] + + state = { + "qty": 0.0, + "stock_value": 0.0 + } + def update_invariants(exp_sles): + for sle in exp_sles: + state["stock_value"] += sle["stock_value_difference"] + state["qty"] += sle["actual_qty"] + sle["stock_value"] = state["stock_value"] + sle["qty_after_transaction"] = state["qty"] + return exp_sles + + old1 = make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[0], + qty=10, rate=10) + self.assertSLEs(old1, update_invariants([ + {"actual_qty": 10, "stock_value_difference": 10*10, "stock_queue": [[10, 10]]}, + ])) + old2 = make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[1], + qty=10, rate=20) + self.assertSLEs(old2, update_invariants([ + {"actual_qty": 10, "stock_value_difference": 10*20, "stock_queue": [[10, 10], [10, 20]]}, + ])) + old3 = make_stock_entry(item_code=item_code, target=warehouse, batch_no=batches[0], + qty=5, rate=15) + + self.assertSLEs(old3, update_invariants([ + {"actual_qty": 5, "stock_value_difference": 5*15, "stock_queue": [[10, 10], [10, 20], [5, 15]]}, + ])) + + new1 = make_stock_entry(item_code=item_code, target=warehouse, qty=10, rate=40) + batches.append(new1.items[0].batch_no) + # assert old queue remains + self.assertSLEs(new1, update_invariants([ + {"actual_qty": 10, "stock_value_difference": 10*40, "stock_queue": [[10, 10], [10, 20], [5, 15]]}, + ])) + + new2 = make_stock_entry(item_code=item_code, target=warehouse, qty=10, rate=42) + batches.append(new2.items[0].batch_no) + self.assertSLEs(new2, update_invariants([ + {"actual_qty": 10, "stock_value_difference": 10*42, "stock_queue": [[10, 10], [10, 20], [5, 15]]}, + ])) + + # consume old batch as per FIFO + consume_old1 = make_stock_entry(item_code=item_code, source=warehouse, qty=15, batch_no=batches[0]) + self.assertSLEs(consume_old1, update_invariants([ + {"actual_qty": -15, "stock_value_difference": -10*10 - 5*20, "stock_queue": [[5, 20], [5, 15]]}, + ])) + + # consume new batch as per batch + consume_new2 = make_stock_entry(item_code=item_code, source=warehouse, qty=10, batch_no=batches[-1]) + self.assertSLEs(consume_new2, update_invariants([ + {"actual_qty": -10, "stock_value_difference": -10*42, "stock_queue": [[5, 20], [5, 15]]}, + ])) + + # finish all old batches + consume_old2 = make_stock_entry(item_code=item_code, source=warehouse, qty=10, batch_no=batches[1]) + self.assertSLEs(consume_old2, update_invariants([ + {"actual_qty": -10, "stock_value_difference": -5*20 - 5*15, "stock_queue": []}, + ])) + + # finish all new batches + consume_new1 = make_stock_entry(item_code=item_code, source=warehouse, qty=10, batch_no=batches[-2]) + self.assertSLEs(consume_new1, update_invariants([ + {"actual_qty": -10, "stock_value_difference": -10*40, "stock_queue": []}, + ])) def create_repack_entry(**args): args = frappe._dict(args) @@ -410,3 +727,118 @@ def create_items(): make_item(d, properties=properties) return items + +def setup_item_valuation_test(valuation_method="FIFO", suffix=None, use_batchwise_valuation=1, batches_list=['X', 'Y']): + from erpnext.stock.doctype.batch.batch import make_batch + from erpnext.stock.doctype.item.test_item import make_item + from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse + + if not suffix: + suffix = get_unique_suffix() + + item = make_item( + f"IV - Test Item {valuation_method} {suffix}", + dict(valuation_method=valuation_method, has_batch_no=1, create_new_batch=1) + ) + warehouses = [create_warehouse(f"IV - Test Warehouse {i}") for i in ['J', 'K']] + batches = [f"IV - Test Batch {i} {valuation_method} {suffix}" for i in batches_list] + + for i, batch_id in enumerate(batches): + if not frappe.db.exists("Batch", batch_id): + ubw = use_batchwise_valuation + if isinstance(use_batchwise_valuation, (list, tuple)): + ubw = use_batchwise_valuation[i] + batch = frappe.get_doc(frappe._dict( + doctype="Batch", + batch_id=batch_id, + item=item.item_code, + use_batchwise_valuation=ubw + ) + ).insert() + batch.use_batchwise_valuation = ubw + batch.db_update() + + return item.item_code, warehouses, batches + +def create_purchase_receipt_entries_for_batchwise_item_valuation_test(pr_entry_list): + from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt + prs = [] + + for item, warehouse, batch_no, qty, rate in pr_entry_list: + pr = make_purchase_receipt(item=item, warehouse=warehouse, qty=qty, rate=rate, batch_no=batch_no) + prs.append(pr) + + return prs + +def create_delivery_note_entries_for_batchwise_item_valuation_test(dn_entry_list): + from erpnext.selling.doctype.sales_order.sales_order import make_delivery_note + from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order + dns = [] + for item, warehouse, batch_no, qty, rate in dn_entry_list: + so = make_sales_order( + rate=rate, + qty=qty, + item=item, + warehouse=warehouse, + against_blanket_order=0 + ) + + dn = make_delivery_note(so.name) + dn.items[0].batch_no = batch_no + dn.insert() + dn.submit() + dns.append(dn) + return dns + +def fetch_sle_details_for_doc_list(doc_list, columns, as_dict=1): + return frappe.db.sql(f""" + SELECT { ', '.join(columns)} + FROM `tabStock Ledger Entry` + WHERE + voucher_no IN %(voucher_nos)s + and docstatus = 1 + ORDER BY timestamp(posting_date, posting_time) ASC, CREATION ASC + """, dict( + voucher_nos=[doc.name for doc in doc_list] + ), as_dict=as_dict) + +def get_stock_value_from_q(q): + return sum(r*q for r,q in json.loads(q)) + +def create_stock_entry_entries_for_batchwise_item_valuation_test(se_entry_list, purpose): + ses = [] + for item, source, target, batch, qty, rate, posting_date in se_entry_list: + args = dict( + item_code=item, + qty=qty, + company="_Test Company", + batch_no=batch, + posting_date=posting_date, + purpose=purpose + ) + + if purpose == "Material Receipt": + args.update( + dict(to_warehouse=target, rate=rate) + ) + + elif purpose == "Material Issue": + args.update( + dict(from_warehouse=source) + ) + + elif purpose == "Material Transfer": + args.update( + dict(from_warehouse=source, to_warehouse=target) + ) + + else: + raise ValueError(f"Invalid purpose: {purpose}") + ses.append(make_stock_entry(**args)) + + return ses + +def get_unique_suffix(): + # Used to isolate valuation sensitive + # tests to prevent future tests from failing. + return str(uuid4())[:8].upper() diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json index 3402972bb89..a882a61e5a5 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json @@ -18,7 +18,6 @@ "items", "section_break_9", "expense_account", - "reconciliation_json", "column_break_13", "difference_amount", "amended_from", @@ -111,15 +110,6 @@ "label": "Cost Center", "options": "Cost Center" }, - { - "fieldname": "reconciliation_json", - "fieldtype": "Long Text", - "hidden": 1, - "label": "Reconciliation JSON", - "no_copy": 1, - "print_hide": 1, - "read_only": 1 - }, { "fieldname": "column_break_13", "fieldtype": "Column Break" @@ -155,7 +145,7 @@ "idx": 1, "is_submittable": 1, "links": [], - "modified": "2021-11-30 01:33:51.437194", + "modified": "2022-02-06 14:28:19.043905", "modified_by": "Administrator", "module": "Stock", "name": "Stock Reconciliation", @@ -178,5 +168,6 @@ "search_fields": "posting_date", "show_name_in_global_search": 1, "sort_field": "modified", - "sort_order": "DESC" + "sort_order": "DESC", + "states": [] } \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index c4ddc9e2d6f..e6b252e8562 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -6,7 +6,8 @@ import frappe -from frappe.utils import add_days, flt, nowdate, nowtime, random_string +from frappe.tests.utils import FrappeTestCase, change_settings +from frappe.utils import add_days, cstr, flt, nowdate, nowtime, random_string from erpnext.accounts.utils import get_stock_and_account_balance from erpnext.stock.doctype.item.test_item import create_item @@ -19,14 +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 ERPNextTestCase, change_settings -class TestStockReconciliation(ERPNextTestCase): +class TestStockReconciliation(FrappeTestCase): @classmethod def setUpClass(cls): - super().setUpClass() create_batch_or_serial_no_items() + super().setUpClass() frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) def tearDown(self): @@ -200,7 +200,6 @@ class TestStockReconciliation(ERPNextTestCase): def test_stock_reco_for_batch_item(self): to_delete_records = [] - to_delete_serial_nos = [] # Add new serial nos item_code = "Stock-Reco-batch-Item-1" @@ -208,20 +207,22 @@ class TestStockReconciliation(ERPNextTestCase): sr = create_stock_reconciliation(item_code=item_code, warehouse = warehouse, qty=5, rate=200, do_not_submit=1) - sr.save(ignore_permissions=True) + sr.save() sr.submit() - self.assertTrue(sr.items[0].batch_no) + batch_no = sr.items[0].batch_no + self.assertTrue(batch_no) to_delete_records.append(sr.name) sr1 = create_stock_reconciliation(item_code=item_code, - warehouse = warehouse, qty=6, rate=300, batch_no=sr.items[0].batch_no) + warehouse = warehouse, qty=6, rate=300, batch_no=batch_no) args = { "item_code": item_code, "warehouse": warehouse, "posting_date": nowdate(), "posting_time": nowtime(), + "batch_no": batch_no, } valuation_rate = get_incoming_rate(args) @@ -230,7 +231,7 @@ class TestStockReconciliation(ERPNextTestCase): sr2 = create_stock_reconciliation(item_code=item_code, - warehouse = warehouse, qty=0, rate=0, batch_no=sr.items[0].batch_no) + warehouse = warehouse, qty=0, rate=0, batch_no=batch_no) stock_value = get_stock_value_on(warehouse, nowdate(), item_code) self.assertEqual(stock_value, 0) @@ -439,8 +440,8 @@ class TestStockReconciliation(ERPNextTestCase): self.assertRaises(frappe.ValidationError, sr.submit) def test_serial_no_cancellation(self): - from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry + item = create_item("Stock-Reco-Serial-Item-9", is_stock_item=1) if not item.has_serial_no: item.has_serial_no = 1 @@ -466,6 +467,31 @@ class TestStockReconciliation(ERPNextTestCase): self.assertEqual(len(active_sr_no), 10) + def test_serial_no_creation_and_inactivation(self): + item = create_item("_TestItemCreatedWithStockReco", is_stock_item=1) + if not item.has_serial_no: + item.has_serial_no = 1 + item.save() + + item_code = item.name + warehouse = "_Test Warehouse - _TC" + + sr = create_stock_reconciliation(item_code=item.name, warehouse=warehouse, + serial_no="SR-CREATED-SR-NO", qty=1, do_not_submit=True, rate=100) + sr.save() + self.assertEqual(cstr(sr.items[0].current_serial_no), "") + sr.submit() + + active_sr_no = frappe.get_all("Serial No", + filters={"item_code": item_code, "warehouse": warehouse, "status": "Active"}) + self.assertEqual(len(active_sr_no), 1) + + sr.cancel() + active_sr_no = frappe.get_all("Serial No", + filters={"item_code": item_code, "warehouse": warehouse, "status": "Active"}) + self.assertEqual(len(active_sr_no), 0) + + def create_batch_item_with_batch(item_name, batch_id): batch_item_doc = create_item(item_name, is_stock_item=1) if not batch_item_doc.has_batch_no: diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index 33d9a6ce414..ec7fb0f4a28 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -5,35 +5,41 @@ "doctype": "DocType", "engine": "InnoDB", "field_order": [ + "defaults_tab", "item_defaults_section", "item_naming_by", "item_group", "stock_uom", - "default_warehouse", "column_break_4", - "valuation_method", + "default_warehouse", "sample_retention_warehouse", - "use_naming_series", - "naming_series_prefix", + "valuation_method", + "price_list_defaults_section", + "auto_insert_price_list_rate_if_missing", + "column_break_12", + "update_existing_price_list_rate", + "stock_validations_tab", "section_break_9", "over_delivery_receipt_allowance", - "role_allowed_to_over_deliver_receive", "mr_qty_allowance", - "column_break_12", - "auto_insert_price_list_rate_if_missing", - "update_existing_price_list_rate", + "column_break_121", + "role_allowed_to_over_deliver_receive", "allow_negative_stock", "show_barcode_field", "clean_description_html", "quality_inspection_settings_section", "action_if_quality_inspection_is_not_submitted", - "column_break_21", + "column_break_23", "action_if_quality_inspection_is_rejected", + "serial_and_batch_item_settings_tab", "section_break_7", "automatically_set_serial_nos_based_on_fifo", "set_qty_in_transactions_based_on_serial_no_input", "column_break_10", "disable_serial_no_and_batch_selector", + "use_naming_series", + "naming_series_prefix", + "stock_planning_tab", "auto_material_request", "auto_indent", "column_break_27", @@ -42,6 +48,7 @@ "allow_from_dn", "column_break_31", "allow_from_pr", + "stock_closing_tab", "control_historical_stock_transactions_section", "stock_frozen_upto", "stock_frozen_upto_days", @@ -92,7 +99,7 @@ "fieldname": "valuation_method", "fieldtype": "Select", "label": "Default Valuation Method", - "options": "FIFO\nMoving Average" + "options": "FIFO\nMoving Average\nLIFO" }, { "description": "The percentage you are allowed to receive or deliver more against the quantity ordered. For example, if you have ordered 100 units, and your Allowance is 10%, then you are allowed to receive 110 units.", @@ -122,7 +129,7 @@ { "fieldname": "section_break_7", "fieldtype": "Section Break", - "label": "Serialised and Batch Setting" + "label": "Serial & Batch Item Settings" }, { "default": "0", @@ -275,10 +282,6 @@ "fieldtype": "Section Break", "label": "Quality Inspection Settings" }, - { - "fieldname": "column_break_21", - "fieldtype": "Column Break" - }, { "default": "Stop", "fieldname": "action_if_quality_inspection_is_rejected", @@ -298,6 +301,44 @@ "fieldname": "update_existing_price_list_rate", "fieldtype": "Check", "label": "Update Existing Price List Rate" + }, + { + "fieldname": "defaults_tab", + "fieldtype": "Tab Break", + "label": "Defaults" + }, + { + "fieldname": "stock_validations_tab", + "fieldtype": "Tab Break", + "label": "Stock Validations" + }, + { + "fieldname": "stock_planning_tab", + "fieldtype": "Tab Break", + "label": "Stock Planning" + }, + { + "fieldname": "stock_closing_tab", + "fieldtype": "Tab Break", + "label": "Stock Closing" + }, + { + "fieldname": "serial_and_batch_item_settings_tab", + "fieldtype": "Tab Break", + "label": "Serial & Batch Item" + }, + { + "fieldname": "column_break_23", + "fieldtype": "Column Break" + }, + { + "fieldname": "price_list_defaults_section", + "fieldtype": "Section Break", + "label": "Price List Defaults" + }, + { + "fieldname": "column_break_121", + "fieldtype": "Column Break" } ], "icon": "icon-cog", @@ -305,7 +346,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2021-11-06 19:40:02.183592", + "modified": "2022-02-05 15:33:43.692736", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings", @@ -324,5 +365,6 @@ "quick_entry": 1, "sort_field": "modified", "sort_order": "ASC", + "states": [], "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_settings/test_stock_settings.py b/erpnext/stock/doctype/stock_settings/test_stock_settings.py index 072b54b8205..13496718ead 100644 --- a/erpnext/stock/doctype/stock_settings/test_stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/test_stock_settings.py @@ -4,11 +4,10 @@ import unittest import frappe - -from erpnext.tests.utils import ERPNextTestCase +from frappe.tests.utils import FrappeTestCase -class TestStockSettings(ERPNextTestCase): +class TestStockSettings(FrappeTestCase): def setUp(self): super().setUp() frappe.db.set_value("Stock Settings", None, "clean_description_html", 0) diff --git a/erpnext/stock/doctype/warehouse/test_warehouse.py b/erpnext/stock/doctype/warehouse/test_warehouse.py index 26db2642e4b..cdb771935b0 100644 --- a/erpnext/stock/doctype/warehouse/test_warehouse.py +++ b/erpnext/stock/doctype/warehouse/test_warehouse.py @@ -3,17 +3,17 @@ import frappe from frappe.test_runner import make_test_records +from frappe.tests.utils import FrappeTestCase from frappe.utils import cint 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(ERPNextTestCase): +class TestWarehouse(FrappeTestCase): def setUp(self): super().setUp() if not frappe.get_value('Item', '_Test Item'): diff --git a/erpnext/stock/doctype/warehouse/warehouse.json b/erpnext/stock/doctype/warehouse/warehouse.json index 05076b51a3e..c695d541bf9 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.json +++ b/erpnext/stock/doctype/warehouse/warehouse.json @@ -244,7 +244,7 @@ "idx": 1, "is_tree": 1, "links": [], - "modified": "2021-12-03 04:40:06.414630", + "modified": "2022-03-01 02:37:48.034944", "modified_by": "Administrator", "module": "Stock", "name": "Warehouse", @@ -301,5 +301,7 @@ "show_name_in_global_search": 1, "sort_field": "modified", "sort_order": "DESC", - "title_field": "warehouse_name" + "states": [], + "title_field": "warehouse_name", + "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 06f8fa71a94..9bec5f74940 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -6,6 +6,7 @@ import json import frappe from frappe import _, throw +from frappe.model import child_table_fields, default_fields from frappe.model.meta import get_field_precision from frappe.utils import add_days, add_months, cint, cstr, flt, getdate @@ -119,8 +120,15 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru out.rate = args.rate or out.price_list_rate out.amount = flt(args.qty) * flt(out.rate) + out = remove_standard_fields(out) return out +def remove_standard_fields(details): + for key in child_table_fields + default_fields: + details.pop(key, None) + return details + + def update_stock(args, out): if (args.get("doctype") == "Delivery Note" or (args.get("doctype") == "Sales Invoice" and args.get('update_stock'))) \ @@ -343,6 +351,7 @@ def get_basic_details(args, item, overwrite_warehouse=True): args.conversion_factor = out.conversion_factor out.stock_qty = out.qty * out.conversion_factor + args.stock_qty = out.stock_qty # calculate last purchase rate if args.get('doctype') in purchase_doctypes: diff --git a/erpnext/stock/onboarding_slide/add_a_few_products_you_buy_or_sell/add_a_few_products_you_buy_or_sell.json b/erpnext/stock/onboarding_slide/add_a_few_products_you_buy_or_sell/add_a_few_products_you_buy_or_sell.json deleted file mode 100644 index 5ee316786ca..00000000000 --- a/erpnext/stock/onboarding_slide/add_a_few_products_you_buy_or_sell/add_a_few_products_you_buy_or_sell.json +++ /dev/null @@ -1,52 +0,0 @@ -{ - "add_more_button": 1, - "app": "ERPNext", - "creation": "2019-11-15 14:41:12.007359", - "docstatus": 0, - "doctype": "Onboarding Slide", - "domains": [], - "help_links": [], - "idx": 0, - "image_src": "", - "is_completed": 0, - "max_count": 3, - "modified": "2019-12-09 17:54:09.602885", - "modified_by": "Administrator", - "name": "Add A Few Products You Buy Or Sell", - "owner": "Administrator", - "ref_doctype": "Item", - "slide_desc": "", - "slide_fields": [ - { - "align": "", - "fieldname": "item", - "fieldtype": "Data", - "label": "Item", - "placeholder": "Product Name", - "reqd": 1 - }, - { - "align": "", - "fieldname": "item_price", - "fieldtype": "Currency", - "label": "Item Price", - "reqd": 1 - }, - { - "align": "", - "fieldtype": "Column Break", - "reqd": 0 - }, - { - "align": "", - "fieldname": "uom", - "fieldtype": "Link", - "label": "UOM", - "options": "UOM", - "reqd": 1 - } - ], - "slide_order": 30, - "slide_title": "Add A Few Products You Buy Or Sell", - "slide_type": "Create" -} \ No newline at end of file diff --git a/erpnext/stock/report/stock_ageing/stock_ageing.py b/erpnext/stock/report/stock_ageing/stock_ageing.py index e6dfc97a998..97a740e1844 100644 --- a/erpnext/stock/report/stock_ageing/stock_ageing.py +++ b/erpnext/stock/report/stock_ageing/stock_ageing.py @@ -12,6 +12,7 @@ from frappe.utils import cint, date_diff, flt from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos Filters = frappe._dict +precision = cint(frappe.db.get_single_value("System Settings", "float_precision")) def execute(filters: Filters = None) -> Tuple: to_date = filters["to_date"] @@ -48,10 +49,13 @@ def format_report_data(filters: Filters, item_details: Dict, to_date: str) -> Li if filters.get("show_warehouse_wise_stock"): row.append(details.warehouse) - row.extend([item_dict.get("total_qty"), average_age, + row.extend([ + flt(item_dict.get("total_qty"), precision), + average_age, range1, range2, range3, above_range3, earliest_age, latest_age, - details.stock_uom]) + details.stock_uom + ]) data.append(row) @@ -79,13 +83,13 @@ def get_range_age(filters: Filters, fifo_queue: List, to_date: str, item_dict: D qty = flt(item[0]) if not item_dict["has_serial_no"] else 1.0 if age <= filters.range1: - range1 += qty + range1 = flt(range1 + qty, precision) elif age <= filters.range2: - range2 += qty + range2 = flt(range2 + qty, precision) elif age <= filters.range3: - range3 += qty + range3 = flt(range3 + qty, precision) else: - above_range3 += qty + above_range3 = flt(above_range3 + qty, precision) return range1, range2, range3, above_range3 @@ -252,6 +256,7 @@ class FIFOSlots: key, fifo_queue, transferred_item_key = self.__init_key_stores(d) if d.voucher_type == "Stock Reconciliation": + # get difference in qty shift as actual qty prev_balance_qty = self.item_details[key].get("qty_after_transaction", 0) d.actual_qty = flt(d.qty_after_transaction) - flt(prev_balance_qty) @@ -264,12 +269,16 @@ class FIFOSlots: self.__update_balances(d, key) + if not self.filters.get("show_warehouse_wise_stock"): + # (Item 1, WH 1), (Item 1, WH 2) => (Item 1) + self.item_details = self.__aggregate_details_by_item(self.item_details) + return self.item_details def __init_key_stores(self, row: Dict) -> Tuple: "Initialise keys and FIFO Queue." - key = (row.name, row.warehouse) if self.filters.get('show_warehouse_wise_stock') else row.name + key = (row.name, row.warehouse) self.item_details.setdefault(key, {"details": row, "fifo_queue": []}) fifo_queue = self.item_details[key]["fifo_queue"] @@ -281,14 +290,16 @@ class FIFOSlots: def __compute_incoming_stock(self, row: Dict, fifo_queue: List, transfer_key: Tuple, serial_nos: List): "Update FIFO Queue on inward stock." - if self.transferred_item_details.get(transfer_key): + transfer_data = self.transferred_item_details.get(transfer_key) + if transfer_data: # inward/outward from same voucher, item & warehouse - slot = self.transferred_item_details[transfer_key].pop(0) - fifo_queue.append(slot) + # eg: Repack with same item, Stock reco for batch item + # consume transfer data and add stock to fifo queue + self.__adjust_incoming_transfer_qty(transfer_data, fifo_queue, row) else: if not serial_nos: - if fifo_queue and flt(fifo_queue[0][0]) < 0: - # neutralize negative stock by adding positive stock + if fifo_queue and flt(fifo_queue[0][0]) <= 0: + # neutralize 0/negative stock by adding positive stock fifo_queue[0][0] += flt(row.actual_qty) fifo_queue[0][1] = row.posting_date else: @@ -319,7 +330,7 @@ class FIFOSlots: elif not fifo_queue: # negative stock, no balance but qty yet to consume fifo_queue.append([-(qty_to_pop), row.posting_date]) - self.transferred_item_details[transfer_key].append([row.actual_qty, row.posting_date]) + self.transferred_item_details[transfer_key].append([qty_to_pop, row.posting_date]) qty_to_pop = 0 else: # qty to pop < slot qty, ample balance @@ -328,6 +339,33 @@ class FIFOSlots: self.transferred_item_details[transfer_key].append([qty_to_pop, slot[1]]) qty_to_pop = 0 + def __adjust_incoming_transfer_qty(self, transfer_data: Dict, fifo_queue: List, row: Dict): + "Add previously removed stock back to FIFO Queue." + transfer_qty_to_pop = flt(row.actual_qty) + + def add_to_fifo_queue(slot): + if fifo_queue and flt(fifo_queue[0][0]) <= 0: + # neutralize 0/negative stock by adding positive stock + fifo_queue[0][0] += flt(slot[0]) + fifo_queue[0][1] = slot[1] + else: + fifo_queue.append(slot) + + while transfer_qty_to_pop: + if transfer_data and 0 < transfer_data[0][0] <= transfer_qty_to_pop: + # bucket qty is not enough, consume whole + transfer_qty_to_pop -= transfer_data[0][0] + add_to_fifo_queue(transfer_data.pop(0)) + elif not transfer_data: + # transfer bucket is empty, extra incoming qty + add_to_fifo_queue([transfer_qty_to_pop, row.posting_date]) + transfer_qty_to_pop = 0 + else: + # ample bucket qty to consume + transfer_data[0][0] -= transfer_qty_to_pop + add_to_fifo_queue([transfer_qty_to_pop, transfer_data[0][1]]) + transfer_qty_to_pop = 0 + def __update_balances(self, row: Dict, key: Union[Tuple, str]): self.item_details[key]["qty_after_transaction"] = row.qty_after_transaction @@ -338,6 +376,27 @@ class FIFOSlots: self.item_details[key]["has_serial_no"] = row.has_serial_no + def __aggregate_details_by_item(self, wh_wise_data: Dict) -> Dict: + "Aggregate Item-Wh wise data into single Item entry." + item_aggregated_data = {} + for key,row in wh_wise_data.items(): + item = key[0] + if not item_aggregated_data.get(item): + item_aggregated_data.setdefault(item, { + "details": frappe._dict(), + "fifo_queue": [], + "qty_after_transaction": 0.0, + "total_qty": 0.0 + }) + item_row = item_aggregated_data.get(item) + item_row["details"].update(row["details"]) + item_row["fifo_queue"].extend(row["fifo_queue"]) + item_row["qty_after_transaction"] += flt(row["qty_after_transaction"]) + item_row["total_qty"] += flt(row["total_qty"]) + item_row["has_serial_no"] = row["has_serial_no"] + + return item_aggregated_data + def __get_stock_ledger_entries(self) -> List[Dict]: sle = frappe.qb.DocType("Stock Ledger Entry") item = self.__get_item_query() # used as derived table in sle query diff --git a/erpnext/stock/report/stock_ageing/stock_ageing_fifo_logic.md b/erpnext/stock/report/stock_ageing/stock_ageing_fifo_logic.md index 5ffe97fd742..3d759dd9989 100644 --- a/erpnext/stock/report/stock_ageing/stock_ageing_fifo_logic.md +++ b/erpnext/stock/report/stock_ageing/stock_ageing_fifo_logic.md @@ -15,6 +15,7 @@ Here, the balance qty is 70. 50 qty is (today-the 1st) days old 20 qty is (today-the 2nd) days old +> Note: We generate FIFO slots warehouse wise as stock reconciliations from different warehouses can cause incorrect values. ### Calculation of FIFO Slots #### Case 1: Outward from sufficient balance qty @@ -70,4 +71,39 @@ Date | Qty | Queue 2nd | -60 | [[-10, 1-12-2021]] 3rd | +5 | [[-5, 3-12-2021]] 4th | +10 | [[5, 4-12-2021]] -4th | +20 | [[5, 4-12-2021], [20, 4-12-2021]] \ No newline at end of file +4th | +20 | [[5, 4-12-2021], [20, 4-12-2021]] + +### Concept of Transfer Qty Bucket +In the case of **Repack**, Quantity that comes in, isn't really incoming. It is just new stock repurposed from old stock, due to incoming-outgoing of the same warehouse. + +Here, stock is consumed from the FIFO Queue. It is then re-added back to the queue. +While adding stock back to the queue we need to know how much to add. +For this we need to keep track of how much was previously consumed. +Hence we use **Transfer Qty Bucket**. + +While re-adding stock, we try to add buckets that were consumed earlier (date intact), to maintain correctness. + +#### Case 1: Same Item-Warehouse in Repack +Eg: +------------------------------------------------------------------------------------- +Date | Qty | Voucher | FIFO Queue | Transfer Qty Buckets +------------------------------------------------------------------------------------- +1st | +500 | PR | [[500, 1-12-2021]] | +2nd | -50 | Repack | [[450, 1-12-2021]] | [[50, 1-12-2021]] +2nd | +50 | Repack | [[450, 1-12-2021], [50, 1-12-2021]] | [] + +- The balance at the end is restored back to 500 +- However, the initial 500 qty bucket is now split into 450 and 50, with the same date +- The net effect is the same as that before the Repack + +#### Case 2: Same Item-Warehouse in Repack with Split Consumption rows +Eg: +------------------------------------------------------------------------------------- +Date | Qty | Voucher | FIFO Queue | Transfer Qty Buckets +------------------------------------------------------------------------------------- +1st | +500 | PR | [[500, 1-12-2021]] | +2nd | -50 | Repack | [[450, 1-12-2021]] | [[50, 1-12-2021]] +2nd | -50 | Repack | [[400, 1-12-2021]] | [[50, 1-12-2021], +- | | | |[50, 1-12-2021]] +2nd | +100 | Repack | [[400, 1-12-2021], [50, 1-12-2021], | [] +- | | | [50, 1-12-2021]] | diff --git a/erpnext/stock/report/stock_ageing/test_stock_ageing.py b/erpnext/stock/report/stock_ageing/test_stock_ageing.py index 949bb7c15a8..2630805c626 100644 --- a/erpnext/stock/report/stock_ageing/test_stock_ageing.py +++ b/erpnext/stock/report/stock_ageing/test_stock_ageing.py @@ -2,24 +2,26 @@ # See license.txt import frappe +from frappe.tests.utils import FrappeTestCase -from erpnext.stock.report.stock_ageing.stock_ageing import FIFOSlots -from erpnext.tests.utils import ERPNextTestCase +from erpnext.stock.report.stock_ageing.stock_ageing import FIFOSlots, format_report_data -class TestStockAgeing(ERPNextTestCase): +class TestStockAgeing(FrappeTestCase): def setUp(self) -> None: self.filters = frappe._dict( company="_Test Company", - to_date="2021-12-10" + to_date="2021-12-10", + range1=30, range2=60, range3=90 ) def test_normal_inward_outward_queue(self): - "Reference: Case 1 in stock_ageing_fifo_logic.md" + "Reference: Case 1 in stock_ageing_fifo_logic.md (same wh)" sle = [ frappe._dict( name="Flask Item", actual_qty=30, qty_after_transaction=30, + warehouse="WH 1", posting_date="2021-12-01", voucher_type="Stock Entry", voucher_no="001", has_serial_no=False, serial_no=None @@ -27,6 +29,7 @@ class TestStockAgeing(ERPNextTestCase): frappe._dict( name="Flask Item", actual_qty=20, qty_after_transaction=50, + warehouse="WH 1", posting_date="2021-12-02", voucher_type="Stock Entry", voucher_no="002", has_serial_no=False, serial_no=None @@ -34,6 +37,7 @@ class TestStockAgeing(ERPNextTestCase): frappe._dict( name="Flask Item", actual_qty=(-10), qty_after_transaction=40, + warehouse="WH 1", posting_date="2021-12-03", voucher_type="Stock Entry", voucher_no="003", has_serial_no=False, serial_no=None @@ -50,11 +54,12 @@ class TestStockAgeing(ERPNextTestCase): self.assertEqual(queue[0][0], 20.0) def test_insufficient_balance(self): - "Reference: Case 3 in stock_ageing_fifo_logic.md" + "Reference: Case 3 in stock_ageing_fifo_logic.md (same wh)" sle = [ frappe._dict( name="Flask Item", actual_qty=(-30), qty_after_transaction=(-30), + warehouse="WH 1", posting_date="2021-12-01", voucher_type="Stock Entry", voucher_no="001", has_serial_no=False, serial_no=None @@ -62,6 +67,7 @@ class TestStockAgeing(ERPNextTestCase): frappe._dict( name="Flask Item", actual_qty=20, qty_after_transaction=(-10), + warehouse="WH 1", posting_date="2021-12-02", voucher_type="Stock Entry", voucher_no="002", has_serial_no=False, serial_no=None @@ -69,6 +75,7 @@ class TestStockAgeing(ERPNextTestCase): frappe._dict( name="Flask Item", actual_qty=20, qty_after_transaction=10, + warehouse="WH 1", posting_date="2021-12-03", voucher_type="Stock Entry", voucher_no="003", has_serial_no=False, serial_no=None @@ -76,6 +83,7 @@ class TestStockAgeing(ERPNextTestCase): frappe._dict( name="Flask Item", actual_qty=10, qty_after_transaction=20, + warehouse="WH 1", posting_date="2021-12-03", voucher_type="Stock Entry", voucher_no="004", has_serial_no=False, serial_no=None @@ -91,11 +99,16 @@ class TestStockAgeing(ERPNextTestCase): self.assertEqual(queue[0][0], 10.0) self.assertEqual(queue[1][0], 10.0) - def test_stock_reconciliation(self): + def test_basic_stock_reconciliation(self): + """ + Ledger (same wh): [+30, reco reset >> 50, -10] + Bal: 40 + """ sle = [ frappe._dict( name="Flask Item", actual_qty=30, qty_after_transaction=30, + warehouse="WH 1", posting_date="2021-12-01", voucher_type="Stock Entry", voucher_no="001", has_serial_no=False, serial_no=None @@ -103,6 +116,7 @@ class TestStockAgeing(ERPNextTestCase): frappe._dict( name="Flask Item", actual_qty=0, qty_after_transaction=50, + warehouse="WH 1", posting_date="2021-12-02", voucher_type="Stock Reconciliation", voucher_no="002", has_serial_no=False, serial_no=None @@ -110,6 +124,7 @@ class TestStockAgeing(ERPNextTestCase): frappe._dict( name="Flask Item", actual_qty=(-10), qty_after_transaction=40, + warehouse="WH 1", posting_date="2021-12-03", voucher_type="Stock Entry", voucher_no="003", has_serial_no=False, serial_no=None @@ -122,5 +137,477 @@ class TestStockAgeing(ERPNextTestCase): queue = result["fifo_queue"] self.assertEqual(result["qty_after_transaction"], result["total_qty"]) + self.assertEqual(result["total_qty"], 40.0) self.assertEqual(queue[0][0], 20.0) self.assertEqual(queue[1][0], 20.0) + + def test_sequential_stock_reco_same_warehouse(self): + """ + Test back to back stock recos (same warehouse). + Ledger: [reco opening >> +1000, reco reset >> 400, -10] + Bal: 390 + """ + sle = [ + frappe._dict( + name="Flask Item", + actual_qty=0, qty_after_transaction=1000, + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Reconciliation", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=0, qty_after_transaction=400, + warehouse="WH 1", + posting_date="2021-12-02", voucher_type="Stock Reconciliation", + voucher_no="003", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-10), qty_after_transaction=390, + warehouse="WH 1", + posting_date="2021-12-03", voucher_type="Stock Entry", + voucher_no="003", + has_serial_no=False, serial_no=None + ) + ] + slots = FIFOSlots(self.filters, sle).generate() + + result = slots["Flask Item"] + queue = result["fifo_queue"] + + self.assertEqual(result["qty_after_transaction"], result["total_qty"]) + self.assertEqual(result["total_qty"], 390.0) + self.assertEqual(queue[0][0], 390.0) + + def test_sequential_stock_reco_different_warehouse(self): + """ + Ledger: + WH | Voucher | Qty + ------------------- + WH1 | Reco | 1000 + WH2 | Reco | 400 + WH1 | SE | -10 + + Bal: WH1 bal + WH2 bal = 990 + 400 = 1390 + """ + sle = [ + frappe._dict( + name="Flask Item", + actual_qty=0, qty_after_transaction=1000, + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Reconciliation", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=0, qty_after_transaction=400, + warehouse="WH 2", + posting_date="2021-12-02", voucher_type="Stock Reconciliation", + voucher_no="003", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-10), qty_after_transaction=990, + warehouse="WH 1", + posting_date="2021-12-03", voucher_type="Stock Entry", + voucher_no="004", + has_serial_no=False, serial_no=None + ) + ] + + item_wise_slots, item_wh_wise_slots = generate_item_and_item_wh_wise_slots( + filters=self.filters,sle=sle + ) + + # test without 'show_warehouse_wise_stock' + item_result = item_wise_slots["Flask Item"] + queue = item_result["fifo_queue"] + + self.assertEqual(item_result["qty_after_transaction"], item_result["total_qty"]) + self.assertEqual(item_result["total_qty"], 1390.0) + self.assertEqual(queue[0][0], 990.0) + self.assertEqual(queue[1][0], 400.0) + + # test with 'show_warehouse_wise_stock' checked + item_wh_balances = [item_wh_wise_slots.get(i).get("qty_after_transaction") for i in item_wh_wise_slots] + self.assertEqual(sum(item_wh_balances), item_result["qty_after_transaction"]) + + def test_repack_entry_same_item_split_rows(self): + """ + Split consumption rows and have single repacked item row (same warehouse). + Ledger: + Item | Qty | Voucher + ------------------------ + Item 1 | 500 | 001 + Item 1 | -50 | 002 (repack) + Item 1 | -50 | 002 (repack) + Item 1 | 100 | 002 (repack) + + Case most likely for batch items. Test time bucket computation. + """ + sle = [ + frappe._dict( # stock up item + name="Flask Item", + actual_qty=500, qty_after_transaction=500, + warehouse="WH 1", + posting_date="2021-12-03", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-50), qty_after_transaction=450, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-50), qty_after_transaction=400, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=100, qty_after_transaction=500, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + ] + slots = FIFOSlots(self.filters, sle).generate() + item_result = slots["Flask Item"] + queue = item_result["fifo_queue"] + + self.assertEqual(item_result["total_qty"], 500.0) + self.assertEqual(queue[0][0], 400.0) + self.assertEqual(queue[1][0], 50.0) + self.assertEqual(queue[2][0], 50.0) + # check if time buckets add up to balance qty + self.assertEqual(sum([i[0] for i in queue]), 500.0) + + def test_repack_entry_same_item_overconsume(self): + """ + Over consume item and have less repacked item qty (same warehouse). + Ledger: + Item | Qty | Voucher + ------------------------ + Item 1 | 500 | 001 + Item 1 | -100 | 002 (repack) + Item 1 | 50 | 002 (repack) + + Case most likely for batch items. Test time bucket computation. + """ + sle = [ + frappe._dict( # stock up item + name="Flask Item", + actual_qty=500, qty_after_transaction=500, + warehouse="WH 1", + posting_date="2021-12-03", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-100), qty_after_transaction=400, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=50, qty_after_transaction=450, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + ] + slots = FIFOSlots(self.filters, sle).generate() + item_result = slots["Flask Item"] + queue = item_result["fifo_queue"] + + self.assertEqual(item_result["total_qty"], 450.0) + self.assertEqual(queue[0][0], 400.0) + self.assertEqual(queue[1][0], 50.0) + # check if time buckets add up to balance qty + self.assertEqual(sum([i[0] for i in queue]), 450.0) + + def test_repack_entry_same_item_overconsume_with_split_rows(self): + """ + Over consume item and have less repacked item qty (same warehouse). + Ledger: + Item | Qty | Voucher + ------------------------ + Item 1 | 20 | 001 + Item 1 | -50 | 002 (repack) + Item 1 | -50 | 002 (repack) + Item 1 | 50 | 002 (repack) + """ + sle = [ + frappe._dict( # stock up item + name="Flask Item", + actual_qty=20, qty_after_transaction=20, + warehouse="WH 1", + posting_date="2021-12-03", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-50), qty_after_transaction=(-30), + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-50), qty_after_transaction=(-80), + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=50, qty_after_transaction=(-30), + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + ] + fifo_slots = FIFOSlots(self.filters, sle) + slots = fifo_slots.generate() + item_result = slots["Flask Item"] + queue = item_result["fifo_queue"] + + self.assertEqual(item_result["total_qty"], -30.0) + self.assertEqual(queue[0][0], -30.0) + + # check transfer bucket + transfer_bucket = fifo_slots.transferred_item_details[('002', 'Flask Item', 'WH 1')] + self.assertEqual(transfer_bucket[0][0], 50) + + def test_repack_entry_same_item_overproduce(self): + """ + Under consume item and have more repacked item qty (same warehouse). + Ledger: + Item | Qty | Voucher + ------------------------ + Item 1 | 500 | 001 + Item 1 | -50 | 002 (repack) + Item 1 | 100 | 002 (repack) + + Case most likely for batch items. Test time bucket computation. + """ + sle = [ + frappe._dict( # stock up item + name="Flask Item", + actual_qty=500, qty_after_transaction=500, + warehouse="WH 1", + posting_date="2021-12-03", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-50), qty_after_transaction=450, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=100, qty_after_transaction=550, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + ] + slots = FIFOSlots(self.filters, sle).generate() + item_result = slots["Flask Item"] + queue = item_result["fifo_queue"] + + self.assertEqual(item_result["total_qty"], 550.0) + self.assertEqual(queue[0][0], 450.0) + self.assertEqual(queue[1][0], 50.0) + self.assertEqual(queue[2][0], 50.0) + # check if time buckets add up to balance qty + self.assertEqual(sum([i[0] for i in queue]), 550.0) + + def test_repack_entry_same_item_overproduce_with_split_rows(self): + """ + Over consume item and have less repacked item qty (same warehouse). + Ledger: + Item | Qty | Voucher + ------------------------ + Item 1 | 20 | 001 + Item 1 | -50 | 002 (repack) + Item 1 | 50 | 002 (repack) + Item 1 | 50 | 002 (repack) + """ + sle = [ + frappe._dict( # stock up item + name="Flask Item", + actual_qty=20, qty_after_transaction=20, + warehouse="WH 1", + posting_date="2021-12-03", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=(-50), qty_after_transaction=(-30), + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=50, qty_after_transaction=20, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + frappe._dict( + name="Flask Item", + actual_qty=50, qty_after_transaction=70, + warehouse="WH 1", + posting_date="2021-12-04", voucher_type="Stock Entry", + voucher_no="002", + has_serial_no=False, serial_no=None + ), + ] + fifo_slots = FIFOSlots(self.filters, sle) + slots = fifo_slots.generate() + item_result = slots["Flask Item"] + queue = item_result["fifo_queue"] + + self.assertEqual(item_result["total_qty"], 70.0) + self.assertEqual(queue[0][0], 20.0) + self.assertEqual(queue[1][0], 50.0) + + # check transfer bucket + transfer_bucket = fifo_slots.transferred_item_details[('002', 'Flask Item', 'WH 1')] + self.assertFalse(transfer_bucket) + + def test_negative_stock_same_voucher(self): + """ + Test negative stock scenario in transfer bucket via repack entry (same wh). + Ledger: + Item | Qty | Voucher + ------------------------ + Item 1 | -50 | 001 + Item 1 | -50 | 001 + Item 1 | 30 | 001 + Item 1 | 80 | 001 + """ + sle = [ + frappe._dict( # stock up item + name="Flask Item", + actual_qty=(-50), qty_after_transaction=(-50), + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( # stock up item + name="Flask Item", + actual_qty=(-50), qty_after_transaction=(-100), + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( # stock up item + name="Flask Item", + actual_qty=30, qty_after_transaction=(-70), + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + ] + fifo_slots = FIFOSlots(self.filters, sle) + slots = fifo_slots.generate() + item_result = slots["Flask Item"] + + # check transfer bucket + transfer_bucket = fifo_slots.transferred_item_details[('001', 'Flask Item', 'WH 1')] + self.assertEqual(transfer_bucket[0][0], 20) + self.assertEqual(transfer_bucket[1][0], 50) + self.assertEqual(item_result["fifo_queue"][0][0], -70.0) + + sle.append(frappe._dict( + name="Flask Item", + actual_qty=80, qty_after_transaction=10, + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + )) + + fifo_slots = FIFOSlots(self.filters, sle) + slots = fifo_slots.generate() + item_result = slots["Flask Item"] + + transfer_bucket = fifo_slots.transferred_item_details[('001', 'Flask Item', 'WH 1')] + self.assertFalse(transfer_bucket) + self.assertEqual(item_result["fifo_queue"][0][0], 10.0) + + def test_precision(self): + "Test if final balance qty is rounded off correctly." + sle = [ + frappe._dict( # stock up item + name="Flask Item", + actual_qty=0.3, qty_after_transaction=0.3, + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + frappe._dict( # stock up item + name="Flask Item", + actual_qty=0.6, qty_after_transaction=0.9, + warehouse="WH 1", + posting_date="2021-12-01", voucher_type="Stock Entry", + voucher_no="001", + has_serial_no=False, serial_no=None + ), + ] + + slots = FIFOSlots(self.filters, sle).generate() + report_data = format_report_data(self.filters, slots, self.filters["to_date"]) + row = report_data[0] # first row in report + bal_qty = row[5] + range_qty_sum = sum([i for i in row[7:11]]) # get sum of range balance + + # check if value of Available Qty column matches with range bucket post format + self.assertEqual(bal_qty, 0.9) + self.assertEqual(bal_qty, range_qty_sum) + +def generate_item_and_item_wh_wise_slots(filters, sle): + "Return results with and without 'show_warehouse_wise_stock'" + item_wise_slots = FIFOSlots(filters, sle).generate() + + filters.show_warehouse_wise_stock = True + item_wh_wise_slots = FIFOSlots(filters, sle).generate() + filters.show_warehouse_wise_stock = False + + return item_wise_slots, item_wh_wise_slots diff --git a/erpnext/stock/report/stock_analytics/test_stock_analytics.py b/erpnext/stock/report/stock_analytics/test_stock_analytics.py index 32df5859375..f6c98f914d2 100644 --- a/erpnext/stock/report/stock_analytics/test_stock_analytics.py +++ b/erpnext/stock/report/stock_analytics/test_stock_analytics.py @@ -1,14 +1,13 @@ import datetime -import unittest from frappe import _dict +from frappe.tests.utils import FrappeTestCase 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(ERPNextTestCase): +class TestStockAnalyticsReport(FrappeTestCase): 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/report/stock_ledger/stock_ledger.js b/erpnext/stock/report/stock_ledger/stock_ledger.js index fe2417bba7e..ef7c2cc7d9e 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.js +++ b/erpnext/stock/report/stock_ledger/stock_ledger.js @@ -86,10 +86,10 @@ frappe.query_reports["Stock Ledger"] = { ], "formatter": function (value, row, column, data, default_formatter) { value = default_formatter(value, row, column, data); - if (column.fieldname == "out_qty" && data.out_qty < 0) { + if (column.fieldname == "out_qty" && data && data.out_qty < 0) { value = "" + value + ""; } - else if (column.fieldname == "in_qty" && data.in_qty > 0) { + else if (column.fieldname == "in_qty" && data && data.in_qty > 0) { value = "" + value + ""; } diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index c60a6ca56ea..81fa0458f29 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -104,6 +104,7 @@ def get_columns(): {"label": _("Incoming Rate"), "fieldname": "incoming_rate", "fieldtype": "Currency", "width": 110, "options": "Company:company:default_currency", "convertible": "rate"}, {"label": _("Valuation Rate"), "fieldname": "valuation_rate", "fieldtype": "Currency", "width": 110, "options": "Company:company:default_currency", "convertible": "rate"}, {"label": _("Balance Value"), "fieldname": "stock_value", "fieldtype": "Currency", "width": 110, "options": "Company:company:default_currency"}, + {"label": _("Value Change"), "fieldname": "stock_value_difference", "fieldtype": "Currency", "width": 110, "options": "Company:company:default_currency"}, {"label": _("Voucher Type"), "fieldname": "voucher_type", "width": 110}, {"label": _("Voucher #"), "fieldname": "voucher_no", "fieldtype": "Dynamic Link", "options": "voucher_type", "width": 100}, {"label": _("Batch"), "fieldname": "batch_no", "fieldtype": "Link", "options": "Batch", "width": 100}, diff --git a/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.py b/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.py index 48753b0edd4..7826d344225 100644 --- a/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.py +++ b/erpnext/stock/report/stock_ledger_invariant_check/stock_ledger_invariant_check.py @@ -60,6 +60,9 @@ def add_invariant_check_fields(sles): fifo_qty += qty fifo_value += qty * rate + if sle.actual_qty < 0: + sle.consumption_rate = sle.stock_value_difference / sle.actual_qty + balance_qty += sle.actual_qty balance_stock_value += sle.stock_value_difference if sle.voucher_type == "Stock Reconciliation" and not sle.batch_no: @@ -90,6 +93,9 @@ def add_invariant_check_fields(sles): sle.fifo_stock_diff = sle.fifo_stock_value - sles[idx - 1].fifo_stock_value sle.fifo_difference_diff = sle.fifo_stock_diff - sle.stock_value_difference + if sle.batch_no: + sle.use_batchwise_valuation = frappe.db.get_value("Batch", sle.batch_no, "use_batchwise_valuation", cache=True) + return sles @@ -134,6 +140,11 @@ def get_columns(): "label": "Batch", "options": "Batch", }, + { + "fieldname": "use_batchwise_valuation", + "fieldtype": "Check", + "label": "Batchwise Valuation", + }, { "fieldname": "actual_qty", "fieldtype": "Float", @@ -145,9 +156,9 @@ def get_columns(): "label": "Incoming Rate", }, { - "fieldname": "outgoing_rate", + "fieldname": "consumption_rate", "fieldtype": "Float", - "label": "Outgoing Rate", + "label": "Consumption Rate", }, { "fieldname": "qty_after_transaction", @@ -167,7 +178,7 @@ def get_columns(): { "fieldname": "stock_queue", "fieldtype": "Data", - "label": "FIFO Queue", + "label": "FIFO/LIFO Queue", }, { diff --git a/erpnext/stock/report/test_reports.py b/erpnext/stock/report/test_reports.py index 1dcf863a9d0..76c20798bfb 100644 --- a/erpnext/stock/report/test_reports.py +++ b/erpnext/stock/report/test_reports.py @@ -1,6 +1,8 @@ import unittest from typing import List, Tuple +import frappe + from erpnext.tests.utils import ReportFilters, ReportName, execute_script_report DEFAULT_FILTERS = { @@ -10,8 +12,12 @@ DEFAULT_FILTERS = { } +batch = frappe.db.get_value("Batch", fieldname=["name"], as_dict=True, order_by="creation desc") + REPORT_FILTER_TEST_CASES: List[Tuple[ReportName, ReportFilters]] = [ ("Stock Ledger", {"_optional": True}), + ("Stock Ledger", {"batch_no": batch}), + ("Stock Ledger", {"item_code": "_Test Item", "warehouse": "_Test Warehouse - _TC"}), ("Stock Balance", {"_optional": True}), ("Stock Projected Qty", {"_optional": True}), ("Batch-Wise Balance History", {}), @@ -40,6 +46,13 @@ REPORT_FILTER_TEST_CASES: List[Tuple[ReportName, ReportFilters]] = [ ("Item Variant Details", {"item": "_Test Variant Item",}), ("Total Stock Summary", {"group_by": "warehouse",}), ("Batch Item Expiry Status", {}), + ("Incorrect Stock Value Report", {"company": "_Test Company with perpetual inventory"}), + ("Incorrect Serial No Valuation", {}), + ("Incorrect Balance Qty After Transaction", {}), + ("Supplier-Wise Sales Analytics", {}), + ("Item Prices", {"items": "Enabled Items only"}), + ("Delayed Item Report", {"based_on": "Sales Invoice"}), + ("Delayed Item Report", {"based_on": "Delivery Note"}), ("Stock Ageing", {"range1": 30, "range2": 60, "range3": 90, "_optional": True}), ("Stock Ledger Invariant Check", { @@ -60,10 +73,11 @@ class TestReports(unittest.TestCase): def test_execute_all_stock_reports(self): """Test that all script report in stock modules are executable with supported filters""" for report, filter in REPORT_FILTER_TEST_CASES: - execute_script_report( - report_name=report, - module="Stock", - filters=filter, - default_filters=DEFAULT_FILTERS, - optional_filters=OPTIONAL_FILTERS if filter.get("_optional") else None, - ) + with self.subTest(report=report): + execute_script_report( + report_name=report, + module="Stock", + filters=filter, + default_filters=DEFAULT_FILTERS, + optional_filters=OPTIONAL_FILTERS if filter.get("_optional") else None, + ) diff --git a/erpnext/stock/spec/README.md b/erpnext/stock/spec/README.md new file mode 100644 index 00000000000..f5a3501fe47 --- /dev/null +++ b/erpnext/stock/spec/README.md @@ -0,0 +1,103 @@ +# Implementation notes for Stock Ledger + + +## Important files + +- `stock/stock_ledger.py` +- `controllers/stock_controller.py` +- `stock/valuation.py` + +## What is in an Stock Ledger Entry (SLE)? + +Stock Ledger Entry is a single row in the Stock Ledger. It signifies some +modification of stock for a particular Item in the specified warehouse. + +- `item_code`: item for which ledger entry is made +- `warehouse`: warehouse where inventory is affected +- `actual_qty`: change in qty +- `qty_after_transaction`: quantity available after the transaction is processed +- `incoming_rate`: rate at which inventory was received. +- `is_cancelled`: if 1 then stock ledger entry is cancelled and should not be used +for any business logic except for the code that handles cancellation. +- `posting_date` & `posting_time`: Specify the temporal ordering of stock ledger + entries. Ties are broken by `creation` timestamp. +- `voucher_type`: Many transaction can create SLE, e.g. Stock Entry, Purchase + Invoice +- `voucher_no`: `name` of the transaction that created SLE +- `voucher_detail_no`: `name` of the child table row from parent transaction + that created the SLE. +- `dependant_sle_voucher_detail_no`: cross-warehouse transfers need this + reference in order to update dependent warehouse rates in case of change in + rate. +- `recalculate_rate`: if this is checked in/out rates are recomputed on + transactions. +- `valuation_rate`: current average valuation rate. +- `stock_value`: current total stock value +- `stock_value_difference`: stock value difference made between last and current + entry. This value is booked in accounting ledger. +- `stock_queue`: if FIFO/LIFO is used this represents queue/stack maintained for + computing incoming rate for inventory getting consumed. +- `batch_no`: batch no for which stock entry is made; each stock entry can only + affect one batch number. +- `serial_no`: newline separated list of serial numbers that were added (if + actual_qty > 0) or else removed. Currently multiple serial nos can have single + SLE but this will likely change in future. + + +## Implementation of Stock Ledger + +Stock Ledger Entry affects stock of combinations of (item_code, warehouse) and +optionally batch no if specified. For simplicity, lets avoid batch no. for now. + + +Stock Ledger Entry table stores stock ledger for all combinations of item_code +and warehouse. So whenever any operations are to be performed on said +item-warehouse combination stock ledger is filtered and sorted by posting +datetime. A typical query that will give you individual ledger looks like this: + +```sql +select * +from `tabStock Ledger Entry` as sle +where + is_cancelled = 0 --- cancelled entries don't affect ledger + and item_code = 'item_code' and warehouse = 'warehouse_name' +order by timestamp(posting_date, posting_time), creation +``` + +New entry is just an update to the last entry which is found by looking at last +row in the filter ledger. + + +### Serial nos + +Serial numbers do not follow any valuation method configuration and they are +consumed at rate they were produced unless they are grouped in which case they +are consumed at weighted average rate. + + +### Batch Nos + +Batches are currently NOT consumed as per batch wise valuation rate, instead +global FIFO queue for the item is used for valuation rate. + + +## Creation process of SLEs + +- SLE creation is usually triggered by Stock Transactions using a method + conventionally named `update_stock_ledger()` This might not be defined for + stock transaction and could be specified somewhere in inheritance hierarchy of + controllers. +- This method produces SLE objects which are processed by `make_sl_entries` in + `stock_ledger.py` which commits the SLE to database. +- `update_entries_after` class is used to process ONLY the inserted SLE's queue + and valuation. +- The change in qty is propagated to future entries immediately. Valuation and + queue for future entries is processed in background using repost item + valuation. + + +## Accounting impact + +- Accounting impact for stock transaction is handled by `get_gl_entries()` + method on controllers. Each transaction has different business logic for + booking the accounting impact. diff --git a/erpnext/stock/spec/reposting.md b/erpnext/stock/spec/reposting.md new file mode 100644 index 00000000000..b0d59fe9bb1 --- /dev/null +++ b/erpnext/stock/spec/reposting.md @@ -0,0 +1,38 @@ +# Stock Reposting + +Stock "reposting" is process of re-processing Stock Ledger Entry and GL Entries +in event of backdated stock transaction. + +*Backdated stock transaction*: Any stock transaction for which some +item-warehouse combination has a future transactions. + +## Why is this required? +Stock Ledger is stateful, it maintains queue, qty at any +point in time. So if you do a backdated transaction all future values change, +queues need to be re-evaluated etc. Watch Nabin and Rohit's conference +presentation for explanation: https://www.youtube.com/watch?v=mw3WAnekGIM + +## How is this implemented? +Whenever backdated transaction is detected, instead of +fully processing it while submitting, the processing is queued using "Repost +Item Valuation" doctype. Every hour a scheduled job runs and processes this +queue (for up to maximum of 25 minutes) + + +## Queue implementation +- "Repost item valuation" (RIV) is automatically submitted from backdated transactions. (check stock_controller.py) +- Draft and cancelled RIV are ignored. +- Keep filter of "submitted" documents when doing anything with RIVs. +- The default status is "Queued". +- When background job runs, it picks the oldest pending reposts and changes the status to "In Progress" and when it finishes it +changes to "Completed" +- There are two more status: "Failed" when reposting failed and "Skipped" when reposting is deemed not necessary so it's skipped. +- technical detail: Entry point for whole process is "repost_entries" function in repost_item_valuation.py + + +## How to identify broken stock data: +There are 4 major reports for checking broken stock data: +- Incorrect balance qty after the transaction - to check if the running total of qty isn't correct. +- Incorrect stock value report - to check incorrect value books in accounts for stock transactions +- Incorrect serial no valuation -specific to serial nos +- Stock ledger invariant check - combined report for checking qty, running total, queue, balance value etc diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index 6663458e651..62017e41593 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -3,10 +3,9 @@ import frappe -from frappe.utils import cstr, flt, nowdate, nowtime +from frappe.utils import cstr, flt, now, nowdate, nowtime from erpnext.controllers.stock_controller import create_repost_item_valuation_entry -from erpnext.stock.utils import update_bin def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False, only_bin=False): @@ -175,6 +174,7 @@ def update_bin_qty(item_code, warehouse, qty_dict=None): bin.set(field, flt(value)) mismatch = True + bin.modified = now() if mismatch: bin.set_projected_qty() bin.db_update() @@ -227,8 +227,6 @@ def set_stock_balance_as_per_serial_no(item_code=None, posting_date=None, postin "sle_id": sle_doc.name }) - update_bin(args) - create_repost_item_valuation_entry({ "item_code": d[0], "warehouse": d[1], diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 0a7ab4009c0..1b90086440f 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -3,11 +3,14 @@ import copy import json +from typing import Optional import frappe from frappe import _ from frappe.model.meta import get_field_precision +from frappe.query_builder.functions import Sum from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, now, nowdate +from pypika import CustomFunction import erpnext from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty @@ -16,14 +19,13 @@ from erpnext.stock.utils import ( get_or_make_bin, get_valuation_method, ) -from erpnext.stock.valuation import FIFOValuation +from erpnext.stock.valuation import FIFOValuation, LIFOValuation, round_off_if_near_zero class NegativeStockError(frappe.ValidationError): pass class SerialNoExistsInFutureTransaction(frappe.ValidationError): pass -_exceptions = frappe.local('stockledger_exceptions') def make_sl_entries(sl_entries, allow_negative_stock=False, via_landed_cost_voucher=False): from erpnext.controllers.stock_controller import future_sle_exists @@ -268,11 +270,10 @@ class update_entries_after(object): self.verbose = verbose self.allow_zero_rate = allow_zero_rate self.via_landed_cost_voucher = via_landed_cost_voucher - self.allow_negative_stock = allow_negative_stock \ - or cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock")) + self.item_code = args.get("item_code") + self.allow_negative_stock = allow_negative_stock or is_negative_stock_allowed(item_code=self.item_code) self.args = frappe._dict(args) - self.item_code = args.get("item_code") if self.args.sle_id: self.args['name'] = self.args.sle_id @@ -447,6 +448,8 @@ class update_entries_after(object): self.wh_data.qty_after_transaction = sle.qty_after_transaction self.wh_data.stock_value = flt(self.wh_data.qty_after_transaction) * flt(self.wh_data.valuation_rate) + elif sle.batch_no and frappe.db.get_value("Batch", sle.batch_no, "use_batchwise_valuation", cache=True): + self.update_batched_values(sle) else: if sle.voucher_type=="Stock Reconciliation" and not sle.batch_no: # assert @@ -461,11 +464,12 @@ class update_entries_after(object): self.wh_data.qty_after_transaction += flt(sle.actual_qty) self.wh_data.stock_value = flt(self.wh_data.qty_after_transaction) * flt(self.wh_data.valuation_rate) else: - self.update_fifo_values(sle) - self.wh_data.qty_after_transaction += flt(sle.actual_qty) + self.update_queue_values(sle) # rounding as per precision self.wh_data.stock_value = flt(self.wh_data.stock_value, self.precision) + if not self.wh_data.qty_after_transaction: + self.wh_data.stock_value = 0.0 stock_value_difference = self.wh_data.stock_value - self.wh_data.prev_stock_value self.wh_data.prev_stock_value = self.wh_data.stock_value @@ -481,6 +485,7 @@ class update_entries_after(object): if not self.args.get("sle_id"): self.update_outgoing_rate_on_transaction(sle) + def validate_negative_stock(self, sle): """ validate negative stock for entries current datetime onwards @@ -629,9 +634,7 @@ class update_entries_after(object): if not self.wh_data.valuation_rate and sle.voucher_detail_no: allow_zero_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) if not allow_zero_rate: - self.wh_data.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, - sle.voucher_type, sle.voucher_no, self.allow_zero_rate, - currency=erpnext.get_company_currency(sle.company), company=sle.company) + self.wh_data.valuation_rate = self.get_fallback_rate(sle) def get_incoming_value_for_serial_nos(self, sle, serial_nos): # get rate from serial nos within same company @@ -697,42 +700,70 @@ class update_entries_after(object): if not self.wh_data.valuation_rate and sle.voucher_detail_no: allow_zero_valuation_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) if not allow_zero_valuation_rate: - self.wh_data.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, - sle.voucher_type, sle.voucher_no, self.allow_zero_rate, - currency=erpnext.get_company_currency(sle.company), company=sle.company) + self.wh_data.valuation_rate = self.get_fallback_rate(sle) - def update_fifo_values(self, sle): + def update_queue_values(self, sle): incoming_rate = flt(sle.incoming_rate) actual_qty = flt(sle.actual_qty) outgoing_rate = flt(sle.outgoing_rate) - fifo_queue = FIFOValuation(self.wh_data.stock_queue) + self.wh_data.qty_after_transaction = round_off_if_near_zero(self.wh_data.qty_after_transaction + actual_qty) + + if self.valuation_method == "LIFO": + stock_queue = LIFOValuation(self.wh_data.stock_queue) + else: + stock_queue = FIFOValuation(self.wh_data.stock_queue) + + _prev_qty, prev_stock_value = stock_queue.get_total_stock_and_value() + if actual_qty > 0: - fifo_queue.add_stock(qty=actual_qty, rate=incoming_rate) + stock_queue.add_stock(qty=actual_qty, rate=incoming_rate) else: def rate_generator() -> float: allow_zero_valuation_rate = self.check_if_allow_zero_valuation_rate(sle.voucher_type, sle.voucher_detail_no) if not allow_zero_valuation_rate: - return get_valuation_rate(sle.item_code, sle.warehouse, - sle.voucher_type, sle.voucher_no, self.allow_zero_rate, - currency=erpnext.get_company_currency(sle.company), company=sle.company) + return self.get_fallback_rate(sle) else: return 0.0 - fifo_queue.remove_stock(qty=abs(actual_qty), outgoing_rate=outgoing_rate, rate_generator=rate_generator) + stock_queue.remove_stock(qty=abs(actual_qty), outgoing_rate=outgoing_rate, rate_generator=rate_generator) - stock_qty, stock_value = fifo_queue.get_total_stock_and_value() + _qty, stock_value = stock_queue.get_total_stock_and_value() - self.wh_data.stock_queue = fifo_queue.get_state() - self.wh_data.stock_value = stock_value - if stock_qty: - self.wh_data.valuation_rate = stock_value / stock_qty + stock_value_difference = stock_value - prev_stock_value + self.wh_data.stock_queue = stock_queue.state + self.wh_data.stock_value = round_off_if_near_zero(self.wh_data.stock_value + stock_value_difference) if not self.wh_data.stock_queue: self.wh_data.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.wh_data.valuation_rate]) + if self.wh_data.qty_after_transaction: + self.wh_data.valuation_rate = self.wh_data.stock_value / self.wh_data.qty_after_transaction + def update_batched_values(self, sle): + incoming_rate = flt(sle.incoming_rate) + actual_qty = flt(sle.actual_qty) + + self.wh_data.qty_after_transaction = round_off_if_near_zero(self.wh_data.qty_after_transaction + actual_qty) + + if actual_qty > 0: + stock_value_difference = incoming_rate * actual_qty + else: + outgoing_rate = get_batch_incoming_rate(item_code=sle.item_code, + warehouse=sle.warehouse, batch_no=sle.batch_no, posting_date=sle.posting_date, + posting_time=sle.posting_time, creation=sle.creation) + if outgoing_rate is None: + # This can *only* happen if qty available for the batch is zero. + # in such case fall back various other rates. + # future entries will correct the overall accounting as each + # batch individually uses moving average rates. + outgoing_rate = self.get_fallback_rate(sle) + stock_value_difference = outgoing_rate * actual_qty + + self.wh_data.stock_value = round_off_if_near_zero(self.wh_data.stock_value + stock_value_difference) + if self.wh_data.qty_after_transaction: + self.wh_data.valuation_rate = self.wh_data.stock_value / self.wh_data.qty_after_transaction def check_if_allow_zero_valuation_rate(self, voucher_type, voucher_detail_no): ref_item_dt = "" @@ -747,6 +778,13 @@ class update_entries_after(object): else: return 0 + def get_fallback_rate(self, sle) -> float: + """When exact incoming rate isn't available use any of other "average" rates as fallback. + This should only get used for negative stock.""" + return get_valuation_rate(sle.item_code, sle.warehouse, + sle.voucher_type, sle.voucher_no, self.allow_zero_rate, + currency=erpnext.get_company_currency(sle.company), company=sle.company, batch_no=sle.batch_no) + def get_sle_before_datetime(self, args): """get previous stock ledger entry before current time-bucket""" sle = get_stock_ledger_entries(args, "<", "desc", "limit 1", for_update=False) @@ -893,22 +931,72 @@ def get_sle_by_voucher_detail_no(voucher_detail_no, excluded_sle=None): ['item_code', 'warehouse', 'posting_date', 'posting_time', 'timestamp(posting_date, posting_time) as timestamp'], as_dict=1) +def get_batch_incoming_rate(item_code, warehouse, batch_no, posting_date, posting_time, creation=None): + + Timestamp = CustomFunction('timestamp', ['date', 'time']) + + sle = frappe.qb.DocType("Stock Ledger Entry") + + timestamp_condition = (Timestamp(sle.posting_date, sle.posting_time) < Timestamp(posting_date, posting_time)) + if creation: + timestamp_condition |= ( + (Timestamp(sle.posting_date, sle.posting_time) == Timestamp(posting_date, posting_time)) + & (sle.creation < creation) + ) + + batch_details = ( + frappe.qb + .from_(sle) + .select( + Sum(sle.stock_value_difference).as_("batch_value"), + Sum(sle.actual_qty).as_("batch_qty") + ) + .where( + (sle.item_code == item_code) + & (sle.warehouse == warehouse) + & (sle.batch_no == batch_no) + & (sle.is_cancelled == 0) + ) + .where(timestamp_condition) + ).run(as_dict=True) + + if batch_details and batch_details[0].batch_qty: + return batch_details[0].batch_value / batch_details[0].batch_qty + + def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, - allow_zero_rate=False, currency=None, company=None, raise_error_if_no_rate=True): + allow_zero_rate=False, currency=None, company=None, raise_error_if_no_rate=True, batch_no=None): if not company: company = frappe.get_cached_value("Warehouse", warehouse, "company") + last_valuation_rate = None + + # Get moving average rate of a specific batch number + if warehouse and batch_no and frappe.db.get_value("Batch", batch_no, "use_batchwise_valuation"): + last_valuation_rate = frappe.db.sql(""" + select sum(stock_value_difference) / sum(actual_qty) + from `tabStock Ledger Entry` + where + item_code = %s + AND warehouse = %s + AND batch_no = %s + AND is_cancelled = 0 + AND NOT (voucher_no = %s AND voucher_type = %s) + """, + (item_code, warehouse, batch_no, voucher_no, voucher_type)) + # Get valuation rate from last sle for the same item and warehouse - last_valuation_rate = frappe.db.sql("""select valuation_rate - from `tabStock Ledger Entry` force index (item_warehouse) - where - item_code = %s - AND warehouse = %s - AND valuation_rate >= 0 - AND is_cancelled = 0 - AND NOT (voucher_no = %s AND voucher_type = %s) - order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse, voucher_no, voucher_type)) + if not last_valuation_rate or last_valuation_rate[0][0] is None: + last_valuation_rate = frappe.db.sql("""select valuation_rate + from `tabStock Ledger Entry` force index (item_warehouse) + where + item_code = %s + AND warehouse = %s + AND valuation_rate >= 0 + AND is_cancelled = 0 + AND NOT (voucher_no = %s AND voucher_type = %s) + order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse, voucher_no, voucher_type)) if not last_valuation_rate: # Get valuation rate from last sle for the item against any warehouse @@ -1045,10 +1133,7 @@ def get_datetime_limit_condition(detail): )""" def validate_negative_qty_in_future_sle(args, allow_negative_stock=False): - allow_negative_stock = cint(allow_negative_stock) \ - or cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock")) - - if allow_negative_stock: + if allow_negative_stock or is_negative_stock_allowed(item_code=args.item_code): return if not (args.actual_qty < 0 or args.voucher_type == "Stock Reconciliation"): return @@ -1117,3 +1202,11 @@ def get_future_sle_with_negative_batch_qty(args): and timestamp(posting_date, posting_time) >= timestamp(%(posting_date)s, %(posting_time)s) limit 1 """, args, as_dict=1) + + +def is_negative_stock_allowed(*, item_code: Optional[str] = None) -> bool: + if cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock", cache=True)): + return True + if item_code and cint(frappe.db.get_value("Item", item_code, "allow_negative_stock", cache=True)): + return True + return False diff --git a/erpnext/stock/tests/test_valuation.py b/erpnext/stock/tests/test_valuation.py index 85788bac7f8..b64ff8e28c8 100644 --- a/erpnext/stock/tests/test_valuation.py +++ b/erpnext/stock/tests/test_valuation.py @@ -1,16 +1,21 @@ +import json import unittest +import frappe +from frappe.tests.utils import FrappeTestCase from hypothesis import given from hypothesis import strategies as st -from erpnext.stock.valuation import FIFOValuation, _round_off_if_near_zero +from erpnext.stock.doctype.item.test_item import make_item +from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry +from erpnext.stock.valuation import FIFOValuation, LIFOValuation, round_off_if_near_zero qty_gen = st.floats(min_value=-1e6, max_value=1e6) value_gen = st.floats(min_value=1, max_value=1e6) stock_queue_generator = st.lists(st.tuples(qty_gen, value_gen), min_size=10) -class TestFifoValuation(unittest.TestCase): +class TestFIFOValuation(unittest.TestCase): def setUp(self): self.queue = FIFOValuation([]) @@ -108,11 +113,11 @@ class TestFifoValuation(unittest.TestCase): self.assertTotalQty(0) def test_rounding_off_near_zero(self): - self.assertEqual(_round_off_if_near_zero(0), 0) - self.assertEqual(_round_off_if_near_zero(1), 1) - self.assertEqual(_round_off_if_near_zero(-1), -1) - self.assertEqual(_round_off_if_near_zero(-1e-8), 0) - self.assertEqual(_round_off_if_near_zero(1e-8), 0) + self.assertEqual(round_off_if_near_zero(0), 0) + self.assertEqual(round_off_if_near_zero(1), 1) + self.assertEqual(round_off_if_near_zero(-1), -1) + self.assertEqual(round_off_if_near_zero(-1e-8), 0) + self.assertEqual(round_off_if_near_zero(1e-8), 0) def test_totals(self): self.queue.add_stock(1, 10) @@ -164,3 +169,184 @@ class TestFifoValuation(unittest.TestCase): total_value -= sum(q * r for q, r in consumed) self.assertTotalQty(total_qty) self.assertTotalValue(total_value) + + +class TestLIFOValuation(unittest.TestCase): + + def setUp(self): + self.stack = LIFOValuation([]) + + def tearDown(self): + qty, value = self.stack.get_total_stock_and_value() + self.assertTotalQty(qty) + self.assertTotalValue(value) + + def assertTotalQty(self, qty): + self.assertAlmostEqual(sum(q for q, _ in self.stack), qty, msg=f"stack: {self.stack}", places=4) + + def assertTotalValue(self, value): + self.assertAlmostEqual(sum(q * r for q, r in self.stack), value, msg=f"stack: {self.stack}", places=2) + + def test_simple_addition(self): + self.stack.add_stock(1, 10) + self.assertTotalQty(1) + + def test_merge_new_stock(self): + self.stack.add_stock(1, 10) + self.stack.add_stock(1, 10) + self.assertEqual(self.stack, [[2, 10]]) + + def test_simple_removal(self): + self.stack.add_stock(1, 10) + self.stack.remove_stock(1) + self.assertTotalQty(0) + + def test_adding_negative_stock_keeps_rate(self): + self.stack = LIFOValuation([[-5.0, 100]]) + self.stack.add_stock(1, 10) + self.assertEqual(self.stack, [[-4, 100]]) + + def test_adding_negative_stock_updates_rate(self): + self.stack = LIFOValuation([[-5.0, 100]]) + self.stack.add_stock(6, 10) + self.assertEqual(self.stack, [[1, 10]]) + + def test_rounding_off(self): + self.stack.add_stock(1.0, 1.0) + self.stack.remove_stock(1.0 - 1e-9) + self.assertTotalQty(0) + + def test_lifo_consumption(self): + self.stack.add_stock(10, 10) + self.stack.add_stock(10, 20) + consumed = self.stack.remove_stock(15) + self.assertEqual(consumed, [[10, 20], [5, 10]]) + self.assertTotalQty(5) + + def test_lifo_consumption_going_negative(self): + self.stack.add_stock(10, 10) + self.stack.add_stock(10, 20) + consumed = self.stack.remove_stock(25) + self.assertEqual(consumed, [[10, 20], [10, 10], [5, 10]]) + self.assertTotalQty(-5) + + def test_lifo_consumption_multiple(self): + self.stack.add_stock(1, 1) + self.stack.add_stock(2, 2) + consumed = self.stack.remove_stock(1) + self.assertEqual(consumed, [[1, 2]]) + + self.stack.add_stock(3, 3) + consumed = self.stack.remove_stock(4) + self.assertEqual(consumed, [[3, 3], [1, 2]]) + + self.stack.add_stock(4, 4) + consumed = self.stack.remove_stock(5) + self.assertEqual(consumed, [[4, 4], [1, 1]]) + + self.stack.add_stock(5, 5) + consumed = self.stack.remove_stock(5) + self.assertEqual(consumed, [[5, 5]]) + + + @given(stock_queue_generator) + def test_lifo_qty_hypothesis(self, stock_stack): + self.stack = LIFOValuation([]) + total_qty = 0 + + for qty, rate in stock_stack: + if qty == 0: + continue + if qty > 0: + self.stack.add_stock(qty, rate) + total_qty += qty + else: + qty = abs(qty) + consumed = self.stack.remove_stock(qty) + self.assertAlmostEqual(qty, sum(q for q, _ in consumed), msg=f"incorrect consumption {consumed}") + total_qty -= qty + self.assertTotalQty(total_qty) + + @given(stock_queue_generator) + def test_lifo_qty_value_nonneg_hypothesis(self, stock_stack): + self.stack = LIFOValuation([]) + total_qty = 0.0 + total_value = 0.0 + + for qty, rate in stock_stack: + # don't allow negative stock + if qty == 0 or total_qty + qty < 0 or abs(qty) < 0.1: + continue + if qty > 0: + self.stack.add_stock(qty, rate) + total_qty += qty + total_value += qty * rate + else: + qty = abs(qty) + consumed = self.stack.remove_stock(qty) + self.assertAlmostEqual(qty, sum(q for q, _ in consumed), msg=f"incorrect consumption {consumed}") + total_qty -= qty + total_value -= sum(q * r for q, r in consumed) + self.assertTotalQty(total_qty) + self.assertTotalValue(total_value) + +class TestLIFOValuationSLE(FrappeTestCase): + ITEM_CODE = "_Test LIFO item" + WAREHOUSE = "_Test Warehouse - _TC" + + @classmethod + def setUpClass(cls) -> None: + super().setUpClass() + make_item(cls.ITEM_CODE, {"valuation_method": "LIFO"}) + + def _make_stock_entry(self, qty, rate=None): + kwargs = { + "item_code": self.ITEM_CODE, + "from_warehouse" if qty < 0 else "to_warehouse": self.WAREHOUSE, + "rate": rate, + "qty": abs(qty), + } + return make_stock_entry(**kwargs) + + def assertStockQueue(self, se, expected_queue): + sle_name = frappe.db.get_value("Stock Ledger Entry", {"voucher_no": se.name, "is_cancelled": 0, "voucher_type": "Stock Entry"}) + sle = frappe.get_doc("Stock Ledger Entry", sle_name) + + stock_queue = json.loads(sle.stock_queue) + + total_qty, total_value = LIFOValuation(stock_queue).get_total_stock_and_value() + self.assertEqual(sle.qty_after_transaction, total_qty) + self.assertEqual(sle.stock_value, total_value) + + if total_qty > 0: + self.assertEqual(stock_queue, expected_queue) + + + def test_lifo_values(self): + + in1 = self._make_stock_entry(1, 1) + self.assertStockQueue(in1, [[1, 1]]) + + in2 = self._make_stock_entry(2, 2) + self.assertStockQueue(in2, [[1, 1], [2, 2]]) + + out1 = self._make_stock_entry(-1) + self.assertStockQueue(out1, [[1, 1], [1, 2]]) + + in3 = self._make_stock_entry(3, 3) + self.assertStockQueue(in3, [[1, 1], [1, 2], [3, 3]]) + + out2 = self._make_stock_entry(-4) + self.assertStockQueue(out2, [[1, 1]]) + + in4 = self._make_stock_entry(4, 4) + self.assertStockQueue(in4, [[1, 1], [4,4]]) + + out3 = self._make_stock_entry(-5) + self.assertStockQueue(out3, []) + + in5 = self._make_stock_entry(5, 5) + self.assertStockQueue(in5, [[5, 5]]) + + out5 = self._make_stock_entry(-5) + self.assertStockQueue(out5, []) diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 3c70b41eda7..f85a04f9447 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -9,6 +9,7 @@ from frappe import _ from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime import erpnext +from erpnext.stock.valuation import FIFOValuation, LIFOValuation class InvalidWarehouseCompany(frappe.ValidationError): pass @@ -103,7 +104,7 @@ def get_stock_balance(item_code, warehouse, posting_date=None, posting_time=None serial_nos = get_serial_nos_data_after_transactions(args) return ((last_entry.qty_after_transaction, last_entry.valuation_rate, serial_nos) - if last_entry else (0.0, 0.0, 0.0)) + if last_entry else (0.0, 0.0, None)) else: return (last_entry.qty_after_transaction, last_entry.valuation_rate) if last_entry else (0.0, 0.0) else: @@ -176,13 +177,7 @@ def get_latest_stock_balance(): def get_bin(item_code, warehouse): bin = frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}) if not bin: - bin_obj = frappe.get_doc({ - "doctype": "Bin", - "item_code": item_code, - "warehouse": warehouse, - }) - bin_obj.flags.ignore_permissions = 1 - bin_obj.insert() + bin_obj = _create_bin(item_code, warehouse) else: bin_obj = frappe.get_doc('Bin', bin, for_update=True) bin_obj.flags.ignore_permissions = True @@ -192,53 +187,65 @@ def get_or_make_bin(item_code: str , warehouse: str) -> 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_obj = _create_bin(item_code, warehouse) bin_record = bin_obj.name - return bin_record -def update_bin(args, allow_negative_stock=False, via_landed_cost_voucher=False): - """WARNING: This function is deprecated. Inline this function instead of using it.""" - 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_name = get_or_make_bin(args.get("item_code"), args.get("warehouse")) - update_stock(bin_name, 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"))) +def _create_bin(item_code, warehouse): + """Create a bin and take care of concurrent inserts.""" + + bin_creation_savepoint = "create_bin" + try: + frappe.db.savepoint(bin_creation_savepoint) + bin_obj = frappe.get_doc(doctype="Bin", item_code=item_code, warehouse=warehouse) + bin_obj.flags.ignore_permissions = 1 + bin_obj.insert() + except frappe.UniqueValidationError: + frappe.db.rollback(save_point=bin_creation_savepoint) # preserve transaction in postgres + bin_obj = frappe.get_last_doc("Bin", {"item_code": item_code, "warehouse": warehouse}) + + return bin_obj @frappe.whitelist() def get_incoming_rate(args, raise_error_if_no_rate=True): """Get Incoming Rate based on valuation method""" - from erpnext.stock.stock_ledger import get_previous_sle, get_valuation_rate + from erpnext.stock.stock_ledger import ( + get_batch_incoming_rate, + get_previous_sle, + get_valuation_rate, + ) if isinstance(args, str): args = json.loads(args) - in_rate = 0 + voucher_no = args.get('voucher_no') or args.get('name') + + in_rate = None if (args.get("serial_no") or "").strip(): in_rate = get_avg_purchase_rate(args.get("serial_no")) + elif args.get("batch_no") and \ + frappe.db.get_value("Batch", args.get("batch_no"), "use_batchwise_valuation", cache=True): + in_rate = get_batch_incoming_rate( + item_code=args.get('item_code'), + warehouse=args.get('warehouse'), + batch_no=args.get("batch_no"), + posting_date=args.get("posting_date"), + posting_time=args.get("posting_time"), + ) else: valuation_method = get_valuation_method(args.get("item_code")) previous_sle = get_previous_sle(args) - if valuation_method == 'FIFO': + if valuation_method in ('FIFO', 'LIFO'): if previous_sle: previous_stock_queue = json.loads(previous_sle.get('stock_queue', '[]') or '[]') - in_rate = get_fifo_rate(previous_stock_queue, args.get("qty") or 0) if previous_stock_queue else 0 + in_rate = _get_fifo_lifo_rate(previous_stock_queue, args.get("qty") or 0, valuation_method) if previous_stock_queue else 0 elif valuation_method == 'Moving Average': in_rate = previous_sle.get('valuation_rate') or 0 - if not in_rate: - voucher_no = args.get('voucher_no') or args.get('name') + if in_rate is None: in_rate = get_valuation_rate(args.get('item_code'), args.get('warehouse'), args.get('voucher_type'), voucher_no, args.get('allow_zero_valuation'), currency=erpnext.get_company_currency(args.get('company')), company=args.get('company'), - raise_error_if_no_rate=raise_error_if_no_rate) + raise_error_if_no_rate=raise_error_if_no_rate, batch_no=args.get("batch_no")) return flt(in_rate) @@ -254,34 +261,30 @@ def get_valuation_method(item_code): """get valuation method from item or default""" val_method = frappe.db.get_value('Item', item_code, 'valuation_method', cache=True) if not val_method: - val_method = frappe.db.get_value("Stock Settings", None, "valuation_method") or "FIFO" + val_method = frappe.db.get_value("Stock Settings", None, "valuation_method", cache=True) or "FIFO" return val_method def get_fifo_rate(previous_stock_queue, qty): """get FIFO (average) Rate from Queue""" - if flt(qty) >= 0: - total = sum(f[0] for f in previous_stock_queue) - return sum(flt(f[0]) * flt(f[1]) for f in previous_stock_queue) / flt(total) if total else 0.0 - else: - available_qty_for_outgoing, outgoing_cost = 0, 0 - qty_to_pop = abs(flt(qty)) - while qty_to_pop and previous_stock_queue: - batch = previous_stock_queue[0] - if 0 < batch[0] <= qty_to_pop: - # if batch qty > 0 - # not enough or exactly same qty in current batch, clear batch - available_qty_for_outgoing += flt(batch[0]) - outgoing_cost += flt(batch[0]) * flt(batch[1]) - qty_to_pop -= batch[0] - previous_stock_queue.pop(0) - else: - # all from current batch - available_qty_for_outgoing += flt(qty_to_pop) - outgoing_cost += flt(qty_to_pop) * flt(batch[1]) - batch[0] -= qty_to_pop - qty_to_pop = 0 + return _get_fifo_lifo_rate(previous_stock_queue, qty, "FIFO") - return outgoing_cost / available_qty_for_outgoing +def get_lifo_rate(previous_stock_queue, qty): + """get LIFO (average) Rate from Queue""" + return _get_fifo_lifo_rate(previous_stock_queue, qty, "LIFO") + + +def _get_fifo_lifo_rate(previous_stock_queue, qty, method): + ValuationKlass = LIFOValuation if method == "LIFO" else FIFOValuation + + stock_queue = ValuationKlass(previous_stock_queue) + if flt(qty) >= 0: + total_qty, total_value = stock_queue.get_total_stock_and_value() + return total_value / total_qty if total_qty else 0.0 + else: + popped_bins = stock_queue.remove_stock(abs(flt(qty))) + + total_qty, total_value = ValuationKlass(popped_bins).get_total_stock_and_value() + return total_value / total_qty if total_qty else 0.0 def get_valid_serial_nos(sr_nos, qty=0, item_code=''): """split serial nos, validate and return list of valid serial nos""" @@ -419,6 +422,19 @@ def is_reposting_item_valuation_in_progress(): if reposting_in_progress: frappe.msgprint(_("Item valuation reposting in progress. Report might show incorrect item valuation."), alert=1) + +def calculate_mapped_packed_items_return(return_doc): + parent_items = set([item.parent_item for item in return_doc.packed_items]) + against_doc = frappe.get_doc(return_doc.doctype, return_doc.return_against) + + for original_bundle, returned_bundle in zip(against_doc.items, return_doc.items): + if original_bundle.item_code in parent_items: + for returned_packed_item, original_packed_item in zip(return_doc.packed_items, against_doc.packed_items): + if returned_packed_item.parent_item == original_bundle.item_code: + returned_packed_item.parent_detail_docname = returned_bundle.name + returned_packed_item.qty = (original_packed_item.qty / original_bundle.qty) * returned_bundle.qty + + def check_pending_reposting(posting_date: str, throw_error: bool = True) -> bool: """Check if there are pending reposting job till the specified posting date.""" diff --git a/erpnext/stock/valuation.py b/erpnext/stock/valuation.py index 45c50830995..e2bd1ad4dfe 100644 --- a/erpnext/stock/valuation.py +++ b/erpnext/stock/valuation.py @@ -1,15 +1,54 @@ +from abc import ABC, abstractmethod, abstractproperty from typing import Callable, List, NewType, Optional, Tuple from frappe.utils import flt -FifoBin = NewType("FifoBin", List[float]) +StockBin = NewType("StockBin", List[float]) # [[qty, rate], ...] # Indexes of values inside FIFO bin 2-tuple QTY = 0 RATE = 1 -class FIFOValuation: +class BinWiseValuation(ABC): + + @abstractmethod + def add_stock(self, qty: float, rate: float) -> None: + pass + + @abstractmethod + def remove_stock( + self, qty: float, outgoing_rate: float = 0.0, rate_generator: Callable[[], float] = None + ) -> List[StockBin]: + pass + + @abstractproperty + def state(self) -> List[StockBin]: + pass + + def get_total_stock_and_value(self) -> Tuple[float, float]: + total_qty = 0.0 + total_value = 0.0 + + for qty, rate in self.state: + total_qty += flt(qty) + total_value += flt(qty) * flt(rate) + + return round_off_if_near_zero(total_qty), round_off_if_near_zero(total_value) + + def __repr__(self): + return str(self.state) + + def __iter__(self): + return iter(self.state) + + def __eq__(self, other): + if isinstance(other, list): + return self.state == other + return type(self) == type(other) and self.state == other.state + + +class FIFOValuation(BinWiseValuation): """Valuation method where a queue of all the incoming stock is maintained. New stock is added at end of the queue. @@ -24,34 +63,14 @@ class FIFOValuation: # ref: https://docs.python.org/3/reference/datamodel.html#slots __slots__ = ["queue",] - def __init__(self, state: Optional[List[FifoBin]]): - self.queue: List[FifoBin] = state if state is not None else [] + def __init__(self, state: Optional[List[StockBin]]): + self.queue: List[StockBin] = state if state is not None else [] - def __repr__(self): - return str(self.queue) - - def __iter__(self): - return iter(self.queue) - - def __eq__(self, other): - if isinstance(other, list): - return self.queue == other - return self.queue == other.queue - - def get_state(self) -> List[FifoBin]: + @property + def state(self) -> List[StockBin]: """Get current state of queue.""" return self.queue - def get_total_stock_and_value(self) -> Tuple[float, float]: - total_qty = 0.0 - total_value = 0.0 - - for qty, rate in self.queue: - total_qty += flt(qty) - total_value += flt(qty) * flt(rate) - - return _round_off_if_near_zero(total_qty), _round_off_if_near_zero(total_value) - def add_stock(self, qty: float, rate: float) -> None: """Update fifo queue with new stock. @@ -78,7 +97,7 @@ class FIFOValuation: def remove_stock( self, qty: float, outgoing_rate: float = 0.0, rate_generator: Callable[[], float] = None - ) -> List[FifoBin]: + ) -> List[StockBin]: """Remove stock from the queue and return popped bins. args: @@ -117,7 +136,7 @@ class FIFOValuation: fifo_bin = self.queue[index] if qty >= fifo_bin[QTY]: # consume current bin - qty = _round_off_if_near_zero(qty - fifo_bin[QTY]) + qty = round_off_if_near_zero(qty - fifo_bin[QTY]) to_consume = self.queue.pop(index) consumed_bins.append(list(to_consume)) @@ -129,14 +148,109 @@ class FIFOValuation: break else: # qty found in current bin consume it and exit - fifo_bin[QTY] = _round_off_if_near_zero(fifo_bin[QTY] - qty) + fifo_bin[QTY] = round_off_if_near_zero(fifo_bin[QTY] - qty) consumed_bins.append([qty, fifo_bin[RATE]]) qty = 0 return consumed_bins -def _round_off_if_near_zero(number: float, precision: int = 7) -> float: +class LIFOValuation(BinWiseValuation): + """Valuation method where a *stack* of all the incoming stock is maintained. + + New stock is added at top of the stack. + Qty consumption happens on Last In First Out basis. + + Stack is implemented using "bins" of [qty, rate]. + + ref: https://en.wikipedia.org/wiki/FIFO_and_LIFO_accounting + Implementation detail: appends and pops both at end of list. + """ + + # specifying the attributes to save resources + # ref: https://docs.python.org/3/reference/datamodel.html#slots + __slots__ = ["stack",] + + def __init__(self, state: Optional[List[StockBin]]): + self.stack: List[StockBin] = state if state is not None else [] + + @property + def state(self) -> List[StockBin]: + """Get current state of stack.""" + return self.stack + + def add_stock(self, qty: float, rate: float) -> None: + """Update lifo stack with new stock. + + args: + qty: new quantity to add + rate: incoming rate of new quantity. + + Behaviour of this is same as FIFO valuation. + """ + if not len(self.stack): + self.stack.append([0, 0]) + + # last row has the same rate, merge new bin. + if self.stack[-1][RATE] == rate: + self.stack[-1][QTY] += qty + else: + # Item has a positive balance qty, add new entry + if self.stack[-1][QTY] > 0: + self.stack.append([qty, rate]) + else: # negative balance qty + qty = self.stack[-1][QTY] + qty + if qty > 0: # new balance qty is positive + self.stack[-1] = [qty, rate] + else: # new balance qty is still negative, maintain same rate + self.stack[-1][QTY] = qty + + + def remove_stock( + self, qty: float, outgoing_rate: float = 0.0, rate_generator: Callable[[], float] = None + ) -> List[StockBin]: + """Remove stock from the stack and return popped bins. + + args: + qty: quantity to remove + rate: outgoing rate - ignored. Kept for backwards compatibility. + rate_generator: function to be called if stack is not found and rate is required. + """ + if not rate_generator: + rate_generator = lambda : 0.0 # noqa + + consumed_bins = [] + while qty: + if not len(self.stack): + # rely on rate generator. + self.stack.append([0, rate_generator()]) + + # start at the end. + index = -1 + + stock_bin = self.stack[index] + if qty >= stock_bin[QTY]: + # consume current bin + qty = round_off_if_near_zero(qty - stock_bin[QTY]) + to_consume = self.stack.pop(index) + consumed_bins.append(list(to_consume)) + + if not self.stack and qty: + # stock finished, qty still remains to be withdrawn + # negative stock, keep in as a negative bin + self.stack.append([-qty, outgoing_rate or stock_bin[RATE]]) + consumed_bins.append([qty, outgoing_rate or stock_bin[RATE]]) + break + else: + # qty found in current bin consume it and exit + stock_bin[QTY] = round_off_if_near_zero(stock_bin[QTY] - qty) + consumed_bins.append([qty, stock_bin[RATE]]) + qty = 0 + + return consumed_bins + + +def round_off_if_near_zero(number: float, precision: int = 7) -> float: """Rounds off the number to zero only if number is close to zero for decimal specified in precision. Precision defaults to 7. """ diff --git a/erpnext/support/doctype/service_level_agreement/service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/service_level_agreement.py index de8f5067878..526b6aa249e 100644 --- a/erpnext/support/doctype/service_level_agreement/service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/service_level_agreement.py @@ -701,7 +701,7 @@ def on_communication_update(doc, status): update_response_and_resolution_metrics(parent, for_resolution) update_agreement_status(parent, for_resolution) - parent.save() + parent.save(ignore_permissions=True) def reset_expected_response_and_resolution(doc): diff --git a/erpnext/templates/generators/item/item.html b/erpnext/templates/generators/item/item.html index 17f6880293c..4070d40d47e 100644 --- a/erpnext/templates/generators/item/item.html +++ b/erpnext/templates/generators/item/item.html @@ -1,4 +1,5 @@ {% extends "templates/web.html" %} +{% from "erpnext/templates/includes/macros.html" import recommended_item_row %} {% block title %} {{ title }} {% endblock %} @@ -9,25 +10,70 @@ {% endblock %} {% block page_content %} -- {{ _("Item Code") }}: - {{ doc.name }} -
-{% if has_variants %} - - {% include "templates/generators/item/item_configure.html" %} -{% else %} - - {% include "templates/generators/item/item_add_to_cart.html" %} -{% endif %} - -+ + {{ _(doc.item_group) }} + + + {{ _("Item Code") }}: + + {{ doc.item_code }} +
+ {% if has_variants %} + + {% include "templates/generators/item/item_configure.html" %} + {% else %} + + {% include "templates/generators/item/item_add_to_cart.html" %} + {% endif %} + +| {{ d.label }} | -{{ d.description }} | +{{ d.label }} | +{{ d.description }} |