From d566a10f5534a931d5f482dd0f640f52ca7f23a3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 20 Dec 2012 18:33:04 +0530 Subject: [PATCH] validate warehouses for manufacture/repack only if bom is used --- stock/doctype/stock_entry/stock_entry.py | 44 +++++++++++++----------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/stock/doctype/stock_entry/stock_entry.py b/stock/doctype/stock_entry/stock_entry.py index 7f2a23e9c6..0252879489 100644 --- a/stock/doctype/stock_entry/stock_entry.py +++ b/stock/doctype/stock_entry/stock_entry.py @@ -71,7 +71,9 @@ class DocType(TransactionBase): source_mandatory = ["Material Issue", "Material Transfer", "Purchase Return"] target_mandatory = ["Material Receipt", "Material Transfer", "Sales Return"] - fg_qty = 0 + validate_for_manufacture_repack = any([d.bom_no for d in self.doclist.get( + {"parentfield": "mtn_details"})]) + for d in getlist(self.doclist, 'mtn_details'): if not d.s_warehouse and not d.t_warehouse: d.s_warehouse = self.doc.from_warehouse @@ -97,26 +99,28 @@ class DocType(TransactionBase): d.s_warehouse = None if self.doc.purpose == "Manufacture/Repack": - if d.bom_no: - d.s_warehouse = None + if validate_for_manufacture_repack: + if d.bom_no: + d.s_warehouse = None + + if not d.t_warehouse: + msgprint(_("Row # ") + "%s: " % cint(d.idx) + + _("Target Warehouse") + _(" is mandatory"), raise_exception=1) + + elif pro_obj and cstr(d.t_warehouse) != pro_obj.doc.fg_warehouse: + msgprint(_("Row # ") + "%s: " % cint(d.idx) + + _("Target Warehouse") + _(" should be same as that in ") + + _("Production Order"), raise_exception=1) - if not d.t_warehouse: - msgprint(_("Row # ") + "%s: " % cint(d.idx) - + _("Target Warehouse") + _(" is mandatory"), raise_exception=1) - - elif pro_obj and cstr(d.t_warehouse) != pro_obj.doc.fg_warehouse: - msgprint(_("Row # ") + "%s: " % cint(d.idx) - + _("Target Warehouse") + _(" should be same as that in ") - + _("Production Order"), raise_exception=1) - - else: - d.t_warehouse = None - if not d.s_warehouse: - msgprint(_("Row # ") + "%s: " % cint(d.idx) - + _("Source Warehouse") + _(" is mandatory"), raise_exception=1) - - if d.s_warehouse == d.t_warehouse: - msgprint(_("Source and Target Warehouse cannot be same"), raise_exception=1) + else: + d.t_warehouse = None + if not d.s_warehouse: + msgprint(_("Row # ") + "%s: " % cint(d.idx) + + _("Source Warehouse") + _(" is mandatory"), raise_exception=1) + + if cstr(d.s_warehouse) == cstr(d.t_warehouse): + msgprint(_("Source and Target Warehouse cannot be same"), + raise_exception=1)