[fix] Pricing rule for pos
This commit is contained in:
parent
dc981dc546
commit
d7de3c606b
@ -32,7 +32,7 @@ def get_pos_data():
|
|||||||
'doc': doc,
|
'doc': doc,
|
||||||
'default_customer': pos_profile.get('customer'),
|
'default_customer': pos_profile.get('customer'),
|
||||||
'items': get_items_list(pos_profile),
|
'items': get_items_list(pos_profile),
|
||||||
'item_groups': get_item_group(pos_profile),
|
'item_groups': get_item_groups(pos_profile),
|
||||||
'customers': customers,
|
'customers': customers,
|
||||||
'address': get_customers_address(customers),
|
'address': get_customers_address(customers),
|
||||||
'serial_no_data': get_serial_no_data(pos_profile, doc.company),
|
'serial_no_data': get_serial_no_data(pos_profile, doc.company),
|
||||||
@ -132,7 +132,7 @@ def get_items_list(pos_profile):
|
|||||||
if pos_profile.get('item_groups'):
|
if pos_profile.get('item_groups'):
|
||||||
# Get items based on the item groups defined in the POS profile
|
# Get items based on the item groups defined in the POS profile
|
||||||
for d in pos_profile.get('item_groups'):
|
for d in pos_profile.get('item_groups'):
|
||||||
item_groups.extend(get_child_nodes('Item Group', d.item_group))
|
item_groups.extend([d.name for d in get_child_nodes('Item Group', d.item_group)])
|
||||||
cond = "item_group in (%s)"%(', '.join(['%s']*len(item_groups)))
|
cond = "item_group in (%s)"%(', '.join(['%s']*len(item_groups)))
|
||||||
|
|
||||||
return frappe.db.sql("""
|
return frappe.db.sql("""
|
||||||
@ -146,14 +146,19 @@ def get_items_list(pos_profile):
|
|||||||
disabled = 0 and has_variants = 0 and is_sales_item = 1 and {cond}
|
disabled = 0 and has_variants = 0 and is_sales_item = 1 and {cond}
|
||||||
""".format(cond=cond), tuple(item_groups), as_dict=1)
|
""".format(cond=cond), tuple(item_groups), as_dict=1)
|
||||||
|
|
||||||
def get_item_group(pos_profile):
|
def get_item_groups(pos_profile):
|
||||||
|
item_group_dict = {}
|
||||||
if pos_profile.get('item_groups'):
|
if pos_profile.get('item_groups'):
|
||||||
item_groups = []
|
item_groups = []
|
||||||
for d in pos_profile.get('item_groups'):
|
for d in pos_profile.get('item_groups'):
|
||||||
item_groups.extend(get_child_nodes('Item Group', d.item_group))
|
item_groups.extend(get_child_nodes('Item Group', d.item_group))
|
||||||
return item_groups
|
|
||||||
else:
|
else:
|
||||||
return frappe.db.sql_list("""Select name from `tabItem Group` order by name""")
|
item_groups = frappe.db.sql("""Select name,
|
||||||
|
lft, rgt from `tabItem Group` order by lft""", as_dict=1)
|
||||||
|
|
||||||
|
for data in item_groups:
|
||||||
|
item_group_dict[data.name] = [data.lft, data.rgt]
|
||||||
|
return item_group_dict
|
||||||
|
|
||||||
def get_customers_list(pos_profile):
|
def get_customers_list(pos_profile):
|
||||||
cond = "1=1"
|
cond = "1=1"
|
||||||
@ -161,7 +166,7 @@ def get_customers_list(pos_profile):
|
|||||||
if pos_profile.get('customer_groups'):
|
if pos_profile.get('customer_groups'):
|
||||||
# Get customers based on the customer groups defined in the POS profile
|
# Get customers based on the customer groups defined in the POS profile
|
||||||
for d in pos_profile.get('customer_groups'):
|
for d in pos_profile.get('customer_groups'):
|
||||||
customer_groups.extend(get_child_nodes('Customer Group', d.customer_group))
|
customer_groups.extend([d.name for d in get_child_nodes('Customer Group', d.customer_group)])
|
||||||
cond = "customer_group in (%s)"%(', '.join(['%s']*len(customer_groups)))
|
cond = "customer_group in (%s)"%(', '.join(['%s']*len(customer_groups)))
|
||||||
|
|
||||||
return frappe.db.sql(""" select name, customer_name, customer_group,
|
return frappe.db.sql(""" select name, customer_name, customer_group,
|
||||||
@ -187,8 +192,8 @@ def get_customers_address(customers):
|
|||||||
|
|
||||||
def get_child_nodes(group_type, root):
|
def get_child_nodes(group_type, root):
|
||||||
lft, rgt = frappe.db.get_value(group_type, root, ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value(group_type, root, ["lft", "rgt"])
|
||||||
return frappe.db.sql_list(""" Select name from `tab{tab}` where
|
return frappe.db.sql(""" Select name, lft, rgt from `tab{tab}` where
|
||||||
lft >= {lft} and rgt <= {rgt}""".format(tab=group_type, lft=lft, rgt=rgt))
|
lft >= {lft} and rgt <= {rgt} order by lft""".format(tab=group_type, lft=lft, rgt=rgt), as_dict=1)
|
||||||
|
|
||||||
def get_serial_no_data(pos_profile, company):
|
def get_serial_no_data(pos_profile, company):
|
||||||
# get itemwise serial no data
|
# get itemwise serial no data
|
||||||
|
@ -407,8 +407,8 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.search_item_group = this.wrapper.find('.search-item-group');
|
this.search_item_group = this.wrapper.find('.search-item-group');
|
||||||
|
sorted_item_groups = this.get_sorted_item_groups()
|
||||||
var dropdown_html = me.item_groups.map(function(item_group) {
|
var dropdown_html = sorted_item_groups.map(function(item_group) {
|
||||||
return "<li><a class='option' data-value='"+item_group+"'>"+item_group+"</a></li>";
|
return "<li><a class='option' data-value='"+item_group+"'>"+item_group+"</a></li>";
|
||||||
}).join("");
|
}).join("");
|
||||||
|
|
||||||
@ -437,6 +437,15 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get_sorted_item_groups: function() {
|
||||||
|
list = {}
|
||||||
|
$.each(this.item_groups, function(i, data) {
|
||||||
|
list[i] = data[0]
|
||||||
|
})
|
||||||
|
|
||||||
|
return Object.keys(list).sort(function(a,b){return list[a]-list[b]})
|
||||||
|
},
|
||||||
|
|
||||||
toggle_more_btn: function() {
|
toggle_more_btn: function() {
|
||||||
if(!this.items || this.items.length <= this.page_len) {
|
if(!this.items || this.items.length <= this.page_len) {
|
||||||
this.wrapper.find(".btn-more").hide();
|
this.wrapper.find(".btn-more").hide();
|
||||||
@ -1091,9 +1100,9 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
|||||||
// $(me.wrapper).find(".pos-item-wrapper").on("click", function () {
|
// $(me.wrapper).find(".pos-item-wrapper").on("click", function () {
|
||||||
$(this.wrapper).on("click", ".pos-item-wrapper", function () {
|
$(this.wrapper).on("click", ".pos-item-wrapper", function () {
|
||||||
me.item_code = '';
|
me.item_code = '';
|
||||||
|
me.customer_validate();
|
||||||
if($(me.pos_bill).is(":hidden")) return;
|
if($(me.pos_bill).is(":hidden")) return;
|
||||||
|
|
||||||
me.customer_validate();
|
|
||||||
if (me.frm.doc.docstatus == 0) {
|
if (me.frm.doc.docstatus == 0) {
|
||||||
me.items = me.get_items($(this).attr("data-item-code"))
|
me.items = me.get_items($(this).attr("data-item-code"))
|
||||||
me.add_to_cart();
|
me.add_to_cart();
|
||||||
@ -1768,7 +1777,7 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
|||||||
var me = this;
|
var me = this;
|
||||||
return $.grep(this.pricing_rules, function (data) {
|
return $.grep(this.pricing_rules, function (data) {
|
||||||
if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) {
|
if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) {
|
||||||
if (data.item_code == item.item_code || in_list(['All Item Groups', item.item_group], data.item_group) || item.brand == data.brand) {
|
if (me.validate_item_condition(data, item)) {
|
||||||
if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) {
|
if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) {
|
||||||
return me.validate_condition(data)
|
return me.validate_condition(data)
|
||||||
} else {
|
} else {
|
||||||
@ -1779,6 +1788,26 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
validate_item_condition: function (data, item) {
|
||||||
|
var apply_on = frappe.model.scrub(data.apply_on);
|
||||||
|
|
||||||
|
return (data.apply_on == 'Item Group')
|
||||||
|
? this.validate_item_group(data.item_group, item.item_group) : (data[apply_on] == item[apply_on]);
|
||||||
|
},
|
||||||
|
|
||||||
|
validate_item_group: function (pr_item_group, cart_item_group) {
|
||||||
|
//pr_item_group = pricing rule's item group
|
||||||
|
//cart_item_group = cart item's item group
|
||||||
|
//this.item_groups has information about item group's lft and rgt
|
||||||
|
//for example: {'Foods': [12, 19]}
|
||||||
|
|
||||||
|
pr_item_group = this.item_groups[pr_item_group]
|
||||||
|
cart_item_group = this.item_groups[cart_item_group]
|
||||||
|
|
||||||
|
return (cart_item_group[0] >= pr_item_group[0] &&
|
||||||
|
cart_item_group[1] <= pr_item_group[1])
|
||||||
|
},
|
||||||
|
|
||||||
validate_condition: function (data) {
|
validate_condition: function (data) {
|
||||||
//This method check condition based on applicable for
|
//This method check condition based on applicable for
|
||||||
condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for]
|
condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for]
|
||||||
|
Loading…
Reference in New Issue
Block a user