mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 19:19:17 +00:00
fixes in test cases and added fiscal year field to stock reco
This commit is contained in:
@@ -610,7 +610,8 @@ class DocType(StockController):
|
||||
'is_cancelled': (is_cancelled ==1) and 'Yes' or 'No',
|
||||
'batch_no': cstr(d.batch_no).strip(),
|
||||
'serial_no': cstr(d.serial_no).strip(),
|
||||
"project": self.doc.project_name
|
||||
"project": self.doc.project_name,
|
||||
"fiscal_year": self.doc.fiscal_year,
|
||||
})
|
||||
|
||||
def get_cust_values(self):
|
||||
|
||||
@@ -230,6 +230,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
se.doc.purpose = "Sales Return"
|
||||
se.doc.sales_invoice_no = si.doc.name
|
||||
se.doc.posting_date = "2013-03-10"
|
||||
se.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
se.doclist[1].item_code = "_Test Item Home Desktop 200"
|
||||
se.doclist[1].qty = returned_qty
|
||||
se.doclist[1].transfer_qty = returned_qty
|
||||
@@ -241,6 +242,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
se = webnotes.bean(copy=test_records[0])
|
||||
se.doc.purpose = "Sales Return"
|
||||
se.doc.posting_date = "2013-03-10"
|
||||
se.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
se.doc.sales_invoice_no = si.doc.name
|
||||
se.doclist[1].qty = returned_qty
|
||||
se.doclist[1].transfer_qty = returned_qty
|
||||
@@ -300,6 +302,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
se.doc.purpose = "Sales Return"
|
||||
se.doc.delivery_note_no = dn.doc.name
|
||||
se.doc.posting_date = "2013-03-10"
|
||||
se.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
se.doclist[1].qty = se.doclist[1].transfer_qty = returned_qty
|
||||
|
||||
se.insert()
|
||||
@@ -399,6 +402,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
se.doc.purpose = "Sales Return"
|
||||
se.doc.delivery_note_no = dn.doc.name
|
||||
se.doc.posting_date = "2013-03-10"
|
||||
se.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
se.doclist[1].qty = se.doclist[1].transfer_qty = returned_qty
|
||||
|
||||
se.insert()
|
||||
@@ -449,6 +453,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
se.doc.purpose = "Purchase Return"
|
||||
se.doc.purchase_receipt_no = pr.doc.name
|
||||
se.doc.posting_date = "2013-03-01"
|
||||
se.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
se.doclist[1].qty = se.doclist[1].transfer_qty = 5
|
||||
se.doclist[1].s_warehouse = "_Test Warehouse"
|
||||
se.insert()
|
||||
@@ -471,6 +476,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
se.doc.purpose = "Purchase Return"
|
||||
se.doc.purchase_receipt_no = pr_docname
|
||||
se.doc.posting_date = "2013-03-01"
|
||||
se.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
se.doclist[1].qty = se.doclist[1].transfer_qty = 6
|
||||
se.doclist[1].s_warehouse = "_Test Warehouse"
|
||||
|
||||
@@ -547,6 +553,7 @@ class TestStockEntry(unittest.TestCase):
|
||||
se.doc.purpose = "Purchase Return"
|
||||
se.doc.purchase_receipt_no = pr.doc.name
|
||||
se.doc.posting_date = "2013-03-01"
|
||||
se.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
se.doclist[1].qty = se.doclist[1].transfer_qty = 5
|
||||
se.doclist[1].s_warehouse = "_Test Warehouse"
|
||||
se.insert()
|
||||
|
||||
@@ -16,17 +16,13 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import _
|
||||
|
||||
from webnotes import _, msgprint
|
||||
from webnotes.utils import cint, flt, getdate
|
||||
|
||||
sql = webnotes.conn.sql
|
||||
msgprint = webnotes.msgprint
|
||||
from accounts.utils import get_fiscal_year
|
||||
from webnotes.model.controller import DocListController
|
||||
|
||||
class InvalidWarehouseCompany(Exception): pass
|
||||
|
||||
class DocType:
|
||||
class DocType(DocListController):
|
||||
def __init__(self, doc, doclist=[]):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
@@ -39,12 +35,14 @@ class DocType:
|
||||
self.actual_amt_check()
|
||||
self.check_stock_frozen_date()
|
||||
self.scrub_posting_time()
|
||||
self.doc.fiscal_year = get_fiscal_year(self.doc.posting_date)[0]
|
||||
|
||||
from accounts.utils import validate_fiscal_year
|
||||
validate_fiscal_year(self.doc.posting_date, self.doc.fiscal_year, self.meta.get_label("posting_date"))
|
||||
|
||||
#check for item quantity available in stock
|
||||
def actual_amt_check(self):
|
||||
if self.doc.batch_no:
|
||||
batch_bal = flt(sql("select sum(actual_qty) from `tabStock Ledger Entry` where warehouse = '%s' and item_code = '%s' and batch_no = '%s'"%(self.doc.warehouse,self.doc.item_code,self.doc.batch_no))[0][0])
|
||||
batch_bal = flt(webnotes.conn.sql("select sum(actual_qty) from `tabStock Ledger Entry` where warehouse = '%s' and item_code = '%s' and batch_no = '%s'"%(self.doc.warehouse,self.doc.item_code,self.doc.batch_no))[0][0])
|
||||
self.doc.fields.update({'batch_bal': batch_bal})
|
||||
|
||||
if (batch_bal + self.doc.actual_qty) < 0:
|
||||
@@ -77,11 +75,11 @@ class DocType:
|
||||
if self.doc.fields.get(k)==None:
|
||||
msgprint("Stock Ledger Entry: '%s' is mandatory" % k, raise_exception = 1)
|
||||
elif k == 'warehouse':
|
||||
if not sql("select name from tabWarehouse where name = '%s'" % self.doc.fields.get(k)):
|
||||
if not webnotes.conn.sql("select name from tabWarehouse where name = '%s'" % self.doc.fields.get(k)):
|
||||
msgprint("Warehouse: '%s' does not exist in the system. Please check." % self.doc.fields.get(k), raise_exception = 1)
|
||||
|
||||
def validate_item(self):
|
||||
item_det = sql("""select name, has_batch_no, docstatus,
|
||||
item_det = webnotes.conn.sql("""select name, has_batch_no, docstatus,
|
||||
ifnull(is_stock_item, 'No') from tabItem where name=%s""",
|
||||
self.doc.item_code)
|
||||
|
||||
@@ -106,7 +104,7 @@ class DocType:
|
||||
raise Exception
|
||||
|
||||
# check if batch belongs to item
|
||||
if not sql("select name from `tabBatch` where item='%s' and name ='%s' and docstatus != 2" % (self.doc.item_code, self.doc.batch_no)):
|
||||
if not webnotes.conn.sql("select name from `tabBatch` where item='%s' and name ='%s' and docstatus != 2" % (self.doc.item_code, self.doc.batch_no)):
|
||||
msgprint("'%s' is not a valid Batch Number for Item '%s'" % (self.doc.batch_no, self.doc.item_code), raise_exception = 1)
|
||||
|
||||
# Nobody can do SL Entries where posting date is before freezing date except authorized person
|
||||
|
||||
@@ -252,7 +252,8 @@ class DocType(StockController):
|
||||
"voucher_no": self.doc.name,
|
||||
"company": self.doc.company,
|
||||
"is_cancelled": "No",
|
||||
"voucher_detail_no": row.voucher_detail_no
|
||||
"voucher_detail_no": row.voucher_detail_no,
|
||||
"fiscal_year": self.doc.fiscal_year,
|
||||
})
|
||||
args.update(opts)
|
||||
# create stock ledger entry
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-01-22 16:50:41",
|
||||
"creation": "2013-03-26 06:51:17",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-03-18 12:48:42",
|
||||
"modified": "2013-03-26 08:32:03",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
@@ -30,7 +30,6 @@
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"amend": 1,
|
||||
"cancel": 1,
|
||||
"create": 1,
|
||||
"doctype": "DocPerm",
|
||||
@@ -41,7 +40,6 @@
|
||||
"permlevel": 0,
|
||||
"read": 1,
|
||||
"report": 1,
|
||||
"role": "Material Manager",
|
||||
"submit": 1,
|
||||
"write": 1
|
||||
},
|
||||
@@ -81,6 +79,15 @@
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "fiscal_year",
|
||||
"fieldtype": "Select",
|
||||
"label": "Fiscal Year",
|
||||
"options": "link:Fiscal Year",
|
||||
"print_hide": 1,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocField",
|
||||
"fieldname": "company",
|
||||
@@ -145,6 +152,12 @@
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm"
|
||||
"amend": 0,
|
||||
"doctype": "DocPerm",
|
||||
"role": "Material Manager"
|
||||
},
|
||||
{
|
||||
"doctype": "DocPerm",
|
||||
"role": "System Manager"
|
||||
}
|
||||
]
|
||||
@@ -228,35 +228,40 @@ class TestStockReconciliation(unittest.TestCase):
|
||||
"voucher_type": "Stock Entry", "voucher_no": "TEST",
|
||||
"item_code": "_Test Item", "warehouse": "_Test Warehouse",
|
||||
"posting_date": "2012-12-12", "posting_time": "01:00",
|
||||
"actual_qty": 20, "incoming_rate": 1000, "company": "_Test Company"
|
||||
"actual_qty": 20, "incoming_rate": 1000, "company": "_Test Company",
|
||||
"fiscal_year": "_Test Fiscal Year 2012",
|
||||
},
|
||||
{
|
||||
"doctype": "Stock Ledger Entry", "__islocal": 1,
|
||||
"voucher_type": "Stock Entry", "voucher_no": "TEST",
|
||||
"item_code": "_Test Item", "warehouse": "_Test Warehouse",
|
||||
"posting_date": "2012-12-15", "posting_time": "02:00",
|
||||
"actual_qty": 10, "incoming_rate": 700, "company": "_Test Company"
|
||||
"actual_qty": 10, "incoming_rate": 700, "company": "_Test Company",
|
||||
"fiscal_year": "_Test Fiscal Year 2012",
|
||||
},
|
||||
{
|
||||
"doctype": "Stock Ledger Entry", "__islocal": 1,
|
||||
"voucher_type": "Stock Entry", "voucher_no": "TEST",
|
||||
"item_code": "_Test Item", "warehouse": "_Test Warehouse",
|
||||
"posting_date": "2012-12-25", "posting_time": "03:00",
|
||||
"actual_qty": -15, "company": "_Test Company"
|
||||
"actual_qty": -15, "company": "_Test Company",
|
||||
"fiscal_year": "_Test Fiscal Year 2012",
|
||||
},
|
||||
{
|
||||
"doctype": "Stock Ledger Entry", "__islocal": 1,
|
||||
"voucher_type": "Stock Entry", "voucher_no": "TEST",
|
||||
"item_code": "_Test Item", "warehouse": "_Test Warehouse",
|
||||
"posting_date": "2012-12-31", "posting_time": "08:00",
|
||||
"actual_qty": -20, "company": "_Test Company"
|
||||
"actual_qty": -20, "company": "_Test Company",
|
||||
"fiscal_year": "_Test Fiscal Year 2012",
|
||||
},
|
||||
{
|
||||
"doctype": "Stock Ledger Entry", "__islocal": 1,
|
||||
"voucher_type": "Stock Entry", "voucher_no": "TEST",
|
||||
"item_code": "_Test Item", "warehouse": "_Test Warehouse",
|
||||
"posting_date": "2013-01-05", "posting_time": "07:00",
|
||||
"actual_qty": 15, "incoming_rate": 1200, "company": "_Test Company"
|
||||
"actual_qty": 15, "incoming_rate": 1200, "company": "_Test Company",
|
||||
"fiscal_year": "_Test Fiscal Year 2013",
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user