Skip to content

Commit

Permalink
test: create po, create pi against po & then return pi - _TC_SCK_178
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek8848 committed Jan 17, 2025
1 parent b8fb0f8 commit d8c2410
Showing 1 changed file with 72 additions and 2 deletions.
74 changes: 72 additions & 2 deletions erpnext/buying/doctype/purchase_order/test_purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import frappe
import pandas as pd
from frappe.tests.utils import FrappeTestCase, change_settings
from frappe.utils import add_days, flt, getdate, nowdate
from frappe.utils import add_days, flt, getdate, nowdate, add_years, today
from frappe.utils.data import today
from datetime import date

from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
from erpnext.accounts.party import get_due_date_from_template
Expand All @@ -28,6 +29,9 @@
make_purchase_invoice as make_pi_from_pr,
)
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
from erpnext.stock.doctype.item.test_item import create_item
from erpnext.buying.doctype.supplier.test_supplier import create_supplier
from io import BytesIO

class TestPurchaseOrder(FrappeTestCase):
Expand Down Expand Up @@ -3792,7 +3796,41 @@ def test_create_po_pr_TC_SCK_177(self):

sle = frappe.get_doc('Stock Ledger Entry',{'voucher_no':pr.name})
self.assertEqual(sle.qty_after_transaction, 2)


def test_create_po_pr_return_pr_TC_SCK_178(self):
create_company()
create_fiscal_year()
supplier = create_supplier(supplier_name="_Test Supplier PO")
item = create_item("_Test PO")
warehouse = create_warehouse("_Test warehouse - _PO", company="_Test Company PO")

po = create_purchase_order(qty=10,company="_Test Company PO",supplier=supplier,item=item.item_code,warehouse=warehouse,do_not_save=1)
po.save()
po.submit()

frappe.db.set_value("Item", "_Test PO", "over_delivery_receipt_allowance", 10)
pr = make_purchase_receipt(po.name)
pr.company = "_Test Company PO"
pr.set_warehouse = warehouse
pr.rejected_warehouse = create_warehouse("_Test Warehouse8", company=pr.company)
pr.get("items")[0].qty = 8
pr.get("items")[0].rejected_qty = 2
pr.insert()
pr.submit()

sle = frappe.get_doc('Stock Ledger Entry',{'voucher_no':pr.name})
self.assertEqual(sle.qty_after_transaction, 2)

pr.load_from_db()
from erpnext.controllers.sales_and_purchase_return import make_return_doc
return_pi = make_return_doc("Purchase Receipt", pr.name,return_against_rejected_qty=True)
return_pi.get("items")[0].qty = -2
return_pi.submit()
pr.reload()

sle = frappe.get_doc('Stock Ledger Entry',{'voucher_no':return_pi.name})
self.assertEqual(sle.actual_qty, -2)

def create_po_for_sc_testing():
from erpnext.controllers.tests.test_subcontracting_controller import (
make_bom_for_subcontracted_items,
Expand Down Expand Up @@ -4079,3 +4117,35 @@ def create_new_account(account_name,company,parent_account):
account.parent_account = parent_account
account.save()
return account.name

def create_company():
company_name = "_Test Company PO"
if not frappe.db.exists("Company", company_name):
company = frappe.new_doc("Company")
company.company_name = company_name
company.country="India",
company.default_currency= "INR",
company.create_chart_of_accounts_based_on= "Standard Template",
company.chart_of_accounts= "Standard",
company = company.save()
company.load_from_db()

return company_name

def create_fiscal_year():
today = date.today()
if today.month >= 4: # Fiscal year starts in April
start_date = date(today.year, 4, 1)
end_date = date(today.year + 1, 3, 31)
else:
start_date = date(today.year - 1, 4, 1)
end_date = date(today.year, 3, 31)

company="_Test Company PO",
fy_doc = frappe.new_doc("Fiscal Year")
fy_doc.year = "2025 PO"
fy_doc.year_start_date = start_date
fy_doc.year_end_date = end_date
fy_doc.append("companies", {"company": company})
fy_doc.submit()

0 comments on commit d8c2410

Please sign in to comment.