From c5570c6341a0548a37400f20a1ef10d744458264 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 25 Mar 2013 15:21:24 +0530 Subject: [PATCH] added warehouse company validation, if warehouse is added to company --- accounts/doctype/journal_voucher/journal_voucher.py | 5 +++++ setup/doctype/company/test_company.py | 6 ++++++ stock/doctype/stock_entry/test_stock_entry.py | 9 ++++++++- stock/doctype/stock_ledger_entry/stock_ledger_entry.py | 10 +++++++++- stock/doctype/warehouse/test_warehouse.py | 8 +++++++- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/accounts/doctype/journal_voucher/journal_voucher.py b/accounts/doctype/journal_voucher/journal_voucher.py index f4bd55cdbf..c58e9bae4c 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.py +++ b/accounts/doctype/journal_voucher/journal_voucher.py @@ -67,6 +67,11 @@ class DocType(AccountsController): remove_against_link_from_jv(self.doc.doctype, self.doc.name, "against_jv") self.make_gl_entries(cancel=1) + + def on_trash(self): + pass + #if self.doc.amended_from: + # webnotes.delete_doc("Journal Voucher", self.doc.amended_from) def validate_debit_credit(self): for d in getlist(self.doclist, 'entries'): diff --git a/setup/doctype/company/test_company.py b/setup/doctype/company/test_company.py index fe793ffce4..6a174ec80f 100644 --- a/setup/doctype/company/test_company.py +++ b/setup/doctype/company/test_company.py @@ -7,4 +7,10 @@ test_records = [ "abbr": "_TC", "default_currency": "INR", }], + [{ + "doctype": "Company", + "company_name": "_Test Company 1", + "abbr": "_TC1", + "default_currency": "USD", + }], ] \ No newline at end of file diff --git a/stock/doctype/stock_entry/test_stock_entry.py b/stock/doctype/stock_entry/test_stock_entry.py index ded71db26b..25018930dd 100644 --- a/stock/doctype/stock_entry/test_stock_entry.py +++ b/stock/doctype/stock_entry/test_stock_entry.py @@ -25,7 +25,14 @@ class TestStockEntry(unittest.TestCase): where item_code='_Test Item'""") self.assertTrue(mr_name) - + + def test_warehouse_company_validation(self): + from stock.doctype.stock_ledger_entry.stock_ledger_entry import InvalidWarehouseCompany + st1 = webnotes.bean(copy=test_records[0]) + st1.doclist[1].t_warehouse="_Test Warehouse 2" + st1.insert() + self.assertRaises(InvalidWarehouseCompany, st1.submit) + def test_material_receipt_gl_entry(self): webnotes.conn.sql("delete from `tabStock Ledger Entry`") webnotes.defaults.set_global_default("auto_inventory_accounting", 1) diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 3089a57081..5ca7dd5bed 100644 --- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -24,7 +24,7 @@ sql = webnotes.conn.sql msgprint = webnotes.msgprint from accounts.utils import get_fiscal_year - +class InvalidWarehouseCompany(Exception): pass class DocType: def __init__(self, doc, doclist=[]): @@ -35,6 +35,7 @@ class DocType: self.validate_mandatory() self.validate_item() self.validate_warehouse_user() + self.validate_warehouse_company() self.actual_amt_check() self.check_stock_frozen_date() self.scrub_posting_time() @@ -63,6 +64,13 @@ class DocType: webnotes.msgprint(_("User not allowed entry in the Warehouse") \ + ": " + webnotes.session.user + " / " + self.doc.warehouse, raise_exception = 1) + 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): mandatory = ['warehouse','posting_date','voucher_type','voucher_no','actual_qty','company'] for k in mandatory: diff --git a/stock/doctype/warehouse/test_warehouse.py b/stock/doctype/warehouse/test_warehouse.py index 99f29c1cc8..26501beab9 100644 --- a/stock/doctype/warehouse/test_warehouse.py +++ b/stock/doctype/warehouse/test_warehouse.py @@ -7,6 +7,12 @@ test_records = [ [{ "doctype": "Warehouse", "warehouse_name": "_Test Warehouse 1", - "warehouse_type": "_Test Warehouse Type" + "warehouse_type": "_Test Warehouse Type", + }], + [{ + "doctype": "Warehouse", + "warehouse_name": "_Test Warehouse 2", + "warehouse_type": "_Test Warehouse Type", + "company": "_Test Company 1" }] ]