mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 05:39:12 +00:00
feat: serial and batch bundle for POS
This commit is contained in:
@@ -44,7 +44,8 @@ erpnext.PointOfSale.ItemDetails = class {
|
||||
<div class="item-image"></div>
|
||||
</div>
|
||||
<div class="discount-section"></div>
|
||||
<div class="form-container"></div>`
|
||||
<div class="form-container"></div>
|
||||
<div class="serial-batch-container"></div>`
|
||||
)
|
||||
|
||||
this.$item_name = this.$component.find('.item-name');
|
||||
@@ -53,6 +54,7 @@ erpnext.PointOfSale.ItemDetails = class {
|
||||
this.$item_image = this.$component.find('.item-image');
|
||||
this.$form_container = this.$component.find('.form-container');
|
||||
this.$dicount_section = this.$component.find('.discount-section');
|
||||
this.$serial_batch_container = this.$component.find('.serial-batch-container');
|
||||
}
|
||||
|
||||
compare_with_current_item(item) {
|
||||
@@ -101,12 +103,9 @@ erpnext.PointOfSale.ItemDetails = class {
|
||||
|
||||
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;
|
||||
|
||||
if ((serialized && no_serial_selected) || (batched && no_batch_selected) ||
|
||||
(serialized && batched && (no_batch_selected || no_serial_selected))) {
|
||||
const no_bundle_selected = !item_row.serial_and_batch_bundle;
|
||||
|
||||
if ((serialized && no_bundle_selected) || (batched && no_bundle_selected)) {
|
||||
frappe.show_alert({
|
||||
message: __("Item is removed since no serial / batch no selected."),
|
||||
indicator: 'orange'
|
||||
@@ -200,13 +199,8 @@ erpnext.PointOfSale.ItemDetails = class {
|
||||
}
|
||||
|
||||
make_auto_serial_selection_btn(item) {
|
||||
if (item.has_serial_no) {
|
||||
if (!item.has_batch_no) {
|
||||
this.$form_container.append(
|
||||
`<div class="grid-filler no-select"></div>`
|
||||
);
|
||||
}
|
||||
const label = __('Auto Fetch Serial Numbers');
|
||||
if (item.has_serial_no || item.has_batch_no) {
|
||||
const label = item.has_serial_no ? __('Select Serial No') : __('Select Batch No');
|
||||
this.$form_container.append(
|
||||
`<div class="btn btn-sm btn-secondary auto-fetch-btn">${label}</div>`
|
||||
);
|
||||
@@ -382,40 +376,19 @@ erpnext.PointOfSale.ItemDetails = class {
|
||||
|
||||
bind_auto_serial_fetch_event() {
|
||||
this.$form_container.on('click', '.auto-fetch-btn', () => {
|
||||
this.batch_no_control && this.batch_no_control.set_value('');
|
||||
let qty = this.qty_control.get_value();
|
||||
let conversion_factor = this.conversion_factor_control.get_value();
|
||||
let expiry_date = this.item_row.has_batch_no ? this.events.get_frm().doc.posting_date : "";
|
||||
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", () => {
|
||||
let frm = this.events.get_frm();
|
||||
let item_row = this.item_row;
|
||||
item_row.outward = 1;
|
||||
item_row.type_of_transaction = "Outward";
|
||||
|
||||
let numbers = frappe.call({
|
||||
method: "erpnext.stock.doctype.serial_no.serial_no.auto_fetch_serial_number",
|
||||
args: {
|
||||
qty: qty * conversion_factor,
|
||||
item_code: this.current_item.item_code,
|
||||
warehouse: this.warehouse_control.get_value() || '',
|
||||
batch_nos: this.current_item.batch_no || '',
|
||||
posting_date: expiry_date,
|
||||
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();
|
||||
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])
|
||||
);
|
||||
} else if (records_length < qty) {
|
||||
frappe.msgprint(
|
||||
__('Fetched only {0} available serial numbers.', [records_length])
|
||||
);
|
||||
this.qty_control.set_value(records_length);
|
||||
}
|
||||
numbers = auto_fetched_serial_numbers.join(`\n`);
|
||||
this.serial_no_control.set_value(numbers);
|
||||
new erpnext.SerialBatchPackageSelector(frm, item_row, (r) => {
|
||||
if (r) {
|
||||
frm.refresh_fields();
|
||||
frappe.model.set_value(item_row.doctype, item_row.name,
|
||||
"serial_and_batch_bundle", r.name);
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user