Merge pull request #27166 from frappe-pr-bot/backport/version-13-hotfix/27086
fix: Don't create inward SLE against SI unless is internal customer enabled
This commit is contained in:
@@ -148,7 +148,7 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
si1 = create_sales_invoice(rate=1000)
|
si1 = create_sales_invoice(rate=1000)
|
||||||
si2 = create_sales_invoice(rate=300)
|
si2 = create_sales_invoice(rate=300)
|
||||||
si3 = create_sales_invoice(qty=-1, rate=300, is_return=1)
|
si3 = create_sales_invoice(qty=-1, rate=300, is_return=1)
|
||||||
|
|
||||||
|
|
||||||
pe = get_payment_entry("Sales Invoice", si1.name, bank_account="_Test Bank - _TC")
|
pe = get_payment_entry("Sales Invoice", si1.name, bank_account="_Test Bank - _TC")
|
||||||
pe.append('references', {
|
pe.append('references', {
|
||||||
@@ -1795,23 +1795,13 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
acc_settings.save()
|
acc_settings.save()
|
||||||
|
|
||||||
def test_inter_company_transaction(self):
|
def test_inter_company_transaction(self):
|
||||||
|
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
|
||||||
|
|
||||||
if not frappe.db.exists("Customer", "_Test Internal Customer"):
|
create_internal_customer(
|
||||||
customer = frappe.get_doc({
|
customer_name="_Test Internal Customer",
|
||||||
"customer_group": "_Test Customer Group",
|
represents_company="_Test Company 1",
|
||||||
"customer_name": "_Test Internal Customer",
|
allowed_to_interact_with="Wind Power LLC"
|
||||||
"customer_type": "Individual",
|
)
|
||||||
"doctype": "Customer",
|
|
||||||
"territory": "_Test Territory",
|
|
||||||
"is_internal_customer": 1,
|
|
||||||
"represents_company": "_Test Company 1"
|
|
||||||
})
|
|
||||||
|
|
||||||
customer.append("companies", {
|
|
||||||
"company": "Wind Power LLC"
|
|
||||||
})
|
|
||||||
|
|
||||||
customer.insert()
|
|
||||||
|
|
||||||
if not frappe.db.exists("Supplier", "_Test Internal Supplier"):
|
if not frappe.db.exists("Supplier", "_Test Internal Supplier"):
|
||||||
supplier = frappe.get_doc({
|
supplier = frappe.get_doc({
|
||||||
@@ -1854,8 +1844,43 @@ class TestSalesInvoice(unittest.TestCase):
|
|||||||
self.assertEqual(target_doc.company, "_Test Company 1")
|
self.assertEqual(target_doc.company, "_Test Company 1")
|
||||||
self.assertEqual(target_doc.supplier, "_Test Internal Supplier")
|
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.
|
||||||
|
"""
|
||||||
|
se = make_stock_entry(
|
||||||
|
item_code="138-CMS Shoe",
|
||||||
|
target="Finished Goods - _TC",
|
||||||
|
company = "_Test Company",
|
||||||
|
qty=1,
|
||||||
|
basic_rate=500
|
||||||
|
)
|
||||||
|
|
||||||
|
si = frappe.copy_doc(test_records[0])
|
||||||
|
si.update_stock = 1
|
||||||
|
si.set_warehouse = "Finished Goods - _TC"
|
||||||
|
si.set_target_warehouse = "Stores - _TC"
|
||||||
|
si.get("items")[0].warehouse = "Finished Goods - _TC"
|
||||||
|
si.get("items")[0].target_warehouse = "Stores - _TC"
|
||||||
|
si.insert()
|
||||||
|
si.submit()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# tear down
|
||||||
|
si.cancel()
|
||||||
|
se.cancel()
|
||||||
|
|
||||||
def test_internal_transfer_gl_entry(self):
|
def test_internal_transfer_gl_entry(self):
|
||||||
## Create internal transfer account
|
## Create internal transfer account
|
||||||
|
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
|
||||||
|
|
||||||
account = create_account(account_name="Unrealized Profit",
|
account = create_account(account_name="Unrealized Profit",
|
||||||
parent_account="Current Liabilities - TCP1", company="_Test Company with perpetual inventory")
|
parent_account="Current Liabilities - TCP1", company="_Test Company with perpetual inventory")
|
||||||
|
|
||||||
@@ -2437,29 +2462,6 @@ def get_taxes_and_charges():
|
|||||||
"row_id": 1
|
"row_id": 1
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def create_internal_customer(customer_name, represents_company, allowed_to_interact_with):
|
|
||||||
if not frappe.db.exists("Customer", customer_name):
|
|
||||||
customer = frappe.get_doc({
|
|
||||||
"customer_group": "_Test Customer Group",
|
|
||||||
"customer_name": customer_name,
|
|
||||||
"customer_type": "Individual",
|
|
||||||
"doctype": "Customer",
|
|
||||||
"territory": "_Test Territory",
|
|
||||||
"is_internal_customer": 1,
|
|
||||||
"represents_company": represents_company
|
|
||||||
})
|
|
||||||
|
|
||||||
customer.append("companies", {
|
|
||||||
"company": allowed_to_interact_with
|
|
||||||
})
|
|
||||||
|
|
||||||
customer.insert()
|
|
||||||
customer_name = customer.name
|
|
||||||
else:
|
|
||||||
customer_name = frappe.db.get_value("Customer", customer_name)
|
|
||||||
|
|
||||||
return customer_name
|
|
||||||
|
|
||||||
def create_internal_supplier(supplier_name, represents_company, allowed_to_interact_with):
|
def create_internal_supplier(supplier_name, represents_company, allowed_to_interact_with):
|
||||||
if not frappe.db.exists("Supplier", supplier_name):
|
if not frappe.db.exists("Supplier", supplier_name):
|
||||||
supplier = frappe.get_doc({
|
supplier = frappe.get_doc({
|
||||||
|
|||||||
@@ -423,7 +423,7 @@ class SellingController(StockController):
|
|||||||
or (cint(self.is_return) and self.docstatus==2)):
|
or (cint(self.is_return) and self.docstatus==2)):
|
||||||
sl_entries.append(self.get_sle_for_source_warehouse(d))
|
sl_entries.append(self.get_sle_for_source_warehouse(d))
|
||||||
|
|
||||||
if d.target_warehouse:
|
if d.target_warehouse and self.get("is_internal_customer"):
|
||||||
sl_entries.append(self.get_sle_for_target_warehouse(d))
|
sl_entries.append(self.get_sle_for_target_warehouse(d))
|
||||||
|
|
||||||
if d.warehouse and ((not cint(self.is_return) and self.docstatus==2)
|
if d.warehouse and ((not cint(self.is_return) and self.docstatus==2)
|
||||||
|
|||||||
@@ -352,3 +352,26 @@ def set_credit_limit(customer, company, credit_limit):
|
|||||||
'credit_limit': credit_limit
|
'credit_limit': credit_limit
|
||||||
})
|
})
|
||||||
customer.credit_limits[-1].db_insert()
|
customer.credit_limits[-1].db_insert()
|
||||||
|
|
||||||
|
def create_internal_customer(customer_name, represents_company, allowed_to_interact_with):
|
||||||
|
if not frappe.db.exists("Customer", customer_name):
|
||||||
|
customer = frappe.get_doc({
|
||||||
|
"doctype": "Customer",
|
||||||
|
"customer_group": "_Test Customer Group",
|
||||||
|
"customer_name": customer_name,
|
||||||
|
"customer_type": "Individual",
|
||||||
|
"territory": "_Test Territory",
|
||||||
|
"is_internal_customer": 1,
|
||||||
|
"represents_company": represents_company
|
||||||
|
})
|
||||||
|
|
||||||
|
customer.append("companies", {
|
||||||
|
"company": allowed_to_interact_with
|
||||||
|
})
|
||||||
|
|
||||||
|
customer.insert()
|
||||||
|
customer_name = customer.name
|
||||||
|
else:
|
||||||
|
customer_name = frappe.db.get_value("Customer", customer_name)
|
||||||
|
|
||||||
|
return customer_name
|
||||||
@@ -430,12 +430,19 @@ class TestDeliveryNote(unittest.TestCase):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def test_delivery_of_bundled_items_to_target_warehouse(self):
|
def test_delivery_of_bundled_items_to_target_warehouse(self):
|
||||||
|
from erpnext.selling.doctype.customer.test_customer import create_internal_customer
|
||||||
|
|
||||||
company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')
|
company = frappe.db.get_value('Warehouse', 'Stores - TCP1', 'company')
|
||||||
|
customer_name = create_internal_customer(
|
||||||
|
customer_name="_Test Internal Customer 2",
|
||||||
|
represents_company="_Test Company with perpetual inventory",
|
||||||
|
allowed_to_interact_with="_Test Company with perpetual inventory"
|
||||||
|
)
|
||||||
|
|
||||||
set_valuation_method("_Test Item", "FIFO")
|
set_valuation_method("_Test Item", "FIFO")
|
||||||
set_valuation_method("_Test Item Home Desktop 100", "FIFO")
|
set_valuation_method("_Test Item Home Desktop 100", "FIFO")
|
||||||
|
|
||||||
target_warehouse=get_warehouse(company=company, abbr="TCP1",
|
target_warehouse = get_warehouse(company=company, abbr="TCP1",
|
||||||
warehouse_name="_Test Customer Warehouse").name
|
warehouse_name="_Test Customer Warehouse").name
|
||||||
|
|
||||||
for warehouse in ("Stores - TCP1", target_warehouse):
|
for warehouse in ("Stores - TCP1", target_warehouse):
|
||||||
@@ -444,10 +451,16 @@ class TestDeliveryNote(unittest.TestCase):
|
|||||||
create_stock_reconciliation(item_code="_Test Item Home Desktop 100", company = company,
|
create_stock_reconciliation(item_code="_Test Item Home Desktop 100", company = company,
|
||||||
expense_account = "Stock Adjustment - TCP1", warehouse=warehouse, qty=500, rate=100)
|
expense_account = "Stock Adjustment - TCP1", warehouse=warehouse, qty=500, rate=100)
|
||||||
|
|
||||||
dn = create_delivery_note(item_code="_Test Product Bundle Item",
|
dn = create_delivery_note(
|
||||||
company='_Test Company with perpetual inventory', cost_center = 'Main - TCP1',
|
item_code="_Test Product Bundle Item",
|
||||||
expense_account = "Cost of Goods Sold - TCP1", do_not_submit=True, qty=5, rate=500,
|
company="_Test Company with perpetual inventory",
|
||||||
warehouse="Stores - TCP1", target_warehouse=target_warehouse)
|
customer=customer_name,
|
||||||
|
cost_center = 'Main - TCP1',
|
||||||
|
expense_account = "Cost of Goods Sold - TCP1",
|
||||||
|
do_not_submit=True,
|
||||||
|
qty=5, rate=500,
|
||||||
|
warehouse="Stores - TCP1",
|
||||||
|
target_warehouse=target_warehouse)
|
||||||
|
|
||||||
dn.submit()
|
dn.submit()
|
||||||
|
|
||||||
@@ -487,6 +500,9 @@ class TestDeliveryNote(unittest.TestCase):
|
|||||||
for i, gle in enumerate(gl_entries):
|
for i, gle in enumerate(gl_entries):
|
||||||
self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account))
|
self.assertEqual([gle.debit, gle.credit], expected_values.get(gle.account))
|
||||||
|
|
||||||
|
# tear down
|
||||||
|
frappe.db.rollback()
|
||||||
|
|
||||||
def test_closed_delivery_note(self):
|
def test_closed_delivery_note(self):
|
||||||
from erpnext.stock.doctype.delivery_note.delivery_note import update_delivery_note_status
|
from erpnext.stock.doctype.delivery_note.delivery_note import update_delivery_note_status
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user