Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pre-prod' into new_test_purcha…
Browse files Browse the repository at this point in the history
…se_order
  • Loading branch information
Abhishek8848 committed Jan 17, 2025
2 parents d8c2410 + 68bff58 commit 4163385
Show file tree
Hide file tree
Showing 2 changed files with 247 additions and 0 deletions.
104 changes: 104 additions & 0 deletions erpnext/accounts/doctype/budget/test_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,110 @@ def test_monthly_budget_against_main_cost_center(self):

self.assertRaises(BudgetError, jv.submit)

def test_provisional_entry_for_service_items_TC_ACC_064(self):
# Step 1: Enable Provisional Accounting in Company Master
company = "_Test Company"
frappe.db.set_value("Company", company, "enable_provisional_accounting_for_non_stock_items", 1)
# Set _Test Cash - _TC as the Provisional Account
frappe.db.set_value("Company", company, "default_provisional_account", "_Test Cash - _TC")

# Step 3: Create a Service Item
service_item = frappe.get_doc({
"doctype": "Item",
"item_code": "_Test Non Stock Item",
"item_group": "Services",
"is_stock_item": 0
})
if not frappe.db.exists("Item", service_item.item_code):
service_item.insert(ignore_permissions=True)

pr = None # Initialize 'pr' to avoid UnboundLocalError
try:
# Step 4: Create a Purchase Receipt with the Service Item
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
pr = make_purchase_receipt(
company=company,
item=service_item.item_code,
rate=1000,
qty=1,
expense_account="_Test Account Cost for Goods Sold - _TC"
)

# Step 5: Validate GL Entries
gl_entries = frappe.get_all("GL Entry", filters={"voucher_no": pr.name}, fields=["account", "debit", "credit"])

# Check GL Entries
expected_entries = [
{"account": "_Test Account Cost for Goods Sold - _TC", "debit": 1000.0, "credit": 0.0},
{"account": "_Test Cash - _TC", "debit": 0.0, "credit": 1000.0}
]
for entry in expected_entries:
self.assertIn(entry, gl_entries, msg=f"Expected GL Entry {entry} not found in {gl_entries}")

print(f"Provisional Accounting validated for {pr.name}")

finally:
# Step 6: Cleanup
if pr and pr.docstatus == 1:
pr.cancel()
if pr:
frappe.delete_doc("Purchase Receipt", pr.name, force=True)
frappe.delete_doc("Item", service_item.name, force=True)

# Reset Company Settings
frappe.db.set_value("Company", company, "enable_provisional_accounting_for_non_stock_items", 0)
frappe.db.set_value("Company", company, "default_provisional_account", "")

def test_provisional_entry_for_service_items_TC_ACC_065(self):
# Step 1: Enable Provisional Accounting in Company Master
company = "_Test Company"
frappe.db.set_value("Company", company, "enable_provisional_accounting_for_non_stock_items", 1)
# Set _Test Cash - _TC as the Provisional Account
frappe.db.set_value("Company", company, "default_provisional_account", "_Test Cash - _TC")

# Step 2: Create a Service Item
service_item = frappe.get_doc({
"doctype": "Item",
"item_code": "_Test Non Stock Item",
"item_group": "Services",
"is_stock_item": 0
})
if not frappe.db.exists("Item", service_item.item_code):
service_item.insert(ignore_permissions=True)

pi = None # Initialize 'pi' to avoid UnboundLocalError
try:
# Step 3: Create a Purchase Invoice with the Service Item
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
pi = make_purchase_invoice(
company=company,
item=service_item.item_code,
rate=1000,
qty=1,
expense_account="_Test Account Cost for Goods Sold - _TC",
# purchase_account="_Test Account Payable - _TC"
)

# Step 4: Validate GL Entries
gl_entries = frappe.get_all("GL Entry", filters={"voucher_no": pi.name}, fields=["account", "debit", "credit"])
# Check GL Entries for Provisional Accounting Treatment
expected_entries = [
{"account": "_Test Account Cost for Goods Sold - _TC", "debit": 1000.0, "credit": 0.0},
{"account": "Creditors - _TC", "debit": 0.0, "credit": 1000.0},
]
for entry in expected_entries:
self.assertIn(entry, gl_entries, msg=f"Expected GL Entry {entry} not found in {gl_entries}")
finally:
# Step 6: Cleanup
if pi and pi.docstatus == 1:
pi.cancel()
if pi:
frappe.delete_doc("Purchase Invoice", pi.name, force=True)
frappe.delete_doc("Item", service_item.name, force=True)

# Reset Company Settings
frappe.db.set_value("Company", company, "enable_provisional_accounting_for_non_stock_items", 0)
frappe.db.set_value("Company", company, "default_provisional_account", "")

def set_total_expense_zero(posting_date, budget_against_field=None, budget_against_CC=None):
if budget_against_field == "project":
Expand Down
143 changes: 143 additions & 0 deletions erpnext/selling/doctype/quotation/test_quotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,149 @@ def test_quotation_to_po_with_drop_ship_with_GST_TC_S_112(self):
purchase_orders[0].reload()
self.assertEqual(sales_order.status, "To Bill")
self.assertEqual(purchase_orders[0].status, "Delivered")


def test_quotation_to_si_with_pi_and_drop_ship_TC_S_114(self):
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
from erpnext.selling.doctype.sales_order.sales_order import make_purchase_order_for_default_supplier
from erpnext.buying.doctype.purchase_order.purchase_order import update_status
from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_invoice as make_pi_from_po
make_item("_Test Item for Drop Shipping", {"is_stock_item": 1, "delivered_by_supplier": 1})
so_items = [
{
"item_code": "_Test Item for Drop Shipping",
"warehouse": "",
"qty": 2,
"rate": 5000,
"delivered_by_supplier": 1,
"supplier": "_Test Supplier",
}]

