diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index c71ea3648b..2610c8655e 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -322,9 +322,9 @@ def get_parent_account(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql( """select name from tabAccount where is_group = 1 and docstatus != 2 and company = %s - and %s like %s order by name limit %s, %s""" + and %s like %s order by name limit %s offset %s""" % ("%s", searchfield, "%s", "%s", "%s"), - (filters["company"], "%%%s%%" % txt, start, page_len), + (filters["company"], "%%%s%%" % txt, page_len, start), as_list=1, ) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 145118957b..8f0fe51e3d 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -1239,7 +1239,7 @@ def get_against_jv(doctype, txt, searchfield, start, page_len, filters): AND jv.docstatus = 1 AND jv.`{0}` LIKE %(txt)s ORDER BY jv.name DESC - LIMIT %(offset)s, %(limit)s + LIMIT %(limit)s offset %(offset)s """.format( searchfield ), diff --git a/erpnext/accounts/doctype/payment_order/payment_order.py b/erpnext/accounts/doctype/payment_order/payment_order.py index 3c45d20770..ff9615d14f 100644 --- a/erpnext/accounts/doctype/payment_order/payment_order.py +++ b/erpnext/accounts/doctype/payment_order/payment_order.py @@ -39,7 +39,7 @@ def get_mop_query(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql( """ select mode_of_payment from `tabPayment Order Reference` where parent = %(parent)s and mode_of_payment like %(txt)s - limit %(start)s, %(page_len)s""", + limit %(page_len)s offset %(start)s""", {"parent": filters.get("parent"), "start": start, "page_len": page_len, "txt": "%%%s%%" % txt}, ) @@ -51,7 +51,7 @@ def get_supplier_query(doctype, txt, searchfield, start, page_len, filters): """ select supplier from `tabPayment Order Reference` where parent = %(parent)s and supplier like %(txt)s and (payment_reference is null or payment_reference='') - limit %(start)s, %(page_len)s""", + limit %(page_len)s offset %(start)s""", {"parent": filters.get("parent"), "start": start, "page_len": page_len, "txt": "%%%s%%" % txt}, ) diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py index e83dc0f11e..e8aee737f2 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -173,7 +173,7 @@ def pos_profile_query(doctype, txt, searchfield, start, page_len, filters): where pfu.parent = pf.name and pfu.user = %(user)s and pf.company = %(company)s and (pf.name like %(txt)s) - and pf.disabled = 0 limit %(start)s, %(page_len)s""", + and pf.disabled = 0 limit %(page_len)s offset %(start)s""", args, ) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index f4a44bd362..e39f22b4cf 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -211,7 +211,7 @@ def set_address_details( else: party_details.update(get_company_address(company)) - if doctype and doctype in ["Delivery Note", "Sales Invoice", "Sales Order"]: + if doctype and doctype in ["Delivery Note", "Sales Invoice", "Sales Order", "Quotation"]: if party_details.company_address: party_details.update( get_fetch_values(doctype, "company_address", party_details.company_address) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index dd10c93b1d..6cf5837d8b 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -197,7 +197,7 @@ class PurchaseOrder(BuyingController): if not item.fg_item: frappe.throw( _("Row #{0}: Finished Good Item is not specified for service item {1}").format( - item.idx, item.item_code + item.idx, item.item_code ) ) else: diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py index d39aec19ba..67affe770f 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -285,7 +285,7 @@ def get_supplier_contacts(doctype, txt, searchfield, start, page_len, filters): """select `tabContact`.name from `tabContact`, `tabDynamic Link` where `tabDynamic Link`.link_doctype = 'Supplier' and (`tabDynamic Link`.link_name=%(name)s and `tabDynamic Link`.link_name like %(txt)s) and `tabContact`.name = `tabDynamic Link`.parent - limit %(start)s, %(page_len)s""", + limit %(page_len)s offset %(start)s""", {"start": start, "page_len": page_len, "txt": "%%%s%%" % txt, "name": filters.get("supplier")}, ) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index eeb5a7f1a9..1497b182e5 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -33,7 +33,7 @@ def employee_query(doctype, txt, searchfield, start, page_len, filters): if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999), idx desc, name, employee_name - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( **{ "fields": ", ".join(fields), "key": searchfield, @@ -65,7 +65,7 @@ def lead_query(doctype, txt, searchfield, start, page_len, filters): if(locate(%(_txt)s, company_name), locate(%(_txt)s, company_name), 99999), idx desc, name, lead_name - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( **{"fields": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)} ), {"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len}, @@ -100,7 +100,7 @@ def customer_query(doctype, txt, searchfield, start, page_len, filters): if(locate(%(_txt)s, customer_name), locate(%(_txt)s, customer_name), 99999), idx desc, name, customer_name - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( **{ "fields": ", ".join(fields), "scond": searchfields, @@ -137,7 +137,7 @@ def supplier_query(doctype, txt, searchfield, start, page_len, filters): if(locate(%(_txt)s, supplier_name), locate(%(_txt)s, supplier_name), 99999), idx desc, name, supplier_name - limit %(start)s, %(page_len)s """.format( + limit %(page_len)s offset %(start)s""".format( **{"field": ", ".join(fields), "key": searchfield, "mcond": get_match_cond(doctype)} ), {"txt": "%%%s%%" % txt, "_txt": txt.replace("%", ""), "start": start, "page_len": page_len}, @@ -167,7 +167,7 @@ def tax_account_query(doctype, txt, searchfield, start, page_len, filters): AND `{searchfield}` LIKE %(txt)s {mcond} ORDER BY idx DESC, name - LIMIT %(offset)s, %(limit)s + LIMIT %(limit)s offset %(offset)s """.format( account_type_condition=account_type_condition, searchfield=searchfield, @@ -351,7 +351,7 @@ def get_project_name(doctype, txt, searchfield, start, page_len, filters): if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999), idx desc, `tabProject`.name asc - limit {start}, {page_len}""".format( + limit {page_len} offset {start}""".format( fields=", ".join(["`tabProject`.{0}".format(f) for f in fields]), cond=cond, scond=searchfields, @@ -383,7 +383,7 @@ def get_delivery_notes_to_be_billed(doctype, txt, searchfield, start, page_len, and return_against in (select name from `tabDelivery Note` where per_billed < 100) ) ) - %(mcond)s order by `tabDelivery Note`.`%(key)s` asc limit %(start)s, %(page_len)s + %(mcond)s order by `tabDelivery Note`.`%(key)s` asc limit %(page_len)s offset %(start)s """ % { "fields": ", ".join(["`tabDelivery Note`.{0}".format(f) for f in fields]), @@ -456,7 +456,7 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters): {match_conditions} group by batch_no {having_clause} order by batch.expiry_date, sle.batch_no desc - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( search_columns=search_columns, cond=cond, match_conditions=get_match_cond(doctype), @@ -483,7 +483,7 @@ def get_batch_no(doctype, txt, searchfield, start, page_len, filters): {match_conditions} order by expiry_date, name desc - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( cond, search_columns=search_columns, search_cond=search_cond, @@ -662,7 +662,7 @@ def warehouse_query(doctype, txt, searchfield, start, page_len, filters): {fcond} {mcond} order by ifnull(`tabBin`.actual_qty, 0) desc limit - {start}, {page_len} + {page_len} offset {start} """.format( bin_conditions=get_filters_cond( doctype, filter_dict.get("Bin"), bin_conditions, ignore_permissions=True diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 3c0a10e086..517e080c97 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -35,7 +35,8 @@ status_map = { ["Draft", None], ["Open", "eval:self.docstatus==1"], ["Lost", "eval:self.status=='Lost'"], - ["Ordered", "has_sales_order"], + ["Partially Ordered", "is_partially_ordered"], + ["Ordered", "is_fully_ordered"], ["Cancelled", "eval:self.docstatus==2"], ], "Sales Order": [ diff --git a/erpnext/controllers/tests/test_subcontracting_controller.py b/erpnext/controllers/tests/test_subcontracting_controller.py index cbdd191102..4ef3d649df 100644 --- a/erpnext/controllers/tests/test_subcontracting_controller.py +++ b/erpnext/controllers/tests/test_subcontracting_controller.py @@ -724,6 +724,57 @@ class TestSubcontractingController(FrappeTestCase): self.assertEqual(value.qty, details.qty) self.assertEqual(value.batch_no, details.batch_no) + def test_sco_supplied_qty(self): + """ + Check if 'Supplied Qty' in SCO's Supplied Items table is reset on submit/cancel. + """ + set_backflush_based_on("Material Transferred for Subcontract") + service_items = [ + { + "warehouse": "_Test Warehouse - _TC", + "item_code": "Subcontracted Service Item 1", + "qty": 5, + "rate": 100, + "fg_item": "Subcontracted Item SA1", + "fg_item_qty": 5, + }, + { + "warehouse": "_Test Warehouse - _TC", + "item_code": "Subcontracted Service Item 5", + "qty": 6, + "rate": 100, + "fg_item": "Subcontracted Item SA5", + "fg_item_qty": 6, + }, + ] + sco = get_subcontracting_order(service_items=service_items) + rm_items = [ + {"item_code": "Subcontracted SRM Item 1", "qty": 5, "main_item_code": "Subcontracted Item SA1"}, + {"item_code": "Subcontracted SRM Item 2", "qty": 5, "main_item_code": "Subcontracted Item SA1"}, + {"item_code": "Subcontracted SRM Item 3", "qty": 5, "main_item_code": "Subcontracted Item SA1"}, + {"item_code": "Subcontracted SRM Item 5", "qty": 6, "main_item_code": "Subcontracted Item SA5"}, + {"item_code": "Subcontracted SRM Item 4", "qty": 6, "main_item_code": "Subcontracted Item SA5"}, + ] + itemwise_details = make_stock_in_entry(rm_items=rm_items) + + for item in rm_items: + item["sco_rm_detail"] = sco.items[0].name if item.get("qty") == 5 else sco.items[1].name + + se = make_stock_transfer_entry( + sco_no=sco.name, + rm_items=rm_items, + itemwise_details=copy.deepcopy(itemwise_details), + ) + + sco.reload() + for item in sco.get("supplied_items"): + self.assertIn(item.supplied_qty, [5.0, 6.0]) + + se.cancel() + sco.reload() + for item in sco.get("supplied_items"): + self.assertEqual(item.supplied_qty, 0.0) + def add_second_row_in_scr(scr): item_dict = {} diff --git a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py index 3fe2198966..da283435b9 100644 --- a/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py +++ b/erpnext/manufacturing/report/bom_variance_report/bom_variance_report.py @@ -102,7 +102,7 @@ def get_work_orders(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql( """select name from `tabWork Order` where name like %(name)s and {0} and produced_qty > qty and docstatus = 1 - order by name limit {1}, {2}""".format( + order by name limit {2} offset {1}""".format( cond, start, page_len ), {"name": "%%%s%%" % txt}, diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index 620fcadceb..1524fb7c9e 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -970,7 +970,7 @@ def get_payroll_entries_for_jv(doctype, txt, searchfield, start, page_len, filte and name not in (select reference_name from `tabJournal Entry Account` where reference_type="Payroll Entry") - order by name limit %(start)s, %(page_len)s""".format( + order by name limit %(page_len)s offset %(start)s""".format( key=searchfield ), {"txt": "%%%s%%" % txt, "start": start, "page_len": page_len}, @@ -1039,7 +1039,7 @@ def employee_query(doctype, txt, searchfield, start, page_len, filters): if(locate(%(_txt)s, employee_name), locate(%(_txt)s, employee_name), 99999), idx desc, name, employee_name - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( **{ "key": searchfield, "fcond": get_filters_cond(doctype, filters, conditions), diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py index 8a8e1d1bf5..c613fe633d 100644 --- a/erpnext/projects/doctype/project/project.py +++ b/erpnext/projects/doctype/project/project.py @@ -391,7 +391,7 @@ def get_users_for_project(doctype, txt, searchfield, start, page_len, filters): if(locate(%(_txt)s, full_name), locate(%(_txt)s, full_name), 99999), idx desc, name, full_name - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( **{ "key": searchfield, "fcond": get_filters_cond(doctype, filters, conditions), diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 4575fb544c..0e409fce9c 100755 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -288,7 +288,7 @@ def get_project(doctype, txt, searchfield, start, page_len, filters): %(mcond)s {search_condition} order by name - limit %(start)s, %(page_len)s""".format( + limit %(page_len)s offset %(start)s""".format( search_columns=search_columns, search_condition=search_cond ), { diff --git a/erpnext/projects/doctype/timesheet/timesheet.py b/erpnext/projects/doctype/timesheet/timesheet.py index 2ef966b319..88d5beef17 100644 --- a/erpnext/projects/doctype/timesheet/timesheet.py +++ b/erpnext/projects/doctype/timesheet/timesheet.py @@ -328,7 +328,7 @@ def get_timesheet(doctype, txt, searchfield, start, page_len, filters): ts.status in ('Submitted', 'Payslip') and tsd.parent = ts.name and tsd.docstatus = 1 and ts.total_billable_amount > 0 and tsd.parent LIKE %(txt)s {condition} - order by tsd.parent limit %(start)s, %(page_len)s""".format( + order by tsd.parent limit %(page_len)s offset %(start)s""".format( condition=condition ), { @@ -515,7 +515,7 @@ def get_timesheets_list( tsd.project IN %(projects)s ) ORDER BY `end_date` ASC - LIMIT {0}, {1} + LIMIT {1} offset {0} """.format( limit_start, limit_page_length ), diff --git a/erpnext/projects/utils.py b/erpnext/projects/utils.py index 000ea66275..3cc4da4f07 100644 --- a/erpnext/projects/utils.py +++ b/erpnext/projects/utils.py @@ -25,7 +25,7 @@ def query_task(doctype, txt, searchfield, start, page_len, filters): case when `%s` like %s then 0 else 1 end, `%s`, subject - limit %s, %s""" + limit %s offset %s""" % (searchfield, "%s", "%s", match_conditions, "%s", searchfield, "%s", searchfield, "%s", "%s"), - (search_string, search_string, order_by_string, order_by_string, start, page_len), + (search_string, search_string, order_by_string, order_by_string, page_len, start), ) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index ee48ccb24a..0262469571 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -287,7 +287,7 @@ def get_regional_address_details(party_details, doctype, company): return party_details if ( - doctype in ("Sales Invoice", "Delivery Note", "Sales Order") + doctype in ("Sales Invoice", "Delivery Note", "Sales Order", "Quotation") and party_details.company_gstin and party_details.company_gstin[:2] != party_details.place_of_supply[:2] ) or ( diff --git a/erpnext/selling/doctype/product_bundle/product_bundle.py b/erpnext/selling/doctype/product_bundle/product_bundle.py index 575b956686..ac83c0f046 100644 --- a/erpnext/selling/doctype/product_bundle/product_bundle.py +++ b/erpnext/selling/doctype/product_bundle/product_bundle.py @@ -78,7 +78,7 @@ def get_new_item_code(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql( """select name, item_name, description from tabItem where is_stock_item=0 and name not in (select name from `tabProduct Bundle`) - and %s like %s %s limit %s, %s""" + and %s like %s %s limit %s offset %s""" % (searchfield, "%s", get_match_cond(doctype), "%s", "%s"), - ("%%%s%%" % txt, start, page_len), + ("%%%s%%" % txt, page_len, start), ) diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 34e9a52e11..70ae085051 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -20,6 +20,20 @@ frappe.ui.form.on('Quotation', { frm.set_df_property('packed_items', 'cannot_add_rows', true); frm.set_df_property('packed_items', 'cannot_delete_rows', true); + + frm.set_query('company_address', function(doc) { + if(!doc.company) { + frappe.throw(__('Please set Company')); + } + + return { + query: 'frappe.contacts.doctype.address.address.address_query', + filters: { + link_doctype: 'Company', + link_name: doc.company + } + }; + }); }, refresh: function(frm) { @@ -70,7 +84,7 @@ erpnext.selling.QuotationController = class QuotationController extends erpnext. } } - if(doc.docstatus == 1 && doc.status!=='Lost') { + if(doc.docstatus == 1 && !(['Lost', 'Ordered']).includes(doc.status)) { if(!doc.valid_till || frappe.datetime.get_diff(doc.valid_till, frappe.datetime.get_today()) >= 0) { cur_frm.add_custom_button(__('Sales Order'), cur_frm.cscript['Make Sales Order'], __('Create')); diff --git a/erpnext/selling/doctype/quotation/quotation.json b/erpnext/selling/doctype/quotation/quotation.json index 75443abe49..5dfd8f2965 100644 --- a/erpnext/selling/doctype/quotation/quotation.json +++ b/erpnext/selling/doctype/quotation/quotation.json @@ -897,7 +897,7 @@ "no_copy": 1, "oldfieldname": "status", "oldfieldtype": "Select", - "options": "Draft\nOpen\nReplied\nOrdered\nLost\nCancelled\nExpired", + "options": "Draft\nOpen\nReplied\nPartially Ordered\nOrdered\nLost\nCancelled\nExpired", "print_hide": 1, "read_only": 1, "reqd": 1 @@ -986,7 +986,7 @@ "idx": 82, "is_submittable": 1, "links": [], - "modified": "2022-04-07 11:01:31.157084", + "modified": "2022-06-11 20:35:32.635804", "modified_by": "Administrator", "module": "Selling", "name": "Quotation", diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index 548813ddef..d5fd946bde 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -70,8 +70,32 @@ class Quotation(SellingController): title=_("Unpublished Item"), ) - def has_sales_order(self): - return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1}) + def get_ordered_status(self): + ordered_items = frappe._dict( + frappe.db.get_all( + "Sales Order Item", + {"prevdoc_docname": self.name, "docstatus": 1}, + ["item_code", "sum(qty)"], + group_by="item_code", + as_list=1, + ) + ) + + status = "Open" + if ordered_items: + status = "Ordered" + + for item in self.get("items"): + if item.qty > ordered_items.get(item.item_code, 0.0): + status = "Partially Ordered" + + return status + + def is_fully_ordered(self): + return self.get_ordered_status() == "Ordered" + + def is_partially_ordered(self): + return self.get_ordered_status() == "Partially Ordered" def update_lead(self): if self.quotation_to == "Lead" and self.party_name: diff --git a/erpnext/selling/doctype/quotation/quotation_list.js b/erpnext/selling/doctype/quotation/quotation_list.js index 4c8f9c4f84..32fce1f2ad 100644 --- a/erpnext/selling/doctype/quotation/quotation_list.js +++ b/erpnext/selling/doctype/quotation/quotation_list.js @@ -25,6 +25,8 @@ frappe.listview_settings['Quotation'] = { get_indicator: function(doc) { if(doc.status==="Open") { return [__("Open"), "orange", "status,=,Open"]; + } else if (doc.status==="Partially Ordered") { + return [__("Partially Ordered"), "yellow", "status,=,Partially Ordered"]; } else if(doc.status==="Ordered") { return [__("Ordered"), "green", "status,=,Ordered"]; } else if(doc.status==="Lost") { 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 99afe813cb..13d5069ea6 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -107,7 +107,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te ORDER BY item.name asc LIMIT - {start}, {page_length}""".format( + {page_length} offset {start}""".format( start=start, page_length=page_length, lft=lft, @@ -204,7 +204,7 @@ def item_group_query(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql( """ select distinct name from `tabItem Group` - where {condition} and (name like %(txt)s) limit {start}, {page_len}""".format( + where {condition} and (name like %(txt)s) limit {page_len} offset {start}""".format( condition=cond, start=start, page_len=page_len ), {"txt": "%%%s%%" % txt}, diff --git a/erpnext/setup/doctype/party_type/party_type.py b/erpnext/setup/doctype/party_type/party_type.py index d07ab08450..cf7cba8452 100644 --- a/erpnext/setup/doctype/party_type/party_type.py +++ b/erpnext/setup/doctype/party_type/party_type.py @@ -21,7 +21,7 @@ def get_party_type(doctype, txt, searchfield, start, page_len, filters): return frappe.db.sql( """select name from `tabParty Type` where `{key}` LIKE %(txt)s {cond} - order by name limit %(start)s, %(page_len)s""".format( + order by name limit %(page_len)s offset %(start)s""".format( key=searchfield, cond=cond ), {"txt": "%" + txt + "%", "start": start, "page_len": page_len}, diff --git a/erpnext/stock/doctype/item_alternative/item_alternative.py b/erpnext/stock/doctype/item_alternative/item_alternative.py index 0f93bb9e95..fb1a28d846 100644 --- a/erpnext/stock/doctype/item_alternative/item_alternative.py +++ b/erpnext/stock/doctype/item_alternative/item_alternative.py @@ -77,7 +77,7 @@ def get_alternative_items(doctype, txt, searchfield, start, page_len, filters): union (select item_code from `tabItem Alternative` where alternative_item_code = %(item_code)s and item_code like %(txt)s - and two_way = 1) limit {0}, {1} + and two_way = 1) limit {1} offset {0} """.format( start, page_len ), diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py index e9ccf5fc77..e5b9de8789 100644 --- a/erpnext/stock/doctype/packing_slip/packing_slip.py +++ b/erpnext/stock/doctype/packing_slip/packing_slip.py @@ -203,7 +203,7 @@ def item_details(doctype, txt, searchfield, start, page_len, filters): where name in ( select item_code FROM `tabDelivery Note Item` where parent= %s) and %s like "%s" %s - limit %s, %s """ + limit %s offset %s """ % ("%s", searchfield, "%s", get_match_cond(doctype), "%s", "%s"), - ((filters or {}).get("delivery_note"), "%%%s%%" % txt, start, page_len), + ((filters or {}).get("delivery_note"), "%%%s%%" % txt, page_len, start), ) diff --git a/erpnext/stock/doctype/quality_inspection/quality_inspection.py b/erpnext/stock/doctype/quality_inspection/quality_inspection.py index 331d3e812b..13abfad455 100644 --- a/erpnext/stock/doctype/quality_inspection/quality_inspection.py +++ b/erpnext/stock/doctype/quality_inspection/quality_inspection.py @@ -232,7 +232,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): FROM `tab{doc}` WHERE parent=%(parent)s and docstatus < 2 and item_code like %(txt)s {qi_condition} {cond} {mcond} - ORDER BY item_code limit {start}, {page_len} + ORDER BY item_code limit {page_len} offset {start} """.format( doc=filters.get("from"), cond=cond, @@ -252,7 +252,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters): WHERE name = %(reference_name)s and docstatus < 2 and production_item like %(txt)s {qi_condition} {cond} {mcond} ORDER BY production_item - LIMIT {start}, {page_len} + limit {page_len} offset {start} """.format( doc=filters.get("from"), cond=cond, diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 19f05618a9..6599eddd4a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -2005,24 +2005,30 @@ class StockEntry(StockController): ): # Get SCO Supplied Items Details - parent = frappe.qb.DocType("Subcontracting Order") - child = frappe.qb.DocType("Subcontracting Order Supplied Item") - item_wh = ( - frappe.qb.from_(parent) - .inner_join(child) - .on(parent.name == child.parent) - .select(child.rm_item_code, child.reserve_warehouse) - .where(parent.name == self.subcontracting_order) - ).run(as_list=True) - - item_wh = frappe._dict(item_wh) + sco_supplied_items = frappe.db.get_all( + "Subcontracting Order Supplied Item", + filters={"parent": self.subcontracting_order}, + fields=["name", "rm_item_code", "reserve_warehouse"], + ) + # Get Items Supplied in Stock Entries against SCO supplied_items = get_supplied_items(self.subcontracting_order) - for name, item in supplied_items.items(): - frappe.db.set_value("Subcontracting Order Supplied Item", name, item) - # Update reserved sub contracted quantity in bin based on Supplied Item Details and + for row in sco_supplied_items: + key, item = row.name, {} + if not supplied_items.get(key): + # no stock transferred against SCO Supplied Items row + item = {"supplied_qty": 0, "returned_qty": 0, "total_supplied_qty": 0} + else: + item = supplied_items.get(key) + + frappe.db.set_value("Subcontracting Order Supplied Item", row.name, item) + + # RM Item-Reserve Warehouse Dict + item_wh = {x.get("rm_item_code"): x.get("reserve_warehouse") for x in sco_supplied_items} + for d in self.get("items"): + # Update reserved sub contracted quantity in bin based on Supplied Item Details and item_code = d.get("original_item") or d.get("item_code") reserve_warehouse = item_wh.get(item_code) if not (reserve_warehouse and item_code): diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py index 3ed056f55e..0768cc3fa6 100644 --- a/erpnext/templates/pages/product_search.py +++ b/erpnext/templates/pages/product_search.py @@ -56,7 +56,10 @@ def get_product_data(search=None, start=0, limit=12): search = "%" + cstr(search) + "%" # order by - query += """ ORDER BY ranking desc, modified desc limit %s, %s""" % (cint(start), cint(limit)) + query += """ ORDER BY ranking desc, modified desc limit %s offset %s""" % ( + cint(limit), + cint(start), + ) return frappe.db.sql(query, {"search": search}, as_dict=1) # nosemgrep diff --git a/erpnext/utilities/bot.py b/erpnext/utilities/bot.py deleted file mode 100644 index 5c2e576dd2..0000000000 --- a/erpnext/utilities/bot.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and Contributors -# See license.txt - - -import frappe -from frappe import _ -from frappe.utils.bot import BotParser - - -class FindItemBot(BotParser): - def get_reply(self): - if self.startswith("where is", "find item", "locate"): - if not frappe.has_permission("Warehouse"): - raise frappe.PermissionError - - item = "%{0}%".format(self.strip_words(self.query, "where is", "find item", "locate")) - items = frappe.db.sql( - """select name from `tabItem` where item_code like %(txt)s - or item_name like %(txt)s or description like %(txt)s""", - dict(txt=item), - ) - - if items: - out = [] - warehouses = frappe.get_all("Warehouse") - for item in items: - found = False - for warehouse in warehouses: - qty = frappe.db.get_value( - "Bin", {"item_code": item[0], "warehouse": warehouse.name}, "actual_qty" - ) - if qty: - out.append( - _("{0} units of [{1}](/app/Form/Item/{1}) found in [{2}](/app/Form/Warehouse/{2})").format( - qty, item[0], warehouse.name - ) - ) - found = True - - if not found: - out.append(_("[{0}](/app/Form/Item/{0}) is out of stock").format(item[0])) - - return "\n\n".join(out) - - else: - return _("Did not find any item called {0}").format(item)