From 801029e055825df797a48c188e3130d4cc7fd091 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 17 Nov 2016 00:14:21 +0530 Subject: [PATCH] Added item groups, customer groups in the POS profile. --- .../doctype/pos_customer_group/__init__.py | 0 .../pos_customer_group.json | 66 +++++++++ .../pos_customer_group/pos_customer_group.py | 10 ++ .../doctype/pos_item_group/__init__.py | 0 .../pos_item_group/pos_item_group.json | 66 +++++++++ .../doctype/pos_item_group/pos_item_group.py | 10 ++ .../doctype/pos_profile/pos_profile.js | 24 +++ .../doctype/pos_profile/pos_profile.json | 140 ++++++++++++++---- .../doctype/pos_profile/pos_profile.py | 11 ++ erpnext/accounts/doctype/sales_invoice/pos.py | 35 +++-- erpnext/accounts/page/pos/pos.js | 4 +- 11 files changed, 322 insertions(+), 44 deletions(-) create mode 100644 erpnext/accounts/doctype/pos_customer_group/__init__.py create mode 100644 erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json create mode 100644 erpnext/accounts/doctype/pos_customer_group/pos_customer_group.py create mode 100644 erpnext/accounts/doctype/pos_item_group/__init__.py create mode 100644 erpnext/accounts/doctype/pos_item_group/pos_item_group.json create mode 100644 erpnext/accounts/doctype/pos_item_group/pos_item_group.py diff --git a/erpnext/accounts/doctype/pos_customer_group/__init__.py b/erpnext/accounts/doctype/pos_customer_group/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json b/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json new file mode 100644 index 0000000000..4f6a675fb6 --- /dev/null +++ b/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.json @@ -0,0 +1,66 @@ +{ + "allow_copy": 0, + "allow_import": 0, + "allow_rename": 0, + "beta": 0, + "creation": "2016-11-16 15:27:16.413449", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "customer_group", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 1, + "label": "Customer Group", + "length": 0, + "no_copy": 0, + "options": "Customer Group", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + } + ], + "hide_heading": 0, + "hide_toolbar": 0, + "idx": 0, + "image_view": 0, + "in_create": 0, + "in_dialog": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2016-11-16 15:27:25.730507", + "modified_by": "Administrator", + "module": "Accounts", + "name": "POS Customer Group", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "sort_field": "modified", + "sort_order": "DESC", + "track_seen": 0 +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.py b/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.py new file mode 100644 index 0000000000..85c1c9f8dd --- /dev/null +++ b/erpnext/accounts/doctype/pos_customer_group/pos_customer_group.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class POSCustomerGroup(Document): + pass diff --git a/erpnext/accounts/doctype/pos_item_group/__init__.py b/erpnext/accounts/doctype/pos_item_group/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/accounts/doctype/pos_item_group/pos_item_group.json b/erpnext/accounts/doctype/pos_item_group/pos_item_group.json new file mode 100644 index 0000000000..b278765234 --- /dev/null +++ b/erpnext/accounts/doctype/pos_item_group/pos_item_group.json @@ -0,0 +1,66 @@ +{ + "allow_copy": 0, + "allow_import": 0, + "allow_rename": 0, + "beta": 0, + "creation": "2016-11-16 15:26:47.706713", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "item_group", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 1, + "label": "Item Group", + "length": 0, + "no_copy": 0, + "options": "Item Group", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + } + ], + "hide_heading": 0, + "hide_toolbar": 0, + "idx": 0, + "image_view": 0, + "in_create": 0, + "in_dialog": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2016-11-16 15:27:32.263630", + "modified_by": "Administrator", + "module": "Accounts", + "name": "POS Item Group", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "sort_field": "modified", + "sort_order": "DESC", + "track_seen": 0 +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/pos_item_group/pos_item_group.py b/erpnext/accounts/doctype/pos_item_group/pos_item_group.py new file mode 100644 index 0000000000..ceaa57ba60 --- /dev/null +++ b/erpnext/accounts/doctype/pos_item_group/pos_item_group.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class POSItemGroup(Document): + pass diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.js b/erpnext/accounts/doctype/pos_profile/pos_profile.js index c1aa0c3cb5..bbbab73e1c 100755 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.js +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.js @@ -26,6 +26,30 @@ frappe.ui.form.on("POS Profile", "onload", function(frm) { }); }); +frappe.ui.form.on("POS Profile", { + setup: function(frm) { + frm.trigger("get_query_for_groups") + }, + + get_query_for_groups: function(frm) { + frm.fields_dict['item_groups'].grid.get_field('item_group').get_query = function(frm, cdt, cdn) { + return{ + filters: { + 'is_group': 0 + } + } + } + + frm.fields_dict['customer_groups'].grid.get_field('customer_group').get_query = function(frm, cdt, cdn) { + return{ + filters: { + 'is_group': 0 + } + } + } + } +}) + // Income Account // -------------------------------- cur_frm.fields_dict['income_account'].get_query = function(doc,cdt,cdn) { diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json index f450121817..e6cfd7409b 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.json +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json @@ -375,6 +375,114 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "section_break_14", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "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_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "item_groups", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Item Groups", + "length": 0, + "no_copy": 0, + "options": "POS Item Group", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "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_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "column_break_16", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "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_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fieldname": "customer_groups", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Customer Groups", + "length": 0, + "no_copy": 0, + "options": "POS Customer Group", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "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_on_submit": 0, "bold": 0, @@ -543,34 +651,6 @@ "set_only_once": 0, "unique": 0 }, - { - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fieldname": "customer_group", - "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_list_view": 0, - "label": "Customer Group", - "length": 0, - "no_copy": 0, - "options": "Customer Group", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "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_on_submit": 0, "bold": 0, @@ -951,8 +1031,8 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-11-03 15:53:33.820428", - "modified_by": "Administrator", + "modified": "2016-11-17 00:20:51.377850", + "modified_by": "rohit@erpnext.com", "module": "Accounts", "name": "POS Profile", "owner": "Administrator", diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.py b/erpnext/accounts/doctype/pos_profile/pos_profile.py index 5f4d5bc75d..ef497bfe29 100644 --- a/erpnext/accounts/doctype/pos_profile/pos_profile.py +++ b/erpnext/accounts/doctype/pos_profile/pos_profile.py @@ -13,6 +13,7 @@ class POSProfile(Document): def validate(self): self.check_for_duplicate() self.validate_all_link_fields() + self.validate_duplicate_groups() def check_for_duplicate(self): res = frappe.db.sql("""select name, user from `tabPOS Profile` @@ -37,6 +38,16 @@ class POSProfile(Document): "company": self.company, "name": link_dn}): frappe.throw(_("{0} does not belong to Company {1}").format(link_dn, self.company)) + def validate_duplicate_groups(self): + item_groups = [d.item_group for d in self.item_groups] + customer_groups = [d.customer_group for d in self.customer_groups] + + if len(item_groups) != len(set(item_groups)): + frappe.throw(_("Duplicate item group found in the item group table"), title = "Duplicate Item Group") + + if len(customer_groups) != len(set(customer_groups)): + frappe.throw(_("Duplicate customer group found in the cutomer group table"), title = "Duplicate Customer Group") + def before_save(self): set_account_for_mode_of_payment(self) diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py index 1d1a122011..ec30cb00a7 100644 --- a/erpnext/accounts/doctype/sales_invoice/pos.py +++ b/erpnext/accounts/doctype/sales_invoice/pos.py @@ -31,7 +31,7 @@ def get_pos_data(): 'doc': doc, 'default_customer': pos_profile.get('customer'), 'items': get_items(doc, pos_profile), - 'customers': get_customers(pos_profile, doc, company_data.default_currency), + 'customers': get_customers_list(pos_profile), 'pricing_rules': get_pricing_rules(doc), 'print_template': print_template, 'meta': { @@ -106,7 +106,7 @@ def update_tax_table(doc): def get_items(doc, pos_profile): item_list = [] - for item in frappe.get_all("Item", fields=["*"], filters={'disabled': 0, 'has_variants': 0, 'is_sales_item': 1}): + for item in get_items_list(pos_profile): item_doc = frappe.get_doc('Item', item.name) if item_doc.taxes: item.taxes = json.dumps(dict(([d.tax_type, d.tax_rate] for d in @@ -129,6 +129,26 @@ def get_items(doc, pos_profile): return item_list +def get_items_list(pos_profile): + cond = "1=1" + item_groups = [] + if pos_profile.get('item_groups'): + cond = "item_group in (%s)"%(', '.join(['%s']*len(pos_profile.get('item_groups')))) + item_groups = [d.item_group for d in pos_profile.get('item_groups')] + + return frappe.db.sql(""" select * from tabItem where disabled = 0 and has_variants = 0 + and is_sales_item = 1 and {cond}""".format(cond=cond), tuple(item_groups), as_dict=1) or [] + +def get_customers_list(pos_profile): + cond = "1=1" + customer_groups = [] + if pos_profile.get('customer_groups'): + cond = "customer_group in (%s)"%(', '.join(['%s']*len(pos_profile.get('customer_groups')))) + customer_groups = [d.customer_group for d in pos_profile.get('customer_groups')] + + return frappe.db.sql(""" select * from tabCustomer where disabled = 0 + and {cond}""".format(cond=cond), tuple(customer_groups), as_dict=1) or {} + def get_item_warehouse_for_company(company, warehouse): if frappe.db.get_value('Warehouse', warehouse, 'company') != company: warehouse = None @@ -149,17 +169,6 @@ def get_serial_nos(item, pos_profile, company): return serial_no_list -def get_customers(pos_profile, doc, company_currency): - filters = {'disabled': 0} - customer_list = [] - customers = frappe.get_all("Customer", fields=["*"], filters = filters) - - for customer in customers: - customer_currency = get_party_account_currency('Customer', customer.name, doc.company) or doc.currency - if customer_currency == doc.currency or customer_currency == company_currency: - customer_list.append(customer) - return customer_list - def get_pricing_rules(doc): pricing_rules = "" if doc.ignore_pricing_rule == 0: diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js index 32e9b3ab60..cfc95821e2 100644 --- a/erpnext/accounts/page/pos/pos.js +++ b/erpnext/accounts/page/pos/pos.js @@ -387,7 +387,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ var $wrap = me.wrapper.find(".item-list"); me.wrapper.find(".item-list").empty(); - if (this.items) { + if (this.items.length > 0) { $.each(this.items, function(index, obj) { if(index < 30){ $(frappe.render_template("pos_item", { @@ -400,6 +400,8 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ })).tooltip().appendTo($wrap); } }); + } else { + $("

Searching record not found.

").appendTo($wrap) } if(this.items.length == 1