fix: allow to change the batch in the subcontracting receipt (#43584)

This commit is contained in:
rohitwaghchaure
2024-10-09 13:04:13 +05:30
committed by GitHub
parent 7fc51cc832
commit fc67867a60
4 changed files with 120 additions and 25 deletions

View File

@@ -249,11 +249,15 @@ frappe.ui.form.on("Subcontracting Receipt", {
});
frm.set_query("batch_no", "supplied_items", (doc, cdt, cdn) => {
var row = locals[cdt][cdn];
let row = locals[cdt][cdn];
let filters = {
item_code: row.rm_item_code,
warehouse: doc.supplier_warehouse,
};
return {
filters: {
item: row.rm_item_code,
},
query: "erpnext.controllers.queries.get_batch_no",
filters: filters,
};
});

View File

@@ -257,9 +257,14 @@ class SubcontractingReceipt(SubcontractingController):
frappe.db.get_single_value("Buying Settings", "backflush_raw_materials_of_subcontract_based_on")
== "BOM"
and self.supplied_items
and not any(item.serial_and_batch_bundle for item in self.supplied_items)
):
self.supplied_items = []
if not any(
item.serial_and_batch_bundle or item.batch_no or item.serial_no
for item in self.supplied_items
):
self.supplied_items = []
else:
self.update_rate_for_supplied_items()
@frappe.whitelist()
def get_scrap_items(self, recalculate_rate=False):

View File

@@ -1370,6 +1370,66 @@ class TestSubcontractingReceipt(IntegrationTestCase):
frappe.db.set_single_value("Stock Settings", "use_serial_batch_fields", 1)
def test_change_batch_for_raw_materials(self):
set_backflush_based_on("BOM")
fg_item = make_item(properties={"is_stock_item": 1, "is_sub_contracted_item": 1}).name
rm_item1 = make_item(
properties={
"is_stock_item": 1,
"has_batch_no": 1,
"create_new_batch": 1,
"batch_number_series": "BNGS-.####",
}
).name
bom = make_bom(item=fg_item, raw_materials=[rm_item1])
second_batch_no = None
for row in bom.items:
se = make_stock_entry(
item_code=row.item_code,
qty=1,
target="_Test Warehouse 1 - _TC",
rate=300,
)
se.reload()
se1 = make_stock_entry(
item_code=row.item_code,
qty=1,
target="_Test Warehouse 1 - _TC",
rate=300,
)
se1.reload()
second_batch_no = get_batch_from_bundle(se1.items[0].serial_and_batch_bundle)
service_items = [
{
"warehouse": "_Test Warehouse - _TC",
"item_code": "Subcontracted Service Item 1",
"qty": 1,
"rate": 100,
"fg_item": fg_item,
"fg_item_qty": 1,
},
]
sco = get_subcontracting_order(service_items=service_items)
scr = make_subcontracting_receipt(sco.name)
scr.save()
scr.reload()
scr.supplied_items[0].batch_no = second_batch_no
scr.supplied_items[0].use_serial_batch_fields = 1
scr.submit()
scr.reload()
batch_no = get_batch_from_bundle(scr.supplied_items[0].serial_and_batch_bundle)
self.assertEqual(batch_no, second_batch_no)
self.assertEqual(scr.items[0].rm_cost_per_qty, 300)
self.assertEqual(scr.items[0].service_cost_per_qty, 100)
def make_return_subcontracting_receipt(**args):
args = frappe._dict(args)