blob: e1f3d00157f16bcdd40bdf1d0d5c5f7041600a95 [file] [log] [blame]
Rushabh Mehtafe027b32016-03-28 13:21:43 +05301# Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and Contributors
2# See license.txt
3
4from __future__ import unicode_literals
5
6from frappe.utils.bot import BotParser
7
8import frappe
9from frappe import _
10
11class FindItemBot(BotParser):
12 def get_reply(self):
13 if self.startswith('where is', 'find item', 'locate'):
14 item = '%{0}%'.format(self.strip_words(self.query, 'where is', 'find item', 'locate'))
15 items = frappe.db.sql('''select name from `tabItem` where item_code like %(txt)s
16 or item_name like %(txt)s or description like %(txt)s''', dict(txt=item))
17
18 if items:
19 out = []
20 warehouses = frappe.get_all("Warehouse")
21 for item in items:
22 found = False
23 for warehouse in warehouses:
24 qty = frappe.db.get_value("Bin", {'item_code': item[0], 'warehouse': warehouse.name}, 'actual_qty')
25 if qty:
26 out.append(_('{0} units of [{1}](#Form/Item/{1}) found in [{2}](#Form/Warehouse/{2})').format(qty,
27 item[0], warehouse.name))
28 found = True
29
30 if not found:
31 out.append(_('[{0}](#Form/Item/{0}) is out of stock').format(item[0]))
32
33 return "\n\n".join(out)
34
35 else:
36 return _("Did not find any item called {0}".format(item))