changed stock_frozen_upto to stock_frozen_upto_days, and added validation for it in stock ledger

This commit is contained in:
Thura Hlaing
2014-01-27 16:54:02 +06:30
parent 98d4622ed8
commit 9d5566634c
3 changed files with 35 additions and 24 deletions

View File

@@ -1,3 +1,4 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt # License: GNU General Public License v3. See license.txt
@@ -6,6 +7,7 @@ import webnotes
from webnotes import msgprint from webnotes import msgprint
from webnotes.utils import flt, getdate from webnotes.utils import flt, getdate
from webnotes.model.controller import DocListController from webnotes.model.controller import DocListController
from datetime import timedelta, date
class DocType(DocListController): class DocType(DocListController):
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
@@ -88,6 +90,15 @@ class DocType(DocListController):
if getdate(self.doc.posting_date) <= getdate(stock_frozen_upto) and not stock_auth_role in webnotes.user.get_roles(): if getdate(self.doc.posting_date) <= getdate(stock_frozen_upto) and not stock_auth_role in webnotes.user.get_roles():
msgprint("You are not authorized to do / modify back dated stock entries before %s" % getdate(stock_frozen_upto).strftime('%d-%m-%Y'), raise_exception=1) msgprint("You are not authorized to do / modify back dated stock entries before %s" % getdate(stock_frozen_upto).strftime('%d-%m-%Y'), raise_exception=1)
stock_frozen_upto_days = webnotes.conn.get_value('Stock Settings', None, 'stock_frozen_upto_days') or 0
if stock_frozen_upto_days:
stock_auth_role = webnotes.conn.get_value('Stock Settings', None,'stock_auth_role')
posting_date = getdate(self.doc.posting_date)
frozen_days = timedelta(days=stock_frozen_upto_days)
if posting_date + frozen_days <= date.today() and not stock_auth_role in webnotes.user.get_roles():
msgprint("You are not authorized to do / modify back dated stock entries %d ago" %stock_frozen_upto_days, raise_exception=1)
def scrub_posting_time(self): def scrub_posting_time(self):
if not self.doc.posting_time or self.doc.posting_time == '00:0': if not self.doc.posting_time or self.doc.posting_time == '00:0':
self.doc.posting_time = '00:00' self.doc.posting_time = '00:00'

View File

@@ -21,7 +21,7 @@ class DocType:
self.doc.get("item_naming_by")=="Naming Series", hide_name_field=True) self.doc.get("item_naming_by")=="Naming Series", hide_name_field=True)
stock_frozen_limit = 356 stock_frozen_limit = 356
submitted_stock_frozen = self.doc.fields.get("stock_frozen_upto") submitted_stock_frozen = self.doc.fields.get("stock_frozen_upto_days")
if submitted_stock_frozen > stock_frozen_limit: if submitted_stock_frozen > stock_frozen_limit:
self.doc.fields["stock_frozen_upto"] = stock_frozen_limit self.doc.fields["stock_frozen_upto_days"] = stock_frozen_limit
webnotes.msgprint (_("Stocks cannot be freezed for days larger than %d.") %stock_frozen_limit) webnotes.msgprint (_("Stocks cannot be freezed for days larger than %d.") %stock_frozen_limit)

View File

@@ -2,7 +2,7 @@
{ {
"creation": "2013-06-24 16:37:54", "creation": "2013-06-24 16:37:54",
"docstatus": 0, "docstatus": 0,
"modified": "2014-01-27 13:29:56", "modified": "2014-01-27 17:29:56",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@@ -117,9 +117,9 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "stock_frozen_upto", "fieldname": "stock_frozen_upto_days",
"fieldtype": "Int", "fieldtype": "Int",
"label": "Stock Frozen Upto" "label": "Stock Frozen Upto [Days Ago]"
}, },
{ {
"doctype": "DocField", "doctype": "DocField",