Add online, offline option, fix search

This commit is contained in:
Faris Ansari 2017-08-29 15:27:17 +05:30
parent 655f86d5e2
commit c70bbacd34
5 changed files with 80 additions and 40 deletions

View File

@ -18,8 +18,9 @@
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"fieldname": "type_of_pos", "default": "0",
"fieldtype": "Select", "fieldname": "is_online",
"fieldtype": "Check",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
@ -27,10 +28,10 @@
"in_global_search": 0, "in_global_search": 0,
"in_list_view": 0, "in_list_view": 0,
"in_standard_filter": 0, "in_standard_filter": 0,
"label": "Type of POS", "label": "Online",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Online\nOffline", "options": "",
"permlevel": 0, "permlevel": 0,
"precision": "", "precision": "",
"print_hide": 0, "print_hide": 0,
@ -54,7 +55,7 @@
"issingle": 1, "issingle": 1,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2017-08-28 16:46:41.732676", "modified": "2017-08-29 14:34:36.166049",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "POS Settings", "name": "POS Settings",

View File

@ -7,10 +7,4 @@ import frappe
from frappe.model.document import Document from frappe.model.document import Document
class POSSettings(Document): class POSSettings(Document):
def validate(self): pass
link = 'point-of-sale' if self.type_of_pos == 'Online' else 'pos'
desktop_icon = frappe.db.get_value('Desktop Icon', {'module_name': 'POS'}, 'name')
if desktop_icon:
doc = frappe.get_doc('Desktop Icon', desktop_icon)
doc.link = link
doc.save()

View File

