示例#1
0
文件: api.py 项目: finbyz/roopdyes
def update_cost():
	from erpnext.manufacturing.doctype.bom.bom import get_boms_in_bottom_up_order

	bom_list = get_boms_in_bottom_up_order()
	for bom in bom_list:
		bom_obj = frappe.get_doc("BOM", bom)
		bom_obj.update_cost(update_parent=False, from_child_bom=True)

		operating_cost = flt(bom_obj.fuel_gas_quantity) * flt(bom_obj.fuel_gas_rate)
		bom_obj.db_set("total_cost",bom_obj.raw_material_cost + operating_cost - bom_obj.scrap_material_cost)
		per_unit_price = flt(bom_obj.total_cost) / flt(bom_obj.quantity)
		#print(bom_obj.name, flt(bom_obj.raw_material_cost) , flt(bom_obj.fuel_gas_quantity) * flt(bom_obj.fuel_gas_rate), flt(bom_obj.total_cost), flt(bom_obj.quantity), flt(bom_obj.total_cost) /flt(bom_obj.quantity))
		bom_obj.db_set('per_unit_price',flt(bom_obj.total_cost) / flt(bom_obj.quantity))
		bom_obj.db_set('operating_cost', operating_cost)

		# if bom_obj.per_unit_price != per_unit_price:
			# bom_obj.db_set('per_unit_price', per_unit_price)
		if frappe.db.exists("Item Price",{"item_code":bom_obj.item,"price_list":bom_obj.buying_price_list}):
			name = frappe.db.get_value("Item Price",{"item_code":bom_obj.item,"price_list":bom_obj.buying_price_list},'name')
			frappe.db.set_value("Item Price",name,"price_list_rate", per_unit_price)
		else:
			item_price = frappe.new_doc("Item Price")
			item_price.price_list = bom_obj.buying_price_list
			item_price.item_code = bom_obj.item
			item_price.price_list_rate = per_unit_price
			
			item_price.save()
def update_cost():
	frappe.db.auto_commit_on_many_writes = 1
	bom_list = get_boms_in_bottom_up_order()
	for bom in bom_list:
		frappe.get_doc("BOM", bom).update_cost(update_parent=False, from_child_bom=True)

	frappe.db.auto_commit_on_many_writes = 0
示例#3
0
def update_cost():
	from erpnext.manufacturing.doctype.bom.bom import get_boms_in_bottom_up_order

	bom_list = get_boms_in_bottom_up_order()
	for bom in bom_list:
		bom_obj = frappe.get_doc("BOM", bom)
		bom_obj.update_cost(update_parent=False, from_child_bom=True)
		if not bom_obj.is_multiple_item:
			bom_obj.cost_ratio_of_first_item = 100.0
		for row in bom_obj.items:
			row.db_set('per_unit_rate', flt(row.amount)/bom_obj.quantity * flt(bom_obj.cost_ratio_of_first_item/100.0))
		for row in bom_obj.scrap_items:
			row.db_set('per_unit_rate', flt(row.amount)/bom_obj.quantity * flt(bom_obj.cost_ratio_of_first_item/100.0))
			
		bom_obj.db_set("volume_amount",flt(bom_obj.volume_quantity) * flt(bom_obj.volume_rate))
		bom_obj.db_set("etp_amount",flt(bom_obj.etp_qty) * flt(bom_obj.etp_rate))
		bom_obj.db_set('total_operational_cost',flt(bom_obj.additional_amount) + flt(bom_obj.volume_amount) + flt(bom_obj.etp_amount))
		bom_obj.db_set('total_scrap_cost', abs(bom_obj.scrap_material_cost))
		bom_obj.db_set("total_cost",bom_obj.raw_material_cost + bom_obj.total_operational_cost - flt(bom_obj.scrap_material_cost) )
		per_unit_price = flt(bom_obj.total_cost) / flt(bom_obj.quantity)
		bom_obj.db_set('per_unit_price',flt(bom_obj.total_cost) / flt(bom_obj.quantity) * flt(bom_obj.cost_ratio_of_first_item/100.0))
		bom_obj.db_set('per_unit_volume_cost',flt(bom_obj.volume_amount/bom_obj.quantity) * flt(bom_obj.cost_ratio_of_first_item/100.0))	
		bom_obj.db_set('per_unit_additional_cost',flt(flt(bom_obj.additional_amount)/bom_obj.quantity) * flt(bom_obj.cost_ratio_of_first_item/100.0))
		bom_obj.db_set('per_unit_rmc',flt(flt(bom_obj.raw_material_cost)/bom_obj.quantity) * flt(bom_obj.cost_ratio_of_first_item/100.0))
		bom_obj.db_set('per_unit_operational_cost',flt(flt(bom_obj.total_operational_cost)/bom_obj.quantity) * flt(bom_obj.cost_ratio_of_first_item/100.0))
		bom_obj.db_set('per_unit_scrap_cost',flt(flt(bom_obj.total_scrap_cost)/bom_obj.quantity) * flt(bom_obj.cost_ratio_of_first_item/100.0))

		# if bom_obj.per_unit_price != per_unit_price:
			# bom_obj.db_set('per_unit_price', per_unit_price)
		if frappe.db.exists("Item Price",{"item_code":bom_obj.item,"price_list":bom_obj.buying_price_list}):
			name = frappe.db.get_value("Item Price",{"item_code":bom_obj.item,"price_list":bom_obj.buying_price_list},'name')
			frappe.db.set_value("Item Price",name,"price_list_rate", per_unit_price)
		else:
			item_price = frappe.new_doc("Item Price")
			item_price.price_list = bom_obj.buying_price_list
			item_price.item_code = bom_obj.item
			item_price.price_list_rate = per_unit_price
			
			item_price.save()
		frappe.db.commit()
