From 57dfe41f60f21c1560e1717b479fe030d1e9e765 Mon Sep 17 00:00:00 2001 From: avanzosc1 Date: Thu, 11 Sep 2014 14:08:32 +0200 Subject: [PATCH 1/6] [ADD] mrp_operations_time_control --- mrp_operations_time_control/__init__.py | 20 ++++ mrp_operations_time_control/__openerp__.py | 34 ++++++ .../models/__init__.py | 24 ++++ .../models/operation_time.py | 93 ++++++++++++++++ .../views/mrp_production_view.xml | 47 ++++++++ .../views/operation_time_view.xml | 104 ++++++++++++++++++ 6 files changed, 322 insertions(+) create mode 100644 mrp_operations_time_control/__init__.py create mode 100644 mrp_operations_time_control/__openerp__.py create mode 100644 mrp_operations_time_control/models/__init__.py create mode 100644 mrp_operations_time_control/models/operation_time.py create mode 100644 mrp_operations_time_control/views/mrp_production_view.xml create mode 100644 mrp_operations_time_control/views/operation_time_view.xml diff --git a/mrp_operations_time_control/__init__.py b/mrp_operations_time_control/__init__.py new file mode 100644 index 0000000000..55ac1ae580 --- /dev/null +++ b/mrp_operations_time_control/__init__.py @@ -0,0 +1,20 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +from . import models diff --git a/mrp_operations_time_control/__openerp__.py b/mrp_operations_time_control/__openerp__.py new file mode 100644 index 0000000000..2c49c8ab6a --- /dev/null +++ b/mrp_operations_time_control/__openerp__.py @@ -0,0 +1,34 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +{ + "name": "MRP Operations Time Control", + "version": "1.0", + "depends": ["base", "mrp", "mrp_operations_extension"], + "author": "OdooMRP team", + "contributors": ["Mikel Arregi "], + "category": "mrp", + "description": """ + Manufacturing operations time control + """, + 'data': ["views/operation_time_view.xml", + "views/mrp_production_view.xml"], + "installable": True, + "auto_install": False, +} diff --git a/mrp_operations_time_control/models/__init__.py b/mrp_operations_time_control/models/__init__.py new file mode 100644 index 0000000000..40162f8b29 --- /dev/null +++ b/mrp_operations_time_control/models/__init__.py @@ -0,0 +1,24 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2008-2013 AvanzOSC S.L. (Mikel Arregi) All Rights Reserved +# +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +from . import operation_time diff --git a/mrp_operations_time_control/models/operation_time.py b/mrp_operations_time_control/models/operation_time.py new file mode 100644 index 0000000000..6a2205f5b7 --- /dev/null +++ b/mrp_operations_time_control/models/operation_time.py @@ -0,0 +1,93 @@ + +# -*- encoding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2008-2013 AvanzOSC S.L. (Mikel Arregi) All Rights Reserved +# +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +############################################################################## + +from openerp import api, models, fields, exceptions +from datetime import datetime +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT + + +class MrpProductionWorkcenterLine(models.Model): + + _inherit = 'mrp.production.workcenter.line' + 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({ + 'start_date': fields.Datetime.now(), + 'operation_time': self.id, + 'user': self.env.uid}) + + def _write_end_date_operation_line(self): + self.operation_time_lines[-1].end_date = fields.Datetime.now() + + def action_start_working(self): + result = super(MrpProductionWorkcenterLine, + self).action_start_working() + self._create_operation_line() + return result + + def action_pause(self): + result = super(MrpProductionWorkcenterLine, self).action_pause() + self._write_end_date_operation_line() + return result + + def action_resume(self): + result = super(MrpProductionWorkcenterLine, self).action_resume() + self._create_operation_line() + return result + + def action_done(self): + result = super(MrpProductionWorkcenterLine, self).action_done() + self._write_end_date_operation_line() + return result + + +class OperationTimeLine(models.Model): + + _name = 'operation.time.line' + _rec_name = 'operation_time' + + def _default_user(self): + return self.env.uid + + 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='Uptime', compute='operation_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): + 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 diff --git a/mrp_operations_time_control/views/mrp_production_view.xml b/mrp_operations_time_control/views/mrp_production_view.xml new file mode 100644 index 0000000000..c64888ef63 --- /dev/null +++ b/mrp_operations_time_control/views/mrp_production_view.xml @@ -0,0 +1,47 @@ + + + + + mrp.production.operation.buttons.form + + mrp.production + + + + + + + + + + + + + mrp.production.operation.time.form + + mrp.production + + + + + + + + + diff --git a/mrp_operations_time_control/views/operation_time_view.xml b/mrp_operations_time_control/views/operation_time_view.xml new file mode 100644 index 0000000000..a04f55c058 --- /dev/null +++ b/mrp_operations_time_control/views/operation_time_view.xml @@ -0,0 +1,104 @@ + + + + + + operation.time.line.search + operation.time.line + + + + + + + + + + + + + Operation Time Form View + mrp.production.workcenter.line + + + + + + + + + + + + + + + + + + Operation Time Form View + mrp.production.workcenter.line + + + + - - - - - - - - - + + mrp.production.operation.time.form mrp.production - - - + + + + + diff --git a/mrp_operations_time_control/views/operation_time_view.xml b/mrp_operations_time_control/views/operation_time_view.xml index a04f55c058..7ccad95400 100644 --- a/mrp_operations_time_control/views/operation_time_view.xml +++ b/mrp_operations_time_control/views/operation_time_view.xml @@ -30,15 +30,9 @@ - - - - - - - + Operation Time Form View mrp.production.workcenter.line @@ -46,15 +40,20 @@ ref="mrp_operations.mrp_production_workcenter_tree_view_inherit" /> -