Fixed Stock Entry Test Cases frappe/frappe#478
This commit is contained in:
parent
103cc58cb6
commit
2ce39cf770
@ -124,7 +124,7 @@ class PurchaseInvoice(BuyingController):
|
|||||||
check_list = []
|
check_list = []
|
||||||
for d in self.get('entries'):
|
for d in self.get('entries'):
|
||||||
if d.purchase_order and not d.purchase_order in check_list and not d.purchase_receipt:
|
if d.purchase_order and not d.purchase_order in check_list and not d.purchase_receipt:
|
||||||
check_list.append(d.purhcase_order)
|
check_list.append(d.purchase_order)
|
||||||
stopped = frappe.db.sql("select name from `tabPurchase Order` where status = 'Stopped' and name = %s", d.purchase_order)
|
stopped = frappe.db.sql("select name from `tabPurchase Order` where status = 'Stopped' and name = %s", d.purchase_order)
|
||||||
if stopped:
|
if stopped:
|
||||||
msgprint("One cannot do any transaction against 'Purchase Order' : %s, it's status is 'Stopped'" % (d.purhcase_order))
|
msgprint("One cannot do any transaction against 'Purchase Order' : %s, it's status is 'Stopped'" % (d.purhcase_order))
|
||||||
|
@ -758,18 +758,17 @@ def make_return_jv(stock_entry):
|
|||||||
result = make_return_jv_from_purchase_receipt(se, ref)
|
result = make_return_jv_from_purchase_receipt(se, ref)
|
||||||
|
|
||||||
# create jv doc and fetch balance for each unique row item
|
# create jv doc and fetch balance for each unique row item
|
||||||
jv_list = [{
|
jv = frappe.new_doc("Journal Voucher")
|
||||||
"__islocal": 1,
|
jv.update({
|
||||||
"doctype": "Journal Voucher",
|
|
||||||
"posting_date": se.posting_date,
|
"posting_date": se.posting_date,
|
||||||
"voucher_type": se.purpose == "Sales Return" and "Credit Note" or "Debit Note",
|
"voucher_type": se.purpose == "Sales Return" and "Credit Note" or "Debit Note",
|
||||||
"fiscal_year": se.fiscal_year,
|
"fiscal_year": se.fiscal_year,
|
||||||
"company": se.company
|
"company": se.company
|
||||||
}]
|
})
|
||||||
|
|
||||||
from erpnext.accounts.utils import get_balance_on
|
from erpnext.accounts.utils import get_balance_on
|
||||||
for r in result:
|
for r in result:
|
||||||
jv_list.append({
|
jv.append("entries", {
|
||||||
"__islocal": 1,
|
"__islocal": 1,
|
||||||
"doctype": "Journal Voucher Detail",
|
"doctype": "Journal Voucher Detail",
|
||||||
"parentfield": "entries",
|
"parentfield": "entries",
|
||||||
@ -780,7 +779,7 @@ def make_return_jv(stock_entry):
|
|||||||
if r.get("account") else 0
|
if r.get("account") else 0
|
||||||
})
|
})
|
||||||
|
|
||||||
return jv_list
|
return jv
|
||||||
|
|
||||||
def make_return_jv_from_sales_invoice(se, ref):
|
def make_return_jv_from_sales_invoice(se, ref):
|
||||||
# customer account entry
|
# customer account entry
|
||||||
@ -804,9 +803,9 @@ def make_return_jv_from_sales_invoice(se, ref):
|
|||||||
|
|
||||||
def get_sales_account_from_item(doc, ref_item):
|
def get_sales_account_from_item(doc, ref_item):
|
||||||
account = None
|
account = None
|
||||||
if not ref_item.income_account:
|
if not getattr(ref_item, "income_account", None):
|
||||||
if ref_item.parent_item:
|
if ref_item.parent_item:
|
||||||
parent_item = doc.get({"item_code": ref_item.parent_item})[0]
|
parent_item = doc.get(doc.fname, {"item_code": ref_item.parent_item})[0]
|
||||||
account = parent_item.income_account
|
account = parent_item.income_account
|
||||||
else:
|
else:
|
||||||
account = ref_item.income_account
|
account = ref_item.income_account
|
||||||
@ -818,7 +817,7 @@ def make_return_jv_from_delivery_note(se, ref):
|
|||||||
ref.doc.name)
|
ref.doc.name)
|
||||||
|
|
||||||
if not invoices_against_delivery:
|
if not invoices_against_delivery:
|
||||||
sales_orders_against_delivery = [d.against_sales_order for d in ref.doc.get_all_children() if d.against_sales_order]
|
sales_orders_against_delivery = [d.against_sales_order for d in ref.doc.get_all_children() if getattr(d, "against_sales_order", None)]
|
||||||
|
|
||||||
if sales_orders_against_delivery:
|
if sales_orders_against_delivery:
|
||||||
invoices_against_delivery = get_invoice_list("Sales Invoice Item", "sales_order",
|
invoices_against_delivery = get_invoice_list("Sales Invoice Item", "sales_order",
|
||||||
@ -877,7 +876,8 @@ def make_return_jv_from_purchase_receipt(se, ref):
|
|||||||
|
|
||||||
if not invoice_against_receipt:
|
if not invoice_against_receipt:
|
||||||
purchase_orders_against_receipt = [d.prevdoc_docname for d in
|
purchase_orders_against_receipt = [d.prevdoc_docname for d in
|
||||||
ref.get({"prevdoc_doctype": "Purchase Order"}) if d.prevdoc_docname]
|
ref.doc.get(ref.doc.fname, {"prevdoc_doctype": "Purchase Order"})
|
||||||
|
if getattr(d, "prevdoc_docname", None)]
|
||||||
|
|
||||||
if purchase_orders_against_receipt:
|
if purchase_orders_against_receipt:
|
||||||
invoice_against_receipt = get_invoice_list("Purchase Invoice Item", "purchase_order",
|
invoice_against_receipt = get_invoice_list("Purchase Invoice Item", "purchase_order",
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, unittest
|
import frappe, unittest
|
||||||
|
import frappe.defaults
|
||||||
from frappe.utils import flt, getdate
|
from frappe.utils import flt, getdate
|
||||||
from erpnext.stock.doctype.serial_no.serial_no import *
|
from erpnext.stock.doctype.serial_no.serial_no import *
|
||||||
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
|
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
|
||||||
@ -31,7 +32,6 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
st2.submit()
|
st2.submit()
|
||||||
|
|
||||||
from erpnext.stock.utils import reorder_item
|
from erpnext.stock.utils import reorder_item
|
||||||
|
|
||||||
reorder_item()
|
reorder_item()
|
||||||
|
|
||||||
mr_name = frappe.db.sql("""select parent from `tabMaterial Request Item`
|
mr_name = frappe.db.sql("""select parent from `tabMaterial Request Item`
|
||||||
@ -39,8 +39,6 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertTrue(mr_name)
|
self.assertTrue(mr_name)
|
||||||
|
|
||||||
frappe.db.set_default("company", self.old_default_company)
|
|
||||||
|
|
||||||
def test_material_receipt_gl_entry(self):
|
def test_material_receipt_gl_entry(self):
|
||||||
self._clear_stock_account_balance()
|
self._clear_stock_account_balance()
|
||||||
set_perpetual_inventory()
|
set_perpetual_inventory()
|
||||||
@ -367,14 +365,14 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
|
|
||||||
def _test_sales_return_jv(self, se):
|
def _test_sales_return_jv(self, se):
|
||||||
from erpnext.stock.doctype.stock_entry.stock_entry import make_return_jv
|
from erpnext.stock.doctype.stock_entry.stock_entry import make_return_jv
|
||||||
jv_list = make_return_jv(se.name)
|
jv = make_return_jv(se.name)
|
||||||
|
|
||||||
self.assertEqual(len(jv_list), 3)
|
self.assertEqual(len(jv.get("entries")), 2)
|
||||||
self.assertEqual(jv_list[0].get("voucher_type"), "Credit Note")
|
self.assertEqual(jv.get("voucher_type"), "Credit Note")
|
||||||
self.assertEqual(jv_list[0].get("posting_date"), se.posting_date)
|
self.assertEqual(jv.get("posting_date"), se.posting_date)
|
||||||
self.assertEqual(jv_list[1].get("account"), "_Test Customer - _TC")
|
self.assertEqual(jv.get("entries")[0].get("account"), "_Test Customer - _TC")
|
||||||
self.assertEqual(jv_list[2].get("account"), "Sales - _TC")
|
self.assertEqual(jv.get("entries")[1].get("account"), "Sales - _TC")
|
||||||
self.assertTrue(jv_list[1].get("against_invoice"))
|
self.assertTrue(jv.get("entries")[0].get("against_invoice"))
|
||||||
|
|
||||||
def test_make_return_jv_for_sales_invoice_non_packing_item(self):
|
def test_make_return_jv_for_sales_invoice_non_packing_item(self):
|
||||||
self._clear_stock_account_balance()
|
self._clear_stock_account_balance()
|
||||||
@ -527,14 +525,14 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
|
|
||||||
def _test_purchase_return_jv(self, se):
|
def _test_purchase_return_jv(self, se):
|
||||||
from erpnext.stock.doctype.stock_entry.stock_entry import make_return_jv
|
from erpnext.stock.doctype.stock_entry.stock_entry import make_return_jv
|
||||||
jv_list = make_return_jv(se.name)
|
jv = make_return_jv(se.name)
|
||||||
|
|
||||||
self.assertEqual(len(jv_list), 3)
|
self.assertEqual(len(jv.get("entries")), 2)
|
||||||
self.assertEqual(jv_list[0].get("voucher_type"), "Debit Note")
|
self.assertEqual(jv.get("voucher_type"), "Debit Note")
|
||||||
self.assertEqual(jv_list[0].get("posting_date"), se.posting_date)
|
self.assertEqual(jv.get("posting_date"), se.posting_date)
|
||||||
self.assertEqual(jv_list[1].get("account"), "_Test Supplier - _TC")
|
self.assertEqual(jv.get("entries")[0].get("account"), "_Test Supplier - _TC")
|
||||||
self.assertEqual(jv_list[2].get("account"), "_Test Account Cost for Goods Sold - _TC")
|
self.assertEqual(jv.get("entries")[1].get("account"), "_Test Account Cost for Goods Sold - _TC")
|
||||||
self.assertTrue(jv_list[1].get("against_voucher"))
|
self.assertTrue(jv.get("entries")[0].get("against_voucher"))
|
||||||
|
|
||||||
def test_make_return_jv_for_purchase_receipt(self):
|
def test_make_return_jv_for_purchase_receipt(self):
|
||||||
self._clear_stock_account_balance()
|
self._clear_stock_account_balance()
|
||||||
@ -774,10 +772,9 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
|
|
||||||
# permission tests
|
# permission tests
|
||||||
def test_warehouse_user(self):
|
def test_warehouse_user(self):
|
||||||
import frappe.defaults
|
|
||||||
set_perpetual_inventory(0)
|
set_perpetual_inventory(0)
|
||||||
|
|
||||||
frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", "Restriction")
|
frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC", "test@example.com", "Restriction")
|
||||||
frappe.defaults.add_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", "Restriction")
|
frappe.defaults.add_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", "Restriction")
|
||||||
frappe.get_doc("User", "test@example.com")\
|
frappe.get_doc("User", "test@example.com")\
|
||||||
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
|
||||||
@ -797,15 +794,17 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
st1.insert()
|
st1.insert()
|
||||||
st1.submit()
|
st1.submit()
|
||||||
|
|
||||||
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", parenttype="Restriction")
|
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC",
|
||||||
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", parenttype="Restriction")
|
"test@example.com", parenttype="Restriction")
|
||||||
|
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 2 - _TC1",
|
||||||
|
"test2@example.com", parenttype="Restriction")
|
||||||
|
|
||||||
def test_freeze_stocks (self):
|
def test_freeze_stocks (self):
|
||||||
self._clear_stock_account_balance()
|
self._clear_stock_account_balance()
|
||||||
frappe.db.set_value('Stock Settings', None,'stock_auth_role', '')
|
frappe.db.set_value('Stock Settings', None,'stock_auth_role', '')
|
||||||
|
|
||||||
# test freeze_stocks_upto
|
# test freeze_stocks_upto
|
||||||
date_newer_than_test_records = add_days(getdate(test_records[0][0]['posting_date']), 5)
|
date_newer_than_test_records = add_days(getdate(test_records[0]['posting_date']), 5)
|
||||||
frappe.db.set_value("Stock Settings", None, "stock_frozen_upto", date_newer_than_test_records)
|
frappe.db.set_value("Stock Settings", None, "stock_frozen_upto", date_newer_than_test_records)
|
||||||
se = frappe.copy_doc(test_records[0]).insert()
|
se = frappe.copy_doc(test_records[0]).insert()
|
||||||
self.assertRaises (StockFreezeError, se.submit)
|
self.assertRaises (StockFreezeError, se.submit)
|
||||||
|
@ -169,9 +169,13 @@ def get_sle_before_datetime(args, for_update=False):
|
|||||||
def get_sle_after_datetime(args, for_update=False):
|
def get_sle_after_datetime(args, for_update=False):
|
||||||
"""get Stock Ledger Entries after a particular datetime, for reposting"""
|
"""get Stock Ledger Entries after a particular datetime, for reposting"""
|
||||||
# NOTE: using for update of
|
# NOTE: using for update of
|
||||||
return get_stock_ledger_entries(args,
|
conditions = ["timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s)"]
|
||||||
["timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s)"],
|
|
||||||
"asc", for_update=for_update)
|
# Excluding name: Workaround for MariaDB timestamp() floating microsecond issue
|
||||||
|
if args.get("name"):
|
||||||
|
conditions.append("name!=%(name)s")
|
||||||
|
|
||||||
|
return get_stock_ledger_entries(args, conditions, "asc", for_update=for_update)
|
||||||
|
|
||||||
def get_stock_ledger_entries(args, conditions=None, order="desc", limit=None, for_update=False):
|
def get_stock_ledger_entries(args, conditions=None, order="desc", limit=None, for_update=False):
|
||||||
"""get stock ledger entries filtered by specific posting datetime conditions"""
|
"""get stock ledger entries filtered by specific posting datetime conditions"""
|
||||||
@ -180,7 +184,7 @@ def get_stock_ledger_entries(args, conditions=None, order="desc", limit=None, fo
|
|||||||
if not args.get("posting_time"):
|
if not args.get("posting_time"):
|
||||||
args["posting_time"] = "00:00"
|
args["posting_time"] = "00:00"
|
||||||
|
|
||||||
return frappe.db.sql("""select * from `tabStock Ledger Entry`
|
return frappe.db.sql("""select *, timestamp(posting_date, posting_time) as "timestamp" from `tabStock Ledger Entry`
|
||||||
where item_code = %%(item_code)s
|
where item_code = %%(item_code)s
|
||||||
and warehouse = %%(warehouse)s
|
and warehouse = %%(warehouse)s
|
||||||
and ifnull(is_cancelled, 'No')='No'
|
and ifnull(is_cancelled, 'No')='No'
|
||||||
|
@ -189,7 +189,7 @@ def reorder_item():
|
|||||||
and exists (select name from `tabItem`
|
and exists (select name from `tabItem`
|
||||||
where `tabItem`.name = `tabBin`.item_code and
|
where `tabItem`.name = `tabBin`.item_code and
|
||||||
is_stock_item='Yes' and (is_purchase_item='Yes' or is_sub_contracted_item='Yes') and
|
is_stock_item='Yes' and (is_purchase_item='Yes' or is_sub_contracted_item='Yes') and
|
||||||
(ifnull(end_of_life, '')='' or end_of_life > now()))""", as_dict=True)
|
(ifnull(end_of_life, '')='' or end_of_life > curdate()))""", as_dict=True)
|
||||||
for bin in bin_list:
|
for bin in bin_list:
|
||||||
#check if re-order is required
|
#check if re-order is required
|
||||||
item_reorder = frappe.db.get("Item Reorder",
|
item_reorder = frappe.db.get("Item Reorder",
|
||||||
@ -235,20 +235,18 @@ def create_material_request(material_requests):
|
|||||||
if not items:
|
if not items:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
mr = [{
|
mr = frappe.new_doc("Material Request")
|
||||||
"doctype": "Material Request",
|
mr.update({
|
||||||
"company": company,
|
"company": company,
|
||||||
"fiscal_year": current_fiscal_year,
|
"fiscal_year": current_fiscal_year,
|
||||||
"transaction_date": nowdate(),
|
"transaction_date": nowdate(),
|
||||||
"material_request_type": request_type
|
"material_request_type": request_type
|
||||||
}]
|
})
|
||||||
|
|
||||||
for d in items:
|
for d in items:
|
||||||
item = frappe.get_doc("Item", d.item_code)
|
item = frappe.get_doc("Item", d.item_code)
|
||||||
mr.append({
|
mr.append("indent_details", {
|
||||||
"doctype": "Material Request Item",
|
"doctype": "Material Request Item",
|
||||||
"parenttype": "Material Request",
|
|
||||||
"parentfield": "indent_details",
|
|
||||||
"item_code": d.item_code,
|
"item_code": d.item_code,
|
||||||
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
|
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
|
||||||
"uom": item.stock_uom,
|
"uom": item.stock_uom,
|
||||||
@ -260,10 +258,9 @@ def create_material_request(material_requests):
|
|||||||
"brand": item.brand,
|
"brand": item.brand,
|
||||||
})
|
})
|
||||||
|
|
||||||
mr_doc = frappe.get_doc(mr)
|
mr.insert()
|
||||||
mr_doc.insert()
|
mr.submit()
|
||||||
mr_doc.submit()
|
mr_list.append(mr)
|
||||||
mr_list.append(mr_doc)
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
if frappe.local.message_log:
|
if frappe.local.message_log:
|
||||||
|
Loading…
Reference in New Issue
Block a user