brotherton-erpnext/erpnext/utilities/bot.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.3 KiB
Python
Raw Normal View History

2016-03-28 07:51:43 +00:00
# Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt
from __future__ import unicode_literals
from frappe.utils.bot import BotParser
import frappe
from frappe import _
class FindItemBot(BotParser):
def get_reply(self):
if self.startswith('where is', 'find item', 'locate'):
2016-03-29 06:23:07 +00:00
if not frappe.has_permission('Warehouse'):
raise frappe.PermissionError
2016-03-28 07:51:43 +00:00
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:
2020-11-18 09:30:34 +00:00
out.append(_('{0} units of [{1}](/app/Form/Item/{1}) found in [{2}](/app/Form/Warehouse/{2})').format(qty,
2016-03-28 07:51:43 +00:00
item[0], warehouse.name))
found = True
if not found:
2020-11-18 09:30:34 +00:00
out.append(_('[{0}](/app/Form/Item/{0}) is out of stock').format(item[0]))
2016-03-28 07:51:43 +00:00
return "\n\n".join(out)
else:
2020-01-29 09:36:18 +00:00
return _("Did not find any item called {0}").format(item)