Merge pull request #25928 from nextchamp-saqib/pos-fixes-8
fix(pos): multiple pos issues
This commit is contained in:
commit
d689068d82
@ -17,7 +17,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
|||||||
var me = this;
|
var me = this;
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice', 'Timesheet'];
|
this.frm.ignore_doctypes_on_cancel_all = ['POS Invoice', 'Timesheet', 'POS Invoice Merge Log', 'POS Closing Entry'];
|
||||||
if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) {
|
if(!this.frm.doc.__islocal && !this.frm.doc.customer && this.frm.doc.debit_to) {
|
||||||
// show debit_to in print format
|
// show debit_to in print format
|
||||||
this.frm.set_df_property("debit_to", "print_hide", 0);
|
this.frm.set_df_property("debit_to", "print_hide", 0);
|
||||||
|
@ -8,38 +8,52 @@ from frappe.utils import cint
|
|||||||
from erpnext.accounts.doctype.pos_profile.pos_profile import get_item_groups
|
from erpnext.accounts.doctype.pos_profile.pos_profile import get_item_groups
|
||||||
from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_stock_availability
|
from erpnext.accounts.doctype.pos_invoice.pos_invoice import get_stock_availability
|
||||||
|
|
||||||
from six import string_types
|
def search_by_term(search_term, warehouse, price_list):
|
||||||
|
result = search_for_serial_or_batch_or_barcode_number(search_term)
|
||||||
|
|
||||||
|
item_code = result.get("item_code") or search_term
|
||||||
|
serial_no = result.get("serial_no") or ""
|
||||||
|
batch_no = result.get("batch_no") or ""
|
||||||
|
barcode = result.get("barcode") or ""
|
||||||
|
|
||||||
|
if result:
|
||||||
|
item_info = frappe.db.get_value("Item", item_code,
|
||||||
|
["name as item_code", "item_name", "description", "stock_uom", "image as item_image", "is_stock_item"],
|
||||||
|
as_dict=1)
|
||||||
|
|
||||||
|
item_stock_qty = get_stock_availability(item_code, warehouse)
|
||||||
|
price_list_rate, currency = frappe.db.get_value('Item Price', {
|
||||||
|
'price_list': price_list,
|
||||||
|
'item_code': item_code
|
||||||
|
}, ["price_list_rate", "currency"])
|
||||||
|
|
||||||
|
item_info.update({
|
||||||
|
'serial_no': serial_no,
|
||||||
|
'batch_no': batch_no,
|
||||||
|
'barcode': barcode,
|
||||||
|
'price_list_rate': price_list_rate,
|
||||||
|
'currency': currency,
|
||||||
|
'actual_qty': item_stock_qty
|
||||||
|
})
|
||||||
|
|
||||||
|
return {'items': [item_info]}
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_items(start, page_length, price_list, item_group, pos_profile, search_value=""):
|
def get_items(start, page_length, price_list, item_group, pos_profile, search_term=""):
|
||||||
data = dict()
|
warehouse, hide_unavailable_items = frappe.db.get_value(
|
||||||
|
'POS Profile', pos_profile, ['warehouse', 'hide_unavailable_items'])
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
warehouse, hide_unavailable_items = frappe.db.get_value('POS Profile', pos_profile, ['warehouse', 'hide_unavailable_items'])
|
if search_term:
|
||||||
|
result = search_by_term(search_term, warehouse, price_list)
|
||||||
|
if result:
|
||||||
|
return result
|
||||||
|
|
||||||
if not frappe.db.exists('Item Group', item_group):
|
if not frappe.db.exists('Item Group', item_group):
|
||||||
item_group = get_root_of('Item Group')
|
item_group = get_root_of('Item Group')
|
||||||
|
|
||||||
if search_value:
|
condition = get_conditions(search_term)
|
||||||
data = search_serial_or_batch_or_barcode_number(search_value)
|
|
||||||
|
|
||||||
item_code = data.get("item_code") if data.get("item_code") else search_value
|
|
||||||
serial_no = data.get("serial_no") if data.get("serial_no") else ""
|
|
||||||
batch_no = data.get("batch_no") if data.get("batch_no") else ""
|
|
||||||
barcode = data.get("barcode") if data.get("barcode") else ""
|
|
||||||
|
|
||||||
if data:
|
|
||||||
item_info = frappe.db.get_value(
|
|
||||||
"Item", data.get("item_code"),
|
|
||||||
["name as item_code", "item_name", "description", "stock_uom", "image as item_image", "is_stock_item"]
|
|
||||||
, as_dict=1)
|
|
||||||
item_info.setdefault('serial_no', serial_no)
|
|
||||||
item_info.setdefault('batch_no', batch_no)
|
|
||||||
item_info.setdefault('barcode', barcode)
|
|
||||||
|
|
||||||
return { 'items': [item_info] }
|
|
||||||
|
|
||||||
condition = get_conditions(item_code, serial_no, batch_no, barcode)
|
|
||||||
condition += get_item_group_condition(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'])
|
||||||
@ -106,14 +120,10 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_va
|
|||||||
})
|
})
|
||||||
result.append(row)
|
result.append(row)
|
||||||
|
|
||||||
res = {
|
return {'items': result}
|
||||||
'items': result
|
|
||||||
}
|
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def search_serial_or_batch_or_barcode_number(search_value):
|
def search_for_serial_or_batch_or_barcode_number(search_value):
|
||||||
# search barcode no
|
# search barcode no
|
||||||
barcode_data = frappe.db.get_value('Item Barcode', {'barcode': search_value}, ['barcode', 'parent as item_code'], as_dict=True)
|
barcode_data = frappe.db.get_value('Item Barcode', {'barcode': search_value}, ['barcode', 'parent as item_code'], as_dict=True)
|
||||||
if barcode_data:
|
if barcode_data:
|
||||||
@ -139,27 +149,21 @@ def filter_service_items(items):
|
|||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def get_conditions(item_code, serial_no, batch_no, barcode):
|
def get_conditions(search_term):
|
||||||
if serial_no or batch_no or barcode:
|
|
||||||
return "item.name = {0}".format(frappe.db.escape(item_code))
|
|
||||||
|
|
||||||
return make_condition(item_code)
|
|
||||||
|
|
||||||
def make_condition(item_code):
|
|
||||||
condition = "("
|
condition = "("
|
||||||
condition += """item.name like {item_code}
|
condition += """item.name like {search_term}
|
||||||
or item.item_name like {item_code}""".format(item_code = frappe.db.escape('%' + item_code + '%'))
|
or item.item_name like {search_term}""".format(search_term=frappe.db.escape('%' + search_term + '%'))
|
||||||
condition += add_search_fields_condition(item_code)
|
condition += add_search_fields_condition(search_term)
|
||||||
condition += ")"
|
condition += ")"
|
||||||
|
|
||||||
return condition
|
return condition
|
||||||
|
|
||||||
def add_search_fields_condition(item_code):
|
def add_search_fields_condition(search_term):
|
||||||
condition = ''
|
condition = ''
|
||||||
search_fields = frappe.get_all('POS Search Fields', fields = ['fieldname'])
|
search_fields = frappe.get_all('POS Search Fields', fields = ['fieldname'])
|
||||||
if search_fields:
|
if search_fields:
|
||||||
for field in search_fields:
|
for field in search_fields:
|
||||||
condition += " or item.{0} like {1}".format(field['fieldname'], frappe.db.escape('%' + item_code + '%'))
|
condition += " or item.`{0}` like {1}".format(field['fieldname'], frappe.db.escape('%' + search_term + '%'))
|
||||||
return condition
|
return condition
|
||||||
|
|
||||||
def get_item_group_condition(pos_profile):
|
def get_item_group_condition(pos_profile):
|
||||||
|
@ -133,13 +133,24 @@ erpnext.PointOfSale.ItemDetails = class {
|
|||||||
this.$item_description.html(get_description_html());
|
this.$item_description.html(get_description_html());
|
||||||
this.$item_price.html(format_currency(price_list_rate, this.currency));
|
this.$item_price.html(format_currency(price_list_rate, this.currency));
|
||||||
if (image) {
|
if (image) {
|
||||||
this.$item_image.html(`<img src="${image}" alt="${image}">`);
|
this.$item_image.html(
|
||||||
|
`<img
|
||||||
|
onerror="cur_pos.item_details.handle_broken_image(this)"
|
||||||
|
class="h-full" src="${image}"
|
||||||
|
alt="${frappe.get_abbr(item_name)}"
|
||||||
|
style="object-fit: cover;">`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
this.$item_image.html(`<div class="item-abbr">${frappe.get_abbr(item_name)}</div>`);
|
this.$item_image.html(`<div class="item-abbr">${frappe.get_abbr(item_name)}</div>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle_broken_image($img) {
|
||||||
|
const item_abbr = $($img).attr('alt');
|
||||||
|
$($img).replaceWith(`<div class="item-abbr">${item_abbr}</div>`);
|
||||||
|
}
|
||||||
|
|
||||||
render_discount_dom(item) {
|
render_discount_dom(item) {
|
||||||
if (item.discount_percentage) {
|
if (item.discount_percentage) {
|
||||||
this.$dicount_section.html(
|
this.$dicount_section.html(
|
||||||
|
@ -51,7 +51,7 @@ erpnext.PointOfSale.ItemSelector = class {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get_items({start = 0, page_length = 40, search_value=''}) {
|
get_items({start = 0, page_length = 40, search_term=''}) {
|
||||||
const doc = this.events.get_frm().doc;
|
const doc = this.events.get_frm().doc;
|
||||||
const price_list = (doc && doc.selling_price_list) || this.price_list;
|
const price_list = (doc && doc.selling_price_list) || this.price_list;
|
||||||
let { item_group, pos_profile } = this;
|
let { item_group, pos_profile } = this;
|
||||||
@ -61,7 +61,7 @@ erpnext.PointOfSale.ItemSelector = class {
|
|||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.selling.page.point_of_sale.point_of_sale.get_items",
|
method: "erpnext.selling.page.point_of_sale.point_of_sale.get_items",
|
||||||
freeze: true,
|
freeze: true,
|
||||||
args: { start, page_length, price_list, item_group, search_value, pos_profile },
|
args: { start, page_length, price_list, item_group, search_term, pos_profile },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +80,7 @@ erpnext.PointOfSale.ItemSelector = class {
|
|||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const { item_image, serial_no, batch_no, barcode, actual_qty, stock_uom, price_list_rate } = item;
|
const { item_image, serial_no, batch_no, barcode, actual_qty, stock_uom, price_list_rate } = item;
|
||||||
const indicator_color = actual_qty > 10 ? "green" : actual_qty <= 0 ? "red" : "orange";
|
const indicator_color = actual_qty > 10 ? "green" : actual_qty <= 0 ? "red" : "orange";
|
||||||
|
const precision = flt(price_list_rate, 2) % 1 != 0 ? 2 : 0;
|
||||||
|
|
||||||
let qty_to_display = actual_qty;
|
let qty_to_display = actual_qty;
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ erpnext.PointOfSale.ItemSelector = class {
|
|||||||
<div class="item-name">
|
<div class="item-name">
|
||||||
${frappe.ellipsis(item.item_name, 18)}
|
${frappe.ellipsis(item.item_name, 18)}
|
||||||
</div>
|
</div>
|
||||||
<div class="item-rate">${format_currency(price_list_rate, item.currency, 0) || 0}</div>
|
<div class="item-rate">${format_currency(price_list_rate, item.currency, precision) || 0}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
);
|
);
|
||||||
@ -302,7 +303,7 @@ erpnext.PointOfSale.ItemSelector = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.get_items({ search_value: search_term })
|
this.get_items({ search_term })
|
||||||
.then(({ message }) => {
|
.then(({ message }) => {
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
const { items, serial_no, batch_no, barcode } = message;
|
const { items, serial_no, batch_no, barcode } = message;
|
||||||
|
@ -171,7 +171,7 @@ erpnext.PointOfSale.Payment = class {
|
|||||||
|
|
||||||
this.setup_listener_for_payments();
|
this.setup_listener_for_payments();
|
||||||
|
|
||||||
this.$payment_modes.on('click', '.shortcut', () => {
|
this.$payment_modes.on('click', '.shortcut', function() {
|
||||||
const value = $(this).attr('data-value');
|
const value = $(this).attr('data-value');
|
||||||
me.selected_mode.set_value(value);
|
me.selected_mode.set_value(value);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user