diff --git a/activity_validation/__manifest__.py b/activity_validation/__manifest__.py index a1b11913..618ad808 100644 --- a/activity_validation/__manifest__.py +++ b/activity_validation/__manifest__.py @@ -19,7 +19,7 @@ ############################################################################## { "name": "Activity Validation", - "version": "16.0.2", + "version": "17.0.0.1", "author": "OmniaSolutions", "website": "https://github.com/OmniaGit/odooplm", "category": "Custom", @@ -45,7 +45,7 @@ "qweb": ["static/src/xml/*.xml"], 'assets': { 'web.assets_backend': [ - "activity_validation/static/src/js/systray_activity_menu.js", + #"activity_validation/static/src/js/systray_activity_menu.js", ] }, "installable": True, diff --git a/activity_validation/models/__init__.py b/activity_validation/models/__init__.py index fffdd56e..8b44145e 100644 --- a/activity_validation/models/__init__.py +++ b/activity_validation/models/__init__.py @@ -19,9 +19,11 @@ # along with this program. If not, see . # ############################################################################## -from . import mail_activity_type -from . import mail_activity -from . import mail_activity_children_rel from . import res_users from . import product_product +from . import mail_activity +from . import mail_activity_type +from . import mail_activity_shedule +from . import mail_activity_children_rel # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +0 \ No newline at end of file diff --git a/activity_validation/models/mail_activity.py b/activity_validation/models/mail_activity.py index b9c2295a..d2c6efb7 100755 --- a/activity_validation/models/mail_activity.py +++ b/activity_validation/models/mail_activity.py @@ -35,12 +35,12 @@ class MailActivity(models.Model): _inherit = 'mail.activity' plm_state = fields.Selection([ - ('cancel', _('Cancel')), - ('exception', _('Exception')), + ('draft', _('draft')), + ('in_progress', _('In Progress')), ('eco', _('Change Order')), ('done', _('Done')), - ('in_progress', _('In Progress')), - ('draft', _('draft')), + ('cancel', _('Cancel')), + ('exception', _('Exception')), ], default='draft', string=_('Plm State')) diff --git a/activity_validation/models/mail_activity_children_rel.py b/activity_validation/models/mail_activity_children_rel.py index 78cf4f09..911dd285 100755 --- a/activity_validation/models/mail_activity_children_rel.py +++ b/activity_validation/models/mail_activity_children_rel.py @@ -36,7 +36,7 @@ class MailActivityChildrenRel(models.Model): _name = 'mail.activity.children.rel' - _description = "Activiti children relation" + _description = "Activity children relation" name = fields.Char('Name') user_id = fields.Many2one('res.users', 'User') @@ -44,3 +44,14 @@ class MailActivityChildrenRel(models.Model): mail_children_activity_id = fields.Many2one('mail.activity', 'Child Activity') mail_parent_activity_id = fields.Many2one('mail.activity', 'Parent Activity') plm_state = fields.Selection(related='mail_children_activity_id.plm_state') + +class MailActivityChildrenRel(models.TransientModel): + _name = 'mail.activity.children.rel.shedule' + _description = "Activity children relation shedule" + + name = fields.Char('Name') + user_id = fields.Many2one('res.users', 'User') + activity_user_id = fields.Many2one(related='mail_children_activity_id.activity_user_id') + mail_children_activity_id = fields.Many2one('mail.activity.schedule', 'Child Activity') + mail_parent_activity_id = fields.Many2one('mail.activity.schedule', 'Parent Activity') + plm_state = fields.Selection(related='mail_children_activity_id.plm_state') diff --git a/activity_validation/models/mail_activity_shedule.py b/activity_validation/models/mail_activity_shedule.py new file mode 100644 index 00000000..9c240884 --- /dev/null +++ b/activity_validation/models/mail_activity_shedule.py @@ -0,0 +1,306 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OmniaSolutions, ERP-PLM-CAD Open Source Solutions +# Copyright (C) 2011-2019 https://OmniaSolutions.website +# +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this prograIf not, see . +# +############################################################################## +''' +Created on Nov 16, 2019 + +@author: mboscolo +''' +import logging +import datetime +from odoo import models +from odoo import fields +from odoo import api +from odoo import _ +from odoo.exceptions import UserError +from datetime import timedelta +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT + + +class MailActivitySchedule(models.TransientModel): + _inherit = 'mail.activity.schedule' + + + plm_state = fields.Selection([ + ('draft', _('draft')), + ('in_progress', _('In Progress')), + ('eco', _('Change Order')), + ('done', _('Done')), + ('cancel', _('Cancel')), + ('exception', _('Exception')), + ], + default='draft', + string=_('Plm State')) + children_ids = fields.One2many('mail.activity.children.rel.shedule', + 'mail_parent_activity_id', + _('ECR Activities')) + name = fields.Char('Name') + change_activity_type = fields.Selection(related='activity_type_id.change_activity_type') + has_parent = fields.Boolean(_('Has parent ECR'), compute="_compute_has_parent_ecr", store=True) + has_parent_eco = fields.Boolean(_('Has parent ECO'), compute="_compute_has_parent_eco", store=True) + eco_child_ids = fields.One2many('mail.activity.schedule', + 'mail_parent_eco_activity_id', + _('ECO Activities')) + mail_parent_eco_activity_id = fields.Many2one('mail.activity.schedule', _('ECO Parent Activity')) + default_plm_activity = fields.Many2one('mail.activity.type', compute='_compute_mail_activity_type') + is_eco = fields.Boolean(_('Is ECO')) + + def _compute_mail_activity_type(self): + for activity_id in self: + activity_id.default_plm_activity = self.env.ref('plm.mail_activity_plm_activity') + + def getParentECRActivity(self, activity_id): + parent_activity = self.env['mail.activity.children.rel.shedule'].search([('mail_children_activity_id', '=', activity_id.id)]) + return parent_activity.mapped('mail_parent_activity_id') + + def getParentECOActivity(self, activity_id): + return activity_id.mail_parent_eco_activity_id + + @api.depends('children_ids') + def _compute_has_parent_ecr(self): + for activity_id in self: + activities = self.getParentECRActivity(activity_id) + if not activities: + activity_id.has_parent = False + else: + activity_id.has_parent = True + + @api.depends('children_ids') + def _compute_has_parent_eco(self): + for activity_id in self: + activities = self.getParentECOActivity(activity_id) + if not activities: + activity_id.has_parent_eco = False + else: + activity_id.has_parent_eco = True + + @api.onchange('activity_type_id') + def changeActivityTypeId(self): + for activity_id in self: + activity_ids = [] + if activity_id.isCustomType(): + for user_id in activity_id.activity_type_id.activity_user_ids: + vals = { + 'name': '%s - %s' % (activity_id.activity_type_id.name, user_id.name), + 'user_id': user_id.id, + 'mail_children_activity_id': False, + } + rel_id = self.env['mail.activity.children.rel.shedule'].create(vals) + activity_ids.append(rel_id.id) + activity_id.write({ + 'children_ids': [(6, False, activity_ids)] + }) + + def write(self, vals): + ret = super(MailActivitySchedule, self).write(vals) + for activity_id in self: + if self.env.user.has_group('activity_validation.group_force_activity_validation_admin'): + return ret + if activity_id.plm_state == 'done' and 'plm_state' not in vals: + raise UserError('You cannot modify a confirmed activity') + return ret + + def checkConfirmed(self, check=False): + if self.env.user.has_group('activity_validation.group_force_activity_validation_admin'): + return + for activity_id in self: + if check and activity_id.plm_state not in ['done', 'eco']: + raise UserError('Cannot confirm activity because some activities are not done.') + for child in activity_id.children_ids: + child.mail_children_activity_id.checkConfirmed(True) + + def action_done(self): + ret = super(MailActivitySchedule, self).action_done() + if self.exists(): + self.checkConfirmed() + self.plm_state = 'done' + return ret + + def action_done_schedule_next(self): + ret = super(MailActivitySchedule, self).action_done_schedule_next() + if self.exists(): + self.checkConfirmed() + self.plm_state = 'done' + return ret + + def action_feedback(self, feedback=False, attachment_ids=None): + for activity_id in self: + if activity_id.exists(): + activity_id.plm_state = 'done' + if activity_id.mail_parent_eco_activity_id: + close = True + for child in activity_id.mail_parent_eco_activity_id.eco_child_ids: + if child.plm_state != 'done': + close = False + if close: + activity_id.mail_parent_eco_activity_id.action_to_eco() + ret = super(MailActivitySchedule, self).action_feedback(feedback, attachment_ids) + return ret + + def activity_format(self): + out = [] + for res_dict in super(MailActivitySchedule, self).activity_format(): + if res_dict.get('plm_state', 'draft') not in ['done', 'cancel']: + out.append(res_dict) + return out + + def isCustomType(self): + for activity_id in self: + if activity_id.activity_type_id.change_activity_type in ['request', 'plm_activity']: + return True + return False + + def unlink(self): + for activity_id in self: + if activity_id.isCustomType(): + if not self.env.su: + return + return super(MailActivitySchedule, self).unlink() + + def clearChildrenActivities(self): + for child_id in self.children_ids: + for child_rel in child_id.mail_children_activity_id.sudo(): + if child_rel.mail_children_activity_id.plm_state == 'draft': + child_rel.mail_children_activity_id.unlink() + child_rel.unlink() + + def action_to_draft(self): + self.clearChildrenActivities() + self.changeActivityTypeId() + for activity_id in self: + activity_id.plm_state = 'draft' + return self.reopenActivity(activity_id.id) + + def action_to_done(self): + for activity_id in self: + activity_id.plm_state = 'done' + if activity_id.is_eco: + self.checkChildrenECODone(activity_id) + parents = self.getParentECOActivity(activity_id) + else: + self.checkChildrenECRDone(activity_id) + parents = self.getParentECRActivity(activity_id) + close = True + if parents.children_ids: + for child_activity_id in parents.children_ids: + if child_activity_id.plm_state != 'done': + close = False + if close: + parents._action_done() + else: + activity_id._action_done() + + def action_to_exception(self): + for activity_id in self: + activity_id.plm_state = 'exception' + if not activity_id.is_eco: + parents = self.getParentECRActivity(activity_id) + else: + parents = self.getParentECOActivity(activity_id) + parents.plm_state = 'exception' + return self.reopenActivity(activity_id.id) + + def action_to_cancel(self): + for activity_id in self: + activity_id.plm_state = 'cancel' + self.cancelChildrenECO(activity_id) + self.cancelChildrenECR(activity_id) + activity_id._action_done() + + def cancelChildrenECR(self, activity_id): + for child in activity_id.children_ids: + if child.plm_state not in ['done', 'cancel']: + child.action_to_cancel() + + def cancelChildrenECO(self, activity_id): + for child in activity_id.children_ids: + if child.plm_state not in ['done', 'cancel']: + child.mail_children_activity_id.action_to_cancel() + + def checkChildrenECODone(self, activity_id): + do_eco = True + for child in activity_id.eco_child_ids: + if child.plm_state not in ['done', 'cancel']: + do_eco = False + if not do_eco: + raise UserError(_('You cannot move to Done because there are pending ECO activities.')) + + def checkChildrenECRDone(self, activity_id): + do_ecr = True + for child in activity_id.children_ids: + if child.plm_state not in ['done', 'cancel']: + do_ecr = False + if not do_ecr: + raise UserError(_('You cannot move to ECO or to Done because there are pending ECR activities.')) + + def action_to_eco(self): + for activity_id in self: + self.checkChildrenECRDone(activity_id) + activity_id.plm_state = 'eco' + activity_id.is_eco = True + + def action_in_progress(self): + for activity_id in self: + for line_id in activity_id.children_ids: + if not line_id.mail_children_activity_id: + activity_vals = { + 'activity_type_id': activity_id.activity_type_id.id, + 'date_deadline': activity_id.date_deadline, + 'user_id': line_id.user_id.id, + 'plm_state': 'draft', + 'name': line_id.name, + 'note': line_id.name, + 'res_model_id': activity_id.res_model_id.id, + 'res_id': activity_id.res_id, + } + new_activity_id = self.create(activity_vals) + line_id.mail_children_activity_id = new_activity_id.id + line_id.mail_parent_activity_id = activity_id.id + activity_id.plm_state = 'in_progress' + return self.reopenActivity(activity_id.id) + + def reopenActivity(self, res_id): + out_act_dict = {'name': _('Activity'), + 'view_type': 'form', + 'target': 'new', + 'res_model': 'mail.activity', + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_id': res_id} + return out_act_dict + + def action_open_releted_ent(self): + for activity in self: + return {'name': activity.display_name, + 'view_type': 'form', + 'target': 'new', + 'res_model': activity.res_model, + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_id': activity.res_id} + return {} + + + def name_get(self): + out = [] + for activity in self: + name = '%s | %s' % (activity.summary or activity.activity_type_id.display_name, activity.user_id.display_name or '') + out.append((activity.id, name)) + return out \ No newline at end of file diff --git a/activity_validation/security/security.xml b/activity_validation/security/security.xml index 7b992427..687e918d 100755 --- a/activity_validation/security/security.xml +++ b/activity_validation/security/security.xml @@ -52,6 +52,24 @@ + + Mail activity validation admin + + + + + + + + + Mail activity validation admin + + + + + + + diff --git a/activity_validation/static/src/js/systray_activity_menu.js b/activity_validation/static/src/js/systray_activity_menu.js deleted file mode 100644 index 31caba3c..00000000 --- a/activity_validation/static/src/js/systray_activity_menu.js +++ /dev/null @@ -1,40 +0,0 @@ -odoo.define('activity_validation.systray.ActivityMenu', function (require) { -"use strict"; - -var session = require('web.session'); - -var ActivityMenuH = require('mail.systray.ActivityMenu'); - -ActivityMenuH.include({ - /** - * Redirect to particular model view - * @private - * @param {MouseEvent} event - */ - _onActivityFilterClick: function (event) { - // fetch the data from the button otherwise fetch the ones from the parent (.o_mail_preview). - var data = _.extend({}, $(event.currentTarget).data(), $(event.target).data()); - var context = {}; - if (data.filter === 'my') { - context['search_default_activities_overdue'] = 1; - context['search_default_activities_today'] = 1; - } else { - context['search_default_activities_' + data.filter] = 1; - } - // Necessary because activity_ids of mail.activity.mixin has auto_join - // So, duplicates are faking the count and "Load more" doesn't show up - context['force_search_count'] = 1; - context['from_activity_counter'] = 1; - this.do_action({ - type: 'ir.actions.act_window', - name: data.model_name, - res_model: data.res_model, - views: [[false, 'kanban'], [false, 'list'], [false, 'form']], - search_view_id: [false], - domain: [['activity_user_id', '=', session.uid]], - context:context, - }); - }, -}); - -}); \ No newline at end of file diff --git a/activity_validation/static/src/xml/import_js.xml b/activity_validation/static/src/xml/import_js.xml deleted file mode 100755 index 71b5aef3..00000000 --- a/activity_validation/static/src/xml/import_js.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/activity_validation/views/mail_activity.xml b/activity_validation/views/mail_activity.xml index ffea7fae..118c5dc7 100755 --- a/activity_validation/views/mail_activity.xml +++ b/activity_validation/views/mail_activity.xml @@ -2,7 +2,7 @@ - + mail.activity.view.tree.activity.validation mail.activity @@ -13,6 +13,104 @@ + + plm.mail.activity.schedule.view.form.inherit + mail.activity.schedule + + + + + + +
+
+ +
+
+ +
+ + + + +
+
+ mail.activity.inherit mail.activity @@ -20,27 +118,40 @@ -
-

@@ -53,8 +164,13 @@
-