Fetch items of item groups defined in the pos profile (#11763)
This commit is contained in:
parent
c43c5cae5a
commit
f591a220c9
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
from frappe.utils import cint, now
|
from frappe.utils import cint, now
|
||||||
|
from erpnext.accounts.doctype.sales_invoice.pos import get_child_nodes
|
||||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import set_account_for_mode_of_payment
|
from erpnext.accounts.doctype.sales_invoice.sales_invoice import set_account_for_mode_of_payment
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
@ -95,6 +96,17 @@ class POSProfile(Document):
|
|||||||
else:
|
else:
|
||||||
frappe.defaults.set_global_default("is_pos", 1)
|
frappe.defaults.set_global_default("is_pos", 1)
|
||||||
|
|
||||||
|
def get_item_groups(pos_profile):
|
||||||
|
item_groups = []
|
||||||
|
pos_profile = frappe.get_doc('POS Profile', pos_profile)
|
||||||
|
|
||||||
|
if pos_profile.get('item_groups'):
|
||||||
|
# Get items based on the item groups defined in the POS profile
|
||||||
|
for data in pos_profile.get('item_groups'):
|
||||||
|
item_groups.extend(["'%s'"%d.name for d in get_child_nodes('Item Group', data.item_group)])
|
||||||
|
|
||||||
|
return list(set(item_groups))
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_series():
|
def get_series():
|
||||||
return frappe.get_meta("Sales Invoice").get_field("naming_series").options or ""
|
return frappe.get_meta("Sales Invoice").get_field("naming_series").options or ""
|
||||||
|
@ -265,6 +265,38 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_bulk_edit": 0,
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"depends_on": "is_pos",
|
||||||
|
"fieldname": "pos_profile",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_global_search": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "POS Profile",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 1,
|
||||||
|
"options": "POS Profile",
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 1,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_bulk_edit": 0,
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -295,37 +327,6 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"allow_bulk_edit": 0,
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"columns": 0,
|
|
||||||
"fieldname": "pos_profile",
|
|
||||||
"fieldtype": "Link",
|
|
||||||
"hidden": 1,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"ignore_xss_filter": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_global_search": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"in_standard_filter": 0,
|
|
||||||
"label": "POS Profile",
|
|
||||||
"length": 0,
|
|
||||||
"no_copy": 0,
|
|
||||||
"options": "POS Profile",
|
|
||||||
"permlevel": 0,
|
|
||||||
"precision": "",
|
|
||||||
"print_hide": 1,
|
|
||||||
"print_hide_if_no_value": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"remember_last_selected_value": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 0,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_bulk_edit": 0,
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -4532,7 +4533,7 @@
|
|||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"menu_index": 0,
|
"menu_index": 0,
|
||||||
"modified": "2017-11-23 12:36:53.731902",
|
"modified": "2017-11-28 19:12:37.795207",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Sales Invoice",
|
"name": "Sales Invoice",
|
||||||
|
@ -1006,6 +1006,14 @@ class POSItems {
|
|||||||
this.filter_items({ item_group: item_group });
|
this.filter_items({ item_group: item_group });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
get_query: () => {
|
||||||
|
return {
|
||||||
|
query: 'erpnext.selling.page.point_of_sale.point_of_sale.item_group_query',
|
||||||
|
filters: {
|
||||||
|
pos_profile: this.frm.doc.pos_profile
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
parent: this.wrapper.find('.item-group-field'),
|
parent: this.wrapper.find('.item-group-field'),
|
||||||
render_input: true
|
render_input: true
|
||||||
@ -1174,7 +1182,8 @@ class POSItems {
|
|||||||
page_length,
|
page_length,
|
||||||
'price_list': this.frm.doc.selling_price_list,
|
'price_list': this.frm.doc.selling_price_list,
|
||||||
item_group,
|
item_group,
|
||||||
search_value
|
search_value,
|
||||||
|
'pos_profile': this.frm.doc.pos_profile
|
||||||
}
|
}
|
||||||
}).then(r => {
|
}).then(r => {
|
||||||
// const { items, serial_no, batch_no } = r.message;
|
// const { items, serial_no, batch_no } = r.message;
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, json
|
import frappe, json
|
||||||
from frappe.utils.nestedset import get_root_of
|
from frappe.utils.nestedset import get_root_of
|
||||||
|
from erpnext.accounts.doctype.pos_profile.pos_profile import get_item_groups
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_items(start, page_length, price_list, item_group, search_value=""):
|
def get_items(start, page_length, price_list, item_group, search_value="", pos_profile=None):
|
||||||
serial_no = ""
|
serial_no = ""
|
||||||
batch_no = ""
|
batch_no = ""
|
||||||
barcode = ""
|
barcode = ""
|
||||||
@ -33,6 +34,9 @@ def get_items(start, page_length, price_list, item_group, search_value=""):
|
|||||||
|
|
||||||
item_code, condition = get_conditions(item_code, serial_no, batch_no, barcode)
|
item_code, condition = get_conditions(item_code, serial_no, batch_no, barcode)
|
||||||
|
|
||||||
|
if pos_profile:
|
||||||
|
condition += get_item_group_condition(pos_profile)
|
||||||
|
|
||||||
lft, rgt = frappe.db.get_value('Item Group', item_group, ['lft', 'rgt'])
|
lft, rgt = frappe.db.get_value('Item Group', item_group, ['lft', 'rgt'])
|
||||||
# locate function is used to sort by closest match from the beginning of the value
|
# locate function is used to sort by closest match from the beginning of the value
|
||||||
res = frappe.db.sql("""select i.name as item_code, i.item_name, i.image as item_image,
|
res = frappe.db.sql("""select i.name as item_code, i.item_name, i.image as item_image,
|
||||||
@ -95,3 +99,28 @@ def submit_invoice(doc):
|
|||||||
doc.submit()
|
doc.submit()
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
def get_item_group_condition(pos_profile):
|
||||||
|
cond = "and 1=1"
|
||||||
|
item_groups = get_item_groups(pos_profile)
|
||||||
|
if item_groups:
|
||||||
|
cond = "and i.item_group in (%s)"%(', '.join(['%s']*len(item_groups)))
|
||||||
|
|
||||||
|
return cond % tuple(item_groups)
|
||||||
|
|
||||||
|
def item_group_query(doctype, txt, searchfield, start, page_len, filters):
|
||||||
|
item_groups = []
|
||||||
|
cond = "1=1"
|
||||||
|
pos_profile= filters.get('pos_profile')
|
||||||
|
|
||||||
|
if pos_profile:
|
||||||
|
item_groups = get_item_groups(pos_profile)
|
||||||
|
|
||||||
|
if item_groups:
|
||||||
|
cond = "name in (%s)"%(', '.join(['%s']*len(item_groups)))
|
||||||
|
cond = cond % tuple(item_groups)
|
||||||
|
|
||||||
|
return frappe.db.sql(""" select distinct name from `tabItem Group`
|
||||||
|
where {condition} and (name like %(txt)s) limit {start}, {page_len}"""
|
||||||
|
.format(condition = cond, start=start, page_len= page_len),
|
||||||
|
{'txt': '%%%s%%' % txt})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user