Skip to content

Commit

Permalink
fix: using DN for transfer w/o internal customer (frappe#27798)
Browse files Browse the repository at this point in the history
This used to be work before though not "advertised", since a lot of
users have started using it as feature, it can't be broken now.
  • Loading branch information
ankush authored Oct 5, 2021
1 parent d2f5d31 commit df1f8fd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
12 changes: 4 additions & 8 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1947,11 +1947,7 @@ def test_inter_company_transaction(self):
self.assertEqual(target_doc.company, "_Test Company 1")
self.assertEqual(target_doc.supplier, "_Test Internal Supplier")

def test_sle_if_target_warehouse_exists_accidentally(self):
"""
Check if inward entry exists if Target Warehouse accidentally exists
but Customer is not an internal customer.
"""
def test_sle_for_target_warehouse(self):
se = make_stock_entry(
item_code="138-CMS Shoe",
target="Finished Goods - _TC",
Expand All @@ -1972,9 +1968,9 @@ def test_sle_if_target_warehouse_exists_accidentally(self):
sles = frappe.get_all("Stock Ledger Entry", filters={"voucher_no": si.name},
fields=["name", "actual_qty"])

# check if only one SLE for outward entry is created
self.assertEqual(len(sles), 1)
self.assertEqual(sles[0].actual_qty, -1)
# check if both SLEs are created
self.assertEqual(len(sles), 2)
self.assertEqual(sum(d.actual_qty for d in sles), 0.0)

# tear down
si.cancel()
Expand Down
8 changes: 7 additions & 1 deletion erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def update_stock_ledger(self):
or (cint(self.is_return) and self.docstatus==2)):
sl_entries.append(self.get_sle_for_source_warehouse(d))

if d.target_warehouse and self.get("is_internal_customer"):
if d.target_warehouse:
sl_entries.append(self.get_sle_for_target_warehouse(d))

if d.warehouse and ((not cint(self.is_return) and self.docstatus==2)
Expand Down Expand Up @@ -559,6 +559,12 @@ def validate_target_warehouse(self):
frappe.throw(_("Row {0}: Delivery Warehouse ({1}) and Customer Warehouse ({2}) can not be same")
.format(d.idx, warehouse, warehouse))

if not self.get("is_internal_customer") and any(d.get("target_warehouse") for d in items):
msg = _("Target Warehouse set for some items but the customer is not an internal customer.")
msg += " " + _("This {} will be treated as material transfer.").format(_(self.doctype))
frappe.msgprint(msg, title="Internal Transfer")


def validate_items(self):
# validate items to see if they have is_sales_item enabled
from erpnext.controllers.buying_controller import validate_item_type
Expand Down
1 change: 0 additions & 1 deletion erpnext/stock/doctype/delivery_note/delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def validate_warehouse(self):
if not d['warehouse'] and frappe.db.get_value("Item", d['item_code'], "is_stock_item") == 1:
frappe.throw(_("Warehouse required for stock Item {0}").format(d["item_code"]))


def update_current_stock(self):
if self.get("_action") and self._action != "update_after_submit":
for d in self.get('items'):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@
"width": "100px"
},
{
"depends_on": "eval:parent.is_internal_customer",
"depends_on": "eval:parent.is_internal_customer || doc.target_warehouse",
"fieldname": "target_warehouse",
"fieldtype": "Link",
"hidden": 1,
Expand Down Expand Up @@ -759,12 +759,12 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2021-02-23 01:04:08.588104",
"modified": "2021-10-05 12:12:44.018872",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note Item",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
}
}

0 comments on commit df1f8fd

Please sign in to comment.