From 61f05132dbd0cd3d0ed76e04f2d45a8a6ebf1c66 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 17 Nov 2022 11:00:01 +0100 Subject: [PATCH 01/13] feat: validate repost item valuation against accounts freeze date --- .../repost_item_valuation.py | 19 +++++++++++++-- .../test_repost_item_valuation.py | 23 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) 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 d6f9bae5da..5fc0ee094f 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -5,7 +5,7 @@ import frappe from frappe import _ from frappe.exceptions import QueryDeadlockError, QueryTimeoutError from frappe.model.document import Document -from frappe.utils import cint, get_link_to_form, get_weekday, now, nowtime +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 @@ -25,6 +25,21 @@ class RepostItemValuation(Document): self.set_status(write=False) self.reset_field_values() self.set_company() + self.validate_accounts_freeze() + + def validate_accounts_freeze(self): + acc_settings = frappe.db.get_value( + 'Accounts Settings', + 'Accounts Settings', + ['acc_frozen_upto', 'frozen_accounts_modifier'], + as_dict=1 + ) + if not acc_settings.acc_frozen_upto: + return + if acc_settings.frozen_accounts_modifier and self.owner in get_users_with_role(acc_settings.frozen_accounts_modifier): + return + if getdate(self.posting_date) <= getdate(acc_settings.acc_frozen_upto): + frappe.throw(_("You cannot repost item valuation before {}").format(acc_settings.acc_frozen_upto)) def reset_field_values(self): if self.based_on == "Transaction": @@ -240,7 +255,7 @@ def _get_directly_dependent_vouchers(doc): def notify_error_to_stock_managers(doc, traceback): recipients = get_users_with_role("Stock Manager") if not recipients: - get_users_with_role("System Manager") + recipients = get_users_with_role("System Manager") subject = _("Error while reposting item valuation") message = ( 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 e0f2479710..dc03c79b33 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 @@ -327,3 +327,26 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin): # outstanding should not be affected sinv.reload() self.assertEqual(sinv.outstanding_amount, 100) + + def test_account_freeze_validation(self): + today = nowdate() + + riv = frappe.get_doc( + doctype="Repost Item Valuation", + item_code="_Test Item", + warehouse="_Test Warehouse - _TC", + based_on="Item and Warehouse", + posting_date=today, + posting_time="00:01:00", + ) + riv.flags.dont_run_in_test = True # keep it queued + + accounts_settings = frappe.get_doc("Accounts Settings") + accounts_settings.acc_frozen_upto = today + accounts_settings.frozen_accounts_modifier = '' + accounts_settings.save() + + self.assertRaises(frappe.ValidationError, riv.save) + + accounts_settings.acc_frozen_upto = '' + accounts_settings.save() \ No newline at end of file From be15419bd5d3481dd83c7c4fedbb010d3e0e13d9 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Thu, 17 Nov 2022 11:00:34 +0100 Subject: [PATCH 02/13] chore: pre-commit --- .../repost_item_valuation.py | 16 ++++++++++------ .../test_repost_item_valuation.py | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) 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 5fc0ee094f..b62933821c 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -29,17 +29,21 @@ class RepostItemValuation(Document): def validate_accounts_freeze(self): acc_settings = frappe.db.get_value( - 'Accounts Settings', - 'Accounts Settings', - ['acc_frozen_upto', 'frozen_accounts_modifier'], - as_dict=1 + "Accounts Settings", + "Accounts Settings", + ["acc_frozen_upto", "frozen_accounts_modifier"], + as_dict=1, ) if not acc_settings.acc_frozen_upto: return - if acc_settings.frozen_accounts_modifier and self.owner in get_users_with_role(acc_settings.frozen_accounts_modifier): + if acc_settings.frozen_accounts_modifier and self.owner in get_users_with_role( + acc_settings.frozen_accounts_modifier + ): return if getdate(self.posting_date) <= getdate(acc_settings.acc_frozen_upto): - frappe.throw(_("You cannot repost item valuation before {}").format(acc_settings.acc_frozen_upto)) + frappe.throw( + _("You cannot repost item valuation before {}").format(acc_settings.acc_frozen_upto) + ) def reset_field_values(self): if self.based_on == "Transaction": 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 dc03c79b33..f1667757a7 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 @@ -343,10 +343,10 @@ class TestRepostItemValuation(FrappeTestCase, StockTestMixin): accounts_settings = frappe.get_doc("Accounts Settings") accounts_settings.acc_frozen_upto = today - accounts_settings.frozen_accounts_modifier = '' + accounts_settings.frozen_accounts_modifier = "" accounts_settings.save() self.assertRaises(frappe.ValidationError, riv.save) - accounts_settings.acc_frozen_upto = '' - accounts_settings.save() \ No newline at end of file + accounts_settings.acc_frozen_upto = "" + accounts_settings.save() From b482e3876dccb2547330b95c1c8d4f2cf7039918 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Wed, 23 Nov 2022 18:59:15 +0530 Subject: [PATCH 03/13] fix: check for session user rather than owner --- .../repost_item_valuation/repost_item_valuation.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 b62933821c..a98d16e390 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -36,11 +36,12 @@ class RepostItemValuation(Document): ) if not acc_settings.acc_frozen_upto: return - if acc_settings.frozen_accounts_modifier and self.owner in get_users_with_role( - acc_settings.frozen_accounts_modifier - ): - return if getdate(self.posting_date) <= getdate(acc_settings.acc_frozen_upto): + if acc_settings.frozen_accounts_modifier and frappe.session.user in get_users_with_role( + acc_settings.frozen_accounts_modifier + ): + frappe.msgprint(_("Caution: This might alter frozen accounts.")) + return frappe.throw( _("You cannot repost item valuation before {}").format(acc_settings.acc_frozen_upto) ) From 88a0aa4077b6cd96800a813e5ba163b573d01f47 Mon Sep 17 00:00:00 2001 From: Dany Robert Date: Wed, 23 Nov 2022 19:04:11 +0530 Subject: [PATCH 04/13] chore: pre-commit --- .../doctype/repost_item_valuation/repost_item_valuation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 a98d16e390..8e914e6b80 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -37,8 +37,9 @@ class RepostItemValuation(Document): if not acc_settings.acc_frozen_upto: return if getdate(self.posting_date) <= getdate(acc_settings.acc_frozen_upto): - if acc_settings.frozen_accounts_modifier and frappe.session.user in get_users_with_role( + if ( acc_settings.frozen_accounts_modifier + and frappe.session.user in get_users_with_role(acc_settings.frozen_accounts_modifier) ): frappe.msgprint(_("Caution: This might alter frozen accounts.")) return From 95a620a30d67e6b2ac5137d87efa97f3f149b95f Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Thu, 24 Nov 2022 15:40:05 +0530 Subject: [PATCH 05/13] fix(pos): warehouse should be in company Signed-off-by: Sabu Siyad --- erpnext/accounts/doctype/pos_invoice/pos_invoice.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js index 15c292211c..c868d9ec7e 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js @@ -12,6 +12,8 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex company() { erpnext.accounts.dimensions.update_dimension(this.frm, this.frm.doctype); + this.frm.set_value("set_warehouse", ""); + this.frm.set_value("taxes_and_charges", ""); } onload(doc) { From 4ad0e2ed7eb925c893a84ef00964fbc1cab09cc6 Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Thu, 24 Nov 2022 16:11:26 +0530 Subject: [PATCH 06/13] feat(pos): invoice: fitler warehouse by company Signed-off-by: Sabu Siyad --- erpnext/accounts/doctype/pos_invoice/pos_invoice.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js index c868d9ec7e..40df6187d2 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js @@ -19,11 +19,20 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex onload(doc) { super.onload(); this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice Merge Log', 'POS Closing Entry']; + if(doc.__islocal && doc.is_pos && frappe.get_route_str() !== 'point-of-sale') { this.frm.script_manager.trigger("is_pos"); this.frm.refresh_fields(); } + this.frm.set_query("set_warehouse", function(doc) { + return { + filters: { + company: doc.company ? doc.company : '', + } + } + }); + erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype); } From cc63415887071b7675b95b6698884fd61847ab73 Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Fri, 25 Nov 2022 15:06:06 +0530 Subject: [PATCH 07/13] fix(pos): filter on customer groups Signed-off-by: Sabu Siyad --- .../doctype/pos_invoice/pos_invoice.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js index 15c292211c..fa11b7d9d8 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.js +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.js @@ -5,6 +5,8 @@ frappe.provide("erpnext.accounts"); erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnext.selling.SellingController { + settings = {}; + setup(doc) { this.setup_posting_date_time_check(); super.setup(doc); @@ -25,8 +27,13 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex erpnext.accounts.dimensions.setup_dimension_filters(this.frm, this.frm.doctype); } + onload_post_render(frm) { + this.pos_profile(frm); + } + refresh(doc) { super.refresh(); + if (doc.docstatus == 1 && !doc.is_return) { this.frm.add_custom_button(__('Return'), this.make_sales_return, __('Create')); this.frm.page.set_inner_btn_group_as_primary(__('Create')); @@ -36,6 +43,18 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex this.frm.return_print_format = "Sales Invoice Return"; this.frm.set_value('consolidated_invoice', ''); } + + this.frm.set_query("customer", (function () { + const customer_groups = this.settings?.customer_groups; + + if (!customer_groups?.length) return {}; + + return { + filters: { + customer_group: ["in", customer_groups], + } + } + }).bind(this)); } is_pos() { @@ -88,6 +107,25 @@ erpnext.selling.POSInvoiceController = class POSInvoiceController extends erpnex }); } + pos_profile(frm) { + if (!frm.pos_profile || frm.pos_profile == '') { + this.update_customer_groups_settings([]); + return; + } + + frappe.call({ + method: "erpnext.selling.page.point_of_sale.point_of_sale.get_pos_profile_data", + args: { "pos_profile": frm.pos_profile }, + callback: ({ message: profile }) => { + this.update_customer_groups_settings(profile?.customer_groups); + }, + }); + } + + update_customer_groups_settings(customer_groups) { + this.settings.customer_groups = customer_groups?.map((group) => group.name) + } + amount(){ this.write_off_outstanding_amount_automatically() } From 0f87d329d616c65249e180c57011cda4955e1e23 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Fri, 25 Nov 2022 17:03:00 +0530 Subject: [PATCH 08/13] fix: only show serial no batch selector only once --- erpnext/stock/doctype/stock_entry/stock_entry.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 266ea5f674..b9102445e0 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -1079,7 +1079,8 @@ erpnext.stock.select_batch_and_serial_no = (frm, item) => { if (frm.doc.purpose === 'Material Receipt') return; frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() { - new erpnext.SerialNoBatchSelector({ + if (frm.batch_selector?.dialog?.display) return; + frm.batch_selector = new erpnext.SerialNoBatchSelector({ frm: frm, item: item, warehouse_details: get_warehouse_type_and_name(item), From 6ebe8ad60d62645b1604481ff6d9b2b97a0fc104 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 28 Nov 2022 17:37:41 +0530 Subject: [PATCH 09/13] fix(ux): Action buttons in Bank Reconciliation --- .../doctype/bank_clearance/bank_clearance.js | 28 ++++++++++++++---- .../bank_clearance/bank_clearance.json | 29 ++++--------------- .../doctype/bank_clearance/bank_clearance.py | 2 -- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/erpnext/accounts/doctype/bank_clearance/bank_clearance.js b/erpnext/accounts/doctype/bank_clearance/bank_clearance.js index 7e57c2fc47..ceba99a56a 100644 --- a/erpnext/accounts/doctype/bank_clearance/bank_clearance.js +++ b/erpnext/accounts/doctype/bank_clearance/bank_clearance.js @@ -37,6 +37,14 @@ frappe.ui.form.on("Bank Clearance", { refresh: function(frm) { frm.disable_save(); + + if (frm.doc.account && frm.doc.from_date && frm.doc.to_date) { + frm.add_custom_button(__('Get Payment Entries'), () => + frm.trigger("get_payment_entries") + ); + + frm.change_custom_button_type('Get Payment Entries', null, 'primary'); + } }, update_clearance_date: function(frm) { @@ -46,22 +54,30 @@ frappe.ui.form.on("Bank Clearance", { callback: function(r, rt) { frm.refresh_field("payment_entries"); frm.refresh_fields(); + + if (!frm.doc.payment_entries.length) { + frm.change_custom_button_type('Get Payment Entries', null, 'primary'); + frm.change_custom_button_type('Update Clearance Date', null, 'default'); + } } }); }, + get_payment_entries: function(frm) { return frappe.call({ method: "get_payment_entries", doc: frm.doc, callback: function(r, rt) { frm.refresh_field("payment_entries"); - frm.refresh_fields(); - $(frm.fields_dict.payment_entries.wrapper).find("[data-fieldname=amount]").each(function(i,v){ - if (i !=0){ - $(v).addClass("text-right") - } - }) + if (frm.doc.payment_entries.length) { + frm.add_custom_button(__('Update Clearance Date'), () => + frm.trigger("update_clearance_date") + ); + + frm.change_custom_button_type('Get Payment Entries', null, 'default'); + frm.change_custom_button_type('Update Clearance Date', null, 'primary'); + } } }); } diff --git a/erpnext/accounts/doctype/bank_clearance/bank_clearance.json b/erpnext/accounts/doctype/bank_clearance/bank_clearance.json index a436d1effb..591d01949b 100644 --- a/erpnext/accounts/doctype/bank_clearance/bank_clearance.json +++ b/erpnext/accounts/doctype/bank_clearance/bank_clearance.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_copy": 1, "creation": "2013-01-10 16:34:05", "doctype": "DocType", @@ -13,11 +14,8 @@ "bank_account", "include_reconciled_entries", "include_pos_transactions", - "get_payment_entries", "section_break_10", - "payment_entries", - "update_clearance_date", - "total_amount" + "payment_entries" ], "fields": [ { @@ -76,11 +74,6 @@ "fieldtype": "Check", "label": "Include POS Transactions" }, - { - "fieldname": "get_payment_entries", - "fieldtype": "Button", - "label": "Get Payment Entries" - }, { "fieldname": "section_break_10", "fieldtype": "Section Break" @@ -91,25 +84,14 @@ "fieldtype": "Table", "label": "Payment Entries", "options": "Bank Clearance Detail" - }, - { - "fieldname": "update_clearance_date", - "fieldtype": "Button", - "label": "Update Clearance Date" - }, - { - "fieldname": "total_amount", - "fieldtype": "Currency", - "label": "Total Amount", - "options": "account_currency", - "read_only": 1 } ], "hide_toolbar": 1, "icon": "fa fa-check", "idx": 1, "issingle": 1, - "modified": "2020-04-06 16:12:06.628008", + "links": [], + "modified": "2022-11-28 17:24:13.008692", "modified_by": "Administrator", "module": "Accounts", "name": "Bank Clearance", @@ -126,5 +108,6 @@ "quick_entry": 1, "read_only": 1, "sort_field": "modified", - "sort_order": "ASC" + "sort_order": "ASC", + "states": [] } \ No newline at end of file diff --git a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py index 78c3526654..80878ac506 100644 --- a/erpnext/accounts/doctype/bank_clearance/bank_clearance.py +++ b/erpnext/accounts/doctype/bank_clearance/bank_clearance.py @@ -179,7 +179,6 @@ class BankClearance(Document): ) self.set("payment_entries", []) - self.total_amount = 0.0 default_currency = erpnext.get_default_currency() for d in entries: @@ -198,7 +197,6 @@ class BankClearance(Document): d.pop("debit") d.pop("account_currency") row.update(d) - self.total_amount += flt(amount) @frappe.whitelist() def update_clearance_date(self): From fa152214552e37236ff927e35ed09d016933a26c Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 28 Nov 2022 19:22:35 +0530 Subject: [PATCH 10/13] fix: Auto repeat date validations --- erpnext/controllers/accounts_controller.py | 4 ++++ erpnext/controllers/buying_controller.py | 1 + erpnext/controllers/selling_controller.py | 1 + 3 files changed, 6 insertions(+) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 1849e8b3b5..dc42a89df7 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -239,6 +239,10 @@ class AccountsController(TransactionBase): else: item.set(field_map.get(self.doctype), default_deferred_account) + def validate_auto_repeat_subscription_dates(self): + if getdate(self.from_date) > getdate(self.to_date): + frappe.throw(_("To Date cannot be before From Date"), title=_("Invalid Auto Repeat Date")) + def validate_deferred_start_and_end_date(self): for d in self.items: if d.get("enable_deferred_revenue") or d.get("enable_deferred_expense"): diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 48fe7cb083..051460474a 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -41,6 +41,7 @@ class BuyingController(SubcontractingController): self.validate_from_warehouse() self.set_supplier_address() self.validate_asset_return() + self.validate_auto_repeat_subscription_dates() if self.doctype == "Purchase Invoice": self.validate_purchase_receipt_if_update_stock() diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index e8e9076975..f4276802b7 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -40,6 +40,7 @@ class SellingController(StockController): self.set_customer_address() self.validate_for_duplicate_items() self.validate_target_warehouse() + self.validate_auto_repeat_subscription_dates() def set_missing_values(self, for_validate=False): From 6a47fb6c9e9e93553b622a795217f3a15ded1eb9 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 28 Nov 2022 22:47:44 +0530 Subject: [PATCH 11/13] chore: Update condition --- erpnext/controllers/accounts_controller.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index dc42a89df7..b7a80c1019 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -240,7 +240,11 @@ class AccountsController(TransactionBase): item.set(field_map.get(self.doctype), default_deferred_account) def validate_auto_repeat_subscription_dates(self): - if getdate(self.from_date) > getdate(self.to_date): + if ( + self.get("from_date") + and self.get("to_date") + and getdate(self.from_date) > getdate(self.to_date) + ): frappe.throw(_("To Date cannot be before From Date"), title=_("Invalid Auto Repeat Date")) def validate_deferred_start_and_end_date(self): From b2105a8be7ba3891df1253a94c8322632db22956 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 28 Nov 2022 22:51:35 +0530 Subject: [PATCH 12/13] fix: incorrect balance qty --- .../stock/doctype/stock_reconciliation/stock_reconciliation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index d92d0f1686..260c1344b1 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -348,6 +348,9 @@ class StockReconciliation(StockController): if row.qty: args = self.get_sle_for_items(row) + if row.serial_no and row.batch_no: + args["qty_after_transaction"] = row.qty + args.update( { "actual_qty": row.qty, From b606a9684beb7a7f3256fad25c9389dc7e763d4f Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 29 Nov 2022 00:08:07 +0530 Subject: [PATCH 13/13] test: test case for serialized batched item --- .../stock_reconciliation.py | 6 ++-- .../test_stock_reconciliation.py | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 260c1344b1..3a0b38a0fc 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -230,7 +230,7 @@ class StockReconciliation(StockController): if item.has_serial_no or item.has_batch_no: has_serial_no = True - self.get_sle_for_serialized_items(row, sl_entries) + self.get_sle_for_serialized_items(row, sl_entries, item) else: if row.serial_no or row.batch_no: frappe.throw( @@ -282,7 +282,7 @@ class StockReconciliation(StockController): if has_serial_no and sl_entries: self.update_valuation_rate_for_serial_no() - def get_sle_for_serialized_items(self, row, sl_entries): + def get_sle_for_serialized_items(self, row, sl_entries, item): from erpnext.stock.stock_ledger import get_previous_sle serial_nos = get_serial_nos(row.serial_no) @@ -348,7 +348,7 @@ class StockReconciliation(StockController): if row.qty: args = self.get_sle_for_items(row) - if row.serial_no and row.batch_no: + if item.has_serial_no and item.has_batch_no: args["qty_after_transaction"] = row.qty args.update( diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 7b984d3847..eaea301432 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -644,6 +644,38 @@ class TestStockReconciliation(FrappeTestCase, StockTestMixin): ) self.assertEqual(len(active_sr_no), 0) + def test_serial_no_batch_no_item(self): + item = self.make_item( + "Test Serial No Batch No Item", + { + "is_stock_item": 1, + "has_serial_no": 1, + "has_batch_no": 1, + "serial_no_series": "SRS9.####", + "batch_number_series": "BNS9.####", + "create_new_batch": 1, + }, + ) + + warehouse = "_Test Warehouse - _TC" + + sr = create_stock_reconciliation( + item_code=item.name, + warehouse=warehouse, + qty=1, + rate=100, + ) + + sl_entry = frappe.db.get_value( + "Stock Ledger Entry", + {"voucher_type": "Stock Reconciliation", "voucher_no": sr.name}, + ["actual_qty", "qty_after_transaction"], + as_dict=1, + ) + + self.assertEqual(flt(sl_entry.actual_qty), 1.0) + self.assertEqual(flt(sl_entry.qty_after_transaction), 1.0) + def create_batch_item_with_batch(item_name, batch_id): batch_item_doc = create_item(item_name, is_stock_item=1)