Production plan cleanup and fixes

This commit is contained in:
Nabin Hait 2012-11-29 19:26:49 +05:30
parent 375ba8ef0a
commit 6aa80071e5
6 changed files with 517 additions and 720 deletions

View File

@ -192,7 +192,7 @@ class DocType:
# check total debit / credit # check total debit / credit
# Due to old wrong entries (total debit != total credit) some voucher could be cancelled # Due to old wrong entries (total debit != total credit) some voucher could be cancelled
if abs(self.td - self.tc) > 0.01 and not cancel: if abs(self.td - self.tc) > 0.004 and not cancel:
msgprint("Debit and Credit not equal for this voucher: Diff (Debit) is %s" % (self.td-self.tc)) msgprint("Debit and Credit not equal for this voucher: Diff (Debit) is %s" % (self.td-self.tc))
raise Exception raise Exception

View File

@ -1,159 +1,109 @@
# DocType, Production Plan Item
[ [
# These values are common in all dictionaries
{ {
'creation': '2012-03-27 14:36:03', "owner": "Administrator",
'docstatus': 0, "docstatus": 0,
'modified': '2012-03-27 14:36:03', "creation": "2012-07-03 13:30:04",
'modified_by': u'Administrator', "modified_by": "Administrator",
'owner': u'Administrator' "modified": "2012-11-29 19:02:38"
}, },
# These values are common for all DocType
{ {
'autoname': u'PPID/.#####', "istable": 1,
'colour': u'White:FFF', "autoname": "PPID/.#####",
'default_print_format': u'Standard', "name": "__common__",
'doctype': 'DocType', "default_print_format": "Standard",
'istable': 1, "doctype": "DocType",
'module': u'Production', "module": "Production"
'name': '__common__',
'section_style': u'Simple',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 27
}, },
# These values are common for all DocField
{ {
'doctype': u'DocField', "name": "__common__",
'name': '__common__', "parent": "Production Plan Item",
'parent': u'Production Plan Item', "doctype": "DocField",
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType' "parentfield": "fields"
}, },
# DocType, Production Plan Item
{ {
'doctype': 'DocType', "name": "Production Plan Item",
'name': u'Production Plan Item' "doctype": "DocType"
}, },
# DocField
{ {
'doctype': u'DocField', "permlevel": 0,
'fieldname': u'sales_order', "oldfieldtype": "Link",
'fieldtype': u'Data', "colour": "White:FFF",
'label': u'Sales Order', "doctype": "DocField",
'oldfieldname': u'source_docname', "label": "Item Code",
'oldfieldtype': u'Data', "oldfieldname": "item_code",
'permlevel': 1 "width": "150px",
"trigger": "Client",
"fieldname": "item_code",
"fieldtype": "Link",
"reqd": 1,
"options": "Item"
}, },
# DocField
{ {
'colour': u'White:FFF', "oldfieldtype": "Link",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'item_code', "label": "BOM No",
'fieldtype': u'Link', "oldfieldname": "bom_no",
'label': u'Item Code', "width": "100px",
'oldfieldname': u'item_code', "options": "BOM",
'oldfieldtype': u'Link', "fieldname": "bom_no",
'options': u'Item', "fieldtype": "Link",
'permlevel': 0, "reqd": 1,
'reqd': 1, "permlevel": 0
'trigger': u'Client',
'width': u'150px'
}, },
# DocField
{ {
'doctype': u'DocField', "default": "0.00",
'fieldname': u'bom_no', "oldfieldtype": "Currency",
'fieldtype': u'Link', "doctype": "DocField",
'label': u'BOM No', "label": "Planned Qty",
'oldfieldname': u'bom_no', "oldfieldname": "planned_qty",
'oldfieldtype': u'Link', "width": "100px",
'options': u'BOM', "fieldname": "planned_qty",
'permlevel': 0, "fieldtype": "Currency",
'reqd': 1, "reqd": 1,
'width': u'100px' "permlevel": 0
}, },
# DocField
{ {
'default': u'0.00', "oldfieldtype": "Data",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'so_pending_qty', "label": "Sales Order",
'fieldtype': u'Currency', "oldfieldname": "source_docname",
'label': u'SO Pending Qty', "options": "Sales Order",
'oldfieldname': u'prevdoc_reqd_qty', "fieldname": "sales_order",
'oldfieldtype': u'Currency', "fieldtype": "Link",
'permlevel': 1, "permlevel": 1
'reqd': 0,
'width': u'100px'
}, },
# DocField
{ {
'default': u'0.00', "default": "0.00",
'doctype': u'DocField', "oldfieldtype": "Currency",
'fieldname': u'planned_qty', "doctype": "DocField",
'fieldtype': u'Currency', "label": "SO Pending Qty",
'label': u'Planned Qty', "oldfieldname": "prevdoc_reqd_qty",
'oldfieldname': u'planned_qty', "width": "100px",
'oldfieldtype': u'Currency', "fieldname": "so_pending_qty",
'permlevel': 0, "fieldtype": "Currency",
'reqd': 1, "reqd": 0,
'width': u'100px' "permlevel": 1
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Data",
'fieldname': u'stock_uom', "doctype": "DocField",
'fieldtype': u'Data', "label": "UOM",
'label': u'UOM', "oldfieldname": "stock_uom",
'oldfieldname': u'stock_uom', "width": "80px",
'oldfieldtype': u'Data', "fieldname": "stock_uom",
'permlevel': 1, "fieldtype": "Data",
'reqd': 1, "reqd": 1,
'width': u'80px' "permlevel": 1
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Text",
'fieldname': u'description', "doctype": "DocField",
'fieldtype': u'Text', "label": "Description",
'label': u'Description', "oldfieldname": "description",
'oldfieldname': u'description', "width": "200px",
'oldfieldtype': u'Text', "fieldname": "description",
'permlevel': 1, "fieldtype": "Text",
'width': u'200px' "permlevel": 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'parent_packing_item',
'fieldtype': u'Link',
'label': u'Parent Packing Item',
'oldfieldname': u'parent_item',
'oldfieldtype': u'Link',
'options': u'Item',
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'is_pro_created',
'fieldtype': u'Check',
'label': u'Is PRO Created',
'oldfieldname': u'pro_created',
'oldfieldtype': u'Check',
'permlevel': 1
} }
] ]

