|
|
@ -6,7 +6,7 @@ import unittest |
|
|
|
import json |
|
|
|
import frappe, erpnext |
|
|
|
import frappe.defaults |
|
|
|
from frappe.utils import cint, flt, cstr, today, random_string |
|
|
|
from frappe.utils import cint, flt, cstr, today, random_string, add_days |
|
|
|
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice |
|
|
|
from erpnext.stock.doctype.item.test_item import create_item |
|
|
|
from erpnext import set_perpetual_inventory |
|
|
@ -665,6 +665,59 @@ class TestPurchaseReceipt(unittest.TestCase): |
|
|
|
warehouse.account = '' |
|
|
|
warehouse.save() |
|
|
|
|
|
|
|
def test_backdated_purchase_receipt(self): |
|
|
|
# make purchase receipt for default company |
|
|
|
make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4") |
|
|
|
|
|
|
|
# try to make another backdated PR |
|
|
|
posting_date = add_days(today(), -1) |
|
|
|
pr = make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4", |
|
|
|
do_not_submit=True) |
|
|
|
|
|
|
|
pr.set_posting_time = 1 |
|
|
|
pr.posting_date = posting_date |
|
|
|
pr.save() |
|
|
|
|
|
|
|
self.assertRaises(frappe.ValidationError, pr.submit) |
|
|
|
|
|
|
|
# make purchase receipt for other company backdated |
|
|
|
pr = make_purchase_receipt(company="_Test Company 5", warehouse="Stores - _TC5", |
|
|
|
do_not_submit=True) |
|
|
|
|
|
|
|
pr.set_posting_time = 1 |
|
|
|
pr.posting_date = posting_date |
|
|
|
pr.submit() |
|
|
|
|
|
|
|
# Allowed to submit for other company's PR |
|
|
|
self.assertEqual(pr.docstatus, 1) |
|
|
|
|
|
|
|
def test_backdated_purchase_receipt_for_same_company_different_warehouse(self): |
|
|
|
# make purchase receipt for default company |
|
|
|
make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4") |
|
|
|
|
|
|
|
# try to make another backdated PR |
|
|
|
posting_date = add_days(today(), -1) |
|
|
|
pr = make_purchase_receipt(company="_Test Company 4", warehouse="Stores - _TC4", |
|
|
|
do_not_submit=True) |
|
|
|
|
|
|
|
pr.set_posting_time = 1 |
|
|
|
pr.posting_date = posting_date |
|
|
|
pr.save() |
|
|
|
|
|
|
|
self.assertRaises(frappe.ValidationError, pr.submit) |
|
|
|
|
|
|
|
# make purchase receipt for other company backdated |
|
|
|
pr = make_purchase_receipt(company="_Test Company 4", warehouse="Finished Goods - _TC4", |
|
|
|
do_not_submit=True) |
|
|
|
|
|
|
|
pr.set_posting_time = 1 |
|
|
|
pr.posting_date = posting_date |
|
|
|
pr.submit() |
|
|
|
|
|
|
|
# Allowed to submit for other company's PR |
|
|
|
self.assertEqual(pr.docstatus, 1) |
|
|
|
|
|
|
|
|
|
|
|
def get_sl_entries(voucher_type, voucher_no): |
|
|
|
return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference |
|
|
|
from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s |
|
|
|