From a50808a077b8d6475ff360b611cd5f0a8cb37d65 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 18 Jan 2024 18:03:16 +0530 Subject: [PATCH 1/5] refactor: delete transactions in background --- erpnext/setup/doctype/company/company.js | 66 ++++++++++++++---------- erpnext/setup/doctype/company/company.py | 34 +++++++++++- 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js index 1bd469b956..340a917ffa 100644 --- a/erpnext/setup/doctype/company/company.js +++ b/erpnext/setup/doctype/company/company.js @@ -140,38 +140,48 @@ frappe.ui.form.on("Company", { }, delete_company_transactions: function(frm) { - frappe.verify_password(function() { - var d = frappe.prompt({ - fieldtype:"Data", - fieldname: "company_name", - label: __("Please enter the company name to confirm"), - reqd: 1, - description: __("Please make sure you really want to delete all the transactions for this company. Your master data will remain as it is. This action cannot be undone.") + frappe.call({ + method: "erpnext.setup.doctype.company.company.is_deletion_job_running", + args: { + company: frm.doc.name }, - function(data) { - if(data.company_name !== frm.doc.name) { - frappe.msgprint(__("Company name not same")); - return; + freeze: true, + callback: function(r) { + if(!r.exc) { + frappe.verify_password(function() { + var d = frappe.prompt({ + fieldtype:"Data", + fieldname: "company_name", + label: __("Please enter the company name to confirm"), + reqd: 1, + description: __("Please make sure you really want to delete all the transactions for this company. Your master data will remain as it is. This action cannot be undone.") + }, + function(data) { + if(data.company_name !== frm.doc.name) { + frappe.msgprint(__("Company name not same")); + return; + } + frappe.call({ + method: "erpnext.setup.doctype.company.company.create_transaction_deletion_request", + args: { + company: data.company_name + }, + freeze: true, + callback: function(r, rt) { }, + onerror: function() { + frappe.msgprint(__("Wrong Password")); + } + }); + }, + __("Delete all the Transactions for this Company"), __("Delete") + ); + d.get_primary_btn().addClass("btn-danger"); + }); } - frappe.call({ - method: "erpnext.setup.doctype.company.company.create_transaction_deletion_request", - args: { - company: data.company_name - }, - freeze: true, - callback: function(r, rt) { - if(!r.exc) - frappe.msgprint(__("Successfully deleted all transactions related to this company!")); - }, - onerror: function() { - frappe.msgprint(__("Wrong Password")); - } - }); + }, - __("Delete all the Transactions for this Company"), __("Delete") - ); - d.get_primary_btn().addClass("btn-danger"); }); + } }); diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index ec953b885e..68a3854b0d 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -11,7 +11,8 @@ 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.desk.page.setup_wizard.setup_wizard import make_records -from frappe.utils import cint, formatdate, get_timestamp, today +from frappe.utils import cint, formatdate, get_link_to_form, get_timestamp, today +from frappe.utils.background_jobs import get_job, is_job_enqueued from frappe.utils.nestedset import NestedSet, rebuild_tree from erpnext.accounts.doctype.account.account import get_account_currency @@ -900,8 +901,37 @@ def get_default_company_address(name, sort_key="is_primary_address", existing_ad return None +def generate_id_for_deletion_job(company): + return "delete_company_transactions_" + company + + +@frappe.whitelist() +def is_deletion_job_running(company): + job_id = generate_id_for_deletion_job(company) + job_name = get_job(job_id).get_id() # job name will have site prefix + if is_job_enqueued(job_id): + frappe.throw( + _("A Transaction Deletion Job: {0} is already running for {1}").format( + frappe.bold(get_link_to_form("RQ Job", job_name)), frappe.bold(company) + ) + ) + + @frappe.whitelist() def create_transaction_deletion_request(company): + is_deletion_job_running(company) + job_id = generate_id_for_deletion_job(company) + tdr = frappe.get_doc({"doctype": "Transaction Deletion Record", "company": company}) tdr.insert() - tdr.submit() + + frappe.enqueue( + "frappe.utils.background_jobs.run_doc_method", + doctype=tdr.doctype, + name=tdr.name, + doc_method="submit", + job_id=job_id, + queue="long", + enqueue_after_commit=True, + ) + frappe.msgprint(_("A Transaction Deletion Job is triggered for {0}").format(frappe.bold(company))) From b2d9380596dd8ca134777148337ef039f10cc2ca Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Fri, 19 Jan 2024 17:08:02 +0530 Subject: [PATCH 2/5] fix: party field in pdf html --- .../accounts_receivable/accounts_receivable.html | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html index ed3b991559..7d8d33c46b 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.html +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.html @@ -10,10 +10,8 @@

{%= __(report.report_name) %}

- {% if (filters.customer_name) { %} - {%= filters.customer_name %} - {% } else { %} - {%= filters.customer || filters.supplier %} + {% if (filters.party) { %} + {%= __(filters.party) %} {% } %}

@@ -141,7 +139,7 @@ {%= __("Reference") %} {% } %} {% if(!filters.show_future_payments) { %} - {%= (filters.customer || filters.supplier) ? __("Remarks"): __("Party") %} + {%= (filters.party) ? __("Remarks"): __("Party") %} {% } %} {%= __("Invoiced Amount") %} {% if(!filters.show_future_payments) { %} @@ -158,7 +156,7 @@ {%= __("Remaining Balance") %} {% } %} {% } else { %} - {%= (filters.customer || filters.supplier) ? __("Remarks"): __("Party") %} + {%= (filters.party) ? __("Remarks"): __("Party") %} {%= __("Total Invoiced Amount") %} {%= __("Total Paid Amount") %} {%= report.report_name === "Accounts Receivable Summary" ? __('Credit Note Amount') : __('Debit Note Amount') %} @@ -187,7 +185,7 @@ {% if(!filters.show_future_payments) { %} - {% if(!(filters.customer || filters.supplier)) { %} + {% if(!(filters.party)) { %} {%= data[i]["party"] %} {% if(data[i]["customer_name"] && data[i]["customer_name"] != data[i]["party"]) { %}
{%= data[i]["customer_name"] %} @@ -260,7 +258,7 @@ {% if(data[i]["party"]|| " ") { %} {% if(!data[i]["is_total_row"]) { %} - {% if(!(filters.customer || filters.supplier)) { %} + {% if(!(filters.party)) { %} {%= data[i]["party"] %} {% if(data[i]["customer_name"] && data[i]["customer_name"] != data[i]["party"]) { %}
{%= data[i]["customer_name"] %} From ebc8230d4564385b151e19f21d57172afe803108 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 21 Jan 2024 18:05:20 +0530 Subject: [PATCH 3/5] fix: key error during reposting --- erpnext/stock/stock_ledger.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index a6206ac8dc..0370666263 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -439,7 +439,7 @@ def get_distinct_item_warehouse(args=None, doc=None, reposting_data=None): reposting_data = get_reposting_data(doc.reposting_data_file) if reposting_data and reposting_data.distinct_item_and_warehouse: - return reposting_data.distinct_item_and_warehouse + return parse_distinct_items_and_warehouses(reposting_data.distinct_item_and_warehouse) distinct_item_warehouses = {} @@ -457,6 +457,16 @@ def get_distinct_item_warehouse(args=None, doc=None, reposting_data=None): return distinct_item_warehouses +def parse_distinct_items_and_warehouses(distinct_items_and_warehouses): + new_dict = frappe._dict({}) + + # convert string keys to tuple + for k, v in distinct_items_and_warehouses.items(): + new_dict[frappe.safe_eval(k)] = frappe._dict(v) + + return new_dict + + def get_affected_transactions(doc, reposting_data=None) -> Set[Tuple[str, str]]: if not reposting_data and doc and doc.reposting_data_file: reposting_data = get_reposting_data(doc.reposting_data_file) From b4393bc03d68769f57678bb56a09baf7b4ec3dc0 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 21 Jan 2024 19:47:53 +0530 Subject: [PATCH 4/5] fix: added button to make serial / batch from Purchase Invoice --- .../purchase_invoice_item/purchase_invoice_item.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index 9cf4e4fd7c..26984d96ef 100644 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -64,6 +64,7 @@ "warehouse", "from_warehouse", "quality_inspection", + "add_serial_batch_bundle", "serial_and_batch_bundle", "serial_no", "col_br_wh", @@ -913,12 +914,18 @@ "fieldtype": "Link", "label": "WIP Composite Asset", "options": "Asset" + }, + { + "depends_on": "eval:parent.update_stock === 1", + "fieldname": "add_serial_batch_bundle", + "fieldtype": "Button", + "label": "Add Serial / Batch No" } ], "idx": 1, "istable": 1, "links": [], - "modified": "2023-12-25 22:00:28.043555", + "modified": "2024-01-21 19:46:25.537861", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Item", From 63ffce58cce6c68c210572287024da9ca414aca9 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 21 Jan 2024 20:59:38 +0530 Subject: [PATCH 5/5] test: fixed test --- erpnext/manufacturing/doctype/work_order/test_work_order.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index aa5db57fa8..f6e9a07063 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -998,12 +998,6 @@ class TestWorkOrder(FrappeTestCase): make_job_card(wo_order.name, operations) job_card = frappe.db.get_value("Job Card", {"work_order": wo_order.name, "docstatus": 0}, "name") - update_job_card(job_card, 10, 2) - - stock_entry = frappe.get_doc(make_stock_entry(wo_order.name, "Manufacture", 10)) - for row in stock_entry.items: - if row.is_scrap_item: - self.assertEqual(row.qty, 2) def test_close_work_order(self): items = [