@ -8,8 +8,16 @@ frappe.pages['pos'].on_page_load = function (wrapper) {
single_column: true single_column: true
}); });
frappe.db.get_value('POS Settings', {name: 'POS Settings'}, 'is_online', (r) => {
if (r && r.is_online && !cint(r.is_online)) {
// offline
wrapper.pos = new erpnext.pos.PointOfSale(wrapper); wrapper.pos = new erpnext.pos.PointOfSale(wrapper);
cur_pos = wrapper.pos; cur_pos = wrapper.pos;
} else {
// online
frappe.set_route('point-of-sale');
}
});
} }
frappe.pages['pos'].refresh = function (wrapper) { frappe.pages['pos'].refresh = function (wrapper) {

View File

@ -7,8 +7,16 @@ frappe.pages['point-of-sale'].on_page_load = function(wrapper) {
single_column: true single_column: true
}); });
frappe.db.get_value('POS Settings', {name: 'POS Settings'}, 'is_online', (r) => {
if (r && r.is_online && cint(r.is_online)) {
// online
wrapper.pos = new PointOfSale(wrapper); wrapper.pos = new PointOfSale(wrapper);
window.cur_pos = wrapper.pos; window.cur_pos = wrapper.pos;
} else {
// offline
frappe.set_route('pos');
}
});
}; };
class PointOfSale { class PointOfSale {
@ -117,16 +125,12 @@ class PointOfSale {
wrapper: this.wrapper.find('.item-container'), wrapper: this.wrapper.find('.item-container'),
pos_profile: this.pos_profile, pos_profile: this.pos_profile,
events: { events: {
item_click: (item_code) => { update_cart: (item, field, value) => {
if(!this.frm.doc.customer) { if(!this.frm.doc.customer) {
frappe.throw(__('Please select a customer')); frappe.throw(__('Please select a customer'));
} }
this.update_item_in_cart(item, field, value);
this.update_item_in_cart(item_code, 'qty', '+1');
this.cart && this.cart.unselect_all(); this.cart && this.cart.unselect_all();
},
update_cart: (item, field, value) => {
this.update_item_in_cart(item, field, value)
} }
} }
}); });
@ -146,7 +150,7 @@ class PointOfSale {
} }
if(field === 'qty' && (item.serial_no || item.batch_no)) { if(field === 'qty' && (item.serial_no || item.batch_no)) {
this.select_batch_and_serial_no(item) this.select_batch_and_serial_no(item);
} else { } else {
this.update_item_in_frm(item, field, value) this.update_item_in_frm(item, field, value)
.then(() => { .then(() => {
@ -257,6 +261,13 @@ class PointOfSale {
} }
}).then(r => { }).then(r => {
this.pos_profile = r.message; this.pos_profile = r.message;
if (!this.pos_profile) {
this.pos_profile = {
currency: frappe.defaults.get_default('currency'),
selling_price_list: frappe.defaults.get_default('selling_price_list')
};
}
}); });
} }
@ -307,9 +318,9 @@ class PointOfSale {
this.page.clear_menu(); this.page.clear_menu();
// for mobile // for mobile
this.page.add_menu_item(__("Pay"), function () { // this.page.add_menu_item(__("Pay"), function () {
// //
}).addClass('visible-xs'); // }).addClass('visible-xs');
this.page.add_menu_item(__("Form View"), function () { this.page.add_menu_item(__("Form View"), function () {
var doc = frappe.model.sync(me.frm.doc); var doc = frappe.model.sync(me.frm.doc);
@ -319,6 +330,10 @@ class PointOfSale {
this.page.add_menu_item(__("POS Profile"), function () { this.page.add_menu_item(__("POS Profile"), function () {
frappe.set_route('List', 'POS Profile'); frappe.set_route('List', 'POS Profile');
}); });
this.page.add_menu_item(__('POS Settings'), function() {
frappe.set_route('Form', 'POS Settings');
});
} }
set_form_action() { set_form_action() {
@ -740,8 +755,7 @@ class POSItems {
this.pos_profile = pos_profile; this.pos_profile = pos_profile;
this.items = {}; this.items = {};
this.events = events; this.events = events;
this.currency = this.pos_profile.currency || this.currency = this.pos_profile.currency;
frappe.defaults.get_default('currency');
this.make_dom(); this.make_dom();
this.make_fields(); this.make_fields();
@ -751,10 +765,11 @@ class POSItems {
// bootstrap with 20 items // bootstrap with 20 items
this.get_items() this.get_items()
.then((items, serial_no) => { .then(({ items }) => {
this.all_items = items;
this.items = items; this.items = items;
}) this.render_items(items);
.then(() => this.render_items()); });
} }
make_dom() { make_dom() {
@ -795,8 +810,11 @@ class POSItems {
}); });
this.search_field.$input.on('input', (e) => { this.search_field.$input.on('input', (e) => {
clearTimeout(this.last_search);
this.last_search = setTimeout(() => {
const search_term = e.target.value; const search_term = e.target.value;
this.filter_items({ search_term }); this.filter_items({ search_term });
}, 300);
}); });
this.item_group_field = frappe.ui.form.make_control({ this.item_group_field = frappe.ui.form.make_control({
@ -861,18 +879,26 @@ class POSItems {
this.render_items(items); this.render_items(items);
return; return;
} }
} else {
return this.render_items(this.all_items);
} }
this.get_items({search_value: search_term, item_group }) this.get_items({search_value: search_term, item_group })
.then((items) => { .then(({ items, serial_no, batch_no }) => {
if (search_term) { if (search_term) {
this.search_index[search_term] = items; this.search_index[search_term] = items;
} }
this.render_items(items); this.render_items(items);
if(this.serial_no) { if(serial_no) {
this.events.update_cart(items[0].item_code, this.events.update_cart(items[0].item_code,
'serial_no', this.serial_no); 'serial_no', serial_no);
this.search_field.set_value('');
}
if(batch_no) {
this.events.update_cart(items[0].item_code,
'batch_no', serial_no);
this.search_field.set_value('');
} }
}); });
} }
@ -882,7 +908,7 @@ class POSItems {
this.wrapper.on('click', '.pos-item-wrapper', function(e) { this.wrapper.on('click', '.pos-item-wrapper', function(e) {
const $item = $(this); const $item = $(this);
const item_code = $item.attr('data-item-code'); const item_code = $item.attr('data-item-code');
me.events.item_click.apply(null, [item_code]); me.events.update_cart(item_code, 'qty', '+1');
}); });
} }
@ -944,10 +970,10 @@ class POSItems {
search_value search_value
} }
}).then(r => { }).then(r => {
const { items, serial_no } = r.message; // const { items, serial_no, batch_no } = r.message;
this.serial_no = serial_no || ""; // this.serial_no = serial_no || "";
res(items); res(r.message);
}); });
}); });
} }

View File

@ -15,6 +15,7 @@ from erpnext.controllers.accounts_controller import get_taxes_and_charges
def get_items(start, page_length, price_list, item_group, search_value=""): def get_items(start, page_length, price_list, item_group, search_value=""):
condition = "" condition = ""
serial_no = "" serial_no = ""
batch_no = ""
item_code = search_value item_code = search_value
if search_value: if search_value:
@ -23,6 +24,11 @@ def get_items(start, page_length, price_list, item_group, search_value=""):
if serial_no_data: if serial_no_data:
serial_no, item_code = serial_no_data serial_no, item_code = serial_no_data
if not serial_no:
batch_no_data = frappe.db.get_value('Batch', search_value, ['name', 'item'])
if batch_no_data:
batch_no, item_code = batch_no_data
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,
@ -52,6 +58,11 @@ def get_items(start, page_length, price_list, item_group, search_value=""):
'serial_no': serial_no 'serial_no': serial_no
}) })
if batch_no:
res.update({
'batch_no': batch_no
})
return res return res
@frappe.whitelist() @frappe.whitelist()