Skip to content

Commit

Permalink
fix: valuation rate for the subcontracting receipt supplied items wit…
Browse files Browse the repository at this point in the history
…h Serial and Batch Bundle (backport #38094) (backport #38097) (#38101)

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 3e77c0b)

Co-authored-by: rohitwaghchaure <[email protected]>
(cherry picked from commit 28e6e5d)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mergify[bot] authored Nov 14, 2023
1 parent 9f9a4a9 commit 880cea5
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 3 deletions.
13 changes: 13 additions & 0 deletions erpnext/controllers/subcontracting_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,18 @@ def __set_supplied_items(self):
(row.item_code, row.get(self.subcontract_data.order_field))
] -= 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):
if self.is_new():
return
Expand Down Expand Up @@ -681,6 +693,7 @@ def __prepare_supplied_items(self):
self.__remove_changed_rows()
self.__set_supplied_items()
self.__modify_serial_and_batch_bundle()
self.__set_rate_for_serial_and_batch_bundle()

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"posting_date",
"posting_time",
"is_adjustment_entry",
"auto_created_serial_and_batch_bundle",
"column_break_6",
"voucher_type",
"voucher_no",
Expand Down Expand Up @@ -340,6 +341,13 @@
"fieldname": "is_adjustment_entry",
"fieldtype": "Check",
"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,
Expand All @@ -348,7 +356,7 @@
"in_create": 1,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-10-23 18:07:42.063615",
"modified": "2023-11-14 16:47:39.791967",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Ledger Entry",
Expand Down
10 changes: 9 additions & 1 deletion erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ def validate_item(self):
frappe.throw(_(error_msg))

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:
frappe.db.set_value(
Expand All @@ -143,6 +145,12 @@ def set_serial_and_batch_bundle(self, sn_doc):
@property
def child_doctype(self):
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":
child_doctype = "Stock Entry Detail"

Expand Down
4 changes: 3 additions & 1 deletion erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,9 @@ def process_sle(self, sle):
sle.doctype = "Stock Ledger Entry"
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)

def reset_actual_qty_for_stock_reco(self, sle):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ frappe.ui.form.on('Subcontracting Receipt', {
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) => {
if (frm.doc.docstatus > 0) {
frm.add_custom_button(__('Stock Ledger'), () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,97 @@ def test_subcontracting_receipt_for_batch_raw_materials_without_material_transfe
self.assertEqual(scr.items[0].rm_cost_per_qty, 300)
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):
# Step - 1: Set Backflush Based On as "BOM"
set_backflush_based_on("BOM")
Expand Down

0 comments on commit 880cea5

Please sign in to comment.