2020-07-23 13:21:26 +00:00
|
|
|
erpnext.PointOfSale.ItemDetails = class {
|
2021-01-28 12:28:55 +00:00
|
|
|
constructor({ wrapper, events, settings }) {
|
2020-07-23 13:21:26 +00:00
|
|
|
this.wrapper = wrapper;
|
2020-09-10 13:58:46 +00:00
|
|
|
this.events = events;
|
2021-01-28 12:28:55 +00:00
|
|
|
this.allow_rate_change = settings.allow_rate_change;
|
|
|
|
this.allow_discount_change = settings.allow_discount_change;
|
2020-09-10 13:58:46 +00:00
|
|
|
this.current_item = {};
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
this.init_component();
|
|
|
|
}
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
init_component() {
|
|
|
|
this.prepare_dom();
|
|
|
|
this.init_child_components();
|
2020-07-23 13:21:26 +00:00
|
|
|
this.bind_events();
|
|
|
|
this.attach_shortcuts();
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
prepare_dom() {
|
|
|
|
this.wrapper.append(
|
2020-11-11 17:29:10 +00:00
|
|
|
`<section class="item-details-container"></section>`
|
2020-09-10 13:58:46 +00:00
|
|
|
)
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-11-11 17:29:10 +00:00
|
|
|
this.$component = this.wrapper.find('.item-details-container');
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
init_child_components() {
|
2020-07-23 13:21:26 +00:00
|
|
|
this.$component.html(
|
2020-11-11 17:29:10 +00:00
|
|
|
`<div class="item-details-header">
|
|
|
|
<div class="label">Item Details</div>
|
|
|
|
<div class="close-btn">
|
|
|
|
<svg width="32" height="32" viewBox="0 0 14 14" fill="none">
|
|
|
|
<path d="M4.93764 4.93759L7.00003 6.99998M9.06243 9.06238L7.00003 6.99998M7.00003 6.99998L4.93764 9.06238L9.06243 4.93759" stroke="#8D99A6"/>
|
|
|
|
</svg>
|
2020-07-23 13:21:26 +00:00
|
|
|
</div>
|
2020-11-11 17:29:10 +00:00
|
|
|
</div>
|
|
|
|
<div class="item-display">
|
|
|
|
<div class="item-name-desc-price">
|
|
|
|
<div class="item-name"></div>
|
|
|
|
<div class="item-desc"></div>
|
|
|
|
<div class="item-price"></div>
|
2020-07-23 13:21:26 +00:00
|
|
|
</div>
|
2020-11-11 17:29:10 +00:00
|
|
|
<div class="item-image"></div>
|
|
|
|
</div>
|
|
|
|
<div class="discount-section"></div>
|
|
|
|
<div class="form-container"></div>`
|
2020-07-23 13:21:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
this.$item_name = this.$component.find('.item-name');
|
2020-11-11 17:29:10 +00:00
|
|
|
this.$item_description = this.$component.find('.item-desc');
|
2020-07-23 13:21:26 +00:00
|
|
|
this.$item_price = this.$component.find('.item-price');
|
|
|
|
this.$item_image = this.$component.find('.item-image');
|
|
|
|
this.$form_container = this.$component.find('.form-container');
|
|
|
|
this.$dicount_section = this.$component.find('.discount-section');
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
toggle_item_details_section(item) {
|
2020-11-11 17:29:10 +00:00
|
|
|
const { item_code, batch_no, uom } = this.current_item;
|
2020-07-23 13:21:26 +00:00
|
|
|
const item_code_is_same = item && item_code === item.item_code;
|
|
|
|
const batch_is_same = item && batch_no == item.batch_no;
|
|
|
|
const uom_is_same = item && uom === item.uom;
|
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
this.item_has_changed = !item ? false : item_code_is_same && batch_is_same && uom_is_same ? false : true;
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
this.events.toggle_item_selector(this.item_has_changed);
|
2020-07-23 13:21:26 +00:00
|
|
|
this.toggle_component(this.item_has_changed);
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-07-23 13:21:26 +00:00
|
|
|
if (this.item_has_changed) {
|
2020-09-10 13:58:46 +00:00
|
|
|
this.doctype = item.doctype;
|
2020-07-23 13:21:26 +00:00
|
|
|
this.item_meta = frappe.get_meta(this.doctype);
|
|
|
|
this.name = item.name;
|
|
|
|
this.item_row = item;
|
2020-09-10 13:58:46 +00:00
|
|
|
this.currency = this.events.get_frm().doc.currency;
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
this.current_item = { item_code: item.item_code, batch_no: item.batch_no, uom: item.uom };
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-07-23 13:21:26 +00:00
|
|
|
this.render_dom(item);
|
|
|
|
this.render_discount_dom(item);
|
|
|
|
this.render_form(item);
|
|
|
|
} else {
|
|
|
|
this.validate_serial_batch_item();
|
|
|
|
this.current_item = {};
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-07-23 13:21:26 +00:00
|
|
|
validate_serial_batch_item() {
|
|
|
|
const doc = this.events.get_frm().doc;
|
|
|
|
const item_row = doc.items.find(item => item.name === this.name);
|
|
|
|
|
|
|
|
if (!item_row) return;
|
|
|
|
|
|
|
|
const serialized = item_row.has_serial_no;
|
|
|
|
const batched = item_row.has_batch_no;
|
|
|
|
const no_serial_selected = !item_row.serial_no;
|
|
|
|
const no_batch_selected = !item_row.batch_no;
|
|
|
|
|
2021-01-29 03:26:22 +00:00
|
|
|
if ((serialized && no_serial_selected) || (batched && no_batch_selected) ||
|
2020-07-23 13:21:26 +00:00
|
|
|
(serialized && batched && (no_batch_selected || no_serial_selected))) {
|
|
|
|
|
|
|
|
frappe.show_alert({
|
|
|
|
message: __("Item will be removed since no serial / batch no selected."),
|
|
|
|
indicator: 'orange'
|
|
|
|
});
|
|
|
|
frappe.utils.play_sound("cancel");
|
|
|
|
this.events.remove_item_from_cart();
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
render_dom(item) {
|
2020-11-11 17:29:10 +00:00
|
|
|
let { item_name, description, image, price_list_rate } = item;
|
2020-07-23 13:21:26 +00:00
|
|
|
|
|
|
|
function get_description_html() {
|
|
|
|
if (description) {
|
2020-11-11 17:29:10 +00:00
|
|
|
description = description.indexOf('...') === -1 && description.length > 140 ? description.substr(0, 139) + '...' : description;
|
2020-07-23 13:21:26 +00:00
|
|
|
return description;
|
|
|
|
}
|
|
|
|
return ``;
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-07-23 13:21:26 +00:00
|
|
|
this.$item_name.html(item_name);
|
|
|
|
this.$item_description.html(get_description_html());
|
|
|
|
this.$item_price.html(format_currency(price_list_rate, this.currency));
|
|
|
|
if (image) {
|
2020-11-11 17:29:10 +00:00
|
|
|
this.$item_image.html(`<img src="${image}" alt="${image}">`);
|
2020-07-23 13:21:26 +00:00
|
|
|
} else {
|
2020-11-11 17:29:10 +00:00
|
|
|
this.$item_image.html(`<div class="item-abbr">${frappe.get_abbr(item_name)}</div>`);
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
render_discount_dom(item) {
|
2020-07-23 13:21:26 +00:00
|
|
|
if (item.discount_percentage) {
|
|
|
|
this.$dicount_section.html(
|
2020-11-11 17:29:10 +00:00
|
|
|
`<div class="item-rate">${format_currency(item.price_list_rate, this.currency)}</div>
|
|
|
|
<div class="item-discount">${item.discount_percentage}% off</div>`
|
2020-07-23 13:21:26 +00:00
|
|
|
)
|
|
|
|
this.$item_price.html(format_currency(item.rate, this.currency));
|
|
|
|
} else {
|
|
|
|
this.$dicount_section.html(``)
|
|
|
|
}
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
render_form(item) {
|
2020-07-23 13:21:26 +00:00
|
|
|
const fields_to_display = this.get_form_fields(item);
|
|
|
|
this.$form_container.html('');
|
|
|
|
|
|
|
|
fields_to_display.forEach((fieldname, idx) => {
|
|
|
|
this.$form_container.append(
|
2020-11-11 17:29:10 +00:00
|
|
|
`<div class="${fieldname}-control" data-fieldname="${fieldname}"></div>`
|
2020-07-23 13:21:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const field_meta = this.item_meta.fields.find(df => df.fieldname === fieldname);
|
|
|
|
fieldname === 'discount_percentage' ? (field_meta.label = __('Discount (%)')) : '';
|
|
|
|
const me = this;
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-07-23 13:21:26 +00:00
|
|
|
this[`${fieldname}_control`] = frappe.ui.form.make_control({
|
2021-01-29 03:26:22 +00:00
|
|
|
df: {
|
|
|
|
...field_meta,
|
2020-07-23 13:21:26 +00:00
|
|
|
onchange: function() {
|
|
|
|
me.events.form_updated(me.doctype, me.name, fieldname, this.value);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
parent: this.$form_container.find(`.${fieldname}-control`),
|
|
|
|
render_input: true,
|
|
|
|
})
|
|
|
|
this[`${fieldname}_control`].set_value(item[fieldname]);
|
|
|
|
});
|
|
|
|
|
|
|
|
this.make_auto_serial_selection_btn(item);
|
|
|
|
|
|
|
|
this.bind_custom_control_change_event();
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2020-07-23 13:21:26 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
get_form_fields(item) {
|
2020-10-26 05:47:04 +00:00
|
|
|
const fields = ['qty', 'uom', 'rate', 'conversion_factor', 'discount_percentage', 'warehouse', 'actual_qty', 'price_list_rate'];
|
2020-07-23 13:21:26 +00:00
|
|
|
if (item.has_serial_no) fields.push('serial_no');
|
|
|
|
if (item.has_batch_no) fields.push('batch_no');
|
|
|
|
return fields;
|
|
|
|
}
|
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
make_auto_serial_selection_btn(item) {
|
2020-07-23 13:21:26 +00:00
|
|
|
if (item.has_serial_no) {
|
|
|
|
if (!item.has_batch_no) {
|
|
|
|
this.$form_container.append(
|
|
|
|
`<div class="grid-filler no-select"></div>`
|
2021-02-01 14:42:47 +00:00
|
|
|
);
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
this.$form_container.append(
|
2020-11-11 17:29:10 +00:00
|
|
|
`<div class="btn btn-sm btn-secondary auto-fetch-btn">Auto Fetch Serial Numbers</div>`
|
2021-02-01 14:42:47 +00:00
|
|
|
);
|
2020-11-11 17:29:10 +00:00
|
|
|
this.$form_container.find('.serial_no-control').find('textarea').css('height', '6rem');
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
bind_custom_control_change_event() {
|
2020-07-23 13:21:26 +00:00
|
|
|
const me = this;
|
|
|
|
if (this.rate_control) {
|
2021-01-28 12:28:55 +00:00
|
|
|
if (this.allow_rate_change) {
|
|
|
|
this.rate_control.df.onchange = function() {
|
|
|
|
if (this.value || flt(this.value) === 0) {
|
|
|
|
me.events.form_updated(me.doctype, me.name, 'rate', this.value).then(() => {
|
|
|
|
const item_row = frappe.get_doc(me.doctype, me.name);
|
|
|
|
const doc = me.events.get_frm().doc;
|
|
|
|
me.$item_price.html(format_currency(item_row.rate, doc.currency));
|
|
|
|
me.render_discount_dom(item_row);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.rate_control.df.read_only = 1;
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
2021-01-28 12:28:55 +00:00
|
|
|
this.rate_control.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.discount_percentage_control && !this.allow_discount_change) {
|
|
|
|
this.discount_percentage_control.df.read_only = 1;
|
|
|
|
this.discount_percentage_control.refresh();
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.warehouse_control) {
|
|
|
|
this.warehouse_control.df.reqd = 1;
|
|
|
|
this.warehouse_control.df.onchange = function() {
|
|
|
|
if (this.value) {
|
|
|
|
me.events.form_updated(me.doctype, me.name, 'warehouse', this.value).then(() => {
|
|
|
|
me.item_stock_map = me.events.get_item_stock_map();
|
|
|
|
const available_qty = me.item_stock_map[me.item_row.item_code][this.value];
|
|
|
|
if (available_qty === undefined) {
|
|
|
|
me.events.get_available_stock(me.item_row.item_code, this.value).then(() => {
|
|
|
|
// item stock map is updated now reset warehouse
|
|
|
|
me.warehouse_control.set_value(this.value);
|
|
|
|
})
|
|
|
|
} else if (available_qty === 0) {
|
|
|
|
me.warehouse_control.set_value('');
|
2020-10-26 05:47:04 +00:00
|
|
|
const bold_item_code = me.item_row.item_code.bold();
|
|
|
|
const bold_warehouse = this.value.bold();
|
|
|
|
frappe.throw(
|
|
|
|
__('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse])
|
|
|
|
);
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
me.actual_qty_control.set_value(available_qty);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-10-26 05:47:04 +00:00
|
|
|
this.warehouse_control.df.get_query = () => {
|
|
|
|
return {
|
|
|
|
filters: { company: this.events.get_frm().doc.company }
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
2020-10-26 05:47:04 +00:00
|
|
|
};
|
|
|
|
this.warehouse_control.refresh();
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.serial_no_control) {
|
|
|
|
this.serial_no_control.df.reqd = 1;
|
|
|
|
this.serial_no_control.df.onchange = async function() {
|
|
|
|
!me.current_item.batch_no && await me.auto_update_batch_no();
|
|
|
|
me.events.form_updated(me.doctype, me.name, 'serial_no', this.value);
|
|
|
|
}
|
|
|
|
this.serial_no_control.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.batch_no_control) {
|
|
|
|
this.batch_no_control.df.reqd = 1;
|
|
|
|
this.batch_no_control.df.get_query = () => {
|
|
|
|
return {
|
|
|
|
query: 'erpnext.controllers.queries.get_batch_no',
|
|
|
|
filters: {
|
|
|
|
item_code: me.item_row.item_code,
|
2020-10-26 05:47:04 +00:00
|
|
|
warehouse: me.item_row.warehouse,
|
|
|
|
posting_date: me.events.get_frm().doc.posting_date
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.batch_no_control.df.onchange = function() {
|
|
|
|
me.events.set_value_in_current_cart_item('batch-no', this.value);
|
2020-09-10 13:58:46 +00:00
|
|
|
me.events.form_updated(me.doctype, me.name, 'batch_no', this.value);
|
|
|
|
me.current_item.batch_no = this.value;
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
this.batch_no_control.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.uom_control) {
|
|
|
|
this.uom_control.df.onchange = function() {
|
|
|
|
me.events.set_value_in_current_cart_item('uom', this.value);
|
|
|
|
me.events.form_updated(me.doctype, me.name, 'uom', this.value);
|
|
|
|
me.current_item.uom = this.value;
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-10-26 05:47:04 +00:00
|
|
|
const item_row = frappe.get_doc(me.doctype, me.name);
|
|
|
|
me.conversion_factor_control.df.read_only = (item_row.stock_uom == this.value);
|
|
|
|
me.conversion_factor_control.refresh();
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-26 05:47:04 +00:00
|
|
|
|
|
|
|
frappe.model.on("POS Invoice Item", "*", (fieldname, value, item_row) => {
|
2020-11-11 17:29:10 +00:00
|
|
|
const field_control = this[`${fieldname}_control`];
|
2021-01-29 03:26:22 +00:00
|
|
|
const { item_code, batch_no, uom } = this.current_item;
|
2020-11-11 17:29:10 +00:00
|
|
|
const item_code_is_same = item_code === item_row.item_code;
|
|
|
|
const batch_is_same = batch_no == item_row.batch_no;
|
|
|
|
const uom_is_same = uom === item_row.uom;
|
2021-01-28 12:28:55 +00:00
|
|
|
const item_is_same = item_code_is_same && batch_is_same && uom_is_same ? true : false;
|
2020-11-11 17:29:10 +00:00
|
|
|
|
2021-01-28 12:28:55 +00:00
|
|
|
if (item_is_same && field_control && field_control.get_value() !== value) {
|
2020-10-26 05:47:04 +00:00
|
|
|
field_control.set_value(value);
|
|
|
|
cur_pos.update_cart_html(item_row);
|
|
|
|
}
|
|
|
|
});
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
async auto_update_batch_no() {
|
2020-07-23 13:21:26 +00:00
|
|
|
if (this.serial_no_control && this.batch_no_control) {
|
|
|
|
const selected_serial_nos = this.serial_no_control.get_value().split(`\n`).filter(s => s);
|
|
|
|
if (!selected_serial_nos.length) return;
|
|
|
|
|
2021-01-29 03:26:22 +00:00
|
|
|
// find batch nos of the selected serial no
|
2020-07-23 13:21:26 +00:00
|
|
|
const serials_with_batch_no = await frappe.db.get_list("Serial No", {
|
|
|
|
filters: { 'name': ["in", selected_serial_nos]},
|
|
|
|
fields: ["batch_no", "name"]
|
|
|
|
});
|
|
|
|
const batch_serial_map = serials_with_batch_no.reduce((acc, r) => {
|
|
|
|
acc[r.batch_no] || (acc[r.batch_no] = []);
|
|
|
|
acc[r.batch_no] = [...acc[r.batch_no], r.name];
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
// set current item's batch no and serial no
|
|
|
|
const batch_no = Object.keys(batch_serial_map)[0];
|
|
|
|
const batch_serial_nos = batch_serial_map[batch_no].join(`\n`);
|
|
|
|
// eg. 10 selected serial no. -> 5 belongs to first batch other 5 belongs to second batch
|
2020-09-10 13:58:46 +00:00
|
|
|
const serial_nos_belongs_to_other_batch = selected_serial_nos.length !== batch_serial_map[batch_no].length;
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
const current_batch_no = this.batch_no_control.get_value();
|
2020-07-23 13:21:26 +00:00
|
|
|
current_batch_no != batch_no && await this.batch_no_control.set_value(batch_no);
|
|
|
|
|
|
|
|
if (serial_nos_belongs_to_other_batch) {
|
|
|
|
this.serial_no_control.set_value(batch_serial_nos);
|
|
|
|
this.qty_control.set_value(batch_serial_map[batch_no].length);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete batch_serial_map[batch_no];
|
|
|
|
|
|
|
|
if (serial_nos_belongs_to_other_batch)
|
|
|
|
this.events.clone_new_batch_item_in_frm(batch_serial_map, this.current_item);
|
|
|
|
}
|
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
bind_events() {
|
2020-07-23 13:21:26 +00:00
|
|
|
this.bind_auto_serial_fetch_event();
|
|
|
|
this.bind_fields_to_numpad_fields();
|
|
|
|
|
|
|
|
this.$component.on('click', '.close-btn', () => {
|
|
|
|
this.events.close_item_details();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
attach_shortcuts() {
|
2020-10-26 05:47:04 +00:00
|
|
|
this.wrapper.find('.close-btn').attr("title", "Esc");
|
2020-07-23 13:21:26 +00:00
|
|
|
frappe.ui.keys.on("escape", () => {
|
|
|
|
const item_details_visible = this.$component.is(":visible");
|
|
|
|
if (item_details_visible) {
|
|
|
|
this.events.close_item_details();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
bind_fields_to_numpad_fields() {
|
2020-07-23 13:21:26 +00:00
|
|
|
const me = this;
|
|
|
|
this.$form_container.on('click', '.input-with-feedback', function() {
|
|
|
|
const fieldname = $(this).attr('data-fieldname');
|
|
|
|
if (this.last_field_focused != fieldname) {
|
|
|
|
me.events.item_field_focused(fieldname);
|
|
|
|
this.last_field_focused = fieldname;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-01-29 03:26:22 +00:00
|
|
|
|
2020-09-10 13:58:46 +00:00
|
|
|
bind_auto_serial_fetch_event() {
|
2020-07-23 13:21:26 +00:00
|
|
|
this.$form_container.on('click', '.auto-fetch-btn', () => {
|
2020-10-26 05:47:04 +00:00
|
|
|
this.batch_no_control && this.batch_no_control.set_value('');
|
2020-07-23 13:21:26 +00:00
|
|
|
let qty = this.qty_control.get_value();
|
2020-11-06 12:49:36 +00:00
|
|
|
let conversion_factor = this.conversion_factor_control.get_value();
|
2020-10-26 05:47:04 +00:00
|
|
|
let expiry_date = this.item_row.has_batch_no ? this.events.get_frm().doc.posting_date : "";
|
|
|
|
|
2020-07-23 13:21:26 +00:00
|
|
|
let numbers = frappe.call({
|
|
|
|
method: "erpnext.stock.doctype.serial_no.serial_no.auto_fetch_serial_number",
|
|
|
|
args: {
|
2020-11-06 12:49:36 +00:00
|
|
|
qty: qty * conversion_factor,
|
2020-07-23 13:21:26 +00:00
|
|
|
item_code: this.current_item.item_code,
|
|
|
|
warehouse: this.warehouse_control.get_value() || '',
|
|
|
|
batch_nos: this.current_item.batch_no || '',
|
2020-10-26 05:47:04 +00:00
|
|
|
posting_date: expiry_date,
|
2020-07-23 13:21:26 +00:00
|
|
|
for_doctype: 'POS Invoice'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
numbers.then((data) => {
|
|
|
|
let auto_fetched_serial_numbers = data.message;
|
|
|
|
let records_length = auto_fetched_serial_numbers.length;
|
|
|
|
if (!records_length) {
|
|
|
|
const warehouse = this.warehouse_control.get_value().bold();
|
2020-10-26 05:47:04 +00:00
|
|
|
const item_code = this.current_item.item_code.bold();
|
|
|
|
frappe.msgprint(
|
|
|
|
__('Serial numbers unavailable for Item {0} under warehouse {1}. Please try changing warehouse.', [item_code, warehouse])
|
|
|
|
);
|
2020-07-23 13:21:26 +00:00
|
|
|
} else if (records_length < qty) {
|
2020-10-26 05:47:04 +00:00
|
|
|
frappe.msgprint(
|
|
|
|
__('Fetched only {0} available serial numbers.', [records_length])
|
|
|
|
);
|
2020-07-23 13:21:26 +00:00
|
|
|
this.qty_control.set_value(records_length);
|
|
|
|
}
|
2020-09-10 13:58:46 +00:00
|
|
|
numbers = auto_fetched_serial_numbers.join(`\n`);
|
2020-07-23 13:21:26 +00:00
|
|
|
this.serial_no_control.set_value(numbers);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
toggle_component(show) {
|
2020-11-11 17:29:10 +00:00
|
|
|
show ? this.$component.css('display', 'flex') : this.$component.css('display', 'none');
|
2020-09-10 13:58:46 +00:00
|
|
|
}
|
2020-07-23 13:21:26 +00:00
|
|
|
}
|