Rounding issue fixed for bom quantity
This commit is contained in:
parent
818bacae49
commit
14b8af2e65
@ -197,7 +197,7 @@ class BuyingController(StockController):
|
||||
|
||||
landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \
|
||||
if self.doctype == "Purchase Receipt" else 0.0
|
||||
|
||||
|
||||
item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost
|
||||
+ landed_cost_voucher_amount) / qty_in_stock_uom)
|
||||
else:
|
||||
@ -289,7 +289,8 @@ class BuyingController(StockController):
|
||||
self.append(raw_material_table, d)
|
||||
|
||||
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
|
||||
from `tabBOM` t1, `tabBOM Item` t2
|
||||
where t2.parent = t1.name and t1.item = %s and t1.is_default = 1
|
||||
|
@ -288,8 +288,8 @@ class BOM(Document):
|
||||
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)
|
||||
d.qty_consumed_per_unit = flt(d.qty) / flt(self.quantity)
|
||||
d.amount = flt(d.rate, self.precision("rate", d)) * flt(d.qty, self.precision("qty", d))
|
||||
d.qty_consumed_per_unit = flt(d.qty, self.precision("qty", d)) / flt(self.quantity, self.precision("quantity"))
|
||||
total_rm_cost += d.amount
|
||||
|
||||
self.raw_material_cost = total_rm_cost
|
||||
@ -322,17 +322,19 @@ class BOM(Document):
|
||||
|
||||
def get_child_exploded_items(self, bom_no, qty):
|
||||
""" Add all items from Flat BOM of child BOM"""
|
||||
|
||||
child_fb_items = frappe.db.sql("""select item_code, description, stock_uom, qty, rate,
|
||||
qty_consumed_per_unit from `tabBOM Explosion Item`
|
||||
where parent = %s and docstatus = 1""", bom_no, as_dict = 1)
|
||||
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
|
||||
child_fb_items = frappe.db.sql("""select bom_item.item_code, bom_item.description,
|
||||
bom_item.stock_uom, bom_item.qty, bom_item.rate,
|
||||
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:
|
||||
self.add_to_cur_exploded_items(frappe._dict({
|
||||
'item_code' : d['item_code'],
|
||||
'description' : d['description'],
|
||||
'stock_uom' : d['stock_uom'],
|
||||
'qty' : flt(d['qty_consumed_per_unit'])*qty,
|
||||
'qty' : d['qty_consumed_per_unit']*qty,
|
||||
'rate' : flt(d['rate']),
|
||||
}))
|
||||
|
||||
@ -362,19 +364,21 @@ class BOM(Document):
|
||||
def get_bom_items_as_dict(bom, qty=1, fetch_exploded=1):
|
||||
item_dict = {}
|
||||
|
||||
# Did not use qty_consumed_per_unit in the query, as it leads to rounding loss
|
||||
query = """select
|
||||
bom_item.item_code,
|
||||
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.stock_uom,
|
||||
item.default_warehouse,
|
||||
item.expense_account as expense_account,
|
||||
item.buying_cost_center as cost_center
|
||||
from
|
||||
`tab%(table)s` bom_item, `tabItem` item
|
||||
`tab%(table)s` bom_item, `tabBOM` bom, `tabItem` item
|
||||
where
|
||||
bom_item.docstatus < 2
|
||||
bom_item.parent = bom.name
|
||||
and bom_item.docstatus < 2
|
||||
and bom_item.parent = "%(bom)s"
|
||||
and item.name = bom_item.item_code
|
||||
%(conditions)s
|
||||
|
@ -250,23 +250,24 @@ class ProductionPlanningTool(Document):
|
||||
bom_wise_item_details = {}
|
||||
if self.use_multi_level_bom:
|
||||
# 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,
|
||||
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
|
||||
from `tabBOM Explosion Item` fb,`tabItem` it
|
||||
where it.name = fb.item_code and ifnull(it.is_pro_applicable, 'No') = 'No'
|
||||
from `tabBOM Explosion Item` fb, `tabBOM` bom, `tabItem` it
|
||||
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 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):
|
||||
bom_wise_item_details.setdefault(d.item_code, d)
|
||||
else:
|
||||
# Get all raw materials considering SA items as raw materials,
|
||||
# so no childs of SA items
|
||||
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
|
||||
from `tabBOM Item` bom_item, tabItem item
|
||||
where bom_item.parent = %s and bom_item.docstatus < 2
|
||||
from `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
|
||||
where bom.name = bom_item.parent and bom.name = %s and bom_item.docstatus < 2
|
||||
and bom_item.item_code = item.name
|
||||
group by item_code""", bom, as_dict=1):
|
||||
bom_wise_item_details.setdefault(d.item_code, d)
|
||||
|
Loading…
x
Reference in New Issue
Block a user