[IMP] mrp_operations_time_control: OCA adaptation

This commit is contained in:
Pedro M. Baeza
2015-12-07 11:28:43 +01:00
parent fce63d9bce
commit 399d6be0a2
11 changed files with 504 additions and 258 deletions

View File

@@ -1,20 +1,7 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
##############################################################################
# -*- coding: utf-8 -*-
# © 2015 Avanzosc
# © 2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import api, models, fields
@@ -22,9 +9,8 @@ from openerp import api, models, fields
class MrpProductionWorkcenterLine(models.Model):
_inherit = 'mrp.production.workcenter.line'
operation_time_lines = fields.One2many('operation.time.line',
'operation_time',
string='Operation Time Lines')
operation_time_lines = fields.One2many(
'operation.time.line', 'operation_time', string='Operation Time Lines')
def _create_operation_line(self):
self.env['operation.time.line'].create({
@@ -35,22 +21,26 @@ class MrpProductionWorkcenterLine(models.Model):
def _write_end_date_operation_line(self):
self.operation_time_lines[-1].end_date = fields.Datetime.now()
@api.multi
def action_start_working(self):
result = super(MrpProductionWorkcenterLine,
self).action_start_working()
self._create_operation_line()
return result
@api.multi
def action_pause(self):
result = super(MrpProductionWorkcenterLine, self).action_pause()
self._write_end_date_operation_line()
return result
@api.multi
def action_resume(self):
result = super(MrpProductionWorkcenterLine, self).action_resume()
self._create_operation_line()
return result
@api.multi
def action_done(self):
result = super(MrpProductionWorkcenterLine, self).action_done()
self._write_end_date_operation_line()
@@ -58,7 +48,6 @@ class MrpProductionWorkcenterLine(models.Model):
class OperationTimeLine(models.Model):
_name = 'operation.time.line'
_rec_name = 'operation_time'
@@ -68,19 +57,18 @@ class OperationTimeLine(models.Model):
start_date = fields.Datetime(string='Start Date')
end_date = fields.Datetime(string='End Date')
operation_time = fields.Many2one('mrp.production.workcenter.line')
uptime = fields.Float(string='Machine up time', compute='operation_uptime',
store=True, digits=(12, 6))
production = fields.Many2one('mrp.production',
related='operation_time.production_id',
string='Production', store=True)
uptime = fields.Float(
string='Machine up time', compute='_compute_uptime', store=True,
digits=(12, 6))
production = fields.Many2one(
'mrp.production', related='operation_time.production_id',
string='Production', store=True)
user = fields.Many2one('res.users', string='User', default=_default_user)
@api.one
@api.depends('start_date', 'end_date')
def operation_uptime(self):
def _compute_uptime(self):
if self.end_date and self.start_date:
timedelta = fields.Datetime.from_string(self.end_date) - \
fields.Datetime.from_string(self.start_date)
self.uptime = timedelta.total_seconds() / 3600.
else:
self.uptime = 0