Skip to content

Commit

Permalink
fix: remove from or target warehouse for non internal transfer entries (
Browse files Browse the repository at this point in the history
#37612)

(cherry picked from commit 5136fe1)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Oct 22, 2023
1 parent 50daf70 commit b775eef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
22 changes: 15 additions & 7 deletions erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,21 @@ def set_rate_of_stock_uom(self):
d.stock_uom_rate = d.rate / (d.conversion_factor or 1)

def validate_internal_transfer(self):
if (
self.doctype in ("Sales Invoice", "Delivery Note", "Purchase Invoice", "Purchase Receipt")
and self.is_internal_transfer()
):
self.validate_in_transit_warehouses()
self.validate_multi_currency()
self.validate_packed_items()
if self.doctype in ("Sales Invoice", "Delivery Note", "Purchase Invoice", "Purchase Receipt"):
if self.is_internal_transfer():
self.validate_in_transit_warehouses()
self.validate_multi_currency()
self.validate_packed_items()
else:
self.validate_internal_transfer_warehouse()

def validate_internal_transfer_warehouse(self):
for row in self.items:
if row.get("target_warehouse"):
row.target_warehouse = None

if row.get("from_warehouse"):
row.from_warehouse = None

def validate_in_transit_warehouses(self):
if (
Expand Down
15 changes: 15 additions & 0 deletions erpnext/stock/doctype/delivery_note/test_delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,21 @@ def tearDown(self):
frappe.db.rollback()
frappe.db.set_single_value("Selling Settings", "dont_reserve_sales_order_qty_on_sales_return", 0)

def non_internal_transfer_delivery_note(self):
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse

dn = create_delivery_note(do_not_submit=True)
warehouse = create_warehouse("Internal Transfer Warehouse", dn.company)
dn.items[0].db_set("target_warehouse", "warehouse")

dn.reload()

self.assertEqual(dn.items[0].target_warehouse, warehouse.name)

dn.save()
dn.reload()
self.assertFalse(dn.items[0].target_warehouse)


def create_delivery_note(**args):
dn = frappe.new_doc("Delivery Note")
Expand Down
15 changes: 15 additions & 0 deletions erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,21 @@ def test_purchase_return_with_zero_rate(self):
for entry in gl_entries:
self.assertEqual(abs(entry.debit + entry.credit), abs(sl_entries[0].stock_value_difference))

def non_internal_transfer_purchase_receipt(self):
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse

pr_doc = make_purchase_receipt(do_not_submit=True)
warehouse = create_warehouse("Internal Transfer Warehouse", pr_doc.company)
pr_doc.items[0].db_set("target_warehouse", "warehouse")

pr_doc.reload()

self.assertEqual(pr_doc.items[0].from_warehouse, warehouse.name)

pr_doc.save()
pr_doc.reload()
self.assertFalse(pr_doc.items[0].from_warehouse)


def prepare_data_for_internal_transfer():
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_internal_supplier
Expand Down

0 comments on commit b775eef

Please sign in to comment.