[Production Order] [minor] Cleanup

This commit is contained in:
Rushabh Mehta 2013-08-08 14:16:39 +05:30
parent 43d7de8cdc
commit 2c968cecf5
6 changed files with 51 additions and 29 deletions

View File

@ -10,6 +10,8 @@ from webnotes import msgprint, _
sql = webnotes.conn.sql sql = webnotes.conn.sql
class OverProductionError(webnotes.ValidationError): pass
class DocType: class DocType:
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
@ -71,8 +73,7 @@ class DocType:
cstr(self.doc.production_item) + _(" against sales order") + ": " + cstr(self.doc.production_item) + _(" against sales order") + ": " +
cstr(self.doc.sales_order) + _(" will be ") + cstr(total_qty) + ", " + cstr(self.doc.sales_order) + _(" will be ") + cstr(total_qty) + ", " +
_("which is greater than sales order qty ") + "(" + cstr(so_qty) + ")" + _("which is greater than sales order qty ") + "(" + cstr(so_qty) + ")" +
_("Please reduce qty."), raise_exception=1) _("Please reduce qty."), raise_exception=OverProductionError)
def stop_unstop(self, status): def stop_unstop(self, status):
""" Called from client side on Stop/Unstop event""" """ Called from client side on Stop/Unstop event"""
@ -95,6 +96,8 @@ class DocType:
def on_submit(self): def on_submit(self):
if not self.doc.wip_warehouse:
webnotes.throw(_("WIP Warehouse required before Submit"))
webnotes.conn.set(self.doc,'status', 'Submitted') webnotes.conn.set(self.doc,'status', 'Submitted')
self.update_planned_qty(self.doc.qty) self.update_planned_qty(self.doc.qty)

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-01-10 16:34:16", "creation": "2013-01-10 16:34:16",
"docstatus": 0, "docstatus": 0,
"modified": "2013-07-25 16:38:37", "modified": "2013-08-08 12:21:25",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -152,7 +152,7 @@
"label": "For Warehouse", "label": "For Warehouse",
"options": "Warehouse", "options": "Warehouse",
"read_only": 0, "read_only": 0,
"reqd": 1 "reqd": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
@ -165,7 +165,7 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "Work-in-Progress Warehouse", "label": "Work-in-Progress Warehouse",
"options": "Warehouse", "options": "Warehouse",
"reqd": 1 "reqd": 0
}, },
{ {
"doctype": "DocField", "doctype": "DocField",

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-02-22 01:27:49", "creation": "2013-02-22 01:27:49",
"docstatus": 0, "docstatus": 0,
"modified": "2013-08-07 14:44:20", "modified": "2013-08-08 12:12:27",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -87,6 +87,15 @@
"reqd": 0, "reqd": 0,
"width": "100px" "width": "100px"
}, },
{
"description": "Reserved Warehouse in Sales Order / Finished Goods Warehouse",
"doctype": "DocField",
"fieldname": "warehouse",
"fieldtype": "Link",
"label": "Warehouse",
"options": "Warehouse",
"reqd": 0
},
{ {
"doctype": "DocField", "doctype": "DocField",
"fieldname": "stock_uom", "fieldname": "stock_uom",

View File

@ -7,7 +7,7 @@ from webnotes.utils import cstr, flt, cint, nowdate, add_days
from webnotes.model.doc import addchild, Document from webnotes.model.doc import addchild, Document
from webnotes.model.bean import getlist from webnotes.model.bean import getlist
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import msgprint from webnotes import msgprint, _
sql = webnotes.conn.sql sql = webnotes.conn.sql
@ -70,12 +70,12 @@ class DocType:
and so.docstatus = 1 and so.status != "Stopped" and so.docstatus = 1 and so.status != "Stopped"
and so.company = %s and so.company = %s
and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0) %s and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0) %s
and (exists (select * from `tabItem` item where item.name=so_item.item_code and (exists (select name from `tabItem` item where item.name=so_item.item_code
and (ifnull(item.is_pro_applicable, 'No') = 'Yes' and (ifnull(item.is_pro_applicable, 'No') = 'Yes'
or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s) or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s)
or exists (select * from `tabDelivery Note Packing Item` dnpi or exists (select name from `tabDelivery Note Packing Item` dnpi
where dnpi.parent = so.name and dnpi.parent_item = so_item.item_code where dnpi.parent = so.name and dnpi.parent_item = so_item.item_code
and exists (select * from `tabItem` item where item.name=dnpi.item_code and exists (select name from `tabItem` item where item.name=dnpi.item_code
and (ifnull(item.is_pro_applicable, 'No') = 'Yes' and (ifnull(item.is_pro_applicable, 'No') = 'Yes'
or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s))) or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s)))
""" % ('%s', so_filter, item_filter, item_filter), self.doc.company, as_dict=1) """ % ('%s', so_filter, item_filter, item_filter), self.doc.company, as_dict=1)
@ -107,7 +107,7 @@ class DocType:
if not so_list: if not so_list:
msgprint("Please enter sales order in the above table", raise_exception=1) msgprint("Please enter sales order in the above table", raise_exception=1)
items = sql("""select distinct parent, item_code, items = sql("""select distinct parent, item_code, reserved_warehouse,
(qty - ifnull(delivered_qty, 0)) as pending_qty (qty - ifnull(delivered_qty, 0)) as pending_qty
from `tabSales Order Item` so_item from `tabSales Order Item` so_item
where parent in (%s) and docstatus = 1 and ifnull(qty, 0) > ifnull(delivered_qty, 0) where parent in (%s) and docstatus = 1 and ifnull(qty, 0) > ifnull(delivered_qty, 0)
@ -116,7 +116,7 @@ class DocType:
or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \ or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \
(", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1) (", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1)
dnpi_items = sql("""select distinct dnpi.parent, dnpi.item_code, dnpi_items = sql("""select distinct dnpi.parent, dnpi.item_code, dnpi.warehouse as reserved_warhouse,
(((so_item.qty - ifnull(so_item.delivered_qty, 0)) * dnpi.qty) / so_item.qty) (((so_item.qty - ifnull(so_item.delivered_qty, 0)) * dnpi.qty) / so_item.qty)
as pending_qty as pending_qty
from `tabSales Order Item` so_item, `tabDelivery Note Packing Item` dnpi from `tabSales Order Item` so_item, `tabDelivery Note Packing Item` dnpi
@ -139,6 +139,7 @@ class DocType:
from tabItem where name=%s""", p['item_code']) from tabItem where name=%s""", p['item_code'])
pi = addchild(self.doc, 'pp_details', 'Production Plan Item', self.doclist) pi = addchild(self.doc, 'pp_details', 'Production Plan Item', self.doclist)
pi.sales_order = p['parent'] pi.sales_order = p['parent']
pi.warehouse = p['reserved_warehouse']
pi.item_code = p['item_code'] pi.item_code = p['item_code']
pi.description = item_details and item_details[0][0] or '' pi.description = item_details and item_details[0][0] or ''
pi.stock_uom = item_details and item_details[0][1] or '' pi.stock_uom = item_details and item_details[0][1] or ''
@ -190,34 +191,38 @@ class DocType:
item_dict, bom_dict = {}, {} item_dict, bom_dict = {}, {}
for d in self.doclist.get({"parentfield": "pp_details"}): for d in self.doclist.get({"parentfield": "pp_details"}):
bom_dict[d.bom_no] = bom_dict.get(d.bom_no, 0) + flt(d.planned_qty) bom_dict[d.bom_no] = bom_dict.get(d.bom_no, 0) + flt(d.planned_qty)
item_dict[(d.item_code, d.sales_order)] = { item_dict[(d.item_code, d.sales_order, d.warehouse)] = {
"qty" : flt(item_dict.get((d.item_code, d.sales_order), \ "production_item" : d.item_code,
{}).get("qty")) + flt(d.planned_qty), "sales_order" : d.sales_order,
"qty" : flt(item_dict.get((d.item_code, d.sales_order, d.warehouse),
{}).get("qty")) + flt(d.planned_qty),
"bom_no" : d.bom_no, "bom_no" : d.bom_no,
"description" : d.description, "description" : d.description,
"stock_uom" : d.stock_uom, "stock_uom" : d.stock_uom,
"company" : self.doc.company, "company" : self.doc.company,
"wip_warehouse" : "", "wip_warehouse" : "",
"fg_warehouse" : "", "fg_warehouse" : d.warehouse,
"status" : "Draft", "status" : "Draft",
} }
return bom_dict, item_dict return bom_dict, item_dict
def create_production_order(self, items): def create_production_order(self, items):
"""Create production order. Called from Production Planning Tool""" """Create production order. Called from Production Planning Tool"""
from manufacturing.doctype.production_order.production_order import OverProductionError
pro_list = [] pro_list = []
for item_so in items: for key in items:
pro_doc = Document('Production Order') pro = webnotes.new_bean("Production Order")
pro_doc.production_item = item_so[0] pro.doc.fields.update(items[key])
pro_doc.sales_order = item_so[1]
for key in items[item_so]:
pro_doc.fields[key] = items[item_so][key]
pro_doc.save(new = 1) webnotes.mute_messages = True
try:
get_obj("Production Order", pro_doc.name).validate_production_order_against_so() pro.insert()
pro_list.append(pro_doc.name) pro_list.append(pro.doc.name)
except OverProductionError, e:
pass
webnotes.mute_messages = False
return pro_list return pro_list

View File

@ -2,7 +2,7 @@
{ {
"creation": "2013-01-21 12:03:47", "creation": "2013-01-21 12:03:47",
"docstatus": 0, "docstatus": 0,
"modified": "2013-08-07 17:21:19", "modified": "2013-08-08 12:01:02",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "jai@webnotestech.com" "owner": "jai@webnotestech.com"
}, },

View File

@ -70,10 +70,15 @@ def run_manufacturing(current_date):
ppt.doc.purchase_request_for_warehouse = "Stores - WP" ppt.doc.purchase_request_for_warehouse = "Stores - WP"
ppt.run_method("get_open_sales_orders") ppt.run_method("get_open_sales_orders")
ppt.run_method("get_items_from_so") ppt.run_method("get_items_from_so")
ppt.run_method("get_items_from_so")
ppt.run_method("raise_production_order") ppt.run_method("raise_production_order")
ppt.run_method("raise_purchase_request") ppt.run_method("raise_purchase_request")
# submit production orders
for pro in webnotes.conn.get_values("Production Order", {"docstatus": 0}):
b = webnotes.bean("Production Order", pro[0])
b.doc.wip_warehouse = "Work in Progress - WP"
b.submit()
def make_quotation(current_date): def make_quotation(current_date):
b = webnotes.bean([{ b = webnotes.bean([{
"creation": current_date, "creation": current_date,