Merge pull request #2120 from nabinhait/hotfix

Fixes in BOM and maintenance schedule
This commit is contained in:
Anand Doshi
2014-08-29 15:43:00 +05:30
4 changed files with 37 additions and 22 deletions

View File

@@ -197,7 +197,7 @@ class BuyingController(StockController):
landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \ landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \
if self.doctype == "Purchase Receipt" else 0.0 if self.doctype == "Purchase Receipt" else 0.0
item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost
+ landed_cost_voucher_amount) / qty_in_stock_uom) + landed_cost_voucher_amount) / qty_in_stock_uom)
else: else:
@@ -289,7 +289,8 @@ class BuyingController(StockController):
self.append(raw_material_table, d) self.append(raw_material_table, d)
def get_items_from_default_bom(self, item_code): def get_items_from_default_bom(self, item_code):
bom_items = frappe.db.sql("""select t2.item_code, t2.qty_consumed_per_unit, bom_items = frappe.db.sql("""select t2.item_code,
ifnull(t2.qty, 0) / ifnull(t1.quantity, 1) as qty_consumed_per_unit,
t2.rate, t2.stock_uom, t2.name, t2.description t2.rate, t2.stock_uom, t2.name, t2.description
from `tabBOM` t1, `tabBOM Item` t2 from `tabBOM` t1, `tabBOM Item` t2
where t2.parent = t1.name and t1.item = %s and t1.is_default = 1 where t2.parent = t1.name and t1.item = %s and t1.is_default = 1

View File

@@ -288,8 +288,8 @@ class BOM(Document):
for d in self.get('bom_materials'): for d in self.get('bom_materials'):
if d.bom_no: if d.bom_no:
d.rate = self.get_bom_unitcost(d.bom_no) d.rate = self.get_bom_unitcost(d.bom_no)
d.amount = flt(d.rate) * flt(d.qty) d.amount = flt(d.rate, self.precision("rate", d)) * flt(d.qty, self.precision("qty", d))
d.qty_consumed_per_unit = flt(d.qty) / flt(self.quantity) d.qty_consumed_per_unit = flt(d.qty, self.precision("qty", d)) / flt(self.quantity, self.precision("quantity"))
total_rm_cost += d.amount total_rm_cost += d.amount
self.raw_material_cost = total_rm_cost self.raw_material_cost = total_rm_cost
@@ -322,17 +322,19 @@ class BOM(Document):
def get_child_exploded_items(self, bom_no, qty): def get_child_exploded_items(self, bom_no, qty):
""" Add all items from Flat BOM of child BOM""" """ Add all items from Flat BOM of child BOM"""
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
child_fb_items = frappe.db.sql("""select item_code, description, stock_uom, qty, rate, child_fb_items = frappe.db.sql("""select bom_item.item_code, bom_item.description,
qty_consumed_per_unit from `tabBOM Explosion Item` bom_item.stock_uom, bom_item.qty, bom_item.rate,
where parent = %s and docstatus = 1""", bom_no, as_dict = 1) ifnull(bom_item.qty, 0 ) / ifnull(bom.quantity, 1) as qty_consumed_per_unit
from `tabBOM Explosion Item` bom_item, tabBOM bom
where bom_item.parent = bom.name and bom.name = %s and bom.docstatus = 1""", bom_no, as_dict = 1)
for d in child_fb_items: for d in child_fb_items:
self.add_to_cur_exploded_items(frappe._dict({ self.add_to_cur_exploded_items(frappe._dict({
'item_code' : d['item_code'], 'item_code' : d['item_code'],
'description' : d['description'], 'description' : d['description'],
'stock_uom' : d['stock_uom'], 'stock_uom' : d['stock_uom'],
'qty' : flt(d['qty_consumed_per_unit'])*qty, 'qty' : d['qty_consumed_per_unit']*qty,
'rate' : flt(d['rate']), 'rate' : flt(d['rate']),
})) }))
@@ -362,19 +364,21 @@ class BOM(Document):
def get_bom_items_as_dict(bom, qty=1, fetch_exploded=1): def get_bom_items_as_dict(bom, qty=1, fetch_exploded=1):
item_dict = {} item_dict = {}
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
query = """select query = """select
bom_item.item_code, bom_item.item_code,
item.item_name, item.item_name,
ifnull(sum(bom_item.qty_consumed_per_unit),0) * %(qty)s as qty, sum(ifnull(bom_item.qty, 0)/ifnull(bom.quantity, 1)) * %(qty)s as qty,
item.description, item.description,
item.stock_uom, item.stock_uom,
item.default_warehouse, item.default_warehouse,
item.expense_account as expense_account, item.expense_account as expense_account,
item.buying_cost_center as cost_center item.buying_cost_center as cost_center
from from
`tab%(table)s` bom_item, `tabItem` item `tab%(table)s` bom_item, `tabBOM` bom, `tabItem` item
where where
bom_item.docstatus < 2 bom_item.parent = bom.name
and bom_item.docstatus < 2
and bom_item.parent = "%(bom)s" and bom_item.parent = "%(bom)s"
and item.name = bom_item.item_code and item.name = bom_item.item_code
%(conditions)s %(conditions)s

View File

@@ -250,23 +250,24 @@ class ProductionPlanningTool(Document):
bom_wise_item_details = {} bom_wise_item_details = {}
if self.use_multi_level_bom: if self.use_multi_level_bom:
# get all raw materials with sub assembly childs # get all raw materials with sub assembly childs
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
for d in frappe.db.sql("""select fb.item_code, for d in frappe.db.sql("""select fb.item_code,
ifnull(sum(fb.qty_consumed_per_unit), 0) as qty, ifnull(sum(ifnull(fb.qty, 0)/ifnull(bom.quantity, 1)), 0) as qty,
fb.description, fb.stock_uom, it.min_order_qty fb.description, fb.stock_uom, it.min_order_qty
from `tabBOM Explosion Item` fb,`tabItem` it from `tabBOM Explosion Item` fb, `tabBOM` bom, `tabItem` it
where it.name = fb.item_code and ifnull(it.is_pro_applicable, 'No') = 'No' where bom.name = fb.parent and it.name = fb.item_code and ifnull(it.is_pro_applicable, 'No') = 'No'
and ifnull(it.is_sub_contracted_item, 'No') = 'No' and ifnull(it.is_sub_contracted_item, 'No') = 'No'
and fb.docstatus<2 and fb.parent=%s and fb.docstatus<2 and bom.name=%s
group by item_code, stock_uom""", bom, as_dict=1): group by item_code, stock_uom""", bom, as_dict=1):
bom_wise_item_details.setdefault(d.item_code, d) bom_wise_item_details.setdefault(d.item_code, d)
else: else:
# 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
for d in frappe.db.sql("""select bom_item.item_code, for d in frappe.db.sql("""select bom_item.item_code,
ifnull(sum(bom_item.qty_consumed_per_unit), 0) as qty, ifnull(sum(ifnull(bom_item.qty, 0)/ifnull(bom.quantity, 1)), 0) as qty,
bom_item.description, bom_item.stock_uom, item.min_order_qty bom_item.description, bom_item.stock_uom, item.min_order_qty
from `tabBOM Item` bom_item, tabItem item from `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
where bom_item.parent = %s and bom_item.docstatus < 2 where bom.name = bom_item.parent and bom.name = %s and bom_item.docstatus < 2
and bom_item.item_code = item.name and bom_item.item_code = item.name
group by item_code""", bom, as_dict=1): group by item_code""", bom, as_dict=1):
bom_wise_item_details.setdefault(d.item_code, d) bom_wise_item_details.setdefault(d.item_code, d)

View File

@@ -1,6 +1,6 @@
{ {
"autoname": "MS.#####", "autoname": "MS.#####",
"creation": "2013-01-10 16:34:30.000000", "creation": "2013-01-10 16:34:30",
"docstatus": 0, "docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"fields": [ "fields": [
@@ -213,12 +213,21 @@
"permlevel": 0, "permlevel": 0,
"reqd": 1, "reqd": 1,
"search_index": 0 "search_index": 0
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Maintenance Schedule",
"print_hide": 1,
"read_only": 1
} }
], ],
"icon": "icon-calendar", "icon": "icon-calendar",
"idx": 1, "idx": 1,
"is_submittable": 1, "is_submittable": 1,
"modified": "2014-01-20 17:48:56.000000", "modified": "2014-08-28 11:39:17.152817",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Support", "module": "Support",
"name": "Maintenance Schedule", "name": "Maintenance Schedule",
@@ -239,5 +248,5 @@
"write": 1 "write": 1
} }
], ],
"search_fields": "status,customer,customer_name, sales_order_no" "search_fields": "status,customer,customer_name"
} }