[IMP] mrp_production_real_cost: added test for onchange to increase coveralls

This commit is contained in:
Oihane Crucelaegui
2016-01-20 23:16:49 +01:00
committed by oihane
parent dda6e66e0e
commit 48ae6aa1ac
2 changed files with 43 additions and 14 deletions

View File

@@ -31,16 +31,17 @@ class MrpProductionWorkcenterLine(models.Model):
(product.default_code or ''))
general_acc = workcenter.costs_general_account_id or False
price = -(workcenter.costs_hour * operation_line.uptime)
analytic_vals = production._prepare_real_cost_analytic_line(
journal_id, name, production, product,
general_account=general_acc, workorder=self,
qty=operation_line.uptime, amount=price)
task = task_obj.search([('mrp_production_id', '=', production.id),
('workorder', '=', False)])
analytic_vals['task_id'] = task and task[0].id or False
analytic_vals['product_uom_id'] = hour_uom.id
analytic_line = analytic_line_obj.create(analytic_vals)
return analytic_line
if price:
analytic_vals = production._prepare_real_cost_analytic_line(
journal_id, name, production, product,
general_account=general_acc, workorder=self,
qty=operation_line.uptime, amount=price)
task = task_obj.search(
[('mrp_production_id', '=', production.id),
('workorder', '=', False)])
analytic_vals['task_id'] = task and task[0].id or False
analytic_vals['product_uom_id'] = hour_uom.id
analytic_line_obj.create(analytic_vals)
@api.multi
def _create_pre_post_cost_lines(self, cost_type='pre'):
@@ -97,6 +98,8 @@ class MrpProductionWorkcenterLine(models.Model):
@api.multi
def action_done(self):
not_paused_records = self.filtered(lambda x: x.state != 'pause')
not_paused_records._write_end_date_operation_line()
self._create_analytic_line()
self._create_pre_post_cost_lines(cost_type='post')
result = super(MrpProductionWorkcenterLine, self).action_done()

View File

@@ -4,6 +4,8 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp.tests import common
from openerp import fields
from datetime import timedelta
import time
@@ -14,20 +16,28 @@ class TestMrpProductionRealCost(common.TransactionCase):
'mrp_operations_extension.mrp_production_opeext')
self.production.signal_workflow('button_confirm')
self.production.force_production()
# start date will be used in order to force a long machine uptime
self.start_date = (
fields.Datetime.from_string(fields.Datetime.now()) -
timedelta(hours=1))
def test_flow(self):
line = self.production.workcenter_lines[1]
line.pre_cost = 10
line.post_cost = 20
line.signal_workflow('button_start_working')
self.assertEqual(len(self.production.analytic_line_ids), 1)
line.operation_time_lines[-1].start_date = self.start_date
self.assertEqual(
len(self.production.analytic_line_ids.filtered('amount')), 1)
time.sleep(1)
line.signal_workflow('button_pause')
self.assertEqual(len(self.production.analytic_line_ids), 2)
self.assertEqual(
len(self.production.analytic_line_ids.filtered('amount')), 2)
line.signal_workflow('button_resume')
time.sleep(1)
line.signal_workflow('button_done')
self.assertEqual(len(self.production.analytic_line_ids), 4)
self.assertEqual(
len(self.production.analytic_line_ids.filtered('amount')), 3)
self.production.analytic_line_ids[:1].amount = -10
self.assertTrue(self.production.real_cost)
@@ -36,8 +46,24 @@ class TestMrpProductionRealCost(common.TransactionCase):
initial_price = 999999999
self.production.product_id.standard_price = initial_price
self.production.product_id.cost_method = 'average'
for line in self.production.workcenter_lines:
line.signal_workflow('button_start_working')
line.operation_time_lines[-1].start_date = self.start_date
self.production.action_produce(
self.production.id, self.production.product_qty, 'consume_produce')
self.assertEqual(len(self.production.analytic_line_ids), 4)
self.assertEqual(
len(self.production.analytic_line_ids.filtered('amount')), 4)
self.assertNotEqual(
initial_price, self.production.product_id.standard_price)
def test_onchange_lines_default(self):
workcenter0 = self.browse_ref('mrp.mrp_workcenter_0')
routing = self.env['mrp.routing.workcenter'].new({
'name': 'Test Routing',
'op_wc_lines': [(0, 0, {
'default': True, 'workcenter': workcenter0.id})],
})
routing.onchange_lines_default()
self.assertEqual(routing.workcenter_id, workcenter0)
self.assertEqual(routing.cycle_nbr, workcenter0.capacity_per_cycle)
self.assertEqual(routing.hour_nbr, workcenter0.time_cycle)