View File

@ -1,124 +1,84 @@
# DocType, Production Plan Sales Order
[ [
# These values are common in all dictionaries
{ {
'creation': '2012-03-27 14:36:04', "owner": "Administrator",
'docstatus': 0, "docstatus": 0,
'modified': '2012-03-27 14:36:04', "creation": "2012-07-03 13:30:04",
'modified_by': u'Administrator', "modified_by": "Administrator",
'owner': u'Administrator' "modified": "2012-11-29 17:49:15"
}, },
# These values are common for all DocType
{ {
'autoname': u'PP/.SO/.#####', "istable": 1,
'colour': u'White:FFF', "autoname": "PP/.SO/.#####",
'default_print_format': u'Standard', "name": "__common__",
'doctype': 'DocType', "default_print_format": "Standard",
'istable': 1, "doctype": "DocType",
'module': u'Production', "module": "Production"
'name': '__common__',
'section_style': u'Simple',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 5
}, },
# These values are common for all DocField
{ {
'doctype': u'DocField', "name": "__common__",
'name': '__common__', "parent": "Production Plan Sales Order",
'parent': u'Production Plan Sales Order', "doctype": "DocField",
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType' "parentfield": "fields"
}, },
# These values are common for all DocPerm
{ {
'doctype': u'DocPerm', "name": "__common__",
'name': '__common__', "parent": "Production Plan Sales Order",
'parent': u'Production Plan Sales Order', "read": 1,
'parentfield': u'permissions', "doctype": "DocPerm",
'parenttype': u'DocType', "parenttype": "DocType",
'read': 1, "role": "System Manager",
'role': u'System Manager' "parentfield": "permissions"
}, },
# DocType, Production Plan Sales Order
{ {
'doctype': 'DocType', "name": "Production Plan Sales Order",
'name': u'Production Plan Sales Order' "doctype": "DocType"
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "oldfieldtype": "Data",
'permlevel': 0, "doctype": "DocField",
'write': 1 "label": "Sales Order",
"oldfieldname": "prevdoc_docname",
"width": "150px",
"options": "Sales Order",
"fieldname": "sales_order",
"fieldtype": "Link",
"permlevel": 0
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "oldfieldtype": "Date",
'permlevel': 1 "doctype": "DocField",
"label": "SO Date",
"oldfieldname": "document_date",
"width": "120px",
"fieldname": "sales_order_date",
"fieldtype": "Date",
"permlevel": 1
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'sales_order', "label": "Customer",
'fieldtype': u'Link', "width": "150px",
'label': u'Sales Order', "options": "Customer",
'oldfieldname': u'prevdoc_docname', "fieldname": "customer",
'oldfieldtype': u'Data', "fieldtype": "Link",
'options': u'Sales Order', "permlevel": 1
'permlevel': 0,
'width': u'150px'
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'sales_order_date', "label": "Grand Total",
'fieldtype': u'Date', "width": "120px",
'label': u'Sales Order Date', "fieldname": "grand_total",
'oldfieldname': u'document_date', "fieldtype": "Currency",
'oldfieldtype': u'Date', "permlevel": 1
'permlevel': 1,
'width': u'100px'
}, },
# DocField
{ {
'doctype': u'DocField', "write": 1,
'fieldname': u'customer', "doctype": "DocPerm",
'fieldtype': u'Link', "permlevel": 0
'label': u'Customer',
'options': u'Customer',
'permlevel': 1,
'width': u'150px'
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocPerm",
'fieldname': u'grand_total', "permlevel": 1
'fieldtype': u'Currency',
'label': u'Grand Total',
'permlevel': 1,
'width': u'100px'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'include_in_plan',
'fieldtype': u'Check',
'label': u'Include In Plan',
'oldfieldname': u'include_in_plan',
'oldfieldtype': u'Check',
'permlevel': 0,
'width': u'100px'
} }
] ]

