mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 19:59:12 +00:00
feat: Service Item and Finished Good Map (#36647)
* feat: new DocType `Service Item and Finished Good Map` * fix(ux): filters for Service Item and Finished Good * fix: validations for Service Item and Finished Good * feat: set FG Item on Service Item selection in PO * refactor: one-to-many mapping between service item and finished goods * feat: auto set Service Item for finished good in PO created from PP * feat: auto set Service Item on Finished Good selection in PO * test: add test case for service item and finished goods map * feat: `BOM` field in `Finished Good Detail` * feat: new DocType `Subcontracting BOM` * fix: filters and validations for Subcontracting BOM * feat: auto select Service Item in PO created from PP * test: add test case for PO service item auto pick * feat: pick BOM from Subcontracting BOM in SCO * feat: auto pick `Service Item` on FG select * refactor: remove DocType `Service Item and Finished Goods Map` and `Finished Good Detail` * feat: fetch FG for Service Item * chore: `linter` * refactor: update `Auto Name` expression for Subcontracting BOM
This commit is contained in:
@@ -118,6 +118,24 @@ frappe.ui.form.on("Purchase Order", {
|
||||
frm.set_value("tax_withholding_category", frm.supplier_tds);
|
||||
}
|
||||
},
|
||||
|
||||
get_subcontracting_boms_for_finished_goods: function(fg_item) {
|
||||
return frappe.call({
|
||||
method:"erpnext.subcontracting.doctype.subcontracting_bom.subcontracting_bom.get_subcontracting_boms_for_finished_goods",
|
||||
args: {
|
||||
fg_items: fg_item
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
get_subcontracting_boms_for_service_item: function(service_item) {
|
||||
return frappe.call({
|
||||
method:"erpnext.subcontracting.doctype.subcontracting_bom.subcontracting_bom.get_subcontracting_boms_for_service_item",
|
||||
args: {
|
||||
service_item: service_item
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
frappe.ui.form.on("Purchase Order Item", {
|
||||
@@ -132,15 +150,83 @@ frappe.ui.form.on("Purchase Order Item", {
|
||||
}
|
||||
},
|
||||
|
||||
qty: function(frm, cdt, cdn) {
|
||||
item_code: async function(frm, cdt, cdn) {
|
||||
if (frm.doc.is_subcontracted && !frm.doc.is_old_subcontracting_flow) {
|
||||
var row = locals[cdt][cdn];
|
||||
|
||||
if (row.qty) {
|
||||
row.fg_item_qty = row.qty;
|
||||
if (row.item_code && !row.fg_item) {
|
||||
var result = await frm.events.get_subcontracting_boms_for_service_item(row.item_code)
|
||||
|
||||
if (result.message && Object.keys(result.message).length) {
|
||||
var finished_goods = Object.keys(result.message);
|
||||
|
||||
// Set FG if only one active Subcontracting BOM is found
|
||||
if (finished_goods.length === 1) {
|
||||
row.fg_item = result.message[finished_goods[0]].finished_good;
|
||||
row.uom = result.message[finished_goods[0]].finished_good_uom;
|
||||
refresh_field("items");
|
||||
} else {
|
||||
const dialog = new frappe.ui.Dialog({
|
||||
title: __("Select Finished Good"),
|
||||
size: "small",
|
||||
fields: [
|
||||
{
|
||||
fieldname: "finished_good",
|
||||
fieldtype: "Autocomplete",
|
||||
label: __("Finished Good"),
|
||||
options: finished_goods,
|
||||
}
|
||||
],
|
||||
primary_action_label: __("Select"),
|
||||
primary_action: () => {
|
||||
var subcontracting_bom = result.message[dialog.get_value("finished_good")];
|
||||
|
||||
if (subcontracting_bom) {
|
||||
row.fg_item = subcontracting_bom.finished_good;
|
||||
row.uom = subcontracting_bom.finished_good_uom;
|
||||
refresh_field("items");
|
||||
}
|
||||
|
||||
dialog.hide();
|
||||
},
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
fg_item: async function(frm, cdt, cdn) {
|
||||
if (frm.doc.is_subcontracted && !frm.doc.is_old_subcontracting_flow) {
|
||||
var row = locals[cdt][cdn];
|
||||
|
||||
if (row.fg_item) {
|
||||
var result = await frm.events.get_subcontracting_boms_for_finished_goods(row.fg_item)
|
||||
|
||||
if (result.message && Object.keys(result.message).length) {
|
||||
frappe.model.set_value(cdt, cdn, "item_code", result.message.service_item);
|
||||
frappe.model.set_value(cdt, cdn, "qty", flt(row.fg_item_qty) * flt(result.message.conversion_factor));
|
||||
frappe.model.set_value(cdt, cdn, "uom", result.message.service_item_uom);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
fg_item_qty: async function(frm, cdt, cdn) {
|
||||
if (frm.doc.is_subcontracted && !frm.doc.is_old_subcontracting_flow) {
|
||||
var row = locals[cdt][cdn];
|
||||
|
||||
if (row.fg_item) {
|
||||
var result = await frm.events.get_subcontracting_boms_for_finished_goods(row.fg_item)
|
||||
|
||||
if (result.message && row.item_code == result.message.service_item && row.uom == result.message.service_item_uom) {
|
||||
frappe.model.set_value(cdt, cdn, "qty", flt(row.fg_item_qty) * flt(result.message.conversion_factor));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
erpnext.buying.PurchaseOrderController = class PurchaseOrderController extends erpnext.buying.BuyingController {
|
||||
|
||||
@@ -28,6 +28,9 @@ from erpnext.setup.doctype.item_group.item_group import get_item_group_defaults
|
||||
from erpnext.stock.doctype.item.item import get_item_defaults, get_last_purchase_details
|
||||
from erpnext.stock.stock_balance import get_ordered_qty, update_bin_qty
|
||||
from erpnext.stock.utils import get_bin
|
||||
from erpnext.subcontracting.doctype.subcontracting_bom.subcontracting_bom import (
|
||||
get_subcontracting_boms_for_finished_goods,
|
||||
)
|
||||
|
||||
form_grid_templates = {"items": "templates/form_grid/item_grid.html"}
|
||||
|
||||
@@ -451,6 +454,25 @@ class PurchaseOrder(BuyingController):
|
||||
else:
|
||||
self.db_set("per_received", 0, update_modified=False)
|
||||
|
||||
def set_service_items_for_finished_goods(self):
|
||||
if not self.is_subcontracted or self.is_old_subcontracting_flow:
|
||||
return
|
||||
|
||||
finished_goods_without_service_item = {
|
||||
d.fg_item for d in self.items if (not d.item_code and d.fg_item)
|
||||
}
|
||||
|
||||
if subcontracting_boms := get_subcontracting_boms_for_finished_goods(
|
||||
finished_goods_without_service_item
|
||||
):
|
||||
for item in self.items:
|
||||
if not item.item_code and item.fg_item in subcontracting_boms:
|
||||
subcontracting_bom = subcontracting_boms[item.fg_item]
|
||||
|
||||
item.item_code = subcontracting_bom.service_item
|
||||
item.qty = flt(item.fg_item_qty) * flt(subcontracting_bom.conversion_factor)
|
||||
item.uom = subcontracting_bom.service_item_uom
|
||||
|
||||
def can_update_items(self) -> bool:
|
||||
result = True
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"fg_item",
|
||||
"fg_item_qty",
|
||||
"item_code",
|
||||
"supplier_part_no",
|
||||
"item_name",
|
||||
"brand",
|
||||
"product_bundle",
|
||||
"fg_item",
|
||||
"fg_item_qty",
|
||||
"column_break_4",
|
||||
"schedule_date",
|
||||
"expected_delivery_date",
|
||||
@@ -862,7 +862,7 @@
|
||||
"depends_on": "eval:parent.is_subcontracted && !parent.is_old_subcontracting_flow",
|
||||
"fieldname": "fg_item",
|
||||
"fieldtype": "Link",
|
||||
"label": "Finished Good Item",
|
||||
"label": "Finished Good",
|
||||
"mandatory_depends_on": "eval:parent.is_subcontracted && !parent.is_old_subcontracting_flow",
|
||||
"options": "Item"
|
||||
},
|
||||
@@ -871,7 +871,7 @@
|
||||
"depends_on": "eval:parent.is_subcontracted && !parent.is_old_subcontracting_flow",
|
||||
"fieldname": "fg_item_qty",
|
||||
"fieldtype": "Float",
|
||||
"label": "Finished Good Item Qty",
|
||||
"label": "Finished Good Qty",
|
||||
"mandatory_depends_on": "eval:parent.is_subcontracted && !parent.is_old_subcontracting_flow"
|
||||
},
|
||||
{
|
||||
@@ -902,7 +902,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2022-11-29 16:47:41.364387",
|
||||
"modified": "2023-08-17 10:17:40.893393",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Buying",
|
||||
"name": "Purchase Order Item",
|
||||
|
||||
Reference in New Issue
Block a user