mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-09 01:45:09 +00:00
fix: disassembly prompt with source stock entry field
(cherry picked from commit 68e97808c5)
# Conflicts:
# erpnext/manufacturing/doctype/work_order/work_order.py
This commit is contained in:
@@ -441,7 +441,7 @@ frappe.ui.form.on("Work Order", {
|
||||
|
||||
make_disassembly_order(frm) {
|
||||
erpnext.work_order
|
||||
.show_prompt_for_qty_input(frm, "Disassemble")
|
||||
.show_disassembly_prompt(frm)
|
||||
.then((data) => {
|
||||
if (flt(data.qty) <= 0) {
|
||||
frappe.msgprint(__("Disassemble Qty cannot be less than or equal to <b>0</b>."));
|
||||
@@ -451,11 +451,14 @@ frappe.ui.form.on("Work Order", {
|
||||
work_order_id: frm.doc.name,
|
||||
purpose: "Disassemble",
|
||||
qty: data.qty,
|
||||
source_stock_entry: data.source_stock_entry,
|
||||
});
|
||||
})
|
||||
.then((stock_entry) => {
|
||||
frappe.model.sync(stock_entry);
|
||||
frappe.set_route("Form", stock_entry.doctype, stock_entry.name);
|
||||
if (stock_entry) {
|
||||
frappe.model.sync(stock_entry);
|
||||
frappe.set_route("Form", stock_entry.doctype, stock_entry.name);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1002,6 +1005,60 @@ erpnext.work_order = {
|
||||
return flt(max, precision("qty"));
|
||||
},
|
||||
|
||||
show_disassembly_prompt: function (frm) {
|
||||
let max_qty = flt(frm.doc.produced_qty - frm.doc.disassembled_qty);
|
||||
|
||||
let fields = [
|
||||
{
|
||||
fieldtype: "Link",
|
||||
label: __("Source Manufacture Entry"),
|
||||
fieldname: "source_stock_entry",
|
||||
options: "Stock Entry",
|
||||
description: __("Optional. Select a specific manufacture entry to reverse."),
|
||||
get_query: () => {
|
||||
return {
|
||||
filters: {
|
||||
work_order: frm.doc.name,
|
||||
purpose: "Manufacture",
|
||||
docstatus: 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
onchange: async function () {
|
||||
if (!frm.disassembly_prompt) return;
|
||||
|
||||
let se_name = this.value;
|
||||
let qty = max_qty;
|
||||
if (se_name) {
|
||||
qty = await frappe.xcall(
|
||||
"erpnext.manufacturing.doctype.work_order.work_order.get_disassembly_available_qty",
|
||||
{ stock_entry_name: se_name }
|
||||
);
|
||||
}
|
||||
|
||||
frm.disassembly_prompt.set_value("qty", qty);
|
||||
frm.disassembly_prompt.fields_dict.qty.set_description(__("Max: {0}", [qty]));
|
||||
},
|
||||
},
|
||||
{
|
||||
fieldtype: "Float",
|
||||
label: __("Qty for {0}", [__("Disassemble")]),
|
||||
fieldname: "qty",
|
||||
description: __("Max: {0}", [max_qty]),
|
||||
default: max_qty,
|
||||
},
|
||||
];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
frm.disassembly_prompt = frappe.prompt(
|
||||
fields,
|
||||
(data) => resolve(data),
|
||||
__("Disassemble"),
|
||||
__("Create")
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
show_prompt_for_qty_input: function (frm, purpose, qty, additional_transfer_entry) {
|
||||
let max = !additional_transfer_entry ? this.get_max_transferable_qty(frm, purpose) : qty;
|
||||
|
||||
|
||||
@@ -2376,6 +2376,7 @@ def make_stock_entry(
|
||||
qty: float | None = None,
|
||||
target_warehouse: str | None = None,
|
||||
is_additional_transfer_entry: bool = False,
|
||||
source_stock_entry: str | None = None,
|
||||
):
|
||||
work_order = frappe.get_doc("Work Order", work_order_id)
|
||||
if not frappe.db.get_value("Warehouse", work_order.wip_warehouse, "is_group"):
|
||||
@@ -2416,6 +2417,8 @@ def make_stock_entry(
|
||||
if purpose == "Disassemble":
|
||||
stock_entry.from_warehouse = work_order.fg_warehouse
|
||||
stock_entry.to_warehouse = target_warehouse or work_order.source_warehouse
|
||||
if source_stock_entry:
|
||||
stock_entry.source_stock_entry = source_stock_entry
|
||||
|
||||
stock_entry.set_stock_entry_type()
|
||||
stock_entry.is_additional_transfer_entry = is_additional_transfer_entry
|
||||
@@ -2429,7 +2432,32 @@ def make_stock_entry(
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
<<<<<<< HEAD
|
||||
def get_default_warehouse(company):
|
||||
=======
|
||||
def get_disassembly_available_qty(stock_entry_name: str) -> float:
|
||||
se = frappe.db.get_value("Stock Entry", stock_entry_name, ["fg_completed_qty"], as_dict=True)
|
||||
if not se:
|
||||
return 0.0
|
||||
|
||||
already_disassembled = flt(
|
||||
frappe.db.get_value(
|
||||
"Stock Entry",
|
||||
{
|
||||
"source_stock_entry": stock_entry_name,
|
||||
"purpose": "Disassemble",
|
||||
"docstatus": 1,
|
||||
},
|
||||
[{"SUM": "fg_completed_qty"}],
|
||||
)
|
||||
)
|
||||
|
||||
return flt(se.fg_completed_qty) - already_disassembled
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_default_warehouse(company: str):
|
||||
>>>>>>> 68e97808c5 (fix: disassembly prompt with source stock entry field)
|
||||
wip, fg, scrap = frappe.get_cached_value(
|
||||
"Company", company, ["default_wip_warehouse", "default_fg_warehouse", "default_scrap_warehouse"]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user