View File

@ -14,11 +14,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.cscript.item_code = function(doc,cdt,cdn) { cur_frm.cscript.onload = function(doc, cdt, cdn) {
var d = locals[cdt][cdn]; doc.company = sys_defaults.company;
if (d.item_code) { refresh_field("company");
get_server_fields('get_item_details', d.item_code, 'pp_details', doc, cdt, cdn, 1);
}
} }
cur_frm.cscript.sales_order = function(doc,cdt,cdn) { cur_frm.cscript.sales_order = function(doc,cdt,cdn) {
@ -28,25 +26,35 @@ cur_frm.cscript.sales_order = function(doc,cdt,cdn) {
} }
} }
cur_frm.cscript.item_code = function(doc,cdt,cdn) {
var d = locals[cdt][cdn];
if (d.item_code) {
get_server_fields('get_item_details', d.item_code, 'pp_details', doc, cdt, cdn, 1);
}
}
cur_frm.cscript.download_raw_material = function(doc, cdt, cdn) { cur_frm.cscript.download_materials_required = function(doc, cdt, cdn) {
var callback = function(r, rt){ $c_obj(make_doclist(cdt, cdn), 'validate_data', '', function(r, rt) {
if (r.message) if (!r['exc'])
$c_obj_csv(make_doclist(cdt, cdn), 'download_raw_materials', '', ''); $c_obj_csv(make_doclist(cdt, cdn), 'download_raw_materials', '', '');
});
} }
$c_obj(make_doclist(cdt, cdn), 'validate_data', '', callback)
}
//-------------------------------------------------------------------------------
//
cur_frm.fields_dict['pp_details'].grid.get_field('item_code').get_query = function(doc) { cur_frm.fields_dict['pp_details'].grid.get_field('item_code').get_query = function(doc) {
return 'SELECT DISTINCT `tabItem`.`name`,`tabItem`.`item_name` FROM `tabItem` WHERE (IFNULL(`tabItem`.`end_of_life`,"") = "" OR `tabItem`.`end_of_life`="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) AND `tabItem`.is_pro_applicable = "Yes" AND tabItem.%(key)s like "%s" ORDER BY `tabItem`.`name` LIMIT 50'; return 'SELECT DISTINCT `tabItem`.`name`,`tabItem`.`item_name` \
FROM `tabItem` WHERE `tabItem`.is_pro_applicable = "Yes" \
AND (IFNULL(`tabItem`.`end_of_life`,"") = "" \
OR `tabItem`.`end_of_life`="0000-00-00" OR `tabItem`.`end_of_life` > NOW()) \
AND tabItem.%(key)s like "%s" \
ORDER BY `tabItem`.`name` LIMIT 50';
} }
cur_frm.fields_dict['pp_details'].grid.get_field('bom_no').get_query = function(doc) { cur_frm.fields_dict['pp_details'].grid.get_field('bom_no').get_query = function(doc) {
var d = locals[this.doctype][this.docname]; var d = locals[this.doctype][this.docname];
return 'SELECT DISTINCT `tabBOM`.`name` FROM `tabBOM` WHERE `tabBOM`.`item` = "' + d.item_code + '" AND `tabBOM`.`is_active` = "Yes" AND `tabBOM`.docstatus = 1 AND `tabBOM`.`name` like "%s" ORDER BY `tabBOM`.`name` LIMIT 50'; return 'SELECT DISTINCT `tabBOM`.`name` \
FROM `tabBOM` WHERE `tabBOM`.`item` = "' + d.item_code +
'" AND `tabBOM`.`is_active` = "Yes" AND `tabBOM`.docstatus = 1 \
AND `tabBOM`.`name` like "%s" ORDER BY `tabBOM`.`name` LIMIT 50';
} }
cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query; cur_frm.fields_dict.customer.get_query = erpnext.utils.customer_query;

View File

