Skip to content

Commit

Permalink
fix: validation error has not throw for the batch (backport #38494) (#…
Browse files Browse the repository at this point in the history
…38502)

fix: validation error has not throw for the batch (#38494)

* fix: validation error has not throw for the batch

* chore: fix test cases

(cherry picked from commit 5e9016f)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
  • Loading branch information
mergify[bot] and rohitwaghchaure authored Dec 1, 2023
1 parent 7b363db commit c797c53
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2635,6 +2635,7 @@ def test_internal_transfer_gl_entry(self):
"voucher_type": "Sales Invoice",
"voucher_no": si.name,
"allow_zero_valuation": d.get("allow_zero_valuation"),
"voucher_detail_no": d.name,
},
raise_error_if_no_rate=False,
)
Expand Down
2 changes: 2 additions & 0 deletions erpnext/controllers/buying_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def set_rate_for_standalone_debit_note(self):
"company": self.company,
"voucher_type": self.doctype,
"voucher_no": self.name,
"voucher_detail_no": row.name,
},
raise_error_if_no_rate=False,
)
Expand Down Expand Up @@ -373,6 +374,7 @@ def set_incoming_rate(self):
"voucher_type": self.doctype,
"voucher_no": self.name,
"allow_zero_valuation": d.get("allow_zero_valuation"),
"voucher_detail_no": d.name,
},
raise_error_if_no_rate=False,
)
Expand Down
1 change: 1 addition & 0 deletions erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ def set_incoming_rate(self):
"company": self.company,
"voucher_type": self.doctype,
"voucher_no": self.name,
"voucher_detail_no": d.name,
"allow_zero_valuation": d.get("allow_zero_valuation"),
},
raise_error_if_no_rate=False,
Expand Down
1 change: 1 addition & 0 deletions erpnext/controllers/subcontracting_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ def get_supplied_items_cost(self, item_row_id, reset_outgoing_rate=True):
"posting_date": self.posting_date,
"posting_time": self.posting_time,
"qty": -1 * item.consumed_qty,
"voucher_detail_no": item.name,
"serial_and_batch_bundle": item.serial_and_batch_bundle,
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ def get_sle_for_outward_transaction(self):
"serial_nos": [row.serial_no for row in self.entries if row.serial_no],
"batch_nos": {row.batch_no: row for row in self.entries if row.batch_no},
"voucher_type": self.voucher_type,
"voucher_detail_no": self.voucher_detail_no,
}
)

Expand Down
1 change: 1 addition & 0 deletions erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ def get_args_for_incoming_rate(self, item):
"company": self.company,
"allow_zero_valuation": item.allow_zero_valuation_rate,
"serial_and_batch_bundle": item.serial_and_batch_bundle,
"voucher_detail_no": item.name,
}
)

Expand Down
36 changes: 36 additions & 0 deletions erpnext/stock/doctype/stock_entry/test_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,42 @@ def test_variant_work_order(self):
stock_entry.insert()
self.assertTrue("_Test Variant Item-S" in [d.item_code for d in stock_entry.items])

def test_nagative_stock_for_batch(self):
item = make_item(
"_Test Batch Negative Item",
{
"has_batch_no": 1,
"create_new_batch": 1,
"batch_number_series": "B-BATCH-.##",
"is_stock_item": 1,
},
)

make_stock_entry(item_code=item.name, target="_Test Warehouse - _TC", qty=50, basic_rate=100)

ste = frappe.new_doc("Stock Entry")
ste.purpose = "Material Issue"
ste.company = "_Test Company"
for qty in [50, 20, 30]:
ste.append(
"items",
{
"item_code": item.name,
"s_warehouse": "_Test Warehouse - _TC",
"qty": qty,
"uom": item.stock_uom,
"stock_uom": item.stock_uom,
"conversion_factor": 1,
"transfer_qty": qty,
},
)

ste.set_stock_entry_type()
ste.insert()
make_stock_entry(item_code=item.name, target="_Test Warehouse - _TC", qty=50, basic_rate=100)

self.assertRaises(frappe.ValidationError, ste.submit)

def test_same_serial_nos_in_repack_or_manufacture_entries(self):
s1 = make_serialized_item(target_warehouse="_Test Warehouse - _TC")
serial_nos = get_serial_nos_from_bundle(s1.get("items")[0].serial_and_batch_bundle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ def test_batchwise_item_valuation_moving_average(self):
dns = create_delivery_note_entries_for_batchwise_item_valuation_test(dn_entry_list)
sle_details = fetch_sle_details_for_doc_list(dns, ["stock_value_difference"])
svd_list = [-1 * d["stock_value_difference"] for d in sle_details]
expected_incoming_rates = expected_abs_svd = sorted([75.0, 125.0, 75.0, 125.0])
expected_incoming_rates = expected_abs_svd = [75.0, 125.0, 75.0, 125.0]

self.assertEqual(expected_abs_svd, sorted(svd_list), "Incorrect 'Stock Value Difference' values")
self.assertEqual(expected_abs_svd, svd_list, "Incorrect 'Stock Value Difference' values")
for dn, incoming_rate in zip(dns, expected_incoming_rates):
self.assertTrue(
dn.items[0].incoming_rate in expected_abs_svd,
Expand Down
8 changes: 5 additions & 3 deletions erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def get_serial_no_ledgers(self):
.orderby(bundle.posting_date, bundle.posting_time, bundle.creation)
)

# Important to exclude the current voucher
# Important to exclude the current voucher to calculate correct the stock value difference
if self.sle.voucher_no:
query = query.where(bundle.voucher_no != self.sle.voucher_no)

Expand Down Expand Up @@ -539,8 +539,10 @@ def get_batch_no_ledgers(self) -> List[dict]:
.groupby(child.batch_no)
)

# Important to exclude the current voucher
if self.sle.voucher_no:
# Important to exclude the current voucher detail no / voucher no to calculate the correct stock value difference
if self.sle.voucher_detail_no:
query = query.where(parent.voucher_detail_no != self.sle.voucher_detail_no)
elif self.sle.voucher_no:
query = query.where(parent.voucher_no != self.sle.voucher_no)

if timestamp_condition:
Expand Down

0 comments on commit c797c53

Please sign in to comment.