Merge pull request #1361 from trhura/develop
Pull request for issue #856
This commit is contained in:
commit
115dcc09d4
@ -6,7 +6,7 @@ import webnotes, unittest
|
|||||||
from webnotes.utils import flt
|
from webnotes.utils import flt
|
||||||
from stock.doctype.serial_no.serial_no import *
|
from stock.doctype.serial_no.serial_no import *
|
||||||
from stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
|
from stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
|
||||||
|
from stock.doctype.stock_ledger_entry.stock_ledger_entry import StockFreezeError
|
||||||
|
|
||||||
class TestStockEntry(unittest.TestCase):
|
class TestStockEntry(unittest.TestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
@ -800,6 +800,23 @@ class TestStockEntry(unittest.TestCase):
|
|||||||
serial_no = get_serial_nos(se.doclist[1].serial_no)[0]
|
serial_no = get_serial_nos(se.doclist[1].serial_no)[0]
|
||||||
self.assertFalse(webnotes.conn.get_value("Serial No", serial_no, "warehouse"))
|
self.assertFalse(webnotes.conn.get_value("Serial No", serial_no, "warehouse"))
|
||||||
|
|
||||||
|
def test_freeze_stocks (self):
|
||||||
|
self._clear_stock_account_balance()
|
||||||
|
stock_auth_role = webnotes.conn.set_value('Stock Settings', None,'stock_auth_role', '')
|
||||||
|
|
||||||
|
# test freeze_stocks_upto
|
||||||
|
date_newer_than_test_records = add_days(getdate(test_records[0][0]['posting_date']), 5)
|
||||||
|
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto", date_newer_than_test_records)
|
||||||
|
se = webnotes.bean(copy=test_records[0]).insert()
|
||||||
|
self.assertRaises (StockFreezeError, se.submit)
|
||||||
|
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto", '')
|
||||||
|
|
||||||
|
# test freeze_stocks_upto_days
|
||||||
|
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto_days", 7)
|
||||||
|
se = webnotes.bean(copy=test_records[0]).insert()
|
||||||
|
self.assertRaises (StockFreezeError, se.submit)
|
||||||
|
webnotes.conn.set_value("Stock Settings", None, "stock_frozen_upto_days", 0)
|
||||||
|
|
||||||
def make_serialized_item():
|
def make_serialized_item():
|
||||||
se = webnotes.bean(copy=test_records[0])
|
se = webnotes.bean(copy=test_records[0])
|
||||||
se.doclist[1].item_code = "_Test Serialized Item With Series"
|
se.doclist[1].item_code = "_Test Serialized Item With Series"
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
|
|
||||||
# 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
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
from webnotes import msgprint
|
from webnotes import msgprint
|
||||||
from webnotes.utils import flt, getdate
|
from webnotes.utils import flt, getdate, add_days
|
||||||
from webnotes.model.controller import DocListController
|
from webnotes.model.controller import DocListController
|
||||||
|
from datetime import date
|
||||||
|
|
||||||
|
class StockFreezeError(webnotes.ValidationError): pass
|
||||||
|
|
||||||
class DocType(DocListController):
|
class DocType(DocListController):
|
||||||
def __init__(self, doc, doclist=[]):
|
def __init__(self, doc, doclist=[]):
|
||||||
@ -86,7 +90,15 @@ class DocType(DocListController):
|
|||||||
if stock_frozen_upto:
|
if stock_frozen_upto:
|
||||||
stock_auth_role = webnotes.conn.get_value('Stock Settings', None,'stock_auth_role')
|
stock_auth_role = webnotes.conn.get_value('Stock Settings', None,'stock_auth_role')
|
||||||
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=StockFreezeError)
|
||||||
|
|
||||||
|
stock_frozen_upto_days = int(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')
|
||||||
|
older_than_x_days_ago = (add_days(getdate(self.doc.posting_date), stock_frozen_upto_days) <= date.today())
|
||||||
|
if older_than_x_days_ago and not stock_auth_role in webnotes.user.get_roles():
|
||||||
|
msgprint("You are not authorized to do / modify back dated stock entries older than %d days ago" %stock_frozen_upto_days, raise_exception=StockFreezeError)
|
||||||
|
|
||||||
|
|
||||||
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':
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import webnotes
|
import webnotes
|
||||||
|
from webnotes import _
|
||||||
|
|
||||||
class DocType:
|
class DocType:
|
||||||
def __init__(self, d, dl):
|
def __init__(self, d, dl):
|
||||||
@ -20,3 +20,8 @@ class DocType:
|
|||||||
set_by_naming_series("Item", "item_code",
|
set_by_naming_series("Item", "item_code",
|
||||||
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
|
||||||
|
submitted_stock_frozen = self.doc.stock_frozen_upto_days
|
||||||
|
if submitted_stock_frozen > stock_frozen_limit:
|
||||||
|
self.doc.stock_frozen_upto_days = stock_frozen_limit
|
||||||
|
webnotes.msgprint (_("`Freeze Stocks Older Than` should be smaller than %d days.") %stock_frozen_limit)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
"creation": "2013-06-24 16:37:54",
|
"creation": "2013-06-24 16:37:54",
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"modified": "2013-11-02 19:41:56",
|
"modified": "2014-01-27 20:00:56",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"owner": "Administrator"
|
"owner": "Administrator"
|
||||||
},
|
},
|
||||||
@ -115,6 +115,12 @@
|
|||||||
"fieldtype": "Date",
|
"fieldtype": "Date",
|
||||||
"label": "Stock Frozen Upto"
|
"label": "Stock Frozen Upto"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"doctype": "DocField",
|
||||||
|
"fieldname": "stock_frozen_upto_days",
|
||||||
|
"fieldtype": "Int",
|
||||||
|
"label": "Freeze Stocks Older Than [Days]"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"doctype": "DocField",
|
"doctype": "DocField",
|
||||||
"fieldname": "stock_auth_role",
|
"fieldname": "stock_auth_role",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user