@ -33,22 +33,10 @@ class DocType:
self.doclist = doclist self.doclist = doclist
self.item_dict = {} self.item_dict = {}
def get_item_details(self, item_code):
""" Pull other item details from item master"""
item = sql("""select description, stock_uom, default_bom from `tabItem` where name = %s
and (ifnull(end_of_life,'')='' or end_of_life = '0000-00-00' or end_of_life > now())""", item_code, as_dict =1 )
ret = {
'description' : item and item[0]['description'],
'stock_uom' : item and item[0]['stock_uom'],
'bom_no' : item and item[0]['default_bom']
}
return ret
def get_so_details(self, so): def get_so_details(self, so):
"""Pull other details from so""" """Pull other details from so"""
so = sql("select transaction_date, customer, grand_total from `tabSales Order` where name = %s", so, as_dict = 1) so = sql("""select transaction_date, customer, grand_total
from `tabSales Order` where name = %s""", so, as_dict = 1)
ret = { ret = {
'sales_order_date': so and so[0]['transaction_date'] or '', 'sales_order_date': so and so[0]['transaction_date'] or '',
'customer' : so[0]['customer'] or '', 'customer' : so[0]['customer'] or '',
@ -56,118 +44,117 @@ class DocType:
} }
return ret return ret
def get_item_details(self, item_code):
""" Pull other item details from item master"""
item = sql("""select description, stock_uom, default_bom
from `tabItem` where name = %s""", item_code, as_dict =1)
ret = {
'description' : item and item[0]['description'],
'stock_uom' : item and item[0]['stock_uom'],
'bom_no' : item and item[0]['default_bom']
}
return ret
def clear_so_table(self): def clear_so_table(self):
""" Clears sales order table"""
self.doclist = self.doc.clear_table(self.doclist, 'pp_so_details') self.doclist = self.doc.clear_table(self.doclist, 'pp_so_details')
def clear_item_table(self): def clear_item_table(self):
""" Clears item table"""
self.doclist = self.doc.clear_table(self.doclist, 'pp_details') self.doclist = self.doc.clear_table(self.doclist, 'pp_details')
def get_open_sales_orders(self):
""" Pull sales orders which are pending to deliver based on criteria selected"""
cond = self.get_filter_condition()
open_so = sql("""
select
distinct t1.name, t1.transaction_date, t1.customer, t1.grand_total
from
`tabSales Order` t1, `tabSales Order Item` t2, `tabDelivery Note Packing Item` t3, tabItem t4
where
t1.name = t2.parent and t1.name = t3.parent and t3.parenttype = 'Sales Order' and t1.docstatus = 1 and t2.item_code = t3.parent_item
and t4.name = t3.item_code and t1.status != 'Stopped' and t1.company = '%s' and ifnull(t2.qty, 0) > ifnull(t2.delivered_qty, 0)
and (ifnull(t4.is_pro_applicable, 'No') = 'Yes' or ifnull(t4.is_sub_contracted_item, 'No') = 'Yes') %s
order by t1.name desc
"""% (self.doc.company, cond), as_dict = 1)
self.add_so_in_table(open_so)
def validate_company(self): def validate_company(self):
if not self.doc.company: if not self.doc.company:
msgprint("Please enter Company", raise_exception=1) msgprint("Please enter Company", raise_exception=1)
def get_open_sales_orders(self):
""" Pull sales orders which are pending to deliver based on criteria selected"""
def get_filter_condition(self): so_filter = item_filter = ""
self.validate_company()
cond = ''
if self.doc.from_date: if self.doc.from_date:
cond += ' and t1.transaction_date >= "' + self.doc.from_date + '"' so_filter += ' and so.transaction_date >= "' + self.doc.from_date + '"'
if self.doc.to_date: if self.doc.to_date:
cond += ' and t1.transaction_date <= "' + self.doc.to_date + '"' so_filter += ' and so.transaction_date <= "' + self.doc.to_date + '"'
if self.doc.customer: if self.doc.customer:
cond += ' and t1.customer = "' + self.doc.customer + '"' so_filter += ' and so.customer = "' + self.doc.customer + '"'
if self.doc.fg_item: if self.doc.fg_item:
cond += ' and t3.item_code = "' + self.doc.fg_item + '"' item_filter += ' and item.name = "' + self.doc.fg_item + '"'
return cond
open_so = sql("""
select distinct so.name, so.transaction_date, so.customer, so.grand_total
from `tabSales Order` so, `tabSales Order Item` so_item
where so_item.parent = so.name
and so.docstatus = 1 and so.status != "Stopped"
and so.company = 'Web Notes Technologies Pvt Ltd'
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 (ifnull(item.is_pro_applicable, 'No') = 'Yes'
or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s)
or exists (select * from `tabDelivery Note Packing Item` dnpi
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 (ifnull(item.is_pro_applicable, 'No') = 'Yes'
or ifnull(item.is_sub_contracted_item, 'No') = 'Yes') %s)))
""" % (so_filter, item_filter, item_filter), as_dict=1)
self.add_so_in_table(open_so)
def add_so_in_table(self, open_so): def add_so_in_table(self, open_so):
""" Add sales orders in the table""" """ Add sales orders in the table"""
so_list = [] so_list = [d.sales_order for d in getlist(self.doclist, 'pp_so_details')]
for d in getlist(self.doclist, 'pp_so_details'):
so_list.append(d.sales_order)
for r in open_so: for r in open_so:
if cstr(r['name']) not in so_list: if cstr(r['name']) not in so_list:
pp_so = addchild(self.doc, 'pp_so_details', 'Production Plan Sales Order', 1, self.doclist) pp_so = addchild(self.doc, 'pp_so_details',
'Production Plan Sales Order', 1, self.doclist)
pp_so.sales_order = r['name'] pp_so.sales_order = r['name']
pp_so.sales_order_date = cstr(r['transaction_date']) pp_so.sales_order_date = cstr(r['transaction_date'])
pp_so.customer = cstr(r['customer']) pp_so.customer = cstr(r['customer'])
pp_so.grand_total = flt(r['grand_total']) pp_so.grand_total = flt(r['grand_total'])
def get_items_from_so(self): def get_items_from_so(self):
""" Pull items from Sales Order, only proction item """ Pull items from Sales Order, only proction item
and subcontracted item will be pulled from Packing item and subcontracted item will be pulled from Packing item
and add items in the table and add items in the table
""" """
so = self.get_included_so() items = self.get_items()
items = self.get_packing_items(so)
self.add_items(items) self.add_items(items)
def get_items(self):
so_list = filter(None, [d.sales_order for d in getlist(self.doclist, 'pp_so_details')])
if not so_list:
msgprint("Please enter sales order in the above table", raise_exception=1)
def get_included_so(self): items = sql("""select distinct parent, item_code,
so = "'" + "','".join([cstr(d.sales_order) for d in getlist(self.doclist, 'pp_so_details') if d.include_in_plan]) + "'" (qty - ifnull(delivered_qty, 0)) as pending_qty
return so from `tabSales Order Item` so_item
where parent in (%s) and docstatus = 1 and ifnull(qty, 0) > ifnull(delivered_qty, 0)
and exists (select * from `tabItem` item where item.name=so_item.item_code
and (ifnull(item.is_pro_applicable, 'No') = 'Yes'
or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \
(", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1)
dnpi_items = sql("""select distinct dnpi.parent, dnpi.item_code,
(((so_item.qty - ifnull(so_item.delivered_qty, 0)) * dnpi.qty) / so_item.qty)
as pending_qty
from `tabSales Order Item` so_item, `tabDelivery Note Packing Item` dnpi
where so_item.parent = dnpi.parent and so_item.docstatus = 1
and dnpi.parent_item = so_item.item_code
and so_item.parent in (%s) and ifnull(so_item.qty, 0) > ifnull(so_item.delivered_qty, 0)
and exists (select * from `tabItem` item where item.name=dnpi.item_code
and (ifnull(item.is_pro_applicable, 'No') = 'Yes'
or ifnull(item.is_sub_contracted_item, 'No') = 'Yes'))""" % \
(", ".join(["%s"] * len(so_list))), tuple(so_list), as_dict=1)
return items + dnpi_items
def add_items(self, items):
self.clear_item_table()
def get_packing_items(self, so): for p in items:
packing_items = sql(""" item_details = sql("""select description, stock_uom, default_bom
select from tabItem where name=%s""", p['item_code'])
t0.name, t2.parent_item, t2.item_code,
(t1.qty - ifnull(t1.delivered_qty,0)) * (ifnull(t2.qty,0) / ifnull(t1.qty,1)) as 'pending_qty'
from
`tabSales Order` t0, `tabSales Order Item` t1, `tabDelivery Note Packing Item` t2, `tabItem` t3
where
t0.name = t1.parent and t0.name = t2.parent and t1.name = t2.parent_detail_docname
and t0.name in (%s) and t0.docstatus = 1 and t1.qty > ifnull(t1.delivered_qty,0) and t3.name = t2.item_code
and (ifnull(t3.is_pro_applicable, 'No') = 'Yes' or ifnull(t3.is_sub_contracted_item, 'No') = 'Yes')
""" % so, as_dict=1)
return packing_items
def add_items(self, packing_items):
for d in getlist(self.doclist, 'pp_details'):
if d.sales_order:
d.parent = ''
for p in packing_items:
item_details = sql("select description, stock_uom, default_bom from tabItem where name=%s", p['item_code'])
pi = addchild(self.doc, 'pp_details', 'Production Plan Item', 1, self.doclist) pi = addchild(self.doc, 'pp_details', 'Production Plan Item', 1, self.doclist)
pi.sales_order = p['name'] pi.sales_order = p['parent']
pi.parent_packing_item = p['parent_item']
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 ''
@ -176,16 +163,12 @@ class DocType:
pi.planned_qty = flt(p['pending_qty']) pi.planned_qty = flt(p['pending_qty'])
def validate_data(self): def validate_data(self):
for d in getlist(self.doclist, 'pp_details'): for d in getlist(self.doclist, 'pp_details'):
if not d.pro_created:
self.validate_bom_no(d) self.validate_bom_no(d)
if not flt(d.planned_qty): if not flt(d.planned_qty):
msgprint("Please Enter Planned Qty for item: %s at row no: %s"% (d.item_code, d.idx), raise_exception=1) msgprint("Please Enter Planned Qty for item: %s at row no: %s" %
return 'validated' (d.item_code, d.idx), raise_exception=1)
def validate_bom_no(self, d): def validate_bom_no(self, d):
@ -206,13 +189,10 @@ class DocType:
self.get_raw_materials(bom_dict) self.get_raw_materials(bom_dict)
return self.get_csv() return self.get_csv()
def get_raw_materials(self, bom_dict): def get_raw_materials(self, bom_dict):
""" Get raw materials considering sub-assembly items """ """ Get raw materials considering sub-assembly items """
for bom in bom_dict: for bom in bom_dict:
if self.doc.consider_sa_items == 'Yes': if self.doc.use_multi_level_bom == 'No':
# Get all raw materials considering SA items as raw materials, # Get all raw materials considering SA items as raw materials,
# so no childs of SA items # so no childs of SA items
fl_bom_items = sql(""" fl_bom_items = sql("""
@ -260,8 +240,6 @@ class DocType:
return item_list return item_list
def raise_production_order(self): def raise_production_order(self):
"""It will raise production order (Draft) for all distinct FG items""" """It will raise production order (Draft) for all distinct FG items"""
self.validate_company() self.validate_company()
@ -274,8 +252,7 @@ class DocType:
d.is_pro_created = 1 d.is_pro_created = 1
msgprint("Following Production Order has been generated:\n" + '\n'.join(pro)) msgprint("Following Production Order has been generated:\n" + '\n'.join(pro))
else : else :
msgprint("No Production Order is generated.") msgprint("No Production Order generated.")
def get_distinct_bom(self, action): def get_distinct_bom(self, action):
@ -298,7 +275,7 @@ class DocType:
'bom_no' : item_dict[d][1], 'bom_no' : item_dict[d][1],
'description' : item_dict[d][2], 'description' : item_dict[d][2],
'stock_uom' : item_dict[d][3], 'stock_uom' : item_dict[d][3],
'consider_sa_items' : self.doc.consider_sa_items 'consider_sa_items' : self.doc.use_multi_level_bom == "Yes" and "No" or "Yes"
}) })
return action == 'download_rm' and bom_dict or pp_items return action == 'download_rm' and bom_dict or pp_items

View File

@ -1,318 +1,220 @@
# DocType, Production Planning Tool
[ [
# These values are common in all dictionaries
{ {
'creation': '2012-03-27 14:36:05', "owner": "jai@webnotestech.com",
'docstatus': 0, "docstatus": 0,
'modified': '2012-03-27 14:36:05', "creation": "2012-07-03 13:30:03",
'modified_by': u'Administrator', "modified_by": "Administrator",
'owner': u'jai@webnotestech.com' "modified": "2012-11-29 17:52:20"
}, },
# These values are common for all DocType
{ {
'_last_update': u'1326188323', "read_only": 1,
'colour': u'White:FFF', "issingle": 1,
'default_print_format': u'Standard', "in_create": 1,
'doctype': 'DocType', "default_print_format": "Standard",
'in_create': 1, "doctype": "DocType",
'issingle': 1, "module": "Production",
'module': u'Production', "name": "__common__"
'name': '__common__',
'read_only': 1,
'section_style': u'Tabbed',
'server_code_error': u' ',
'show_in_menu': 1,
'version': 106
}, },
# These values are common for all DocField
{ {
'doctype': u'DocField', "name": "__common__",
'name': '__common__', "parent": "Production Planning Tool",
'parent': u'Production Planning Tool', "doctype": "DocField",
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType', "permlevel": 0,
'permlevel': 0 "parentfield": "fields"
}, },
# These values are common for all DocPerm
{ {
'create': 1, "name": "__common__",
'doctype': u'DocPerm', "parent": "Production Planning Tool",
'name': '__common__', "read": 1,
'parent': u'Production Planning Tool', "create": 1,
'parentfield': u'permissions', "doctype": "DocPerm",
'parenttype': u'DocType', "write": 1,
'permlevel': 0, "parenttype": "DocType",
'read': 1, "permlevel": 0,
'write': 1 "parentfield": "permissions"
}, },
# DocType, Production Planning Tool
{ {
'doctype': 'DocType', "name": "Production Planning Tool",
'name': u'Production Planning Tool' "doctype": "DocType"
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "description": "Select Sales Orders from which you want to create Production Orders.",
'role': u'System Manager' "colour": "White:FFF",
"doctype": "DocField",
"label": "Select Sales Orders",
"fieldname": "select_sales_orders",
"fieldtype": "Section Break"
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "doctype": "DocField",
'role': u'Production User' "width": "50%",
"fieldname": "column_break0",
"fieldtype": "Column Break"
}, },
# DocPerm
{ {
'doctype': u'DocPerm', "doctype": "DocField",
'role': u'Production Manager' "label": "Filter based on item",
"fieldname": "fg_item",
"fieldtype": "Link",
"options": "Item"
}, },
# DocField
{ {
'colour': u'White:FFF', "doctype": "DocField",
'doctype': u'DocField', "label": "Filter based on customer",
'fieldname': u'select_sales_orders', "fieldname": "customer",
'fieldtype': u'Section Break', "fieldtype": "Link",
'label': u'Select Sales Orders' "options": "Customer"
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'column_break0', "label": "Company",
'fieldtype': u'Column Break', "reqd": 1,
'width': u'50%' "fieldname": "company",
"fieldtype": "Link",
"options": "Company"
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'from_date', "width": "50%",
'fieldtype': u'Date', "fieldname": "column_break1",
'label': u'From Date' "fieldtype": "Column Break"
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'to_date', "label": "From Date",
'fieldtype': u'Date', "fieldname": "from_date",
'label': u'To Date' "fieldtype": "Date"
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'fg_item', "label": "To Date",
'fieldtype': u'Link', "fieldname": "to_date",
'label': u'FG Item', "fieldtype": "Date"
'options': u'Item'
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'column_break1', "fieldname": "section_break1",
'fieldtype': u'Column Break', "fieldtype": "Section Break",
'width': u'50%' "options": "Simple"
}, },
# DocField
{ {
'doctype': u'DocField', "description": "Pull sales orders (pending to deliver) based on the above criteria",
'fieldname': u'customer', "colour": "White:FFF",
'fieldtype': u'Link', "doctype": "DocField",
'label': u'Customer', "label": "Get Sales Orders",
'options': u'Customer' "fieldname": "get_sales_orders",
"fieldtype": "Button",
"options": "get_open_sales_orders"
}, },
# DocField
{ {
'doctype': u'DocField', "colour": "White:FFF",
'fieldname': u'company', "doctype": "DocField",
'fieldtype': u'Link', "label": "Production Plan Sales Orders",
'label': u'Company', "fieldname": "pp_so_details",
'options': u'Company', "fieldtype": "Table",
'reqd': 1 "options": "Production Plan Sales Order"
}, },
# DocField
{ {
'doctype': u'DocField', "colour": "White:FFF",
'fieldname': u'section_break0', "doctype": "DocField",
'fieldtype': u'Section Break', "label": "Clear Table",
'options': u'Simple' "trigger": "Client",
"fieldname": "clear_so_table",
"fieldtype": "Button",
"options": "clear_so_table"
}, },
# DocField
{ {
'doctype': u'DocField', "description": "Enter items and planned qty for which you want to raise production orders or download raw materials for analysis.",
'fieldname': u'column_break2', "colour": "White:FFF",
'fieldtype': u'Column Break', "doctype": "DocField",
'width': u'50%' "label": "Create Production Orders",
"fieldname": "create_production_orders",
"fieldtype": "Section Break"
}, },
# DocField
{ {
'doctype': u'DocField', "description": "Pull items from Sales Order mentioned in the above table.",
'fieldname': u'get_sales_orders', "colour": "White:FFF",
'fieldtype': u'Button', "doctype": "DocField",
'label': u'Get Sales Orders', "label": "Get Items",
'options': u'get_open_sales_orders' "fieldname": "get_items_from_so",
"fieldtype": "Button",
"options": "get_items_from_so"
}, },
# DocField
{ {
'doctype': u'DocField', "colour": "White:FFF",
'fieldname': u'column_break3', "doctype": "DocField",
'fieldtype': u'Column Break', "label": "Production Plan Items",
'width': u'50%' "fieldname": "pp_details",
"fieldtype": "Table",
"options": "Production Plan Item"
}, },
# DocField
{ {
'colour': u'White:FFF', "colour": "White:FFF",
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'clear_so_table', "label": "Clear Table",
'fieldtype': u'Button', "trigger": "Client",
'label': u'Clear SO Table', "fieldname": "clear_item_table",
'options': u'clear_so_table', "fieldtype": "Button",
'trigger': u'Client' "options": "clear_item_table"
}, },
# DocField
{ {
'doctype': u'DocField', "description": "If selected as \"No\", all sub-assembly items will be treated as a raw material. Otherwise, BOM for sub-assembly items will be considered for raw materials.",
'fieldname': u'section_break1', "default": "Yes",
'fieldtype': u'Section Break', "colour": "White:FFF",
'options': u'Simple' "doctype": "DocField",
"label": "Use multi-level BOM",
"reqd": 1,
"fieldname": "use_multi_level_bom",
"fieldtype": "Select",
"options": "No\nYes"
}, },
# DocField
{ {
'description': u'Select Sales Orders from which you want to create Production Orders. You can get sales orders based on above criteria.', "doctype": "DocField",
'doctype': u'DocField', "fieldname": "section_break3",
'fieldname': u'pp_so_details', "fieldtype": "Section Break",
'fieldtype': u'Table', "options": "Simple"
'label': u'Production Plan Sales Orders',
'options': u'Production Plan Sales Order'
}, },
# DocField
{ {
'colour': u'White:FFF', "doctype": "DocField",
'doctype': u'DocField', "width": "50%",
'fieldname': u'items', "fieldname": "column_break5",
'fieldtype': u'Section Break', "fieldtype": "Column Break"
'label': u'Items'
}, },
# DocField
{ {
'doctype': u'DocField', "description": "Separate production order will be created for each finished good item.",
'fieldname': u'get_items_from_so', "colour": "White:FFF",
'fieldtype': u'Button', "doctype": "DocField",
'label': u'Get Items from SO', "label": "Raise Production Order",
'options': u'get_items_from_so' "fieldname": "raise_production_order",
"fieldtype": "Button",
"options": "raise_production_order"
}, },
# DocField
{ {
'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'column_break4', "width": "50%",
'fieldtype': u'Column Break', "fieldname": "column_break6",
'width': u'50%' "fieldtype": "Column Break"
}, },
# DocField
{ {
'colour': u'White:FFF', "description": "Download a report containing all raw materials with their latest inventory status",
'doctype': u'DocField', "colour": "White:FFF",
'fieldname': u'clear_item_table', "doctype": "DocField",
'fieldtype': u'Button', "label": "Download Materials Required",
'label': u'Clear Item Table', "trigger": "Client",
'options': u'clear_item_table', "fieldname": "download_materials_required",
'trigger': u'Client' "fieldtype": "Button"
}, },
# DocField
{ {
'doctype': u'DocField', "role": "System Manager",
'fieldname': u'section_break2', "doctype": "DocPerm"
'fieldtype': u'Section Break',
'options': u'Simple'
}, },
# DocField
{ {
'description': u'Enter items and planned qty for which you want to raise production orders or download raw materials for analysis. You can pull items (which are pending to deliver) from SO as well by adding SO in plan.', "role": "Production User",
'doctype': u'DocField', "doctype": "DocPerm"
'fieldname': u'pp_details',
'fieldtype': u'Table',
'label': u'Production Plan Items',
'options': u'Production Plan Item'
}, },
# DocField
{ {
'colour': u'White:FFF', "role": "Production Manager",
'default': u'No', "doctype": "DocPerm"
'description': u'Select "Yes" if stock is maintained and tracked for sub assembly items.',
'doctype': u'DocField',
'fieldname': u'consider_sa_items',
'fieldtype': u'Select',
'label': u'Consider Sub Assemblies as Raw Material',
'options': u'No\nYes',
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'section_break3',
'fieldtype': u'Section Break',
'options': u'Simple'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'column_break5',
'fieldtype': u'Column Break',
'width': u'50%'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'raise_production_order',
'fieldtype': u'Button',
'label': u'Raise Production Order',
'options': u'raise_production_order'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'column_break6',
'fieldtype': u'Column Break',
'width': u'50%'
},
# DocField
{
'colour': u'White:FFF',
'doctype': u'DocField',
'fieldname': u'download_raw_material',
'fieldtype': u'Button',
'label': u'Download Raw Material',
'trigger': u'Client'
} }
] ]