production order: test fixed and added in test_stock_entry.py
This commit is contained in:
parent
166bc2a0e0
commit
052fe82688
@ -45,6 +45,7 @@ class StockController(AccountsController):
|
|||||||
for sle in sle_list:
|
for sle in sle_list:
|
||||||
if warehouse_account.get(sle.warehouse):
|
if warehouse_account.get(sle.warehouse):
|
||||||
# from warehouse account
|
# from warehouse account
|
||||||
|
|
||||||
self.check_expense_account(detail)
|
self.check_expense_account(detail)
|
||||||
|
|
||||||
gl_list.append(self.get_gl_dict({
|
gl_list.append(self.get_gl_dict({
|
||||||
@ -230,10 +231,10 @@ class StockController(AccountsController):
|
|||||||
make_gl_entries(gl_entries)
|
make_gl_entries(gl_entries)
|
||||||
|
|
||||||
def check_expense_account(self, item):
|
def check_expense_account(self, item):
|
||||||
if item.meta.get_field("expense_account") and not item.expense_account:
|
if not item.get("expense_account"):
|
||||||
frappe.throw(_("Expense or Difference account is mandatory for Item {0} as there is difference in value").format(item.item_code))
|
frappe.throw(_("Expense or Difference account is mandatory for Item {0} as there is difference in value").format(item.item_code))
|
||||||
|
|
||||||
if getattr(item, "expense_account", None) and not item.cost_center:
|
if item.get("expense_account") and not item.cost_center:
|
||||||
frappe.throw(_("""Cost Center is mandatory for Item {0}""").format(item.item_code))
|
frappe.throw(_("""Cost Center is mandatory for Item {0}""").format(item.item_code))
|
||||||
|
|
||||||
def get_sl_entries(self, d, args):
|
def get_sl_entries(self, d, args):
|
||||||
|
@ -112,7 +112,7 @@ class ProductionOrder(Document):
|
|||||||
produced_qty = flt(produced_qty[0][0]) if produced_qty else 0
|
produced_qty = flt(produced_qty[0][0]) if produced_qty else 0
|
||||||
|
|
||||||
if produced_qty > self.qty:
|
if produced_qty > self.qty:
|
||||||
frappe.throw(_("Manufactured quantity {0} cannot be greater than planned quanitity {1} in Production Order {2}").format(produced_qty, self.qty, self.name, StockOverProductionError))
|
frappe.throw(_("Manufactured quantity {0} cannot be greater than planned quanitity {1} in Production Order {2}").format(produced_qty, self.qty, self.name), StockOverProductionError)
|
||||||
|
|
||||||
self.db_set("produced_qty", produced_qty)
|
self.db_set("produced_qty", produced_qty)
|
||||||
|
|
||||||
|
@ -7,40 +7,21 @@ import unittest
|
|||||||
import frappe
|
import frappe
|
||||||
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
|
||||||
from erpnext.manufacturing.doctype.production_order.production_order import make_stock_entry
|
from erpnext.manufacturing.doctype.production_order.production_order import make_stock_entry
|
||||||
|
from erpnext.stock.doctype.stock_entry import test_stock_entry
|
||||||
|
|
||||||
class TestProductionOrder(unittest.TestCase):
|
class TestProductionOrder(unittest.TestCase):
|
||||||
def test_planned_qty(self):
|
def test_planned_qty(self):
|
||||||
set_perpetual_inventory(0)
|
set_perpetual_inventory(0)
|
||||||
|
|
||||||
|
planned0 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty") or 0
|
||||||
|
|
||||||
pro_doc = frappe.copy_doc(test_records[0])
|
pro_doc = frappe.copy_doc(test_records[0])
|
||||||
pro_doc.insert()
|
pro_doc.insert()
|
||||||
pro_doc.submit()
|
pro_doc.submit()
|
||||||
|
|
||||||
# add raw materials to stores
|
# add raw materials to stores
|
||||||
s = frappe.new_doc("Stock Entry")
|
test_stock_entry.make_stock_entry("_Test Item", None, "Stores - _TC", 100, 100)
|
||||||
s.purpose = "Material Receipt"
|
test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "Stores - _TC", 100, 100)
|
||||||
s.company = "_Test Company"
|
|
||||||
s.append("mtn_details", {
|
|
||||||
"item_code": "_Test Item",
|
|
||||||
"t_warehouse": "Stores - _TC",
|
|
||||||
"qty": 100,
|
|
||||||
"incoming_rate": 5000
|
|
||||||
})
|
|
||||||
s.insert()
|
|
||||||
s.submit()
|
|
||||||
|
|
||||||
# add raw materials to stores
|
|
||||||
s = frappe.new_doc("Stock Entry")
|
|
||||||
s.purpose = "Material Receipt"
|
|
||||||
s.company = "_Test Company"
|
|
||||||
s.append("mtn_details", {
|
|
||||||
"item_code": "_Test Item Home Desktop 100",
|
|
||||||
"t_warehouse": "Stores - _TC",
|
|
||||||
"qty": 100,
|
|
||||||
"incoming_rate": 1000
|
|
||||||
})
|
|
||||||
s.insert()
|
|
||||||
s.submit()
|
|
||||||
|
|
||||||
# from stores to wip
|
# from stores to wip
|
||||||
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 4))
|
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 4))
|
||||||
@ -56,8 +37,8 @@ class TestProductionOrder(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(frappe.db.get_value("Production Order", pro_doc.name,
|
self.assertEqual(frappe.db.get_value("Production Order", pro_doc.name,
|
||||||
"produced_qty"), 4)
|
"produced_qty"), 4)
|
||||||
self.assertEqual(frappe.db.get_value("Bin", {"item_code": "_Test FG Item",
|
planned1 = frappe.db.get_value("Bin", {"item_code": "_Test FG Item", "warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty")
|
||||||
"warehouse": "_Test Warehouse 1 - _TC"}, "planned_qty"), 6)
|
self.assertEqual(planned1 - planned0, 6)
|
||||||
|
|
||||||
return pro_doc
|
return pro_doc
|
||||||
|
|
||||||
@ -65,11 +46,8 @@ class TestProductionOrder(unittest.TestCase):
|
|||||||
from erpnext.manufacturing.doctype.production_order.production_order import StockOverProductionError
|
from erpnext.manufacturing.doctype.production_order.production_order import StockOverProductionError
|
||||||
pro_doc = self.test_planned_qty()
|
pro_doc = self.test_planned_qty()
|
||||||
|
|
||||||
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Material Transfer", 7))
|
test_stock_entry.make_stock_entry("_Test Item", None, "_Test Warehouse - _TC", 100, 100)
|
||||||
for d in s.get("mtn_details"):
|
test_stock_entry.make_stock_entry("_Test Item Home Desktop 100", None, "_Test Warehouse - _TC", 100, 100)
|
||||||
d.s_warehouse = "Stores - _TC"
|
|
||||||
s.insert()
|
|
||||||
s.submit()
|
|
||||||
|
|
||||||
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture/Repack", 7))
|
s = frappe.get_doc(make_stock_entry(pro_doc.name, "Manufacture/Repack", 7))
|
||||||
s.insert()
|
s.insert()
|
||||||
|
@ -824,3 +824,23 @@ def make_serialized_item():
|
|||||||
return se
|
return se
|
||||||
|
|
||||||
test_records = frappe.get_test_records('Stock Entry')
|
test_records = frappe.get_test_records('Stock Entry')
|
||||||
|
|
||||||
|
def make_stock_entry(item, source, target, qty, incoming_rate=None):
|
||||||
|
s = frappe.new_doc("Stock Entry")
|
||||||
|
if source and target:
|
||||||
|
s.purpose = "Material Transfer"
|
||||||
|
elif source:
|
||||||
|
s.purpose = "Material Issue"
|
||||||
|
else:
|
||||||
|
s.purpose = "Material Receipt"
|
||||||
|
s.company = "_Test Company"
|
||||||
|
s.append("mtn_details", {
|
||||||
|
"item_code": item,
|
||||||
|
"s_warehouse": source,
|
||||||
|
"t_warehouse": target,
|
||||||
|
"qty": qty,
|
||||||
|
"incoming_rate": incoming_rate
|
||||||
|
})
|
||||||
|
s.insert()
|
||||||
|
s.submit()
|
||||||
|
return s
|
||||||
|
Loading…
Reference in New Issue
Block a user