From a378619c9a4dd94bf5fcc59831342c193251e68e Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Wed, 23 Nov 2022 17:52:12 +0530 Subject: [PATCH 01/14] fix(pos): partial return amount update Signed-off-by: Sabu Siyad --- .../public/js/controllers/taxes_and_totals.js | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 4c3e9dcf0a7..ebb7120e91c 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -47,29 +47,36 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { await this.calculate_shipping_charges(); - // Advance calculation applicable to Sales /Purchase Invoice - if(in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype) - && this.frm.doc.docstatus < 2 && !this.frm.doc.is_return) { + // Advance calculation applicable to Sales/Purchase Invoice + if ( + in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype) + && this.frm.doc.docstatus < 2 + && !this.frm.doc.is_return + ) { this.calculate_total_advance(update_paid_amount); } - if (in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) && this.frm.doc.is_pos && - this.frm.doc.is_return) { - if (this.frm.doc.doctype == "Sales Invoice") { - this.set_total_amount_to_default_mop(); - } + if ( + in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) + && this.frm.doc.is_pos + && this.frm.doc.is_return + ) { + this.set_total_amount_to_default_mop(); this.calculate_paid_amount(); } // Sales person's commission - if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) { + if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) { this.calculate_commission(); this.calculate_contribution(); } // Update paid amount on return/debit note creation - if(this.frm.doc.doctype === "Purchase Invoice" && this.frm.doc.is_return - && (this.frm.doc.grand_total > this.frm.doc.paid_amount)) { + if ( + this.frm.doc.doctype === "Purchase Invoice" + && this.frm.doc.is_return + && (this.frm.doc.grand_total > this.frm.doc.paid_amount) + ) { this.frm.doc.paid_amount = flt(this.frm.doc.grand_total, precision("grand_total")); } @@ -775,21 +782,30 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { let grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total; let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total; - if(this.frm.doc.party_account_currency == this.frm.doc.currency) { - var total_amount_to_pay = flt((grand_total - this.frm.doc.total_advance - - this.frm.doc.write_off_amount), precision("grand_total")); + if (this.frm.doc.party_account_currency == this.frm.doc.currency) { + var total_amount_to_pay = flt( + grand_total - this.frm.doc.total_advance - this.frm.doc.write_off_amount, + precision("grand_total") + ); } else { var total_amount_to_pay = flt( - (flt(base_grand_total, precision("base_grand_total")) - - this.frm.doc.total_advance - this.frm.doc.base_write_off_amount), + ( + flt( + base_grand_total, + precision("base_grand_total") + ) + - this.frm.doc.total_advance - this.frm.doc.base_write_off_amount + ), precision("base_grand_total") ); } + this.frm.doc.payments.find(pay => { if (pay.default) { pay.amount = total_amount_to_pay; } }); + this.frm.refresh_fields(); } From 4bd9289d7def384783944f91644cbb50e5c29e1b Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 29 Nov 2022 19:21:48 +0530 Subject: [PATCH 02/14] fix(UX): Alert on change of item rate in Stock Entry --- erpnext/stock/doctype/stock_entry/stock_entry.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index b1167351c48..83c280f72ee 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -659,6 +659,13 @@ class StockEntry(StockController): if d.allow_zero_valuation_rate: d.basic_rate = 0.0 + frappe.msgprint( + _( + "Row {0}: Item rate has been updated to zero as Allow Zero Valuation Rate is checked for item {1}" + ).format(d.idx, d.item_code), + alert=1, + ) + elif d.is_finished_item: if self.purpose == "Manufacture": d.basic_rate = self.get_basic_rate_for_manufactured_item( From ca0485a503aacb7d96700a060bd2367a9d03366a Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Wed, 12 Jan 2022 10:03:36 +0530 Subject: [PATCH 03/14] fix: add company filter in RFQ Items --- .../doctype/request_for_quotation/request_for_quotation.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js index 31a4837d463..98c7dc9bd32 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -22,6 +22,13 @@ frappe.ui.form.on("Request for Quotation",{ } }; } + + frm.set_query('warehouse', 'items', () => ({ + filters: { + company: frm.doc.company, + is_group: 0 + } + })); }, onload: function(frm) { From c5edbe2e2fb8e3c74d71ad91b4200d900d2f79c8 Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Wed, 30 Nov 2022 17:12:06 +0530 Subject: [PATCH 04/14] fix(lint): trailing whitespace Signed-off-by: Sabu Siyad --- erpnext/public/js/controllers/taxes_and_totals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index ebb7120e91c..74810005ed9 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -58,7 +58,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { if ( in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) - && this.frm.doc.is_pos + && this.frm.doc.s_pos && this.frm.doc.is_return ) { this.set_total_amount_to_default_mop(); From 64e5a79a91684c934a0820c843f9296d60bcf36c Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 30 Nov 2022 19:35:30 +0530 Subject: [PATCH 05/14] fix: Error on making stock entry from material request --- erpnext/stock/doctype/material_request/material_request.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/material_request/material_request.py b/erpnext/stock/doctype/material_request/material_request.py index 04aee423647..afad7511be6 100644 --- a/erpnext/stock/doctype/material_request/material_request.py +++ b/erpnext/stock/doctype/material_request/material_request.py @@ -596,7 +596,9 @@ def make_stock_entry(source_name, target_doc=None): if source.material_request_type == "Customer Provided": target.purpose = "Material Receipt" - target.set_missing_values() + target.set_transfer_qty() + target.set_actual_qty() + target.calculate_rate_and_amount(raise_error_if_no_rate=False) target.set_stock_entry_type() target.set_job_card_data() From bfb81ef56f6af482b31d9331bfd13d800dfccb01 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 30 Nov 2022 20:53:41 +0530 Subject: [PATCH 06/14] fix: Due date for month end payment term --- erpnext/controllers/accounts_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index b7a80c10192..5a051e3bafc 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -2311,7 +2311,7 @@ def get_due_date(term, posting_date=None, bill_date=None): elif term.due_date_based_on == "Day(s) after the end of the invoice month": due_date = add_days(get_last_day(date), term.credit_days) elif term.due_date_based_on == "Month(s) after the end of the invoice month": - due_date = add_months(get_last_day(date), term.credit_months) + due_date = get_last_day(add_months(date, term.credit_months)) return due_date @@ -2323,7 +2323,7 @@ def get_discount_date(term, posting_date=None, bill_date=None): elif term.discount_validity_based_on == "Day(s) after the end of the invoice month": discount_validity = add_days(get_last_day(date), term.discount_validity) elif term.discount_validity_based_on == "Month(s) after the end of the invoice month": - discount_validity = add_months(get_last_day(date), term.discount_validity) + discount_validity = get_last_day(add_months(date, term.discount_validity)) return discount_validity From 25522444b8e404af2c2ec328ac38aebf243ef92e Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Wed, 30 Nov 2022 23:25:40 +0530 Subject: [PATCH 07/14] fix: use is_last_day_of_the_month in test_scrap_asset --- erpnext/assets/doctype/asset/test_asset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 136a033b7db..feace84df4f 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -13,6 +13,7 @@ from frappe.utils import ( get_last_day, getdate, nowdate, + is_last_day_of_the_month, ) from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice @@ -264,7 +265,7 @@ class TestAsset(AssetSetup): asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation, asset.precision("gross_purchase_amount"), ) - this_month_depr_amount = 9000.0 if get_last_day(date) == date else 0 + this_month_depr_amount = 9000.0 if is_last_day_of_the_month(date) else 0 self.assertEquals(accumulated_depr_amount, 18000.0 + this_month_depr_amount) From 827ad01d4fe024282cd2afce9c5f09cdfa11d89a Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Wed, 30 Nov 2022 23:56:37 +0530 Subject: [PATCH 08/14] chore: style --- erpnext/assets/doctype/asset/test_asset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index feace84df4f..2bec27371b5 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -12,8 +12,8 @@ from frappe.utils import ( get_first_day, get_last_day, getdate, - nowdate, is_last_day_of_the_month, + nowdate, ) from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice From 4856e750f96f3e135f2a9efffb309d1b4d72502f Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 1 Dec 2022 18:08:32 +0530 Subject: [PATCH 09/14] fix: type error on Sales Pipeline Analytics --- .../report/sales_pipeline_analytics/sales_pipeline_analytics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py b/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py index d23a22ac46d..dea3f2dd36d 100644 --- a/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py +++ b/erpnext/crm/report/sales_pipeline_analytics/sales_pipeline_analytics.py @@ -217,7 +217,7 @@ class SalesPipelineAnalytics(object): def check_for_assigned_to(self, period, value, count_or_amount, assigned_to, info): if self.filters.get("assigned_to"): - for data in json.loads(info.get("opportunity_owner")): + for data in json.loads(info.get("opportunity_owner") or "[]"): if data == self.filters.get("assigned_to"): self.set_formatted_data(period, data, count_or_amount, assigned_to) else: From 3ce8386ca3d29b42e16ab6345e6659909ab34aaa Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Thu, 1 Dec 2022 19:44:49 +0530 Subject: [PATCH 10/14] refactor: remove `balance` from `Warehouse Tree` --- erpnext/stock/doctype/warehouse/warehouse.py | 59 +------------------ .../stock/doctype/warehouse/warehouse_tree.js | 7 --- 2 files changed, 2 insertions(+), 64 deletions(-) diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 6e06d236173..430a8d17e01 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -2,12 +2,10 @@ # License: GNU General Public License v3. See license.txt -from collections import defaultdict - import frappe from frappe import _, throw from frappe.contacts.address_and_contact import load_address_and_contact -from frappe.utils import cint, flt +from frappe.utils import cint from frappe.utils.nestedset import NestedSet from pypika.terms import ExistsCriterion @@ -166,60 +164,7 @@ def get_children(doctype, parent=None, company=None, is_root=False): ["company", "in", (company, None, "")], ] - warehouses = frappe.get_list(doctype, fields=fields, filters=filters, order_by="name") - - company_currency = "" - if company: - company_currency = frappe.get_cached_value("Company", company, "default_currency") - - warehouse_wise_value = get_warehouse_wise_stock_value(company) - - # return warehouses - for wh in warehouses: - wh["balance"] = warehouse_wise_value.get(wh.value) - if company_currency: - wh["company_currency"] = company_currency - return warehouses - - -def get_warehouse_wise_stock_value(company): - warehouses = frappe.get_all( - "Warehouse", fields=["name", "parent_warehouse"], filters={"company": company} - ) - parent_warehouse = {d.name: d.parent_warehouse for d in warehouses} - - filters = {"warehouse": ("in", [data.name for data in warehouses])} - bin_data = frappe.get_all( - "Bin", - fields=["sum(stock_value) as stock_value", "warehouse"], - filters=filters, - group_by="warehouse", - ) - - warehouse_wise_stock_value = defaultdict(float) - for row in bin_data: - if not row.stock_value: - continue - - warehouse_wise_stock_value[row.warehouse] = row.stock_value - update_value_in_parent_warehouse( - warehouse_wise_stock_value, parent_warehouse, row.warehouse, row.stock_value - ) - - return warehouse_wise_stock_value - - -def update_value_in_parent_warehouse( - warehouse_wise_stock_value, parent_warehouse_dict, warehouse, stock_value -): - parent_warehouse = parent_warehouse_dict.get(warehouse) - if not parent_warehouse: - return - - warehouse_wise_stock_value[parent_warehouse] += flt(stock_value) - update_value_in_parent_warehouse( - warehouse_wise_stock_value, parent_warehouse_dict, parent_warehouse, stock_value - ) + return frappe.get_list(doctype, fields=fields, filters=filters, order_by="name") @frappe.whitelist() diff --git a/erpnext/stock/doctype/warehouse/warehouse_tree.js b/erpnext/stock/doctype/warehouse/warehouse_tree.js index e9e14c72466..eb635e6757d 100644 --- a/erpnext/stock/doctype/warehouse/warehouse_tree.js +++ b/erpnext/stock/doctype/warehouse/warehouse_tree.js @@ -17,11 +17,4 @@ frappe.treeview_settings['Warehouse'] = { description: __("Child nodes can be only created under 'Group' type nodes")} ], ignore_fields:["parent_warehouse"], - onrender: function(node) { - if (node.data && node.data.balance!==undefined) { - $('' - + format_currency((node.data.balance), node.data.company_currency) - + '').insertBefore(node.$ul); - } - } } From 5949a7ecff0020bb07de586892cc5d1dec44b904 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 1 Dec 2022 15:59:42 +0530 Subject: [PATCH 11/14] fix: default clear repost logs --- erpnext/patches.txt | 1 + .../patches/v14_0/setup_clear_repost_logs.py | 8 ++++++ erpnext/setup/install.py | 8 ++++++ .../repost_item_valuation.py | 14 +++++++++++ .../test_repost_item_valuation.py | 25 +++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 erpnext/patches/v14_0/setup_clear_repost_logs.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 166faf9c18d..0aad1d34e5f 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -318,3 +318,4 @@ erpnext.patches.v13_0.update_schedule_type_in_loans erpnext.patches.v14_0.create_accounting_dimensions_for_asset_capitalization erpnext.patches.v14_0.update_partial_tds_fields erpnext.patches.v14_0.create_incoterms_and_migrate_shipment +erpnext.patches.v14_0.setup_clear_repost_logs \ No newline at end of file diff --git a/erpnext/patches/v14_0/setup_clear_repost_logs.py b/erpnext/patches/v14_0/setup_clear_repost_logs.py new file mode 100644 index 00000000000..be9ddcab7ad --- /dev/null +++ b/erpnext/patches/v14_0/setup_clear_repost_logs.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, Frappe Technologies Pvt. Ltd. and Contributors +# License: MIT. See LICENSE + +from erpnext.setup.install import setup_log_settings + + +def execute(): + setup_log_settings() diff --git a/erpnext/setup/install.py b/erpnext/setup/install.py index d3b47f985d5..1f7dddfb95b 100644 --- a/erpnext/setup/install.py +++ b/erpnext/setup/install.py @@ -30,6 +30,7 @@ def after_install(): add_company_to_session_defaults() add_standard_navbar_items() add_app_name() + setup_log_settings() frappe.db.commit() @@ -197,3 +198,10 @@ def add_standard_navbar_items(): def add_app_name(): frappe.db.set_value("System Settings", None, "app_name", "ERPNext") + + +def setup_log_settings(): + log_settings = frappe.get_single("Log Settings") + log_settings.append("logs_to_clear", {"ref_doctype": "Repost Item Valuation", "days": 60}) + + log_settings.save(ignore_permissions=True) 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 8e914e6b807..bbed099da96 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -5,6 +5,8 @@ import frappe from frappe import _ from frappe.exceptions import QueryDeadlockError, QueryTimeoutError from frappe.model.document import Document +from frappe.query_builder import DocType, Interval +from frappe.query_builder.functions import Now from frappe.utils import cint, get_link_to_form, get_weekday, getdate, now, nowtime from frappe.utils.user import get_users_with_role from rq.timeouts import JobTimeoutException @@ -21,6 +23,18 @@ RecoverableErrors = (JobTimeoutException, QueryDeadlockError, QueryTimeoutError) class RepostItemValuation(Document): + @staticmethod + def clear_old_logs(days=None): + days = days or 90 + table = DocType("Repost Item Valuation") + frappe.db.delete( + table, + filters=( + (table.modified < (Now() - Interval(days=days))) + & (table.status.isin(["Completed", "Skipped"])) + ), + ) + def validate(self): self.set_status(write=False) self.reset_field_values() diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py index f1667757a75..d212693bed3 100644 --- a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py @@ -86,6 +86,31 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin): msg=f"Exepcted false from : {case}", ) + def test_clear_old_logs(self): + # create 10 logs + for i in range(1, 20): + frappe.get_doc( + doctype="Repost Item Valuation", + item_code="_Test Item", + warehouse="_Test Warehouse - _TC", + based_on="Item and Warehouse", + creation=add_to_date(today(), days=-i * 10), + modified=add_to_date(today(), days=-i * 10), + posting_date=nowdate(), + status="Skipped", + posting_time="00:01:00", + ).insert(ignore_permissions=True) + + logs = frappe.get_all("Repost Item Valuation", filters={"status": "Skipped"}) + self.assertTrue(len(logs) > 10) + + from erpnext.stock.doctype.repost_item_valuation.repost_item_valuation import RepostItemValuation + + RepostItemValuation.clear_old_logs(days=1) + + logs = frappe.get_all("Repost Item Valuation", filters={"status": "Skipped"}) + self.assertTrue(len(logs) == 0) + def test_create_item_wise_repost_item_valuation_entries(self): pr = make_purchase_receipt( company="_Test Company with perpetual inventory", From 2cce6f2a340ba7d052b79b79fc676fb0c575b79c Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 2 Dec 2022 10:58:32 +0530 Subject: [PATCH 12/14] fix: test case --- .../test_repost_item_valuation.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py index d212693bed3..96ac4352dcd 100644 --- a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py @@ -6,8 +6,7 @@ from unittest.mock import MagicMock, call import frappe from frappe.tests.utils import FrappeTestCase -from frappe.utils import nowdate -from frappe.utils.data import add_to_date, today +from frappe.utils import add_days, add_to_date, now, nowdate, today from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice from erpnext.accounts.utils import repost_gle_for_stock_vouchers @@ -89,18 +88,20 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin): def test_clear_old_logs(self): # create 10 logs for i in range(1, 20): - frappe.get_doc( + repost_doc = frappe.get_doc( doctype="Repost Item Valuation", item_code="_Test Item", warehouse="_Test Warehouse - _TC", based_on="Item and Warehouse", - creation=add_to_date(today(), days=-i * 10), - modified=add_to_date(today(), days=-i * 10), posting_date=nowdate(), status="Skipped", posting_time="00:01:00", ).insert(ignore_permissions=True) + repost_doc.load_from_db() + repost_doc.modified = add_days(now(), days=-i * 10) + repost_doc.db_update_all() + logs = frappe.get_all("Repost Item Valuation", filters={"status": "Skipped"}) self.assertTrue(len(logs) > 10) From 3814db02eb0d598e324ac73fcea9fca772d0fcd7 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Mon, 5 Dec 2022 16:22:59 +0530 Subject: [PATCH 13/14] fix: data import mandatory account_head, charge_type --- erpnext/accounts/doctype/sales_invoice/sales_invoice.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json index 18d2b5c9953..b38bce72168 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json @@ -921,6 +921,7 @@ "fieldtype": "Table", "hide_days": 1, "hide_seconds": 1, + "label": "Sales Taxes and Charges", "oldfieldname": "other_charges", "oldfieldtype": "Table", "options": "Sales Taxes and Charges" @@ -2133,7 +2134,7 @@ "link_fieldname": "consolidated_invoice" } ], - "modified": "2022-11-17 17:17:10.883487", + "modified": "2022-12-05 16:18:14.532114", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice", From 713330cbf69bf285b6231c0ea603d6156edfde35 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 5 Dec 2022 18:15:13 +0530 Subject: [PATCH 14/14] fix: non empty FG batch picked while completing work order --- .../doctype/work_order/test_work_order.py | 24 ++++++++++++++++++- .../stock/doctype/stock_entry/stock_entry.py | 13 +++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/test_work_order.py b/erpnext/manufacturing/doctype/work_order/test_work_order.py index 694dc79d4a9..36466ff6d7d 100644 --- a/erpnext/manufacturing/doctype/work_order/test_work_order.py +++ b/erpnext/manufacturing/doctype/work_order/test_work_order.py @@ -635,6 +635,10 @@ class TestWorkOrder(FrappeTestCase): bom.submit() bom_name = bom.name + ste1 = test_stock_entry.make_stock_entry( + item_code=rm1, target="_Test Warehouse - _TC", qty=32, basic_rate=5000.0 + ) + work_order = make_wo_order_test_record( item=fg_item, skip_transfer=True, planned_start_date=now(), qty=1 ) @@ -659,11 +663,29 @@ class TestWorkOrder(FrappeTestCase): work_order.insert() work_order.submit() self.assertEqual(work_order.has_batch_no, 1) - ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 30)) + batches = frappe.get_all("Batch", filters={"reference_name": work_order.name}) + self.assertEqual(len(batches), 3) + batches = [batch.name for batch in batches] + + ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 10)) for row in ste1.get("items"): if row.is_finished_item: self.assertEqual(row.item_code, fg_item) self.assertEqual(row.qty, 10) + self.assertTrue(row.batch_no in batches) + batches.remove(row.batch_no) + + ste1.submit() + + remaining_batches = [] + ste1 = frappe.get_doc(make_stock_entry(work_order.name, "Manufacture", 20)) + for row in ste1.get("items"): + if row.is_finished_item: + self.assertEqual(row.item_code, fg_item) + self.assertEqual(row.qty, 10) + remaining_batches.append(row.batch_no) + + self.assertEqual(sorted(remaining_batches), sorted(batches)) frappe.db.set_value("Manufacturing Settings", None, "make_serial_no_batch_from_work_order", 0) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 83c280f72ee..f6c53f7bca0 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1545,6 +1545,7 @@ class StockEntry(StockController): "reference_name": self.pro_doc.name, "reference_doctype": self.pro_doc.doctype, "qty_to_produce": (">", 0), + "batch_qty": ("=", 0), } fields = ["qty_to_produce as qty", "produced_qty", "name"] @@ -2238,14 +2239,14 @@ class StockEntry(StockController): d.qty -= process_loss_dict[d.item_code][1] def set_serial_no_batch_for_finished_good(self): - args = {} + serial_nos = "" if self.pro_doc.serial_no: - self.get_serial_nos_for_fg(args) + serial_nos = self.get_serial_nos_for_fg() for row in self.items: if row.is_finished_item and row.item_code == self.pro_doc.production_item: - if args.get("serial_no"): - row.serial_no = "\n".join(args["serial_no"][0 : cint(row.qty)]) + if serial_nos: + row.serial_no = "\n".join(serial_nos[0 : cint(row.qty)]) def get_serial_nos_for_fg(self, args): fields = [ @@ -2258,14 +2259,14 @@ class StockEntry(StockController): filters = [ ["Stock Entry", "work_order", "=", self.work_order], ["Stock Entry", "purpose", "=", "Manufacture"], - ["Stock Entry", "docstatus", "=", 1], + ["Stock Entry", "docstatus", "<", 2], ["Stock Entry Detail", "item_code", "=", self.pro_doc.production_item], ] stock_entries = frappe.get_all("Stock Entry", fields=fields, filters=filters) if self.pro_doc.serial_no: - args["serial_no"] = self.get_available_serial_nos(stock_entries) + return self.get_available_serial_nos(stock_entries) def get_available_serial_nos(self, stock_entries): used_serial_nos = []