From b82abb6ecea258586e34802d48e9a700d935118b Mon Sep 17 00:00:00 2001 From: Daniel Dico Date: Mon, 25 Jan 2016 01:05:59 -0500 Subject: [PATCH] [FIX] mrp_project - include timesheet in cost --- mrp_production_real_cost/README.rst | 7 ++++--- mrp_project/__openerp__.py | 4 +++- mrp_project/models/__init__.py | 1 + mrp_project/models/hr_analytic_timesheet.py | 16 ++++++++++++++++ mrp_project/models/mrp_production.py | 5 +++++ mrp_project/models/project_task.py | 5 +++++ mrp_project/views/hr_analytic_timesheet.xml | 17 +++++++++++++++++ 7 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 mrp_project/models/hr_analytic_timesheet.py create mode 100644 mrp_project/views/hr_analytic_timesheet.xml diff --git a/mrp_production_real_cost/README.rst b/mrp_production_real_cost/README.rst index e1c6c98bd..821e9166c 100644 --- a/mrp_production_real_cost/README.rst +++ b/mrp_production_real_cost/README.rst @@ -26,14 +26,15 @@ https://github.com/OCA/product-variant Usage ===== -Operating with a manufacture order, analytic entries adding costs will be +Processing a manufacture order, analytic entries adding costs will be created when: * Some raw material is consumed. * A work order is finished or paused. +* Also, together with *project_timesheet* module, users time is also translated + to costs in the linked analytic account. -Also, thanks to *project_timesheet* modules, users time is also translated to -costs in the linked analytic account. +The sum of all these analytic entries is the real cost. diff --git a/mrp_project/__openerp__.py b/mrp_project/__openerp__.py index f31f096f9..47f7dd49b 100644 --- a/mrp_project/__openerp__.py +++ b/mrp_project/__openerp__.py @@ -12,6 +12,7 @@ "project", ], 'license': 'AGPL-3', + "images": [], "author": "OdooMRP team," "AvanzOSC," "Serv. Tecnol. Avanzados - Pedro M. Baeza," @@ -22,7 +23,8 @@ "views/mrp_production_view.xml", "views/project_project_view.xml", "views/account_analytic_line_view.xml", - "views/project_task_view.xml" + "views/project_task_view.xml", + "views/hr_analytic_timesheet.xml" ], 'installable': True, 'auto_install': False, diff --git a/mrp_project/models/__init__.py b/mrp_project/models/__init__.py index d5f8df4b3..4f8fe9241 100644 --- a/mrp_project/models/__init__.py +++ b/mrp_project/models/__init__.py @@ -8,3 +8,4 @@ from . import account_analytic_line from . import project_project from . import project_task from . import project_task_work +from . import hr_analytic_timesheet diff --git a/mrp_project/models/hr_analytic_timesheet.py b/mrp_project/models/hr_analytic_timesheet.py new file mode 100644 index 000000000..765df5807 --- /dev/null +++ b/mrp_project/models/hr_analytic_timesheet.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Daniel Dico +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from openerp import models, api + + +class HrAnalyticTimesheet(models.Model): + _inherit = "hr.analytic.timesheet" + + @api.model + def create(self, vals): + production = self._context.get('production', False) + vals['mrp_production_id'] = vals.get( + 'mrp_production_id', False) or production and production.id + return super(HrAnalyticTimesheet, self).create(vals) diff --git a/mrp_project/models/mrp_production.py b/mrp_project/models/mrp_production.py index c43a16f79..5d68300b5 100644 --- a/mrp_project/models/mrp_production.py +++ b/mrp_project/models/mrp_production.py @@ -91,3 +91,8 @@ class MrpProductionWorkcenterLine(models.Model): work_ids = fields.One2many( comodel_name="project.task.work", inverse_name="workorder", string="Task works") + + @api.multi + def write(self, vals, update=True): + return super(MrpProductionWorkcenterLine, self.with_context( + production=self.production_id)).write(vals) diff --git a/mrp_project/models/project_task.py b/mrp_project/models/project_task.py index 3679d583c..815b998ff 100644 --- a/mrp_project/models/project_task.py +++ b/mrp_project/models/project_task.py @@ -29,3 +29,8 @@ class ProjectTask(models.Model): (task.id, "[%s] %s" % (task.user_id.name, task.name))) return res return super(ProjectTask, self).name_get() + + @api.multi + def write(self, vals): + return super(ProjectTask, self.with_context( + production=self.mrp_production_id)).write(vals) diff --git a/mrp_project/views/hr_analytic_timesheet.xml b/mrp_project/views/hr_analytic_timesheet.xml new file mode 100644 index 000000000..e1e71db2b --- /dev/null +++ b/mrp_project/views/hr_analytic_timesheet.xml @@ -0,0 +1,17 @@ + + + + + + hr.analytic.timesheet.tree.mrp + hr.analytic.timesheet + + + + + + + + + + \ No newline at end of file