Merge pull request #3215 from neilLasrado/prod-order

Production Order - Fixed cost not considering qty issue
This commit is contained in:
Nabin Hait 2015-05-07 18:55:02 +05:30
commit 53f17009bc
5 changed files with 41 additions and 6 deletions

View File

@ -189,6 +189,10 @@ $.extend(cur_frm.cscript, {
method: "set_production_order_operations"
});
},
qty: function() {
frappe.ui.form.trigger("Production Order", 'bom_no')
},
show_time_logs: function(doc, cdt, cdn) {
var child = locals[cdt][cdn]

View File

@ -63,6 +63,7 @@ class ProductionOrder(Document):
def calculate_operating_cost(self):
self.planned_operating_cost, self.actual_operating_cost = 0.0, 0.0
for d in self.get("operations"):
d.planned_operating_cost = flt(d.hour_rate) * (flt(d.time_in_mins) / 60.0)
d.actual_operating_cost = flt(d.hour_rate) * (flt(d.actual_operation_time) / 60.0)
self.planned_operating_cost += flt(d.planned_operating_cost)
@ -175,14 +176,20 @@ class ProductionOrder(Document):
self.set('operations', [])
operations = frappe.db.sql("""select operation, description, workstation, idx,
hour_rate, time_in_mins, operating_cost as "planned_operating_cost", "Pending" as status
from `tabBOM Operation` where parent = %s order by idx""", self.bom_no, as_dict=1)
hour_rate, time_in_mins, "Pending" as status from `tabBOM Operation`
where parent = %s order by idx""", self.bom_no, as_dict=1)
self.set('operations', operations)
self.calculate_time()
def calculate_time(self):
bom_qty = frappe.db.get_value("BOM", self.bom_no, "quantity")
for d in self.get("operations"):
d.time_in_mins = flt(d.time_in_mins) / flt(bom_qty) * flt(self.qty)
self.calculate_operating_cost()
def get_holidays(self, workstation):
holiday_list = frappe.db.get_value("Workstation", workstation, "holiday_list")

View File

@ -125,7 +125,17 @@ class TestProductionOrder(unittest.TestCase):
"docstatus": 0
})
self.assertRaises(OverProductionLoggedError, time_log2.save)
def test_planned_operating_cost(self):
prod_order = make_prod_order_test_record(item="_Test FG Item 2",
planned_start_date="2014-11-25 00:00:00", qty=1, do_not_save=True)
prod_order.set_production_order_operations()
prod_order.save()
cost = prod_order.planned_operating_cost
prod_order.qty = 2
prod_order.save()
self.assertEqual(prod_order.planned_operating_cost, cost*2)
def make_prod_order_test_record(**args):
args = frappe._dict(args)

View File

@ -150,4 +150,5 @@ erpnext.patches.v5_0.update_advance_paid
erpnext.patches.v5_0.link_warehouse_with_account
erpnext.patches.v5_0.rename_taxes_and_charges_master
execute:frappe.delete_doc("Page", "stock-ledger")
execute:frappe.delete_doc("Page", "stock-level")
execute:frappe.delete_doc("Page", "stock-level")
erpnext.patches.v5_0.reclculate_planned_operating_cost_in_production_order

View File

@ -0,0 +1,13 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
def execute():
for po in frappe.db.sql("""select name from `tabProduction Order` where docstatus < 2""", as_dict=1):
prod_order = frappe.get_doc("Production Order", po.name)
if prod_order.operations:
prod_order.flags.ignore_validate_update_after_submit = True
prod_order.calculate_time()
prod_order.save()