feat: change sabb qty automatically incase of internal transfer PR if sabb only has 1 batch (#47256)

* feat: change sabb qty automatically incase of internal transfer PR if sabb only has 1 batch

* fix: prevent creation of SABB on every save

* perf: optimize code

* fix: remove unnecessary conditon

* refactor: change if to elif

* fix: remove dn_item_qty and set to item.qty

* test: added test

(cherry picked from commit 47927b38a9)
This commit is contained in:
Mihir Kandoi
2025-04-29 11:45:46 +05:30
committed by Mergify
parent cb61e0bd18
commit 9495a2ac9d
3 changed files with 85 additions and 2 deletions

View File

@@ -98,7 +98,29 @@ class BuyingController(SubcontractingController):
item.from_warehouse,
type_of_transaction="Outward",
do_not_submit=True,
qty=item.qty,
)
elif (
not self.is_new()
and item.serial_and_batch_bundle
and next(
(
old_item
for old_item in self.get_doc_before_save().items
if old_item.name == item.name and old_item.qty != item.qty
),
None,
)
and len(
sabe := frappe.get_all(
"Serial and Batch Entry",
filters={"parent": item.serial_and_batch_bundle, "serial_no": ["is", "not set"]},
pluck="name",
)
)
== 1
):
frappe.set_value("Serial and Batch Entry", sabe[0], "qty", item.qty)
def set_rate_for_standalone_debit_note(self):
if self.get("is_return") and self.get("update_stock") and not self.return_against:

View File

@@ -811,7 +811,7 @@ class StockController(AccountsController):
)
def make_package_for_transfer(
self, serial_and_batch_bundle, warehouse, type_of_transaction=None, do_not_submit=None
self, serial_and_batch_bundle, warehouse, type_of_transaction=None, do_not_submit=None, qty=0
):
return make_bundle_for_material_transfer(
is_new=self.is_new(),
@@ -822,6 +822,7 @@ class StockController(AccountsController):
warehouse=warehouse,
type_of_transaction=type_of_transaction,
do_not_submit=do_not_submit,
qty=qty,
)
def get_sl_entries(self, d, args):
@@ -1815,15 +1816,20 @@ def make_bundle_for_material_transfer(**kwargs):
kwargs.type_of_transaction = "Inward"
bundle_doc = frappe.copy_doc(bundle_doc)
bundle_doc.docstatus = 0
bundle_doc.warehouse = kwargs.warehouse
bundle_doc.type_of_transaction = kwargs.type_of_transaction
bundle_doc.voucher_type = kwargs.voucher_type
bundle_doc.voucher_no = "" if kwargs.is_new or kwargs.docstatus == 2 else kwargs.voucher_no
bundle_doc.is_cancelled = 0
qty = 0
if len(bundle_doc.entries) == 1 and kwargs.qty < bundle_doc.total_qty and not bundle_doc.has_serial_no:
qty = kwargs.qty
for row in bundle_doc.entries:
row.is_outward = 0
row.qty = abs(row.qty)
row.qty = abs(qty or row.qty)
row.stock_value_difference = abs(row.stock_value_difference)
if kwargs.type_of_transaction == "Outward":
row.qty *= -1