mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-18 02:55:20 +00:00
This commit is contained in:
@@ -4,17 +4,15 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import cint, cstr, flt, now, nowdate
|
||||
from frappe.model.doc import addchild
|
||||
from frappe.model.bean import getlist
|
||||
from frappe.model.code import get_obj
|
||||
from frappe import msgprint, _
|
||||
|
||||
|
||||
|
||||
class DocType:
|
||||
def __init__(self, doc, doclist=[]):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
from frappe.model.document import Document
|
||||
|
||||
class Bom(Document):
|
||||
|
||||
def autoname(self):
|
||||
last_name = frappe.db.sql("""select max(name) from `tabBOM`
|
||||
@@ -75,7 +73,7 @@ class DocType:
|
||||
msgprint("Item %s does not exist in system" % item[0]['item_code'], raise_exception = 1)
|
||||
|
||||
def set_bom_material_details(self):
|
||||
for item in self.doclist.get({"parentfield": "bom_materials"}):
|
||||
for item in self.get("bom_materials"):
|
||||
ret = self.get_bom_material_detail({"item_code": item.item_code, "bom_no": item.bom_no,
|
||||
"qty": item.qty})
|
||||
|
||||
@@ -128,7 +126,7 @@ class DocType:
|
||||
return rate
|
||||
|
||||
def update_cost(self):
|
||||
for d in self.doclist.get({"parentfield": "bom_materials"}):
|
||||
for d in self.get("bom_materials"):
|
||||
d.rate = self.get_bom_material_detail({
|
||||
'item_code': d.item_code,
|
||||
'bom_no': d.bom_no,
|
||||
@@ -188,8 +186,8 @@ class DocType:
|
||||
|
||||
def clear_operations(self):
|
||||
if not self.doc.with_operations:
|
||||
self.doclist = self.doc.clear_table(self.doclist, 'bom_operations')
|
||||
for d in self.doclist.get({"parentfield": "bom_materials"}):
|
||||
self.set('bom_operations', [])
|
||||
for d in self.get("bom_materials"):
|
||||
d.operation_no = None
|
||||
|
||||
def validate_main_item(self):
|
||||
@@ -210,7 +208,7 @@ class DocType:
|
||||
def validate_operations(self):
|
||||
""" Check duplicate operation no"""
|
||||
self.op = []
|
||||
for d in getlist(self.doclist, 'bom_operations'):
|
||||
for d in self.get('bom_operations'):
|
||||
if cstr(d.operation_no) in self.op:
|
||||
msgprint("Operation no: %s is repeated in Operations Table" %
|
||||
d.operation_no, raise_exception=1)
|
||||
@@ -221,7 +219,7 @@ class DocType:
|
||||
def validate_materials(self):
|
||||
""" Validate raw material entries """
|
||||
check_list = []
|
||||
for m in getlist(self.doclist, 'bom_materials'):
|
||||
for m in self.get('bom_materials'):
|
||||
# check if operation no not in op table
|
||||
if self.doc.with_operations and cstr(m.operation_no) not in self.op:
|
||||
msgprint("""Operation no: %s against item: %s at row no: %s \
|
||||
@@ -315,7 +313,7 @@ class DocType:
|
||||
def calculate_op_cost(self):
|
||||
"""Update workstation rate and calculates totals"""
|
||||
total_op_cost = 0
|
||||
for d in getlist(self.doclist, 'bom_operations'):
|
||||
for d in self.get('bom_operations'):
|
||||
if d.workstation and not d.hour_rate:
|
||||
d.hour_rate = frappe.db.get_value("Workstation", d.workstation, "hour_rate")
|
||||
if d.hour_rate and d.time_in_mins:
|
||||
@@ -326,7 +324,7 @@ class DocType:
|
||||
def calculate_rm_cost(self):
|
||||
"""Fetch RM rate as per today's valuation rate and calculate totals"""
|
||||
total_rm_cost = 0
|
||||
for d in getlist(self.doclist, 'bom_materials'):
|
||||
for d in self.get('bom_materials'):
|
||||
if d.bom_no:
|
||||
d.rate = self.get_bom_unitcost(d.bom_no)
|
||||
d.amount = flt(d.rate) * flt(d.qty)
|
||||
@@ -343,7 +341,7 @@ class DocType:
|
||||
def get_exploded_items(self):
|
||||
""" Get all raw materials including items from child bom"""
|
||||
self.cur_exploded_items = {}
|
||||
for d in getlist(self.doclist, 'bom_materials'):
|
||||
for d in self.get('bom_materials'):
|
||||
if d.bom_no:
|
||||
self.get_child_exploded_items(d.bom_no, d.qty)
|
||||
else:
|
||||
@@ -379,9 +377,9 @@ class DocType:
|
||||
|
||||
def add_exploded_items(self):
|
||||
"Add items to Flat BOM table"
|
||||
self.doclist = self.doc.clear_table(self.doclist, 'flat_bom_details', 1)
|
||||
self.set('flat_bom_details', [])
|
||||
for d in self.cur_exploded_items:
|
||||
ch = addchild(self.doc, 'flat_bom_details', 'BOM Explosion Item', self.doclist)
|
||||
ch = self.doc.append('flat_bom_details', {})
|
||||
for i in self.cur_exploded_items[d].keys():
|
||||
ch.fields[i] = self.cur_exploded_items[d][i]
|
||||
ch.amount = flt(ch.qty) * flt(ch.rate)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
from frappe.model.document import Document
|
||||
|
||||
class BomExplosionItem(Document):
|
||||
pass
|
||||
@@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
from frappe.model.document import Document
|
||||
|
||||
class BomItem(Document):
|
||||
pass
|
||||
@@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
from frappe.model.document import Document
|
||||
|
||||
class BomOperation(Document):
|
||||
pass
|
||||
@@ -7,7 +7,9 @@ from frappe.utils import cstr, flt
|
||||
from frappe.model.code import get_obj
|
||||
from frappe import msgprint, _
|
||||
|
||||
class DocType:
|
||||
from frappe.model.document import Document
|
||||
|
||||
class BomReplaceTool(Document):
|
||||
def __init__( self, doc, doclist=[]):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
|
||||
@@ -10,10 +10,9 @@ from frappe import msgprint, _
|
||||
|
||||
class OverProductionError(frappe.ValidationError): pass
|
||||
|
||||
class DocType:
|
||||
def __init__(self, doc, doclist=[]):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ProductionOrder(Document):
|
||||
|
||||
def validate(self):
|
||||
if self.doc.docstatus == 0:
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ProductionPlanItem(Document):
|
||||
pass
|
||||
@@ -4,6 +4,7 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
class DocType:
|
||||
def __init__(self, d, dl):
|
||||
self.doc, self.doclist = d, dl
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ProductionPlanSalesOrder(Document):
|
||||
pass
|
||||
@@ -4,15 +4,13 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import cstr, flt, cint, nowdate, add_days
|
||||
from frappe.model.doc import addchild, Document
|
||||
from frappe.model.bean import getlist
|
||||
from frappe.model.code import get_obj
|
||||
from frappe import msgprint, _
|
||||
|
||||
class DocType:
|
||||
def __init__(self, doc, doclist=[]):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ProductionPlanningTool(Document):
|
||||
self.item_dict = {}
|
||||
|
||||
def get_so_details(self, so):
|
||||
@@ -39,10 +37,10 @@ class DocType:
|
||||
return ret
|
||||
|
||||
def clear_so_table(self):
|
||||
self.doclist = self.doc.clear_table(self.doclist, 'pp_so_details')
|
||||
self.set('pp_so_details', [])
|
||||
|
||||
def clear_item_table(self):
|
||||
self.doclist = self.doc.clear_table(self.doclist, 'pp_details')
|
||||
self.set('pp_details', [])
|
||||
|
||||
def validate_company(self):
|
||||
if not self.doc.company:
|
||||
@@ -84,11 +82,10 @@ class DocType:
|
||||
""" Add sales orders in the table"""
|
||||
self.clear_so_table()
|
||||
|
||||
so_list = [d.sales_order for d in getlist(self.doclist, 'pp_so_details')]
|
||||
so_list = [d.sales_order for d in self.get('pp_so_details')]
|
||||
for r in open_so:
|
||||
if cstr(r['name']) not in so_list:
|
||||
pp_so = addchild(self.doc, 'pp_so_details',
|
||||
'Production Plan Sales Order', self.doclist)
|
||||
pp_so = self.doc.append('pp_so_details', {})
|
||||
pp_so.sales_order = r['name']
|
||||
pp_so.sales_order_date = cstr(r['transaction_date'])
|
||||
pp_so.customer = cstr(r['customer'])
|
||||
@@ -103,7 +100,7 @@ class DocType:
|
||||
self.add_items(items)
|
||||
|
||||
def get_items(self):
|
||||
so_list = filter(None, [d.sales_order for d in getlist(self.doclist, 'pp_so_details')])
|
||||
so_list = filter(None, [d.sales_order for d in self.get('pp_so_details')])
|
||||
if not so_list:
|
||||
msgprint(_("Please enter sales order in the above table"))
|
||||
return []
|
||||
@@ -138,7 +135,7 @@ class DocType:
|
||||
for p in items:
|
||||
item_details = frappe.db.sql("""select description, stock_uom, default_bom
|
||||
from tabItem where name=%s""", p['item_code'])
|
||||
pi = addchild(self.doc, 'pp_details', 'Production Plan Item', self.doclist)
|
||||
pi = self.doc.append('pp_details', {})
|
||||
pi.sales_order = p['parent']
|
||||
pi.warehouse = p['warehouse']
|
||||
pi.item_code = p['item_code']
|
||||
@@ -151,7 +148,7 @@ class DocType:
|
||||
|
||||
def validate_data(self):
|
||||
self.validate_company()
|
||||
for d in getlist(self.doclist, 'pp_details'):
|
||||
for d in self.get('pp_details'):
|
||||
self.validate_bom_no(d)
|
||||
if not flt(d.planned_qty):
|
||||
frappe.throw("Please Enter Planned Qty for item: %s at row no: %s" %
|
||||
@@ -193,7 +190,7 @@ class DocType:
|
||||
}
|
||||
"""
|
||||
item_dict, bom_dict = {}, {}
|
||||
for d in self.doclist.get({"parentfield": "pp_details"}):
|
||||
for d in self.get("pp_details"):
|
||||
bom_dict.setdefault(d.bom_no, []).append([d.sales_order, flt(d.planned_qty)])
|
||||
item_dict[(d.item_code, d.sales_order, d.warehouse)] = {
|
||||
"production_item" : d.item_code,
|
||||
|
||||
@@ -5,7 +5,9 @@ from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe.utils import flt
|
||||
|
||||
class DocType:
|
||||
from frappe.model.document import Document
|
||||
|
||||
class Workstation(Document):
|
||||
def __init__(self, doc, doclist=[]):
|
||||
self.doc = doc
|
||||
self.doclist = doclist
|
||||
|
||||
Reference in New Issue
Block a user