示例#4
0
def update_cost():
	bom_list = get_boms_in_bottom_up_order()
	for bom in bom_list:
		frappe.get_doc("BOM", bom).update_cost(update_parent=False, from_child_bom=True)
示例#5
0
def update_cost():
    bom_list = get_boms_in_bottom_up_order()
    for bom in bom_list:
        frappe.get_doc("BOM", bom).update_cost(update_parent=False,
                                               from_child_bom=True)
示例#6
0
def update_cost() -> None:
    """Updates Cost for all BOMs from bottom to top."""
    bom_list = get_boms_in_bottom_up_order()
    for bom in bom_list:
        frappe.get_doc("BOM", bom).update_cost(update_parent=False,
                                               from_child_bom=True)
示例#7
0
文件: bom.py 项目: finbyz/chemical
def update_cost():
    from erpnext.manufacturing.doctype.bom.bom import get_boms_in_bottom_up_order

    bom_list = get_boms_in_bottom_up_order()
    for bom in bom_list:
        bom_obj = frappe.get_doc("BOM", bom)
        bom_obj.update_cost(update_parent=False, from_child_bom=True)
        for row in bom_obj.items:
            row.db_set('per_unit_rate', flt(row.amount) / bom_obj.quantity)
        for row in bom_obj.scrap_items:
            row.db_set('per_unit_rate', flt(row.amount) / bom_obj.quantity)

        update_bom_cost(bom,
                        update_parent=True,
                        from_child_bom=False,
                        save=True)

        if bom_obj.is_multiple_item:
            for item in bom_obj.multiple_finish_item:
                if bom_obj.item == item.item_code:
                    bom_obj.db_set(
                        'per_unit_rmc',
                        flt(
                            flt(bom_obj.raw_material_cost * item.qty_ratio /
                                100) / bom_obj.quantity))
        else:
            bom_obj.db_set(
                'per_unit_rmc',
                flt(flt(bom_obj.raw_material_cost) / bom_obj.quantity))

        bom_obj.db_set("volume_amount",
                       flt(bom_obj.volume_quantity) * flt(bom_obj.volume_rate))
        bom_obj.db_set("etp_amount",
                       flt(bom_obj.etp_qty) * flt(bom_obj.etp_rate))
        bom_obj.db_set(
            'total_operational_cost',
            flt(bom_obj.additional_amount) + flt(bom_obj.volume_amount) +
            flt(bom_obj.etp_amount))
        bom_obj.db_set('total_scrap_cost', abs(bom_obj.scrap_material_cost))

        bom_obj.db_set(
            "total_cost", bom_obj.raw_material_cost +
            bom_obj.total_operational_cost - flt(bom_obj.scrap_material_cost))
        if hasattr(bom_obj, 'total_valuation_cost'):
            bom_obj.db_set(
                "total_valuation_cost",
                bom_obj.rmc_valuation_amount + bom_obj.total_operational_cost -
                flt(bom_obj.scrap_material_cost))
            bom_obj.db_set(
                "total_last_purchase_cost", bom_obj.rmc_last_purchase_amount +
                bom_obj.total_operational_cost -
                flt(bom_obj.scrap_material_cost))

        per_unit_price = flt(bom_obj.total_cost) / flt(bom_obj.quantity)
        bom_obj.db_set('per_unit_price',
                       flt(bom_obj.total_cost) / flt(bom_obj.quantity))
        bom_obj.db_set('per_unit_volume_cost',
                       flt(bom_obj.volume_amount / bom_obj.quantity))
        bom_obj.db_set('per_unit_additional_cost',
                       flt(flt(bom_obj.additional_amount) / bom_obj.quantity))
        bom_obj.db_set('per_unit_rmc',
                       flt(flt(bom_obj.raw_material_cost) / bom_obj.quantity))

        if hasattr(bom_obj, 'per_unit_rmc_valuation'):
            bom_obj.db_set(
                'per_unit_rmc_valuation',
                flt(flt(bom_obj.rmc_valuation_amount) / bom_obj.quantity))
            bom_obj.db_set(
                'per_unit_rmc_last_purchase',
                flt(flt(bom_obj.rmc_last_purchase_amount) / bom_obj.quantity))

        bom_obj.db_set(
            'per_unit_operational_cost',
            flt(flt(bom_obj.total_operational_cost) / bom_obj.quantity))
        bom_obj.db_set('per_unit_scrap_cost',
                       flt(flt(bom_obj.total_scrap_cost) / bom_obj.quantity))
        bom_obj.db_update()
        # if bom_obj.per_unit_price != per_unit_price:
        # bom_obj.db_set('per_unit_price', per_unit_price)
        if frappe.db.exists("Item Price", {
                "item_code": bom_obj.item,
                "price_list": bom_obj.buying_price_list
        }):
            name = frappe.db.get_value("Item Price", {
                "item_code": bom_obj.item,
                "price_list": bom_obj.buying_price_list
            }, 'name')
            # frappe.db.set_value("Item Price",name,"price_list_rate", per_unit_price)
            item_doc = frappe.get_doc("Item Price", name)
            item_doc.db_set("price_list_rate", per_unit_price)
            item_doc.db_update()
        else:
            item_price = frappe.new_doc("Item Price")
            item_price.price_list = bom_obj.buying_price_list
            item_price.item_code = bom_obj.item
            item_price.price_list_rate = per_unit_price

            item_price.save()