[ADD] mrp_operations_time_control

This commit is contained in:
avanzosc1
2014-09-11 14:08:32 +02:00
committed by Pedro M. Baeza
parent 18e112e65c
commit 57dfe41f60
6 changed files with 322 additions and 0 deletions

View File

@@ -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

View File

@@ -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 <mikelarregi@avanzosc.es>"],
"category": "mrp",
"description": """
Manufacturing operations time control
""",
'data': ["views/operation_time_view.xml",
"views/mrp_production_view.xml"],
"installable": True,
"auto_install": False,
}

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view"
id="mrp_production_operation_buttons_form_view">
<field name="name">mrp.production.operation.buttons.form
</field>
<field name="model">mrp.production</field>
<field name="inherit_id"
ref="mrp_operations.mrp_production_form_inherit_view" />
<field name="arch" type="xml">
<button name="button_start_working" position="attributes">
<attribute name="icon"></attribute>
</button>
<button name="button_resume" position="attributes">
<attribute name="icon" ></attribute>
</button>
<button name="button_done" position="attributes">
<attribute name="icon" ></attribute>
</button>
<button name="button_pause" position="attributes">
<attribute name="icon" ></attribute>
</button>
<button name="button_draft" position="attributes">
<attribute name="icon" ></attribute>
</button>
<button name="button_cancel" position="attributes">
<attribute name="icon" ></attribute>
</button>
</field>
</record>
<record model="ir.ui.view"
id="mrp_production_operation_time_form_view">
<field name="name">mrp.production.operation.time.form
</field>
<field name="model">mrp.production</field>
<field name="inherit_id"
ref="mrp_operations_extension.mrp_production_form_view_inh" />
<field name="arch" type="xml">
<field name="product_line" position="after">
<field name="operation_time_lines" nolabel="1" colspan="4" col="4"/>
</field>
</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_operation_time_lines_search" model="ir.ui.view">
<field name="name">operation.time.line.search</field>
<field name="model">operation.time.line</field>
<field name="arch" type="xml">
<search string="Search Operation Time Lines">
<group expand="1" string="Group By...">
<filter name="uptimegroup" string="Work Order"
context="{'group_by' : 'operation_time'}" />
<filter name="productiongroup" string="Production Order"
context="{'group_by' : 'production'}" />
<filter name="usergroup" string="User"
context="{'group_by' : 'user'}" />
</group>
</search>
</field>
</record>
<record model="ir.ui.view" id="operation_time_form_view">
<field name="name">Operation Time Form View</field>
<field name="model">mrp.production.workcenter.line</field>
<field name="inherit_id"
ref="mrp_operations.mrp_production_workcenter_form_view_inherit" />
<field name="arch" type="xml">
<page string="Information" position="after">
<page string="Uptime">
<field name="operation_time_lines" />
</page>
</page>
<group string="Product to Produce" position="after">
<group string="Product Lines" colspan="4" col="4">
<field name="routing_wc_line" colspan="4" col="4"/>
<field name="product_line" nolabel="1" colspan="4" col="4"/>
</group>
</group>
</field>
</record>
<record model="ir.ui.view" id="operation_time_tree_view">
<field name="name">Operation Time Form View</field>
<field name="model">mrp.production.workcenter.line</field>
<field name="inherit_id"
ref="mrp_operations.mrp_production_workcenter_tree_view_inherit" />
<field name="arch" type="xml">
<field name="state" position="after">
<button name="button_draft" string="Set Draft" states="cancel" icon="gtk-convert"/>
<button name="button_start_working" string="Start" states="draft" icon="gtk-media-play"/>
<button name="button_resume" string="Resume" states="pause" icon="gtk-media-pause"/>
<button name="button_pause" string="Pending" states="startworking" icon="gtk-media-pause"/>
<button name="button_done" string="Finished" states="startworking" icon="terp-check"/>
</field>
</field>
</record>
<record model="ir.ui.view" id="operation_time_lines_form_view">
<field name="name">operation.time.line.form</field>
<field name="model">operation.time.line</field>
<field name="arch" type="xml">
<form string="Operation time lines">
<group>
<field name="user" readonly="1"/>
<field name="start_date" />
<field name="end_date" />
<field name="operation_time" />
<field name="uptime" />hours
<field name="production"/>
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="operation_time_lines_tree_view">
<field name="name">operation.time.line.tree</field>
<field name="model">operation.time.line</field>
<field name="arch" type="xml">
<tree string="Operation time lines">
<field name="user"/>
<field name="start_date" />
<field name="end_date" />
<field name="operation_time" />
<field name="uptime" sum="Uptime" />
<field name="production"/>
</tree>
</field>
</record>
<record id="operation_time_lines_action" model="ir.actions.act_window">
<field name="name">Operation Time Lines</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">operation.time.line</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_uptimegroup': 1,
'search_default_internal_loc': 1}</field>
</record>
<menuitem action="operation_time_lines_action" id="menu_operation_time_lines_action"
parent="mrp.menu_mrp_manufacturing" sequence="10" />
</data>
</openerp>