fix: valuation rate for the subcontracting receipt supplied items with Serial and Batch Bundle (backport #38094) (#38097)
fix: valuation rate for the subcontracting receipt supplied items with Serial and Batch Bundle (#38094) fix: valuation rate for the subcontracting receipt supplied items with batch (cherry picked from commit 3e77c0b5644c28ed9b4eef22b228fdc4a1283020) Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
parent
77b1eedcf4
commit
28e6e5d910
@ -626,6 +626,18 @@ class SubcontractingController(StockController):
|
|||||||
(row.item_code, row.get(self.subcontract_data.order_field))
|
(row.item_code, row.get(self.subcontract_data.order_field))
|
||||||
] -= row.qty
|
] -= row.qty
|
||||||
|
|
||||||
|
def __set_rate_for_serial_and_batch_bundle(self):
|
||||||
|
if self.doctype != "Subcontracting Receipt":
|
||||||
|
return
|
||||||
|
|
||||||
|
for row in self.get(self.raw_material_table):
|
||||||
|
if not row.get("serial_and_batch_bundle"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
row.rate = frappe.get_cached_value(
|
||||||
|
"Serial and Batch Bundle", row.serial_and_batch_bundle, "avg_rate"
|
||||||
|
)
|
||||||
|
|
||||||
def __modify_serial_and_batch_bundle(self):
|
def __modify_serial_and_batch_bundle(self):
|
||||||
if self.is_new():
|
if self.is_new():
|
||||||
return
|
return
|
||||||
@ -681,6 +693,7 @@ class SubcontractingController(StockController):
|
|||||||
self.__remove_changed_rows()
|
self.__remove_changed_rows()
|
||||||
self.__set_supplied_items()
|
self.__set_supplied_items()
|
||||||
self.__modify_serial_and_batch_bundle()
|
self.__modify_serial_and_batch_bundle()
|
||||||
|
self.__set_rate_for_serial_and_batch_bundle()
|
||||||
|
|
||||||
def __validate_batch_no(self, row, key):
|
def __validate_batch_no(self, row, key):
|
||||||
if row.get("batch_no") and row.get("batch_no") not in self.__transferred_items.get(key).get(
|
if row.get("batch_no") and row.get("batch_no") not in self.__transferred_items.get(key).get(
|
||||||
|
|||||||
@ -12,6 +12,7 @@
|
|||||||
"posting_date",
|
"posting_date",
|
||||||
"posting_time",
|
"posting_time",
|
||||||
"is_adjustment_entry",
|
"is_adjustment_entry",
|
||||||
|
"auto_created_serial_and_batch_bundle",
|
||||||
"column_break_6",
|
"column_break_6",
|
||||||
"voucher_type",
|
"voucher_type",
|
||||||
"voucher_no",
|
"voucher_no",
|
||||||
@ -340,6 +341,13 @@
|
|||||||
"fieldname": "is_adjustment_entry",
|
"fieldname": "is_adjustment_entry",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"label": "Is Adjustment Entry"
|
"label": "Is Adjustment Entry"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"default": "0",
|
||||||
|
"depends_on": "serial_and_batch_bundle",
|
||||||
|
"fieldname": "auto_created_serial_and_batch_bundle",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"label": "Auto Created Serial and Batch Bundle"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hide_toolbar": 1,
|
"hide_toolbar": 1,
|
||||||
@ -348,7 +356,7 @@
|
|||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-10-23 18:07:42.063615",
|
"modified": "2023-11-14 16:47:39.791967",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Stock Ledger Entry",
|
"name": "Stock Ledger Entry",
|
||||||
|
|||||||
@ -129,7 +129,9 @@ class SerialBatchBundle:
|
|||||||
frappe.throw(_(error_msg))
|
frappe.throw(_(error_msg))
|
||||||
|
|
||||||
def set_serial_and_batch_bundle(self, sn_doc):
|
def set_serial_and_batch_bundle(self, sn_doc):
|
||||||
self.sle.db_set("serial_and_batch_bundle", sn_doc.name)
|
self.sle.db_set(
|
||||||
|
{"serial_and_batch_bundle": sn_doc.name, "auto_created_serial_and_batch_bundle": 1}
|
||||||
|
)
|
||||||
|
|
||||||
if sn_doc.is_rejected:
|
if sn_doc.is_rejected:
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
@ -143,6 +145,12 @@ class SerialBatchBundle:
|
|||||||
@property
|
@property
|
||||||
def child_doctype(self):
|
def child_doctype(self):
|
||||||
child_doctype = self.sle.voucher_type + " Item"
|
child_doctype = self.sle.voucher_type + " Item"
|
||||||
|
|
||||||
|
if (
|
||||||
|
self.sle.voucher_type == "Subcontracting Receipt" and self.sle.dependant_sle_voucher_detail_no
|
||||||
|
):
|
||||||
|
child_doctype = "Subcontracting Receipt Supplied Item"
|
||||||
|
|
||||||
if self.sle.voucher_type == "Stock Entry":
|
if self.sle.voucher_type == "Stock Entry":
|
||||||
child_doctype = "Stock Entry Detail"
|
child_doctype = "Stock Entry Detail"
|
||||||
|
|
||||||
|
|||||||
@ -759,7 +759,9 @@ class update_entries_after(object):
|
|||||||
sle.doctype = "Stock Ledger Entry"
|
sle.doctype = "Stock Ledger Entry"
|
||||||
frappe.get_doc(sle).db_update()
|
frappe.get_doc(sle).db_update()
|
||||||
|
|
||||||
if not self.args.get("sle_id"):
|
if not self.args.get("sle_id") or (
|
||||||
|
sle.serial_and_batch_bundle and sle.auto_created_serial_and_batch_bundle
|
||||||
|
):
|
||||||
self.update_outgoing_rate_on_transaction(sle)
|
self.update_outgoing_rate_on_transaction(sle)
|
||||||
|
|
||||||
def reset_actual_qty_for_stock_reco(self, sle):
|
def reset_actual_qty_for_stock_reco(self, sle):
|
||||||
|
|||||||
@ -13,6 +13,16 @@ frappe.ui.form.on('Subcontracting Receipt', {
|
|||||||
frm.trigger('set_queries');
|
frm.trigger('set_queries');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
on_submit(frm) {
|
||||||
|
frm.events.refresh_serial_batch_bundle_field(frm);
|
||||||
|
},
|
||||||
|
|
||||||
|
refresh_serial_batch_bundle_field(frm) {
|
||||||
|
frappe.route_hooks.after_submit = (frm_obj) => {
|
||||||
|
frm_obj.reload_doc();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
refresh: (frm) => {
|
refresh: (frm) => {
|
||||||
if (frm.doc.docstatus > 0) {
|
if (frm.doc.docstatus > 0) {
|
||||||
frm.add_custom_button(__('Stock Ledger'), () => {
|
frm.add_custom_button(__('Stock Ledger'), () => {
|
||||||
|
|||||||
@ -576,6 +576,97 @@ class TestSubcontractingReceipt(FrappeTestCase):
|
|||||||
self.assertEqual(scr.items[0].rm_cost_per_qty, 300)
|
self.assertEqual(scr.items[0].rm_cost_per_qty, 300)
|
||||||
self.assertEqual(scr.items[0].service_cost_per_qty, 100)
|
self.assertEqual(scr.items[0].service_cost_per_qty, 100)
|
||||||
|
|
||||||
|
def test_subcontracting_receipt_valuation_with_auto_created_serial_batch_bundle(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
|
||||||
|
|
||||||
|
rm_item2 = make_item(
|
||||||
|
properties={
|
||||||
|
"is_stock_item": 1,
|
||||||
|
"has_batch_no": 1,
|
||||||
|
"has_serial_no": 1,
|
||||||
|
"create_new_batch": 1,
|
||||||
|
"batch_number_series": "BNGS-.####",
|
||||||
|
"serial_no_series": "BNSS-.####",
|
||||||
|
}
|
||||||
|
).name
|
||||||
|
|
||||||
|
rm_item3 = make_item(
|
||||||
|
properties={
|
||||||
|
"is_stock_item": 1,
|
||||||
|
"has_serial_no": 1,
|
||||||
|
"serial_no_series": "BSSSS-.####",
|
||||||
|
}
|
||||||
|
).name
|
||||||
|
|
||||||
|
bom = make_bom(item=fg_item, raw_materials=[rm_item1, rm_item2, rm_item3])
|
||||||
|
|
||||||
|
rm_batch_no = None
|
||||||
|
for row in bom.items:
|
||||||
|
make_stock_entry(
|
||||||
|
item_code=row.item_code,
|
||||||
|
qty=1,
|
||||||
|
target="_Test Warehouse 1 - _TC",
|
||||||
|
rate=300,
|
||||||
|
)
|
||||||
|
|
||||||
|
make_stock_entry(
|
||||||
|
item_code=row.item_code,
|
||||||
|
qty=1,
|
||||||
|
target="_Test Warehouse 1 - _TC",
|
||||||
|
rate=400,
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
frappe.db.set_single_value(
|
||||||
|
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 1
|
||||||
|
)
|
||||||
|
scr = make_subcontracting_receipt(sco.name)
|
||||||
|
scr.save()
|
||||||
|
for row in scr.supplied_items:
|
||||||
|
self.assertNotEqual(row.rate, 300.00)
|
||||||
|
self.assertFalse(row.serial_and_batch_bundle)
|
||||||
|
|
||||||
|
scr.submit()
|
||||||
|
scr.reload()
|
||||||
|
|
||||||
|
for row in scr.supplied_items:
|
||||||
|
self.assertEqual(row.rate, 300.00)
|
||||||
|
self.assertTrue(row.serial_and_batch_bundle)
|
||||||
|
auto_created_serial_batch = frappe.db.get_value(
|
||||||
|
"Stock Ledger Entry",
|
||||||
|
{"voucher_no": scr.name, "voucher_detail_no": row.name},
|
||||||
|
"auto_created_serial_and_batch_bundle",
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(auto_created_serial_batch)
|
||||||
|
|
||||||
|
self.assertEqual(scr.items[0].rm_cost_per_qty, 900)
|
||||||
|
self.assertEqual(scr.items[0].service_cost_per_qty, 100)
|
||||||
|
frappe.db.set_single_value(
|
||||||
|
"Stock Settings", "auto_create_serial_and_batch_bundle_for_outward", 0
|
||||||
|
)
|
||||||
|
|
||||||
def test_subcontracting_receipt_raw_material_rate(self):
|
def test_subcontracting_receipt_raw_material_rate(self):
|
||||||
# Step - 1: Set Backflush Based On as "BOM"
|
# Step - 1: Set Backflush Based On as "BOM"
|
||||||
set_backflush_based_on("BOM")
|
set_backflush_based_on("BOM")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user