Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: serial no not able to reject for the internal transfer #36467

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions erpnext/controllers/buying_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ def update_stock_ledger(self, allow_negative_stock=False, via_landed_cost_vouche
if d.item_code not in stock_items:
continue

rejected_qty = 0.0
if flt(d.rejected_qty) != 0:
rejected_qty = flt(flt(d.rejected_qty) * flt(d.conversion_factor), d.precision("stock_qty"))

if d.warehouse:
pr_qty = flt(flt(d.qty) * flt(d.conversion_factor), d.precision("stock_qty"))

Expand All @@ -495,6 +499,11 @@ def update_stock_ledger(self, allow_negative_stock=False, via_landed_cost_vouche
},
)

if flt(rejected_qty) != 0:
from_warehouse_sle["actual_qty"] += -1 * rejected_qty
if d.rejected_serial_no:
from_warehouse_sle["serial_no"] += "\n" + cstr(d.rejected_serial_no).strip()

sl_entries.append(from_warehouse_sle)

sle = self.get_sl_entries(
Expand All @@ -520,6 +529,7 @@ def update_stock_ledger(self, allow_negative_stock=False, via_landed_cost_vouche
else 0,
}
)

sl_entries.append(sle)

if d.from_warehouse and (
Expand All @@ -530,23 +540,30 @@ def update_stock_ledger(self, allow_negative_stock=False, via_landed_cost_vouche
d, {"actual_qty": -1 * pr_qty, "warehouse": d.from_warehouse, "recalculate_rate": 1}
)

if flt(rejected_qty) != 0:
from_warehouse_sle["actual_qty"] += -1 * rejected_qty
if d.rejected_serial_no:
from_warehouse_sle["serial_no"] += "\n" + cstr(d.rejected_serial_no).strip()

sl_entries.append(from_warehouse_sle)

if flt(d.rejected_qty) != 0:
if flt(rejected_qty) != 0:
sl_entries.append(
self.get_sl_entries(
d,
{
"warehouse": d.rejected_warehouse,
"actual_qty": flt(flt(d.rejected_qty) * flt(d.conversion_factor), d.precision("stock_qty")),
"actual_qty": rejected_qty,
"serial_no": cstr(d.rejected_serial_no).strip(),
"incoming_rate": 0.0,
"allow_zero_valuation_rate": True,
},
)
)

if self.get("is_old_subcontracting_flow"):
self.make_sl_entries_for_supplier_warehouse(sl_entries)

self.make_sl_entries(
sl_entries,
allow_negative_stock=allow_negative_stock,
Expand Down
64 changes: 64 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,70 @@ def test_backdated_transaction_for_internal_transfer(self):

self.assertEqual(query[0].value, 0)

def test_rejected_qty_for_internal_transfer(self):
from erpnext.stock.doctype.delivery_note.delivery_note import make_inter_company_purchase_receipt
from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note

prepare_data_for_internal_transfer()
customer = "_Test Internal Customer 2"
company = "_Test Company with perpetual inventory"

from_warehouse = create_warehouse("_Test Internal From Warehouse New", company=company)
to_warehouse = create_warehouse("_Test Internal To Warehouse New", company=company)
rejected_warehouse = create_warehouse(
"_Test Rejected Internal To Warehouse New", company=company
)
item_doc = make_item(
"Test Internal Transfer Item DS",
{
"is_purchase_item": 1,
"is_stock_item": 1,
"has_serial_no": 1,
"serial_no_series": "SBNS.#####",
},
)

target_warehouse = create_warehouse("_Test Internal GIT Warehouse New", company=company)

pr = make_purchase_receipt(
item_code=item_doc.name,
company=company,
posting_date=add_days(today(), -1),
warehouse=from_warehouse,
qty=2,
rate=100,
)

dn1 = create_delivery_note(
item_code=item_doc.name,
company=company,
customer=customer,
serial_no=pr.items[0].serial_no,
cost_center="Main - TCP1",
expense_account="Cost of Goods Sold - TCP1",
qty=2,
rate=500,
warehouse=from_warehouse,
target_warehouse=target_warehouse,
)

sns = get_serial_nos(dn1.items[0].serial_no)

self.assertEqual(len(sns), 2)

pr1 = make_inter_company_purchase_receipt(dn1.name)
pr1.items[0].qty = 1.0
pr1.items[0].rejected_qty = 1.0
pr1.items[0].serial_no = sns[0]
pr1.items[0].rejected_serial_no = sns[1]
pr1.items[0].warehouse = to_warehouse
pr1.items[0].rejected_warehouse = rejected_warehouse
pr1.submit()

rejected_serial_no_wh = frappe.get_cached_value("Serial No", sns[1], "warehouse")

self.assertEqual(rejected_warehouse, rejected_serial_no_wh)

def test_backdated_transaction_for_internal_transfer_in_trasit_warehouse_for_purchase_receipt(
self,
):
Expand Down
2 changes: 2 additions & 0 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def make_sl_entries(sl_entries, allow_negative_stock=False, via_landed_cost_vouc
sle_doc = make_entry(sle, allow_negative_stock, via_landed_cost_voucher)

args = sle_doc.as_dict()
args["allow_zero_valuation_rate"] = sle.get("allow_zero_valuation_rate") or False

if sle.get("voucher_type") == "Stock Reconciliation":
# preserve previous_qty_after_transaction for qty reposting
Expand Down Expand Up @@ -109,6 +110,7 @@ def repost_current_voucher(args, allow_negative_stock=False, via_landed_cost_vou
"sle_id": args.get("name"),
"creation": args.get("creation"),
},
allow_zero_rate=args.get("allow_zero_valuation_rate") or False,
allow_negative_stock=allow_negative_stock,
via_landed_cost_voucher=via_landed_cost_voucher,
)
Expand Down
Loading