From 4e92926a525b396173dbc4d6dd476b2ab4874f9b Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Fri, 11 Mar 2022 16:44:21 +0530 Subject: [PATCH 01/23] fix: incorrect payable amount for loan closure - Add penalty amount to payable amount for loan closure --- erpnext/loan_management/doctype/loan_repayment/loan_repayment.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index 67c2b1ee14d1..63dea6f726a2 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -609,5 +609,6 @@ def calculate_amounts(against_loan, posting_date, payment_type=''): amounts['payable_principal_amount'] = amounts['pending_principal_amount'] amounts['interest_amount'] += amounts['unaccrued_interest'] amounts['payable_amount'] = amounts['payable_principal_amount'] + amounts['interest_amount'] + amounts['payable_amount'] = amounts['penalty_amount'] return amounts From 8c76a76154d8976760d19d95f421dd2b0ee238bf Mon Sep 17 00:00:00 2001 From: Abhinav Raut Date: Fri, 11 Mar 2022 16:46:30 +0530 Subject: [PATCH 02/23] fix: incorrect payable amount for loan closure --- .../loan_management/doctype/loan_repayment/loan_repayment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index 63dea6f726a2..f7e75768a821 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -609,6 +609,6 @@ def calculate_amounts(against_loan, posting_date, payment_type=''): amounts['payable_principal_amount'] = amounts['pending_principal_amount'] amounts['interest_amount'] += amounts['unaccrued_interest'] amounts['payable_amount'] = amounts['payable_principal_amount'] + amounts['interest_amount'] - amounts['payable_amount'] = amounts['penalty_amount'] + amounts['payable_amount'] += amounts['penalty_amount'] return amounts From 1b2c6a5b78d4ee2e31817eb78bb1f614b672eda4 Mon Sep 17 00:00:00 2001 From: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> Date: Mon, 21 Mar 2022 17:06:23 +0530 Subject: [PATCH 03/23] fix: Code cleanup --- .../loan_management/doctype/loan_repayment/loan_repayment.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index f7e75768a821..071000015259 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -608,7 +608,6 @@ def calculate_amounts(against_loan, posting_date, payment_type=''): if payment_type == 'Loan Closure': amounts['payable_principal_amount'] = amounts['pending_principal_amount'] amounts['interest_amount'] += amounts['unaccrued_interest'] - amounts['payable_amount'] = amounts['payable_principal_amount'] + amounts['interest_amount'] - amounts['payable_amount'] += amounts['penalty_amount'] + amounts['payable_amount'] = amounts['payable_principal_amount'] + amounts['interest_amount'] + amounts['penalty_amount'] return amounts From 62266b29aa7eccbfcf496508d2d01f11a2259c7f Mon Sep 17 00:00:00 2001 From: Devin Slauenwhite Date: Wed, 30 Mar 2022 14:22:44 -0400 Subject: [PATCH 04/23] fix: exchange rate precision --- erpnext/accounts/doctype/payment_entry/payment_entry.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index b2b818a214dd..7315ae893651 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -532,7 +532,8 @@ frappe.ui.form.on('Payment Entry', { to_currency: to_currency }, callback: function(r, rt) { - frm.set_value(exchange_rate_field, r.message); + const ex_rate = flt(r.message, frm.get_field(exchange_rate_field).get_precision()); + frm.set_value(exchange_rate_field, ex_rate); } }) }, From 4720969ce62c5d2f1a8d3fbb86c6eec391b4a2c4 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 31 Mar 2022 12:14:16 +0530 Subject: [PATCH 05/23] fix: Taxes getting overriden from mapped to target doc --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js | 2 ++ erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 3 +++ 2 files changed, 5 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 1a398aba2ecf..5f6e61090bd6 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -276,6 +276,8 @@ erpnext.accounts.PurchaseInvoice = class PurchaseInvoice extends erpnext.buying. if(this.frm.updating_party_details || this.frm.doc.inter_company_invoice_reference) return; + if (this.frm.doc.__onload && this.frm.doc.__onload.load_after_mapping) return; + erpnext.utils.get_party_details(this.frm, "erpnext.accounts.party.get_party_details", { posting_date: this.frm.doc.posting_date, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index af6a52a6429a..6818955c2f1e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -280,6 +280,9 @@ erpnext.accounts.SalesInvoiceController = class SalesInvoiceController extends e } var me = this; if(this.frm.updating_party_details) return; + + if (this.frm.doc.__onload && this.frm.doc.__onload.load_after_mapping) return; + erpnext.utils.get_party_details(this.frm, "erpnext.accounts.party.get_party_details", { posting_date: this.frm.doc.posting_date, From 2f63ae2ee9782c879d7b7ef806444f41a16ac4c6 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 31 Mar 2022 18:40:09 +0530 Subject: [PATCH 06/23] feat: minor, pick list item reference on delivery note item table --- .../delivery_note_item/delivery_note_item.json | 12 +++++++++++- erpnext/stock/doctype/pick_list/pick_list.py | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) 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 f1f5d96e6289..e2eb2a4bbb27 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -74,6 +74,7 @@ "against_sales_invoice", "si_detail", "dn_detail", + "pick_list_item", "section_break_40", "batch_no", "serial_no", @@ -762,13 +763,22 @@ "fieldtype": "Check", "label": "Grant Commission", "read_only": 1 + }, + { + "fieldname": "pick_list_item", + "fieldtype": "Data", + "hidden": 1, + "label": "Pick List Item", + "no_copy": 1, + "print_hide": 1, + "read_only": 1 } ], "idx": 1, "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2022-02-24 14:42:20.211085", + "modified": "2022-03-31 18:36:24.671913", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 7061ee1eea4b..d3476a88f054 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -534,6 +534,7 @@ def map_pl_locations(pick_list, item_mapper, delivery_note, sales_order=None): dn_item = map_child_doc(source_doc, delivery_note, table_mapper) if dn_item: + dn_item.pick_list_item = location.name dn_item.warehouse = location.warehouse dn_item.qty = flt(location.picked_qty) / (flt(location.conversion_factor) or 1) dn_item.batch_no = location.batch_no From 2f51011f913454c1ca4e96f647af4476c69fbfe3 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 31 Mar 2022 18:47:09 +0530 Subject: [PATCH 07/23] test: test case to check pick list name has mapped or not --- erpnext/stock/doctype/pick_list/test_pick_list.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/stock/doctype/pick_list/test_pick_list.py b/erpnext/stock/doctype/pick_list/test_pick_list.py index 7496b6b1798c..ec5011b93d6f 100644 --- a/erpnext/stock/doctype/pick_list/test_pick_list.py +++ b/erpnext/stock/doctype/pick_list/test_pick_list.py @@ -521,6 +521,8 @@ def test_multiple_dn_creation(self): for dn_item in frappe.get_doc("Delivery Note", dn.name).get("items"): self.assertEqual(dn_item.item_code, "_Test Item") self.assertEqual(dn_item.against_sales_order, sales_order_1.name) + self.assertEqual(dn_item.pick_list_item, pick_list.locations[dn_item.idx - 1].name) + for dn in frappe.get_all( "Delivery Note", filters={"pick_list": pick_list.name, "customer": "_Test Customer 1"}, From bfc34e10840a240a68b976ac8bd4a0e03ca7c153 Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Fri, 1 Apr 2022 11:03:16 +0530 Subject: [PATCH 08/23] fix: check for debit credit difference even after round-off adjustment (#30050) --- erpnext/accounts/general_ledger.py | 43 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 50f37be27b8b..f52e517f7308 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -253,7 +253,7 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False): if not from_repost: validate_cwip_accounts(gl_map) - round_off_debit_credit(gl_map) + process_debit_credit_difference(gl_map) if gl_map: check_freezing_date(gl_map[0]["posting_date"], adv_adj) @@ -302,12 +302,29 @@ def validate_cwip_accounts(gl_map): ) -def round_off_debit_credit(gl_map): +def process_debit_credit_difference(gl_map): precision = get_field_precision( frappe.get_meta("GL Entry").get_field("debit"), currency=frappe.get_cached_value("Company", gl_map[0].company, "default_currency"), ) + voucher_type = gl_map[0].voucher_type + voucher_no = gl_map[0].voucher_no + allowance = get_debit_credit_allowance(voucher_type, precision) + + debit_credit_diff = get_debit_credit_difference(gl_map, precision) + if abs(debit_credit_diff) > allowance: + raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no) + + elif abs(debit_credit_diff) >= (1.0 / (10**precision)): + make_round_off_gle(gl_map, debit_credit_diff, precision) + + debit_credit_diff = get_debit_credit_difference(gl_map, precision) + if abs(debit_credit_diff) > allowance: + raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no) + + +def get_debit_credit_difference(gl_map, precision): debit_credit_diff = 0.0 for entry in gl_map: entry.debit = flt(entry.debit, precision) @@ -316,20 +333,24 @@ def round_off_debit_credit(gl_map): debit_credit_diff = flt(debit_credit_diff, precision) - if gl_map[0]["voucher_type"] in ("Journal Entry", "Payment Entry"): + return debit_credit_diff + + +def get_debit_credit_allowance(voucher_type, precision): + if voucher_type in ("Journal Entry", "Payment Entry"): allowance = 5.0 / (10**precision) else: allowance = 0.5 - if abs(debit_credit_diff) > allowance: - frappe.throw( - _("Debit and Credit not equal for {0} #{1}. Difference is {2}.").format( - gl_map[0].voucher_type, gl_map[0].voucher_no, debit_credit_diff - ) - ) + return allowance - elif abs(debit_credit_diff) >= (1.0 / (10**precision)): - make_round_off_gle(gl_map, debit_credit_diff, precision) + +def raise_debit_credit_not_equal_error(debit_credit_diff, voucher_type, voucher_no): + frappe.throw( + _("Debit and Credit not equal for {0} #{1}. Difference is {2}.").format( + voucher_type, voucher_no, debit_credit_diff + ) + ) def make_round_off_gle(gl_map, debit_credit_diff, precision): From 257623509d9aaa7fa12be124869ed059bbaa821d Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 1 Apr 2022 11:55:19 +0530 Subject: [PATCH 09/23] perf: use cached single docs (#30536) frappe.local is request specific thread local, hence is almost as good as no caching. --- .../doctype/e_commerce_settings/e_commerce_settings.py | 7 +------ .../doctype/education_settings/education_settings.py | 2 +- erpnext/templates/pages/home.py | 8 ++++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py index b5cd067e38f9..881d833eb01a 100644 --- a/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py +++ b/erpnext/e_commerce/doctype/e_commerce_settings/e_commerce_settings.py @@ -146,12 +146,7 @@ def validate_cart_settings(doc=None, method=None): def get_shopping_cart_settings(): - if not getattr(frappe.local, "shopping_cart_settings", None): - frappe.local.shopping_cart_settings = frappe.get_doc( - "E Commerce Settings", "E Commerce Settings" - ) - - return frappe.local.shopping_cart_settings + return frappe.get_cached_doc("E Commerce Settings") @frappe.whitelist(allow_guest=True) diff --git a/erpnext/education/doctype/education_settings/education_settings.py b/erpnext/education/doctype/education_settings/education_settings.py index cde5089e88d1..295aa3a4cba7 100644 --- a/erpnext/education/doctype/education_settings/education_settings.py +++ b/erpnext/education/doctype/education_settings/education_settings.py @@ -41,4 +41,4 @@ def validate(self): def update_website_context(context): - context["lms_enabled"] = frappe.get_doc("Education Settings").enable_lms + context["lms_enabled"] = frappe.get_cached_doc("Education Settings").enable_lms diff --git a/erpnext/templates/pages/home.py b/erpnext/templates/pages/home.py index bca3e5605362..47fb89dea317 100644 --- a/erpnext/templates/pages/home.py +++ b/erpnext/templates/pages/home.py @@ -8,7 +8,7 @@ def get_context(context): - homepage = frappe.get_doc("Homepage") + homepage = frappe.get_cached_doc("Homepage") for item in homepage.products: route = frappe.db.get_value("Website Item", {"item_code": item.item_code}, "route") @@ -20,10 +20,10 @@ def get_context(context): context.homepage = homepage if homepage.hero_section_based_on == "Homepage Section" and homepage.hero_section: - homepage.hero_section_doc = frappe.get_doc("Homepage Section", homepage.hero_section) + homepage.hero_section_doc = frappe.get_cached_doc("Homepage Section", homepage.hero_section) if homepage.slideshow: - doc = frappe.get_doc("Website Slideshow", homepage.slideshow) + doc = frappe.get_cached_doc("Website Slideshow", homepage.slideshow) context.slideshow = homepage.slideshow context.slideshow_header = doc.header context.slides = doc.slideshow_items @@ -46,7 +46,7 @@ def get_context(context): order_by="section_order asc", ) context.homepage_sections = [ - frappe.get_doc("Homepage Section", name) for name in homepage_sections + frappe.get_cached_doc("Homepage Section", name) for name in homepage_sections ] context.metatags = context.metatags or frappe._dict({}) From 65763275aeac949a2b22a834af08c5462b6e0c8d Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 1 Apr 2022 13:47:52 +0530 Subject: [PATCH 10/23] fix: convert dates to datetime before comparing in leave days calculation and fix half day edge case (#30538) --- .../leave_application/leave_application.py | 4 ++-- .../test_leave_application.py | 20 ++++++++++++++++--- .../doctype/salary_slip/test_salary_slip.py | 13 +++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 18c69f7113af..cd6b16866753 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -735,9 +735,9 @@ def get_number_of_leave_days( (Based on the include_holiday setting in Leave Type)""" number_of_days = 0 if cint(half_day) == 1: - if from_date == to_date: + if getdate(from_date) == getdate(to_date): number_of_days = 0.5 - elif half_day_date and half_day_date <= to_date: + elif half_day_date and getdate(from_date) <= getdate(half_day_date) <= getdate(to_date): number_of_days = date_diff(to_date, from_date) + 0.5 else: number_of_days = date_diff(to_date, from_date) + 1 diff --git a/erpnext/hr/doctype/leave_application/test_leave_application.py b/erpnext/hr/doctype/leave_application/test_leave_application.py index f33d0afa4ebf..4c39e15c93d7 100644 --- a/erpnext/hr/doctype/leave_application/test_leave_application.py +++ b/erpnext/hr/doctype/leave_application/test_leave_application.py @@ -205,7 +205,12 @@ def test_separate_leave_ledger_entry_for_boundary_applications(self): # creates separate leave ledger entries frappe.delete_doc_if_exists("Leave Type", "Test Leave Validation", force=1) leave_type = frappe.get_doc( - dict(leave_type_name="Test Leave Validation", doctype="Leave Type", allow_negative=True) + dict( + leave_type_name="Test Leave Validation", + doctype="Leave Type", + allow_negative=True, + include_holiday=True, + ) ).insert() employee = get_employee() @@ -217,8 +222,14 @@ def test_separate_leave_ledger_entry_for_boundary_applications(self): # application across allocations # CASE 1: from date has no allocation, to date has an allocation / both dates have allocation + start_date = add_days(year_start, -10) application = make_leave_application( - employee.name, add_days(year_start, -10), add_days(year_start, 3), leave_type.name + employee.name, + start_date, + add_days(year_start, 3), + leave_type.name, + half_day=1, + half_day_date=start_date, ) # 2 separate leave ledger entries @@ -828,6 +839,7 @@ def test_ledger_entry_creation_on_intermediate_allocation_expiry(self): leave_type_name="_Test_CF_leave_expiry", is_carry_forward=1, expire_carry_forwarded_leaves_after_days=90, + include_holiday=True, ) leave_type.submit() @@ -840,6 +852,8 @@ def test_ledger_entry_creation_on_intermediate_allocation_expiry(self): leave_type=leave_type.name, from_date=add_days(nowdate(), -3), to_date=add_days(nowdate(), 7), + half_day=1, + half_day_date=add_days(nowdate(), -3), description="_Test Reason", company="_Test Company", docstatus=1, @@ -855,7 +869,7 @@ def test_ledger_entry_creation_on_intermediate_allocation_expiry(self): self.assertEqual(len(leave_ledger_entry), 2) self.assertEqual(leave_ledger_entry[0].employee, leave_application.employee) self.assertEqual(leave_ledger_entry[0].leave_type, leave_application.leave_type) - self.assertEqual(leave_ledger_entry[0].leaves, -9) + self.assertEqual(leave_ledger_entry[0].leaves, -8.5) self.assertEqual(leave_ledger_entry[1].leaves, -2) def test_leave_application_creation_after_expiry(self): diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index e1d1fa1fcb46..dbeadc590041 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -1290,7 +1290,16 @@ def create_additional_salary(employee, payroll_period, amount): return salary_date -def make_leave_application(employee, from_date, to_date, leave_type, company=None, submit=True): +def make_leave_application( + employee, + from_date, + to_date, + leave_type, + company=None, + half_day=False, + half_day_date=None, + submit=True, +): leave_application = frappe.get_doc( dict( doctype="Leave Application", @@ -1298,6 +1307,8 @@ def make_leave_application(employee, from_date, to_date, leave_type, company=Non leave_type=leave_type, from_date=from_date, to_date=to_date, + half_day=half_day, + half_day_date=half_day_date, company=company or erpnext.get_default_company() or "_Test Company", status="Approved", leave_approver="test@example.com", From 5d14e7860e7c16e39aacd9455aba278afd195fd1 Mon Sep 17 00:00:00 2001 From: Alberto826 <46285948+Alberto826@users.noreply.github.com> Date: Fri, 1 Apr 2022 11:18:00 +0200 Subject: [PATCH 11/23] Fix: Remove trailing slash "/" from route (#30532) Routes with trailing slash "/" causes a redirect to port 8080 in docker host with reverse proxy. The Student Admission Row template has this issue. --- .../student_admission/templates/student_admission_row.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/education/doctype/student_admission/templates/student_admission_row.html b/erpnext/education/doctype/student_admission/templates/student_admission_row.html index 529d65184a89..dc4587bc9409 100644 --- a/erpnext/education/doctype/student_admission/templates/student_admission_row.html +++ b/erpnext/education/doctype/student_admission/templates/student_admission_row.html @@ -1,6 +1,6 @@
{% set today = frappe.utils.getdate(frappe.utils.nowdate()) %} - +
Date: Thu, 31 Mar 2022 15:37:14 +0530 Subject: [PATCH 13/23] fix: Handle changes in frappe's get_monthly_goal_graph_data API --- erpnext/setup/doctype/company/company_dashboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/setup/doctype/company/company_dashboard.py b/erpnext/setup/doctype/company/company_dashboard.py index ff1e7f1103b2..2d073c1d77ed 100644 --- a/erpnext/setup/doctype/company/company_dashboard.py +++ b/erpnext/setup/doctype/company/company_dashboard.py @@ -14,7 +14,7 @@ def get_data(): "goal_doctype_link": "company", "goal_field": "base_grand_total", "date_field": "posting_date", - "filter_str": "docstatus = 1 and is_opening != 'Yes'", + "filters": {"docstatus": 1, "is_opening": ("!=", "Yes")}, "aggregation": "sum", }, "fieldname": "company", From 767b827b5951b2b85e8f7f714fa43c96df274f31 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 31 Mar 2022 14:21:01 +0530 Subject: [PATCH 14/23] feat: return batch code while scanning serial no --- .../page/point_of_sale/point_of_sale.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 bf629824ad99..400be4c7327a 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -3,6 +3,7 @@ import json +from typing import Dict, Optional import frappe from frappe.utils.nestedset import get_root_of @@ -150,24 +151,34 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te @frappe.whitelist() -def search_for_serial_or_batch_or_barcode_number(search_value): +def search_for_serial_or_batch_or_barcode_number(search_value: str) -> Dict[str, Optional[str]]: + # search barcode no barcode_data = frappe.db.get_value( - "Item Barcode", {"barcode": search_value}, ["barcode", "parent as item_code"], as_dict=True + "Item Barcode", + {"barcode": search_value}, + ["barcode", "parent as item_code"], + as_dict=True, ) if barcode_data: return barcode_data # search serial no serial_no_data = frappe.db.get_value( - "Serial No", search_value, ["name as serial_no", "item_code"], as_dict=True + "Serial No", + search_value, + ["name as serial_no", "item_code", "batch_no"], + as_dict=True, ) if serial_no_data: return serial_no_data # search batch no batch_no_data = frappe.db.get_value( - "Batch", search_value, ["name as batch_no", "item as item_code"], as_dict=True + "Batch", + search_value, + ["name as batch_no", "item as item_code"], + as_dict=True, ) if batch_no_data: return batch_no_data From 530f767098ec5769627e40d92a17e5f162901442 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 31 Mar 2022 14:37:30 +0530 Subject: [PATCH 15/23] revert: "fix: ignore circular dependencies on barcode scan" This reverts commit 98468fab18e08de440f2f6731759d221fe08c416. --- erpnext/public/js/controllers/transaction.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 23c2bd405c14..619639251682 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -404,13 +404,11 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe } barcode(doc, cdt, cdn) { - const d = locals[cdt][cdn]; - if (!d.barcode) { + var d = locals[cdt][cdn]; + if(d.barcode=="" || d.barcode==null) { // barcode cleared, remove item d.item_code = ""; } - // flag required for circular triggers - d._triggerd_from_barcode = true; this.item_code(doc, cdt, cdn); } @@ -431,9 +429,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe this.frm.doc.doctype === 'Delivery Note') { show_batch_dialog = 1; } - if (!item._triggerd_from_barcode) { - item.barcode = null; - } + item.barcode = null; if(item.item_code || item.barcode || item.serial_no) { From 9bf427985fa72ac8f7c5e2c431ff2eb845d74de0 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 31 Mar 2022 14:38:00 +0530 Subject: [PATCH 16/23] fix!: remove barcode field triggers use "scan barcode" field instead for scanning [skip ci] --- erpnext/public/js/controllers/transaction.js | 9 --------- .../stock/doctype/stock_entry/stock_entry.js | 15 --------------- .../stock_reconciliation.js | 18 +----------------- 3 files changed, 1 insertion(+), 41 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 619639251682..f948c60010d1 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -403,15 +403,6 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe var sms_man = new erpnext.SMSManager(this.frm.doc); } - barcode(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if(d.barcode=="" || d.barcode==null) { - // barcode cleared, remove item - d.item_code = ""; - } - this.item_code(doc, cdt, cdn); - } - item_code(doc, cdt, cdn) { var me = this; var item = frappe.get_doc(cdt, cdn); diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 1aafcee5bf88..7564bb266d74 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -646,21 +646,6 @@ frappe.ui.form.on('Stock Entry Detail', { frm.events.calculate_basic_amount(frm, item); }, - barcode: function(doc, cdt, cdn) { - var d = locals[cdt][cdn]; - if (d.barcode) { - frappe.call({ - method: "erpnext.stock.get_item_details.get_item_code", - args: {"barcode": d.barcode }, - callback: function(r) { - if (!r.exe){ - frappe.model.set_value(cdt, cdn, "item_code", r.message); - } - } - }); - } - }, - uom: function(doc, cdt, cdn) { var d = locals[cdt][cdn]; if(d.uom && d.item_code){ diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js index 84f65a077e0c..4438acf8118e 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -163,20 +163,7 @@ frappe.ui.form.on("Stock Reconciliation", { }); } }, - set_item_code: function(doc, cdt, cdn) { - var d = frappe.model.get_doc(cdt, cdn); - if (d.barcode) { - frappe.call({ - method: "erpnext.stock.get_item_details.get_item_code", - args: {"barcode": d.barcode }, - callback: function(r) { - if (!r.exe){ - frappe.model.set_value(cdt, cdn, "item_code", r.message); - } - } - }); - } - }, + set_amount_quantity: function(doc, cdt, cdn) { var d = frappe.model.get_doc(cdt, cdn); if (d.qty & d.valuation_rate) { @@ -214,9 +201,6 @@ frappe.ui.form.on("Stock Reconciliation", { }); frappe.ui.form.on("Stock Reconciliation Item", { - barcode: function(frm, cdt, cdn) { - frm.events.set_item_code(frm, cdt, cdn); - }, warehouse: function(frm, cdt, cdn) { var child = locals[cdt][cdn]; From 47f27a51714f999d32fb0bfa21c13a11b1a964c3 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 1 Apr 2022 15:20:40 +0530 Subject: [PATCH 17/23] refactor: move scan api to stock utils; add item_info --- erpnext/public/js/utils/barcode_scanner.js | 4 +- .../page/point_of_sale/point_of_sale.py | 34 +------------ erpnext/stock/tests/test_utils.py | 31 ++++++++++++ erpnext/stock/utils.py | 49 +++++++++++++++++++ 4 files changed, 83 insertions(+), 35 deletions(-) create mode 100644 erpnext/stock/tests/test_utils.py diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index abea5fcb20bb..0868a6bd76f9 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -21,9 +21,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { // batch_no: "LOT12", // present if batch was scanned // serial_no: "987XYZ", // present if serial no was scanned // } - this.scan_api = - opts.scan_api || - "erpnext.selling.page.point_of_sale.point_of_sale.search_for_serial_or_batch_or_barcode_number"; + this.scan_api = opts.scan_api || "erpnext.stock.utils.scan_barcode"; } process_scan() { 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 400be4c7327a..99afe813cb99 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -10,6 +10,7 @@ from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_stock_availability from erpnext.accounts.doctype.pos_profile.pos_profile import get_child_nodes, get_item_groups +from erpnext.stock.utils import scan_barcode def search_by_term(search_term, warehouse, price_list): @@ -152,38 +153,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te @frappe.whitelist() def search_for_serial_or_batch_or_barcode_number(search_value: str) -> Dict[str, Optional[str]]: - - # search barcode no - barcode_data = frappe.db.get_value( - "Item Barcode", - {"barcode": search_value}, - ["barcode", "parent as item_code"], - as_dict=True, - ) - if barcode_data: - return barcode_data - - # search serial no - serial_no_data = frappe.db.get_value( - "Serial No", - search_value, - ["name as serial_no", "item_code", "batch_no"], - as_dict=True, - ) - if serial_no_data: - return serial_no_data - - # search batch no - batch_no_data = frappe.db.get_value( - "Batch", - search_value, - ["name as batch_no", "item as item_code"], - as_dict=True, - ) - if batch_no_data: - return batch_no_data - - return {} + return scan_barcode(search_value) def get_conditions(search_term): diff --git a/erpnext/stock/tests/test_utils.py b/erpnext/stock/tests/test_utils.py new file mode 100644 index 000000000000..9ee0c9f3b5ab --- /dev/null +++ b/erpnext/stock/tests/test_utils.py @@ -0,0 +1,31 @@ +import frappe +from frappe.tests.utils import FrappeTestCase + +from erpnext.stock.doctype.item.test_item import make_item +from erpnext.stock.utils import scan_barcode + + +class TestStockUtilities(FrappeTestCase): + def test_barcode_scanning(self): + simple_item = make_item(properties={"barcodes": [{"barcode": "12399"}]}) + self.assertEqual(scan_barcode("12399")["item_code"], simple_item.name) + + batch_item = make_item(properties={"has_batch_no": 1, "create_new_batch": 1}) + batch = frappe.get_doc(doctype="Batch", item=batch_item.name).insert() + + batch_scan = scan_barcode(batch.name) + self.assertEqual(batch_scan["item_code"], batch_item.name) + self.assertEqual(batch_scan["batch_no"], batch.name) + self.assertEqual(batch_scan["has_batch_no"], 1) + self.assertEqual(batch_scan["has_serial_no"], 0) + + serial_item = make_item(properties={"has_serial_no": 1}) + serial = frappe.get_doc( + doctype="Serial No", item_code=serial_item.name, serial_no=frappe.generate_hash() + ).insert() + + serial_scan = scan_barcode(serial.name) + self.assertEqual(serial_scan["item_code"], serial_item.name) + self.assertEqual(serial_scan["serial_no"], serial.name) + self.assertEqual(serial_scan["has_batch_no"], 0) + self.assertEqual(serial_scan["has_serial_no"], 1) diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index 4f1891fd750e..d40218e14398 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -3,6 +3,7 @@ import json +from typing import Dict, Optional import frappe from frappe import _ @@ -548,3 +549,51 @@ def check_pending_reposting(posting_date: str, throw_error: bool = True) -> bool ) return bool(reposting_pending) + + +@frappe.whitelist() +def scan_barcode(search_value: str) -> Dict[str, Optional[str]]: + + # search barcode no + barcode_data = frappe.db.get_value( + "Item Barcode", + {"barcode": search_value}, + ["barcode", "parent as item_code"], + as_dict=True, + ) + if barcode_data: + return _update_item_info(barcode_data) + + # search serial no + serial_no_data = frappe.db.get_value( + "Serial No", + search_value, + ["name as serial_no", "item_code", "batch_no"], + as_dict=True, + ) + if serial_no_data: + return _update_item_info(serial_no_data) + + # search batch no + batch_no_data = frappe.db.get_value( + "Batch", + search_value, + ["name as batch_no", "item as item_code"], + as_dict=True, + ) + if batch_no_data: + return _update_item_info(batch_no_data) + + return {} + + +def _update_item_info(scan_result: Dict[str, Optional[str]]) -> Dict[str, Optional[str]]: + if item_code := scan_result.get("item_code"): + if item_info := frappe.get_cached_value( + "Item", + item_code, + ["has_batch_no", "has_serial_no"], + as_dict=True, + ): + scan_result.update(item_info) + return scan_result From 6a069d6efa5a6ae1a8f38415c8c8b6b1799a0ed7 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 1 Apr 2022 16:21:22 +0530 Subject: [PATCH 18/23] feat: dont trigger selector if all info is scanned --- erpnext/public/js/controllers/transaction.js | 6 ++++++ erpnext/public/js/utils/barcode_scanner.js | 20 ++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index f948c60010d1..a4492e8bddb0 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -526,6 +526,12 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe if(!d[k]) d[k] = v; }); + if (d.__disable_batch_serial_selector) { + // reset for future use. + d.__disable_batch_serial_selector = false; + return; + } + if (d.has_batch_no && d.has_serial_no) { d.batch_no = undefined; } diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index 0868a6bd76f9..80a463f85c92 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -50,14 +50,16 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { return; } - me.update_table(data.item_code, data.barcode, data.batch_no, data.serial_no); + me.update_table(data); }); } - update_table(item_code, barcode, batch_no, serial_no) { + update_table(data) { let cur_grid = this.frm.fields_dict[this.items_table_name].grid; let row = null; + const {item_code, barcode, batch_no, serial_no} = data; + // Check if batch is scanned and table has batch no field let batch_no_scan = Boolean(batch_no) && frappe.meta.has_field(cur_grid.doctype, this.batch_no_field); @@ -82,6 +84,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } this.show_scan_message(row.idx, row.item_code); + this.set_selector_trigger_flag(row, data); this.set_item(row, item_code); this.set_serial_no(row, serial_no); this.set_batch_no(row, batch_no); @@ -89,6 +92,19 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { this.clean_up(); } + // batch and serial selector is reduandant when all info can be added by scan + // this flag on item row is used by transaction.js to avoid triggering selector + set_selector_trigger_flag(row, data) { + const {batch_no, serial_no, has_batch_no, has_serial_no} = data; + + const require_selecting_batch = has_batch_no && !batch_no; + const require_selecting_serial = has_serial_no && !serial_no; + + if (!(require_selecting_batch || require_selecting_serial)) { + row.__disable_batch_serial_selector = true; + } + } + set_item(row, item_code) { const item_data = { item_code: item_code }; item_data[this.qty_field] = (row[this.qty_field] || 0) + 1; From c8ead0a7ab2074b1599474c79b1a1f64650ba829 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 1 Apr 2022 20:25:30 +0530 Subject: [PATCH 19/23] fix: dont send empty serial no in get_item_details [skip ci] --- erpnext/stock/get_item_details.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index f72588e034d9..f83f692f642a 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -167,6 +167,9 @@ def update_stock(args, out): reserved_so = get_so_reservation_for_item(args) out.serial_no = get_serial_no(out, args.serial_no, sales_order=reserved_so) + if not out.serial_no: + out.pop("serial_no", None) + def set_valuation_rate(out, args): if frappe.db.exists("Product Bundle", args.item_code, cache=True): From 1736ab57ac785b745f37b733691e1f7acb604173 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 28 Mar 2022 09:37:37 +0530 Subject: [PATCH 20/23] feat: Barcode scanning in Stock Reconciliation [skip ci] --- .../stock_reconciliation.js | 37 ++++++++++++++++-- .../stock_reconciliation.json | 39 ++++++++++++++++++- 2 files changed, 71 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js index 4438acf8118e..3e8ac1f19f89 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -55,6 +55,25 @@ frappe.ui.form.on("Stock Reconciliation", { } }, + scan_barcode: function(frm) { + const barcode_scanner = new erpnext.utils.BarcodeScanner({frm:frm}); + barcode_scanner.process_scan(); + }, + + scan_mode: function(frm) { + if (frm.doc.scan_mode) { + frappe.show_alert({ + message: __("Scan mode enabled, existing quantity will not be fetched."), + indicator: "green" + }); + } + }, + + set_warehouse: function(frm) { + let transaction_controller = new erpnext.TransactionController({frm:frm}); + transaction_controller.autofill_warehouse(frm.doc.items, "warehouse", frm.doc.set_warehouse); + }, + get_items: function(frm) { let fields = [ { @@ -148,15 +167,18 @@ frappe.ui.form.on("Stock Reconciliation", { batch_no: d.batch_no }, callback: function(r) { - frappe.model.set_value(cdt, cdn, "qty", r.message.qty); + const row = frappe.model.get_doc(cdt, cdn); + if (!frm.doc.scan_mode) { + frappe.model.set_value(cdt, cdn, "qty", r.message.qty); + } frappe.model.set_value(cdt, cdn, "valuation_rate", r.message.rate); frappe.model.set_value(cdt, cdn, "current_qty", r.message.qty); frappe.model.set_value(cdt, cdn, "current_valuation_rate", r.message.rate); frappe.model.set_value(cdt, cdn, "current_amount", r.message.rate * r.message.qty); - frappe.model.set_value(cdt, cdn, "amount", r.message.rate * r.message.qty); + frappe.model.set_value(cdt, cdn, "amount", row.qty * row.valuation_rate); frappe.model.set_value(cdt, cdn, "current_serial_no", r.message.serial_nos); - if (frm.doc.purpose == "Stock Reconciliation") { + if (frm.doc.purpose == "Stock Reconciliation" && !frm.doc.scan_mode) { frappe.model.set_value(cdt, cdn, "serial_no", r.message.serial_nos); } } @@ -239,7 +261,14 @@ frappe.ui.form.on("Stock Reconciliation Item", { const serial_nos = child.serial_no.trim().split('\n'); frappe.model.set_value(cdt, cdn, "qty", serial_nos.length); } - } + }, + + items_add: function(frm, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + if (!item.warehouse && frm.doc.set_warehouse) { + frappe.model.set_value(cdt, cdn, "warehouse", frm.doc.set_warehouse); + } + }, }); diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json index a882a61e5a54..e545b8ea5c3c 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.json @@ -14,6 +14,12 @@ "posting_date", "posting_time", "set_posting_time", + "section_break_8", + "set_warehouse", + "section_break_22", + "scan_barcode", + "column_break_12", + "scan_mode", "sb9", "items", "section_break_9", @@ -139,13 +145,44 @@ { "fieldname": "dimension_col_break", "fieldtype": "Column Break" + }, + { + "fieldname": "section_break_8", + "fieldtype": "Section Break" + }, + { + "fieldname": "scan_barcode", + "fieldtype": "Data", + "label": "Scan Barcode", + "options": "Barcode" + }, + { + "default": "0", + "description": "Disables auto-fetching of existing quantity", + "fieldname": "scan_mode", + "fieldtype": "Check", + "label": "Scan Mode" + }, + { + "fieldname": "set_warehouse", + "fieldtype": "Link", + "label": "Default Warehouse", + "options": "Warehouse" + }, + { + "fieldname": "section_break_22", + "fieldtype": "Section Break" + }, + { + "fieldname": "column_break_12", + "fieldtype": "Column Break" } ], "icon": "fa fa-upload-alt", "idx": 1, "is_submittable": 1, "links": [], - "modified": "2022-02-06 14:28:19.043905", + "modified": "2022-03-27 08:57:47.161959", "modified_by": "Administrator", "module": "Stock", "name": "Stock Reconciliation", From f83a1c19891c76e32757124df209995156158c19 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 2 Apr 2022 13:22:36 +0530 Subject: [PATCH 21/23] fix: dont reset barcode in scan mode --- .../doctype/stock_reconciliation/stock_reconciliation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js index 3e8ac1f19f89..05dd105d99d2 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -226,7 +226,7 @@ frappe.ui.form.on("Stock Reconciliation Item", { warehouse: function(frm, cdt, cdn) { var child = locals[cdt][cdn]; - if (child.batch_no) { + if (child.batch_no && !frm.doc.scan_mode) { frappe.model.set_value(child.cdt, child.cdn, "batch_no", ""); } @@ -235,7 +235,7 @@ frappe.ui.form.on("Stock Reconciliation Item", { item_code: function(frm, cdt, cdn) { var child = locals[cdt][cdn]; - if (child.batch_no) { + if (child.batch_no && !frm.doc.scan_mode) { frappe.model.set_value(cdt, cdn, "batch_no", ""); } From deca1aaf063a3a13404ddc7639e14a0a7bf55ff8 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 2 Apr 2022 13:24:37 +0530 Subject: [PATCH 22/23] fix: dont fetch qty in reco if batch is required --- .../stock_reconciliation.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 07a8566d4a4d..5d5a27f1eab2 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -1,6 +1,7 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt +from typing import Optional import frappe from frappe import _, msgprint @@ -706,29 +707,43 @@ def get_itemwise_batch(warehouse, posting_date, company, item_code=None): @frappe.whitelist() def get_stock_balance_for( - item_code, warehouse, posting_date, posting_time, batch_no=None, with_valuation_rate=True + item_code: str, + warehouse: str, + posting_date: str, + posting_time: str, + batch_no: Optional[str] = None, + with_valuation_rate: bool = True, ): frappe.has_permission("Stock Reconciliation", "write", throw=True) - item_dict = frappe.db.get_value("Item", item_code, ["has_serial_no", "has_batch_no"], as_dict=1) + item_dict = frappe.get_cached_value( + "Item", item_code, ["has_serial_no", "has_batch_no"], as_dict=1 + ) if not item_dict: # In cases of data upload to Items table msg = _("Item {} does not exist.").format(item_code) frappe.throw(msg, title=_("Missing")) - serial_nos = "" - with_serial_no = True if item_dict.get("has_serial_no") else False + serial_nos = None + has_serial_no = bool(item_dict.get("has_serial_no")) + has_batch_no = bool(item_dict.get("has_batch_no")) + + if not batch_no and has_batch_no: + # Not enough information to fetch data + return {"qty": 0, "rate": 0, "serial_nos": None} + + # TODO: fetch only selected batch's values data = get_stock_balance( item_code, warehouse, posting_date, posting_time, with_valuation_rate=with_valuation_rate, - with_serial_no=with_serial_no, + with_serial_no=has_serial_no, ) - if with_serial_no: + if has_serial_no: qty, rate, serial_nos = data else: qty, rate = data From e8118fcdf12bd98ff3b2cea67f6aafe6cc11cc4f Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Sat, 2 Apr 2022 13:48:35 +0530 Subject: [PATCH 23/23] fix: doctype layout based on expected tab-order --- .../stock_reconciliation_item.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json b/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json index 6bbba051f985..79c2fcc252c0 100644 --- a/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json +++ b/erpnext/stock/doctype/stock_reconciliation_item/stock_reconciliation_item.json @@ -16,15 +16,15 @@ "amount", "allow_zero_valuation_rate", "serial_no_and_batch_section", - "serial_no", - "column_break_11", "batch_no", + "column_break_11", + "serial_no", "section_break_3", "current_qty", - "current_serial_no", + "current_amount", "column_break_9", "current_valuation_rate", - "current_amount", + "current_serial_no", "section_break_14", "quantity_difference", "column_break_16", @@ -181,7 +181,7 @@ ], "istable": 1, "links": [], - "modified": "2021-05-21 12:13:33.041266", + "modified": "2022-04-02 04:19:40.380587", "modified_by": "Administrator", "module": "Stock", "name": "Stock Reconciliation Item", @@ -190,5 +190,6 @@ "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file