Skip to content

Commit

Permalink
fix: incorrect packing items
Browse files Browse the repository at this point in the history
(cherry picked from commit a686b8c)
(cherry picked from commit ab56470)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed May 12, 2023
1 parent e509664 commit b02ed0d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
4 changes: 4 additions & 0 deletions erpnext/selling/doctype/sales_order/sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,8 @@ def postprocess(source, doc):

@frappe.whitelist()
def make_delivery_note(source_name, target_doc=None, skip_item_mapping=False):
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list

def set_missing_values(source, target):
target.run_method("set_missing_values")
target.run_method("set_po_nos")
Expand All @@ -634,6 +636,8 @@ def set_missing_values(source, target):
if target.company_address:
target.update(get_fetch_values("Delivery Note", "company_address", target.company_address))

make_packing_list(target)

def update_item(source, target, source_parent):
target.base_amount = (flt(source.qty) - flt(source.delivered_qty)) * flt(source.base_rate)
target.amount = (flt(source.qty) - flt(source.delivered_qty)) * flt(source.rate)
Expand Down
69 changes: 69 additions & 0 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,75 @@ def test_delivered_item_material_request(self):

self.assertEqual(mr.items[0].qty, 6)

def test_packed_items_for_partial_sales_order(self):
# test Update Items with product bundle
for product_bundle in [
"_Test Product Bundle Item Partial 1",
"_Test Product Bundle Item Partial 2",
]:
if not frappe.db.exists("Item", product_bundle):
bundle_item = make_item(product_bundle, {"is_stock_item": 0})
bundle_item.append(
"item_defaults", {"company": "_Test Company", "default_warehouse": "_Test Warehouse - _TC"}
)
bundle_item.save(ignore_permissions=True)

for product_bundle in ["_Packed Item Partial 1", "_Packed Item Partial 2"]:
if not frappe.db.exists("Item", product_bundle):
make_item(product_bundle, {"is_stock_item": 1, "stock_uom": "Nos"})

make_stock_entry(item=product_bundle, target="_Test Warehouse - _TC", qty=2, rate=10)

make_product_bundle("_Test Product Bundle Item Partial 1", ["_Packed Item Partial 1"], 1)

make_product_bundle("_Test Product Bundle Item Partial 2", ["_Packed Item Partial 2"], 1)

so = make_sales_order(
item_code="_Test Product Bundle Item Partial 1",
warehouse="_Test Warehouse - _TC",
qty=1,
uom="Nos",
stock_uom="Nos",
conversion_factor=1,
transaction_date=nowdate(),
delivery_note=nowdate(),
do_not_submit=1,
)

so.append(
"items",
{
"item_code": "_Test Product Bundle Item Partial 2",
"warehouse": "_Test Warehouse - _TC",
"qty": 1,
"uom": "Nos",
"stock_uom": "Nos",
"conversion_factor": 1,
"delivery_note": nowdate(),
},
)

so.save()
so.submit()

dn = make_delivery_note(so.name)
dn.remove(dn.items[1])
dn.save()
dn.submit()

self.assertEqual(len(dn.items), 1)
self.assertEqual(len(dn.packed_items), 1)
self.assertEqual(dn.items[0].item_code, "_Test Product Bundle Item Partial 1")

so.load_from_db()

dn = make_delivery_note(so.name)
dn.save()

self.assertEqual(len(dn.items), 1)
self.assertEqual(len(dn.packed_items), 1)
self.assertEqual(dn.items[0].item_code, "_Test Product Bundle Item Partial 2")


def automatically_fetch_payment_terms(enable=1):
accounts_settings = frappe.get_doc("Accounts Settings")
Expand Down

0 comments on commit b02ed0d

Please sign in to comment.