mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-29 09:54:47 +00:00
refactor: use postprocess in mapped_doc to update items in subcontracting controller
This commit is contained in:
@@ -1394,38 +1394,19 @@ def make_rm_stock_entry(
|
|||||||
if target_doc and target_doc.get("items"):
|
if target_doc and target_doc.get("items"):
|
||||||
target_doc.items = []
|
target_doc.items = []
|
||||||
|
|
||||||
stock_entry = get_mapped_doc(
|
def post_process(source_doc, target_doc):
|
||||||
order_doctype,
|
target_doc.purpose = "Send to Subcontractor"
|
||||||
subcontract_order.name,
|
|
||||||
{
|
|
||||||
order_doctype: {
|
|
||||||
"doctype": "Stock Entry",
|
|
||||||
"field_map": {
|
|
||||||
"supplier": "supplier",
|
|
||||||
"supplier_name": "supplier_name",
|
|
||||||
"supplier_address": "supplier_address",
|
|
||||||
"to_warehouse": "supplier_warehouse",
|
|
||||||
},
|
|
||||||
"field_no_map": [field_no_map],
|
|
||||||
"validation": {
|
|
||||||
"docstatus": ["=", 1],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
target_doc,
|
|
||||||
ignore_child_tables=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
stock_entry.purpose = "Send to Subcontractor"
|
|
||||||
|
|
||||||
if order_doctype == "Purchase Order":
|
if order_doctype == "Purchase Order":
|
||||||
stock_entry.purchase_order = subcontract_order.name
|
target_doc.purchase_order = source_doc.name
|
||||||
else:
|
else:
|
||||||
stock_entry.subcontracting_order = subcontract_order.name
|
target_doc.subcontracting_order = source_doc.name
|
||||||
|
|
||||||
stock_entry.set_stock_entry_type()
|
target_doc.set_stock_entry_type()
|
||||||
|
|
||||||
over_transfer_allowance = frappe.get_single_value("Buying Settings", "over_transfer_allowance")
|
over_transfer_allowance = frappe.get_single_value(
|
||||||
|
"Buying Settings", "over_transfer_allowance"
|
||||||
|
)
|
||||||
for fg_item_code in fg_item_code_list:
|
for fg_item_code in fg_item_code_list:
|
||||||
for rm_item in rm_items:
|
for rm_item in rm_items:
|
||||||
if (
|
if (
|
||||||
@@ -1456,7 +1437,7 @@ def make_rm_stock_entry(
|
|||||||
"qty": qty,
|
"qty": qty,
|
||||||
"from_warehouse": rm_item.get("warehouse")
|
"from_warehouse": rm_item.get("warehouse")
|
||||||
or rm_item.get("reserve_warehouse"),
|
or rm_item.get("reserve_warehouse"),
|
||||||
"to_warehouse": subcontract_order.supplier_warehouse,
|
"to_warehouse": source_doc.supplier_warehouse,
|
||||||
"stock_uom": rm_item.get("stock_uom"),
|
"stock_uom": rm_item.get("stock_uom"),
|
||||||
"serial_and_batch_bundle": rm_item.get("serial_and_batch_bundle"),
|
"serial_and_batch_bundle": rm_item.get("serial_and_batch_bundle"),
|
||||||
"main_item_code": fg_item_code,
|
"main_item_code": fg_item_code,
|
||||||
@@ -1473,7 +1454,30 @@ def make_rm_stock_entry(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stock_entry.add_to_stock_entry_detail(items_dict)
|
target_doc.add_to_stock_entry_detail(items_dict)
|
||||||
|
|
||||||
|
stock_entry = get_mapped_doc(
|
||||||
|
order_doctype,
|
||||||
|
subcontract_order.name,
|
||||||
|
{
|
||||||
|
order_doctype: {
|
||||||
|
"doctype": "Stock Entry",
|
||||||
|
"field_map": {
|
||||||
|
"supplier": "supplier",
|
||||||
|
"supplier_name": "supplier_name",
|
||||||
|
"supplier_address": "supplier_address",
|
||||||
|
"to_warehouse": "supplier_warehouse",
|
||||||
|
},
|
||||||
|
"field_no_map": [field_no_map],
|
||||||
|
"validation": {
|
||||||
|
"docstatus": ["=", 1],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
target_doc,
|
||||||
|
ignore_child_tables=True,
|
||||||
|
postprocess=post_process,
|
||||||
|
)
|
||||||
|
|
||||||
if target_doc:
|
if target_doc:
|
||||||
return stock_entry
|
return stock_entry
|
||||||
@@ -1506,6 +1510,8 @@ def add_items_in_ste(ste_doc, row, qty, rm_details, rm_detail_field="sco_rm_deta
|
|||||||
def make_return_stock_entry_for_subcontract(
|
def make_return_stock_entry_for_subcontract(
|
||||||
available_materials, order_doc, rm_details, order_doctype="Subcontracting Order"
|
available_materials, order_doc, rm_details, order_doctype="Subcontracting Order"
|
||||||
):
|
):
|
||||||
|
rm_detail_field = "po_detail" if order_doctype == "Purchase Order" else "sco_rm_detail"
|
||||||
|
|
||||||
def post_process(source_doc, target_doc):
|
def post_process(source_doc, target_doc):
|
||||||
target_doc.purpose = "Material Transfer"
|
target_doc.purpose = "Material Transfer"
|
||||||
|
|
||||||
@@ -1516,6 +1522,21 @@ def make_return_stock_entry_for_subcontract(
|
|||||||
|
|
||||||
target_doc.company = source_doc.company
|
target_doc.company = source_doc.company
|
||||||
target_doc.is_return = 1
|
target_doc.is_return = 1
|
||||||
|
for _key, value in available_materials.items():
|
||||||
|
if not value.qty:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if item_details := value.get("item_details"):
|
||||||
|
item_details["serial_and_batch_bundle"] = None
|
||||||
|
|
||||||
|
if value.batch_no:
|
||||||
|
for batch_no, qty in value.batch_no.items():
|
||||||
|
if qty > 0:
|
||||||
|
add_items_in_ste(target_doc, value, qty, rm_details, rm_detail_field, batch_no)
|
||||||
|
else:
|
||||||
|
add_items_in_ste(target_doc, value, value.qty, rm_details, rm_detail_field)
|
||||||
|
|
||||||
|
target_doc.set_stock_entry_type()
|
||||||
|
|
||||||
ste_doc = get_mapped_doc(
|
ste_doc = get_mapped_doc(
|
||||||
order_doctype,
|
order_doctype,
|
||||||
@@ -1530,27 +1551,6 @@ def make_return_stock_entry_for_subcontract(
|
|||||||
postprocess=post_process,
|
postprocess=post_process,
|
||||||
)
|
)
|
||||||
|
|
||||||
if order_doctype == "Purchase Order":
|
|
||||||
rm_detail_field = "po_detail"
|
|
||||||
else:
|
|
||||||
rm_detail_field = "sco_rm_detail"
|
|
||||||
|
|
||||||
for _key, value in available_materials.items():
|
|
||||||
if not value.qty:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if item_details := value.get("item_details"):
|
|
||||||
item_details["serial_and_batch_bundle"] = None
|
|
||||||
|
|
||||||
if value.batch_no:
|
|
||||||
for batch_no, qty in value.batch_no.items():
|
|
||||||
if qty > 0:
|
|
||||||
add_items_in_ste(ste_doc, value, qty, rm_details, rm_detail_field, batch_no)
|
|
||||||
else:
|
|
||||||
add_items_in_ste(ste_doc, value, value.qty, rm_details, rm_detail_field)
|
|
||||||
|
|
||||||
ste_doc.set_stock_entry_type()
|
|
||||||
|
|
||||||
return ste_doc
|
return ste_doc
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user