Validate warehouse for allowed users and matched company
This commit is contained in:
parent
842e9d60cc
commit
8f05c05bfb
@ -24,7 +24,7 @@ class BuyingController(StockController):
|
|||||||
self.doc.supplier_name = webnotes.conn.get_value("Supplier",
|
self.doc.supplier_name = webnotes.conn.get_value("Supplier",
|
||||||
self.doc.supplier, "supplier_name")
|
self.doc.supplier, "supplier_name")
|
||||||
self.validate_stock_or_nonstock_items()
|
self.validate_stock_or_nonstock_items()
|
||||||
self.validate_warehouse_belongs_to_company()
|
self.validate_warehouse()
|
||||||
|
|
||||||
def set_missing_values(self, for_validate=False):
|
def set_missing_values(self, for_validate=False):
|
||||||
super(BuyingController, self).set_missing_values(for_validate)
|
super(BuyingController, self).set_missing_values(for_validate)
|
||||||
@ -50,17 +50,20 @@ class BuyingController(StockController):
|
|||||||
self.doc.supplier = supplier
|
self.doc.supplier = supplier
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def validate_warehouse(self):
|
||||||
|
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||||
|
|
||||||
|
warehouses = list(set([d.warehouse for d in
|
||||||
|
self.doclist.get({"doctype": self.tname}) if d.warehouse]))
|
||||||
|
|
||||||
|
for w in warehouses:
|
||||||
|
validate_warehouse_user(w)
|
||||||
|
validate_warehouse_company(w, self.doc.company)
|
||||||
|
|
||||||
def get_purchase_tax_details(self):
|
def get_purchase_tax_details(self):
|
||||||
self.doclist = self.doc.clear_table(self.doclist, "purchase_tax_details")
|
self.doclist = self.doc.clear_table(self.doclist, "purchase_tax_details")
|
||||||
self.set_taxes("purchase_tax_details", "purchase_other_charges")
|
self.set_taxes("purchase_tax_details", "purchase_other_charges")
|
||||||
|
|
||||||
def validate_warehouse_belongs_to_company(self):
|
|
||||||
for warehouse, company in webnotes.conn.get_values("Warehouse",
|
|
||||||
self.doclist.get_distinct_values("warehouse"), "company").items():
|
|
||||||
if company and company != self.doc.company:
|
|
||||||
webnotes.msgprint(_("Company mismatch for Warehouse") + (": %s" % (warehouse,)),
|
|
||||||
raise_exception=WrongWarehouseCompany)
|
|
||||||
|
|
||||||
def validate_stock_or_nonstock_items(self):
|
def validate_stock_or_nonstock_items(self):
|
||||||
if not self.get_stock_items():
|
if not self.get_stock_items():
|
||||||
tax_for_valuation = [d.account_head for d in
|
tax_for_valuation = [d.account_head for d in
|
||||||
|
|||||||
@ -22,13 +22,14 @@ class DocType:
|
|||||||
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
|
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
|
||||||
"In Process", "Completed", "Cancelled"])
|
"In Process", "Completed", "Cancelled"])
|
||||||
|
|
||||||
if self.doc.production_item :
|
self.validate_bom_no()
|
||||||
item_detail = sql("select name from `tabItem` where name = '%s' and docstatus != 2"
|
self.validate_sales_order()
|
||||||
% self.doc.production_item, as_dict = 1)
|
self.validate_warehouse()
|
||||||
if not item_detail:
|
|
||||||
msgprint("Item '%s' does not exist or cancelled in the system."
|
|
||||||
% cstr(self.doc.production_item), raise_exception=1)
|
|
||||||
|
|
||||||
|
from utilities.transaction_base import validate_uom_is_integer
|
||||||
|
validate_uom_is_integer(self.doclist, "stock_uom", ["qty", "produced_qty"])
|
||||||
|
|
||||||
|
def validate_bom_no(self):
|
||||||
if self.doc.bom_no:
|
if self.doc.bom_no:
|
||||||
bom = sql("""select name from `tabBOM` where name=%s and docstatus=1
|
bom = sql("""select name from `tabBOM` where name=%s and docstatus=1
|
||||||
and is_active=1 and item=%s"""
|
and is_active=1 and item=%s"""
|
||||||
@ -38,6 +39,7 @@ class DocType:
|
|||||||
May be BOM not exists or inactive or not submitted
|
May be BOM not exists or inactive or not submitted
|
||||||
or for some other item.""" % cstr(self.doc.bom_no), raise_exception=1)
|
or for some other item.""" % cstr(self.doc.bom_no), raise_exception=1)
|
||||||
|
|
||||||
|
def validate_sales_order(self):
|
||||||
if self.doc.sales_order:
|
if self.doc.sales_order:
|
||||||
if not webnotes.conn.sql("""select name from `tabSales Order`
|
if not webnotes.conn.sql("""select name from `tabSales Order`
|
||||||
where name=%s and docstatus = 1""", self.doc.sales_order):
|
where name=%s and docstatus = 1""", self.doc.sales_order):
|
||||||
@ -45,9 +47,12 @@ class DocType:
|
|||||||
|
|
||||||
self.validate_production_order_against_so()
|
self.validate_production_order_against_so()
|
||||||
|
|
||||||
from utilities.transaction_base import validate_uom_is_integer
|
def validate_warehouse(self):
|
||||||
validate_uom_is_integer(self.doclist, "stock_uom", ["qty", "produced_qty"])
|
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||||
|
|
||||||
|
for w in [self.doc.fg_warehouse, self.doc.wip_warehouse]:
|
||||||
|
validate_warehouse_user(w)
|
||||||
|
validate_warehouse_company(w, self.doc.company)
|
||||||
|
|
||||||
def validate_production_order_against_so(self):
|
def validate_production_order_against_so(self):
|
||||||
# already ordered qty
|
# already ordered qty
|
||||||
|
|||||||
@ -127,7 +127,7 @@ class DocType(SellingController):
|
|||||||
self.validate_po()
|
self.validate_po()
|
||||||
self.validate_uom_is_integer("stock_uom", "qty")
|
self.validate_uom_is_integer("stock_uom", "qty")
|
||||||
self.validate_for_items()
|
self.validate_for_items()
|
||||||
self.validate_warehouse_user()
|
self.validate_warehouse()
|
||||||
sales_com_obj = get_obj(dt = 'Sales Common')
|
sales_com_obj = get_obj(dt = 'Sales Common')
|
||||||
sales_com_obj.check_active_sales_items(self)
|
sales_com_obj.check_active_sales_items(self)
|
||||||
sales_com_obj.check_conversion_rate(self)
|
sales_com_obj.check_conversion_rate(self)
|
||||||
@ -148,14 +148,15 @@ class DocType(SellingController):
|
|||||||
if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered'
|
if not self.doc.delivery_status: self.doc.delivery_status = 'Not Delivered'
|
||||||
|
|
||||||
|
|
||||||
def validate_warehouse_user(self):
|
def validate_warehouse(self):
|
||||||
from stock.utils import validate_warehouse_user
|
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||||
|
|
||||||
warehouses = list(set([d.reserved_warehouse for d in
|
warehouses = list(set([d.reserved_warehouse for d in
|
||||||
self.doclist.get({"doctype": self.tname}) if d.reserved_warehouse]))
|
self.doclist.get({"doctype": self.tname}) if d.reserved_warehouse]))
|
||||||
|
|
||||||
for w in warehouses:
|
for w in warehouses:
|
||||||
validate_warehouse_user(w)
|
validate_warehouse_user(w)
|
||||||
|
validate_warehouse_company(w, self.doc.company)
|
||||||
|
|
||||||
def validate_with_previous_doc(self):
|
def validate_with_previous_doc(self):
|
||||||
super(DocType, self).validate_with_previous_doc(self.tname, {
|
super(DocType, self).validate_with_previous_doc(self.tname, {
|
||||||
|
|||||||
@ -68,23 +68,15 @@ class DocType(BuyingController):
|
|||||||
self.doc.status = "Draft"
|
self.doc.status = "Draft"
|
||||||
|
|
||||||
import utilities
|
import utilities
|
||||||
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped",
|
utilities.validate_status(self.doc.status, ["Draft", "Submitted", "Stopped", "Cancelled"])
|
||||||
"Cancelled"])
|
|
||||||
|
|
||||||
# restrict material request type
|
|
||||||
self.validate_value("material_request_type", "in", ["Purchase", "Transfer"])
|
self.validate_value("material_request_type", "in", ["Purchase", "Transfer"])
|
||||||
|
|
||||||
# Get Purchase Common Obj
|
|
||||||
pc_obj = get_obj(dt='Purchase Common')
|
pc_obj = get_obj(dt='Purchase Common')
|
||||||
|
|
||||||
|
|
||||||
# Validate for items
|
|
||||||
pc_obj.validate_for_items(self)
|
pc_obj.validate_for_items(self)
|
||||||
|
|
||||||
# Validate qty against SO
|
|
||||||
self.validate_qty_against_so()
|
self.validate_qty_against_so()
|
||||||
|
|
||||||
|
|
||||||
def update_bin(self, is_submit, is_stopped):
|
def update_bin(self, is_submit, is_stopped):
|
||||||
""" Update Quantity Requested for Purchase in Bin for Material Request of type 'Purchase'"""
|
""" Update Quantity Requested for Purchase in Bin for Material Request of type 'Purchase'"""
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ from webnotes import _, msgprint, ValidationError
|
|||||||
from webnotes.utils import cint, flt, getdate, cstr
|
from webnotes.utils import cint, flt, getdate, cstr
|
||||||
from webnotes.model.controller import DocListController
|
from webnotes.model.controller import DocListController
|
||||||
|
|
||||||
class InvalidWarehouseCompany(ValidationError): pass
|
|
||||||
class SerialNoNotRequiredError(ValidationError): pass
|
class SerialNoNotRequiredError(ValidationError): pass
|
||||||
class SerialNoRequiredError(ValidationError): pass
|
class SerialNoRequiredError(ValidationError): pass
|
||||||
class SerialNoQtyError(ValidationError): pass
|
class SerialNoQtyError(ValidationError): pass
|
||||||
@ -25,7 +24,7 @@ class DocType(DocListController):
|
|||||||
self.doclist = doclist
|
self.doclist = doclist
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
from stock.utils import validate_warehouse_user
|
from stock.utils import validate_warehouse_user, validate_warehouse_company
|
||||||
if not hasattr(webnotes, "new_stock_ledger_entries"):
|
if not hasattr(webnotes, "new_stock_ledger_entries"):
|
||||||
webnotes.new_stock_ledger_entries = []
|
webnotes.new_stock_ledger_entries = []
|
||||||
|
|
||||||
@ -33,7 +32,7 @@ class DocType(DocListController):
|
|||||||
self.validate_mandatory()
|
self.validate_mandatory()
|
||||||
self.validate_item()
|
self.validate_item()
|
||||||
validate_warehouse_user(self.doc.warehouse)
|
validate_warehouse_user(self.doc.warehouse)
|
||||||
self.validate_warehouse_company()
|
validate_warehouse_company(self.doc.warehouse, self.doc.company)
|
||||||
self.scrub_posting_time()
|
self.scrub_posting_time()
|
||||||
|
|
||||||
from accounts.utils import validate_fiscal_year
|
from accounts.utils import validate_fiscal_year
|
||||||
@ -64,13 +63,6 @@ class DocType(DocListController):
|
|||||||
|
|
||||||
sself.doc.fields.pop('batch_bal')
|
sself.doc.fields.pop('batch_bal')
|
||||||
|
|
||||||
def validate_warehouse_company(self):
|
|
||||||
warehouse_company = webnotes.conn.get_value("Warehouse", self.doc.warehouse, "company")
|
|
||||||
if warehouse_company and warehouse_company != self.doc.company:
|
|
||||||
webnotes.msgprint(_("Warehouse does not belong to company.") + " (" + \
|
|
||||||
self.doc.warehouse + ", " + self.doc.company +")",
|
|
||||||
raise_exception=InvalidWarehouseCompany)
|
|
||||||
|
|
||||||
def validate_mandatory(self):
|
def validate_mandatory(self):
|
||||||
mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company']
|
mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company']
|
||||||
for k in mandatory:
|
for k in mandatory:
|
||||||
|
|||||||
@ -9,6 +9,7 @@ from webnotes.defaults import get_global_default
|
|||||||
from webnotes.utils.email_lib import sendmail
|
from webnotes.utils.email_lib import sendmail
|
||||||
|
|
||||||
class UserNotAllowedForWarehouse(webnotes.ValidationError): pass
|
class UserNotAllowedForWarehouse(webnotes.ValidationError): pass
|
||||||
|
class InvalidWarehouseCompany(webnotes.ValidationError): pass
|
||||||
|
|
||||||
def get_stock_balance_on(warehouse, posting_date=None):
|
def get_stock_balance_on(warehouse, posting_date=None):
|
||||||
if not posting_date: posting_date = nowdate()
|
if not posting_date: posting_date = nowdate()
|
||||||
@ -217,6 +218,12 @@ def validate_warehouse_user(warehouse):
|
|||||||
webnotes.throw(_("Not allowed entry in Warehouse") \
|
webnotes.throw(_("Not allowed entry in Warehouse") \
|
||||||
+ ": " + warehouse, UserNotAllowedForWarehouse)
|
+ ": " + warehouse, UserNotAllowedForWarehouse)
|
||||||
|
|
||||||
|
def validate_warehouse_company(warehouse, company):
|
||||||
|
warehouse_company = webnotes.conn.get_value("Warehouse", warehouse, "company")
|
||||||
|
if warehouse_company and warehouse_company != company:
|
||||||
|
webnotes.msgprint(_("Warehouse does not belong to company.") + " (" + \
|
||||||
|
warehouse + ", " + company +")", raise_exception=InvalidWarehouseCompany)
|
||||||
|
|
||||||
def get_sales_bom_buying_amount(item_code, warehouse, voucher_type, voucher_no, voucher_detail_no,
|
def get_sales_bom_buying_amount(item_code, warehouse, voucher_type, voucher_no, voucher_detail_no,
|
||||||
stock_ledger_entries, item_sales_bom):
|
stock_ledger_entries, item_sales_bom):
|
||||||
# sales bom item
|
# sales bom item
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user