quotation = self.create_and_submit_quotation("_Test Item for Drop Shipping", 1, 5000, "Stores - _TC")

sales_order = make_sales_order(quotation.name)
sales_order.delivery_date = add_days(nowdate(), 5)
for i in sales_order.items:
i.delivered_by_supplier =1
i.supplier = "_Test Supplier"
sales_order.save()
sales_order.submit()

quotation.reload()
self.assertEqual(sales_order.status, "To Deliver and Bill")
self.assertEqual(quotation.status, "Ordered")

purchase_orders = make_purchase_order_for_default_supplier(sales_order.name, selected_items=so_items)
for i in purchase_orders[0].items:
i.rate = 3000
purchase_orders[0].submit()

update_status("Delivered", purchase_orders[0].name)
sales_order.reload()
purchase_orders[0].reload()
self.assertEqual(sales_order.status, "To Bill")
self.assertEqual(purchase_orders[0].status, "Delivered")

pi = make_pi_from_po(purchase_orders[0].name)
pi.save()
pi.submit()

gl_entries = frappe.get_all("GL Entry", filters={"voucher_no": pi.name}, fields=["account", "debit", "credit"])
gl_debits = {entry.account: entry.debit for entry in gl_entries}
gl_credits = {entry.account: entry.credit for entry in gl_entries}
self.assertAlmostEqual(gl_debits["Cost of Goods Sold - _TC"], 3000)
self.assertAlmostEqual(gl_credits["Creditors - _TC"], 3000)
self.assertEqual(pi.status, "Unpaid")

si = make_sales_invoice(sales_order.name)
si.save()
si.submit()

self.assertEqual(si.status, "Unpaid")
self.validate_gl_entries(voucher_no= si.name,amount= 5000)


def test_quotation_to_si_with_pi_and_drop_ship_with_GST_TC_S_116(self):
from erpnext.stock.doctype.item.test_item import make_item
from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice
from erpnext.selling.doctype.sales_order.sales_order import make_purchase_order_for_default_supplier
from erpnext.buying.doctype.purchase_order.purchase_order import update_status
from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_invoice as make_pi_from_po
make_item("_Test Item for Drop Shipping", {"is_stock_item": 1, "delivered_by_supplier": 1})
so_items = [
{
"item_code": "_Test Item for Drop Shipping",
"warehouse": "",
"qty": 2,
"rate": 5000,
"delivered_by_supplier": 1,
"supplier": "_Test Supplier",
}]

quotation = make_quotation(item="_Test Item for Drop Shipping", qty=1, rate=5000, warehouse="Stores - _TC",do_not_save =1)
for i in quotation.items:
i.item_tax_template = "GST 18% - _TC"
quotation.tax_category = "In-State"
quotation.taxes_and_charges = "Output GST In-state - _TC"
quotation.save()
quotation.submit()

sales_order = make_sales_order(quotation.name)
sales_order.delivery_date = add_days(nowdate(), 5)
for i in sales_order.items:
i.delivered_by_supplier =1
i.item_tax_template = "GST 18% - _TC"
i.supplier = "_Test Supplier"
sales_order.tax_category = "In-State"
sales_order.taxes_and_charges = "Output GST In-state - _TC"
sales_order.save()
sales_order.submit()

quotation.reload()
self.assertEqual(sales_order.status, "To Deliver and Bill")
self.assertEqual(quotation.status, "Ordered")

purchase_orders = make_purchase_order_for_default_supplier(sales_order.name, selected_items=so_items)
for i in purchase_orders[0].items:
i.rate = 3000
i.item_tax_template = "GST 18% - _TC"
purchase_orders[0].tax_category = "In-State"
purchase_orders[0].taxes_and_charges = "Input GST In-state - _TC"
purchase_orders[0].save()
purchase_orders[0].submit()

update_status("Delivered", purchase_orders[0].name)
sales_order.reload()
purchase_orders[0].reload()
self.assertEqual(sales_order.status, "To Bill")
self.assertEqual(purchase_orders[0].status, "Delivered")

pi = make_pi_from_po(purchase_orders[0].name)
pi.save()
pi.submit()

gl_entries = frappe.get_all("GL Entry", filters={"voucher_no": pi.name}, fields=["account", "debit", "credit"])
gl_debits = {entry.account: entry.debit for entry in gl_entries}
gl_credits = {entry.account: entry.credit for entry in gl_entries}
self.assertAlmostEqual(gl_debits["Cost of Goods Sold - _TC"], 3000)
self.assertAlmostEqual(gl_debits["Input Tax SGST - _TC"], 270)
self.assertAlmostEqual(gl_debits["Input Tax CGST - _TC"], 270)
self.assertAlmostEqual(gl_credits["Creditors - _TC"], 3540)
self.assertEqual(pi.status, "Unpaid")

si = make_sales_invoice(sales_order.name)
si.save()
si.submit()

self.assertEqual(si.status, "Unpaid")
gl_entries = frappe.get_all("GL Entry", filters={"voucher_no": si.name}, fields=["account", "debit", "credit"])
gl_debits = {entry.account: entry.debit for entry in gl_entries}
gl_credits = {entry.account: entry.credit for entry in gl_entries}
self.assertAlmostEqual(gl_debits["Debtors - _TC"], 5900)
self.assertAlmostEqual(gl_credits["Output Tax SGST - _TC"], 450)
self.assertAlmostEqual(gl_credits["Output Tax CGST - _TC"], 450)
self.assertAlmostEqual(gl_credits["Sales - _TC"], 5000)

def stock_check(self,voucher,qty):
stock_entries = frappe.get_all(
Expand Down

0 comments on commit 4163385

Please sign in to comment.