From aba0acec435aa0a4c0404e6cffaeb095c845ef86 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 12 Dec 2017 17:07:32 +0800 Subject: [PATCH 01/16] [ADD][BR1228][T24770]extra_time_application --- extra_time_application/README.rst | 57 ++++++++++++++ extra_time_application/__init__.py | 6 ++ extra_time_application/__manifest__.py | 24 ++++++ extra_time_application/models/__init__.py | 4 + .../models/project_task_inherit.py | 77 +++++++++++++++++++ .../models/task_timesheet.py | 35 +++++++++ .../extra_time_application_security.xml | 7 ++ .../security/ir.model.access.csv | 3 + .../views/extra_time_approve_view.xml | 69 +++++++++++++++++ .../views/project_task_form_inherit.xml | 21 +++++ extra_time_application/wizard/__init__.py | 3 + .../wizard/extra_time_application_wizard.py | 75 ++++++++++++++++++ .../wizard/time_prompt_view.xml | 46 +++++++++++ 13 files changed, 427 insertions(+) create mode 100644 extra_time_application/README.rst create mode 100644 extra_time_application/__init__.py create mode 100644 extra_time_application/__manifest__.py create mode 100644 extra_time_application/models/__init__.py create mode 100644 extra_time_application/models/project_task_inherit.py create mode 100644 extra_time_application/models/task_timesheet.py create mode 100644 extra_time_application/security/extra_time_application_security.xml create mode 100644 extra_time_application/security/ir.model.access.csv create mode 100644 extra_time_application/views/extra_time_approve_view.xml create mode 100644 extra_time_application/views/project_task_form_inherit.xml create mode 100644 extra_time_application/wizard/__init__.py create mode 100644 extra_time_application/wizard/extra_time_application_wizard.py create mode 100644 extra_time_application/wizard/time_prompt_view.xml diff --git a/extra_time_application/README.rst b/extra_time_application/README.rst new file mode 100644 index 00000000..62f6c9f3 --- /dev/null +++ b/extra_time_application/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +====================== +Extra Time Application +====================== + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Elico Corp: `Icon `_. + +Contributors +------------ + +* Miya Xing + + +Maintainer +---------- + +.. image:: https://www.elico-corp.com/logo.png + :alt: Elico Corp + :target: https://www.elico-corp.com + +This module is maintained by Elico Corporation. + +Elico Corp is an innovative actor in China, Hong-Kong and Singapore servicing +well known international companies and as well as local mid-sized businesses. +Since 2010, our seasoned Sino-European consultants have been providing full +range Odoo services: + +* Business consultancy for Gap analysis, BPM, operational work-flows review. +* Ready-to-use ERP packages aimed at starting businesses. +* Odoo implementation for manufacturing, international trading, service industry + and e-commerce. +* Connectors and integration with 3rd party software (Magento, Taobao, Coswin, + Joomla, Prestashop, Tradevine etc...). +* Odoo Support services such as developments, training, maintenance and hosting. + +Our headquarters are located in Shanghai with branch in Singapore servicing +customers from all over Asia Pacific. + +Contact information: `Sales `__ + diff --git a/extra_time_application/__init__.py b/extra_time_application/__init__.py new file mode 100644 index 00000000..dc167772 --- /dev/null +++ b/extra_time_application/__init__.py @@ -0,0 +1,6 @@ +# -*-coding: utf-8 -*- +# © 2016-2017 Elico Corp (https://www.elico-corp.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models +from . import wizard \ No newline at end of file diff --git a/extra_time_application/__manifest__.py b/extra_time_application/__manifest__.py new file mode 100644 index 00000000..d0765522 --- /dev/null +++ b/extra_time_application/__manifest__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (https://www.elico-corp.com) +# Elico Proprietary License v1.0. +# See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Extra Time Application', + 'version': '10.0.1.0.0', + 'author': "Elico Corp", + 'website': 'https://www.elico-corp.com', + 'license': 'Other proprietary', + 'support': 'https://support@elico-corp.com', + 'depends': [ + 'project', + ], + 'data': [ + 'wizard/time_prompt_view.xml', + 'views/extra_time_approve_view.xml', + 'views/project_task_form_inherit.xml', + 'security/extra_time_application_security.xml', + 'security/ir.model.access.csv', + ], + 'installable': True +} diff --git a/extra_time_application/models/__init__.py b/extra_time_application/models/__init__.py new file mode 100644 index 00000000..1fccab42 --- /dev/null +++ b/extra_time_application/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding:utf-8 -*- + +from . import task_timesheet +from . import project_task_inherit diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py new file mode 100644 index 00000000..af816a42 --- /dev/null +++ b/extra_time_application/models/project_task_inherit.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import api, fields, models,_ +from odoo.exceptions import UserError +from lxml import etree + +class ProjectTaskInherit(models.Model): + _inherit = 'project.task' + + sub_extra_time = fields.Float( + 'Extra Time',help='the sum of the extra time', + default='0', + ) + + @api.multi + def write(self, vals): + remaining = self.remaining_hours + for record in vals.get('timesheet_ids'): + if record[0] == 0: + remaining -= record[2]['unit_amount'] + elif record[0] == 2: + item = self.timesheet_ids.search([ + ('id','=',record[1]) + ]) + remaining += item['unit_amount'] + if remaining < 0: + raise UserError( + _('The task have no enough time, please Apply for more extra time')) + res = super(ProjectTaskInherit, self).write(vals) + return res + + @api.multi + def open_extra_time_line(self): + for record in self: + print record + domain = [('task_no', '=', record.name)] + return { + 'name': _('Extra Time Approve'), + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'tree', + 'res_model': 'extra.time.application', + 'target': 'current', + 'domain': domain, + } + + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + res = super(ProjectTaskInherit, self).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, + submenu=submenu) + # if view_type == 'form': + # dom = etree.XML(res['arch']) + # for node in dom.xpath("//field[@name='remaining_hours']"): + # node.set("modifiers", '{"readonly": False}') + # res['arch'] = etree.tostring(dom) + return res + + +# @api.model +# def fields_view_get(self, view_id=None, view_type='form',toolbar=False, submenu=False): +# """Override method to change the modifier based on logged in user""" +# res = super(WsOverview, self). +# fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,submenu=submenu) +# user_id = self.env['res.users'].browse(self._uid) +# dom = etree.XML(res['arch']) +# if user_id.has_group('crm_waste_application.waste_application_portal_user') +# \and not user_id.has_group('crm_waste_application.waste_application_user'): +# for node in dom.xpath("//field[@name='partner_id']"): +# node.set("modifiers", '{"readonly": true}') +# for node1 in dom.xpath("//field[@name='user_id']"): +# node1.set("modifiers", '{"readonly": true}') +# for node in dom.xpath("//field[@name='suez_number']"): +# node.set("modifiers", '{"readonly": true}') +# res['arch'] = etree.tostring(dom) +# return res \ No newline at end of file diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py new file mode 100644 index 00000000..572c642c --- /dev/null +++ b/extra_time_application/models/task_timesheet.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import api, fields, models +from odoo.exceptions import UserError + + +class TaskTimeSheet(models.Model): + _name = 'extra.time.application' + _inherit = ['mail.thread', 'ir.needaction_mixin'] + + submit_user_id = fields.Many2one( + 'res.users', 'Applicant', help='Applicant', + ) + task_no = fields.Many2one('project.task', 'Task No', help='Task No') + reason = fields.Text('Reason', help='the reason of apply') + apply_hours = fields.Float('Apply Hours', help='the length of apply time') + state = fields.Selection([ + ('to_approve', 'To Approve'), + ('approve', 'Approved'), + ('refused', 'Refused'), + ]) + + @api.one + def approve_function(self): + if self.state == 'to_approve': + self.task_no.remaining_hours += self.apply_hours + self.task_no.sub_extra_time += self.apply_hours + self.state = 'approve' + + @api.one + def refuse_function(self): + self.state = 'refused' + + diff --git a/extra_time_application/security/extra_time_application_security.xml b/extra_time_application/security/extra_time_application_security.xml new file mode 100644 index 00000000..648f25e0 --- /dev/null +++ b/extra_time_application/security/extra_time_application_security.xml @@ -0,0 +1,7 @@ + + + + Time Application Manager + + + \ No newline at end of file diff --git a/extra_time_application/security/ir.model.access.csv b/extra_time_application/security/ir.model.access.csv new file mode 100644 index 00000000..03db99b2 --- /dev/null +++ b/extra_time_application/security/ir.model.access.csv @@ -0,0 +1,3 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +access_project_task_manager,project_task_manager,project.model_project_task,extra_time_application.group_project_task_manager,1,1,1,1 + diff --git a/extra_time_application/views/extra_time_approve_view.xml b/extra_time_application/views/extra_time_approve_view.xml new file mode 100644 index 00000000..ce7be0ff --- /dev/null +++ b/extra_time_application/views/extra_time_approve_view.xml @@ -0,0 +1,69 @@ + + + + extra.time.approve.form + extra.time.application + form + +
+
+
+ + + + + + + + + + + + + + + + + +
+
+ + +
+
+
+ + + extra.time.approve.tree + extra.time.application + + + + + + + + + + + + + Extra Time Approve + ir.actions.act_window + extra.time.application + form + form,tree + + + + + +
\ No newline at end of file diff --git a/extra_time_application/views/project_task_form_inherit.xml b/extra_time_application/views/project_task_form_inherit.xml new file mode 100644 index 00000000..c3c88641 --- /dev/null +++ b/extra_time_application/views/project_task_form_inherit.xml @@ -0,0 +1,21 @@ + + + + project.task.form + project.task + + + + + + + + \ No newline at end of file diff --git a/extra_time_application/wizard/__init__.py b/extra_time_application/wizard/__init__.py new file mode 100644 index 00000000..f05e90a1 --- /dev/null +++ b/extra_time_application/wizard/__init__.py @@ -0,0 +1,3 @@ +# -*- coding:utf-8 -*- + +from . import extra_time_application_wizard diff --git a/extra_time_application/wizard/extra_time_application_wizard.py b/extra_time_application/wizard/extra_time_application_wizard.py new file mode 100644 index 00000000..a26f29b6 --- /dev/null +++ b/extra_time_application/wizard/extra_time_application_wizard.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import fields, models,api + +class TimePromptBox(models.TransientModel): + _name = 'extra.time.application.wizard' + + @api.model + def _get_task_no(self): + return self.env['project.task'].browse( + self._context.get('active_id') + ) + + submit_user_id = fields.Many2one( + 'res.users','Applicant',help='Applicant', + default=lambda self: self.env.user + ) + task_no = fields.Many2one('project.task','Task No',help='Task No', + default=_get_task_no + ) + reason = fields.Text('Reason', help='the reason of apply') + apply_hours = fields.Float('Apply Hours',help='the length of apply time') + state = fields.Selection([ + ('to_approve','To Approve'), + ('approve','Approved'), + ('refused','Refused'), + ]) + + + def subscribe(self): + user = self.env.user + is_exist = user.has_group('extra_time_application.group_project_task_manager') + if is_exist: + self.env['extra.time.application'].create({ + 'submit_user_id':self.submit_user_id.id, + 'task_no':self.task_no.id, + 'reason':'Automaticity create From PM or Reviewer', + 'apply_hours':self.apply_hours, + 'state':'approve', + }) + self.task_no.remaining_hours += self.apply_hours + self.task_no.sub_extra_time += self.apply_hours + mail = self.env['mail.mail'].create({ + 'body_html': 'apply time:' + str( + self.apply_hours) + '
reason:' + + self.reason + '
Task:' + str(self.task_no.code), + 'email_to': 'test@example.com', + 'subject': 'Apply Time', + }) + mail.send() + + else: + mail = self.env['mail.mail'].create({ + 'body_html': 'apply time:' + str( + self.apply_hours) + '
reason:' + + self.reason + '
Task:' + self.task_no, + 'email_to': 'test@example.com', + 'subject': 'Apply Time', + }) + mail.send() + self.env['extra.time.application'].create({ + 'submit_user_id': self.submit_user_id.id, + 'task_no': self.task_no.id, + 'reason': self.reason, + 'apply_hours': self.apply_hours, + 'state': 'to_approve', + }) + + + + + + + diff --git a/extra_time_application/wizard/time_prompt_view.xml b/extra_time_application/wizard/time_prompt_view.xml new file mode 100644 index 00000000..a7c1e148 --- /dev/null +++ b/extra_time_application/wizard/time_prompt_view.xml @@ -0,0 +1,46 @@ + + + + + view.time.prompt.form + extra.time.application.wizard + form + +
+ + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Time Application + ir.actions.act_window + extra.time.application.wizard + form + form + new + + + + +
\ No newline at end of file From 126fc0f9d94682be4927b7d8077a7cd50a37989e Mon Sep 17 00:00:00 2001 From: xlm609 Date: Wed, 13 Dec 2017 17:21:51 +0800 Subject: [PATCH 02/16] [FIX]make module more intact --- extra_time_application/models/__init__.py | 1 + .../models/project_project_inherit.py | 9 +++ .../models/project_task_inherit.py | 68 +++++++++++-------- .../models/task_timesheet.py | 3 - .../extra_time_application_security.xml | 13 ++++ .../security/ir.model.access.csv | 3 +- extra_time_application/test/__init__.py | 0 .../test/test_extra_time.py | 0 .../test/test_project_task_save.py | 0 .../views/extra_time_approve_view.xml | 8 +-- .../views/project_task_form_inherit.xml | 17 ++++- .../wizard/extra_time_application_wizard.py | 49 +++++-------- .../wizard/time_prompt_view.xml | 4 +- 13 files changed, 102 insertions(+), 73 deletions(-) create mode 100644 extra_time_application/models/project_project_inherit.py create mode 100644 extra_time_application/test/__init__.py create mode 100644 extra_time_application/test/test_extra_time.py create mode 100644 extra_time_application/test/test_project_task_save.py diff --git a/extra_time_application/models/__init__.py b/extra_time_application/models/__init__.py index 1fccab42..9af443d6 100644 --- a/extra_time_application/models/__init__.py +++ b/extra_time_application/models/__init__.py @@ -2,3 +2,4 @@ from . import task_timesheet from . import project_task_inherit +from . import project_project_inherit diff --git a/extra_time_application/models/project_project_inherit.py b/extra_time_application/models/project_project_inherit.py new file mode 100644 index 00000000..30d7109c --- /dev/null +++ b/extra_time_application/models/project_project_inherit.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com). +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import fields, models + +class ProjectProjectInherit(models.Model): + _inherit='project.project' + + is_modified = fields.Boolean() diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index af816a42..412856c3 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -1,32 +1,54 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (www.elico-corp.com). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models,_ +from openerp import api, fields, models, _ from odoo.exceptions import UserError from lxml import etree + class ProjectTaskInherit(models.Model): _inherit = 'project.task' sub_extra_time = fields.Float( - 'Extra Time',help='the sum of the extra time', + 'Extra Time', help='the sum of the extra time', default='0', ) @api.multi def write(self, vals): + user = self.env.user + is_exist = user.has_group( + 'extra_time_application.group_project_task_manager') remaining = self.remaining_hours - for record in vals.get('timesheet_ids'): + if vals.get('remaining_time'): + self.env['extra.time.application'].create({ + 'submit_user_id': self.submit_user_id.id, + 'task_no': self.task_no.id, + 'reason': 'Automaticity create From PM or Reviewer', + 'apply_hours': self.apply_hours, + 'state': 'approve', + }) + self.task_no.sub_extra_time += \ + vals.get('remaining_hours') - self.apply_hours + for record in vals.get('timesheet_ids', []): if record[0] == 0: remaining -= record[2]['unit_amount'] elif record[0] == 2: item = self.timesheet_ids.search([ - ('id','=',record[1]) + ('id', '=', record[1]) ]) remaining += item['unit_amount'] if remaining < 0: raise UserError( - _('The task have no enough time, please Apply for more extra time')) + _( + 'The task have no enough time, ' + 'please Apply for more extra time' + )) + if not vals.get('project_id.is_modified'): + if not is_exist and self.project_id.user_id != user: + raise UserError( + _( + 'You do not have permission')) res = super(ProjectTaskInherit, self).write(vals) return res @@ -46,32 +68,18 @@ def open_extra_time_line(self): } @api.model - def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False): + def fields_view_get(self, view_id=None, view_type='form', + toolbar=False, submenu=False): res = super(ProjectTaskInherit, self).fields_view_get( view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu) - # if view_type == 'form': - # dom = etree.XML(res['arch']) - # for node in dom.xpath("//field[@name='remaining_hours']"): - # node.set("modifiers", '{"readonly": False}') - # res['arch'] = etree.tostring(dom) + dom = etree.XML(res['arch']) + if view_type == 'form': + user = self.env.user + is_exist = user.has_group( + 'extra_time_application.group_project_task_manager') + if is_exist or self.project_id.is_modified: + for node in dom.xpath("//field[@name='remaining_hours']"): + node.set("modifiers", '{"readonly": false}') + res['arch'] = etree.tostring(dom) return res - - -# @api.model -# def fields_view_get(self, view_id=None, view_type='form',toolbar=False, submenu=False): -# """Override method to change the modifier based on logged in user""" -# res = super(WsOverview, self). -# fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar,submenu=submenu) -# user_id = self.env['res.users'].browse(self._uid) -# dom = etree.XML(res['arch']) -# if user_id.has_group('crm_waste_application.waste_application_portal_user') -# \and not user_id.has_group('crm_waste_application.waste_application_user'): -# for node in dom.xpath("//field[@name='partner_id']"): -# node.set("modifiers", '{"readonly": true}') -# for node1 in dom.xpath("//field[@name='user_id']"): -# node1.set("modifiers", '{"readonly": true}') -# for node in dom.xpath("//field[@name='suez_number']"): -# node.set("modifiers", '{"readonly": true}') -# res['arch'] = etree.tostring(dom) -# return res \ No newline at end of file diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index 572c642c..7d3e07ec 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -2,7 +2,6 @@ # © 2017 Elico Corp (www.elico-corp.com). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import api, fields, models -from odoo.exceptions import UserError class TaskTimeSheet(models.Model): @@ -31,5 +30,3 @@ def approve_function(self): @api.one def refuse_function(self): self.state = 'refused' - - diff --git a/extra_time_application/security/extra_time_application_security.xml b/extra_time_application/security/extra_time_application_security.xml index 648f25e0..2cb3063a 100644 --- a/extra_time_application/security/extra_time_application_security.xml +++ b/extra_time_application/security/extra_time_application_security.xml @@ -4,4 +4,17 @@ Time Application Manager + + Time Application User + + + Extra Time Manager + + + + + extra time rule + + [('submit_user_id','=',user.id)] + \ No newline at end of file diff --git a/extra_time_application/security/ir.model.access.csv b/extra_time_application/security/ir.model.access.csv index 03db99b2..63579bdc 100644 --- a/extra_time_application/security/ir.model.access.csv +++ b/extra_time_application/security/ir.model.access.csv @@ -1,3 +1,4 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" access_project_task_manager,project_task_manager,project.model_project_task,extra_time_application.group_project_task_manager,1,1,1,1 - +access_project_task_user,project_task_user,project.model_project_task,extra_time_application.group_project_task_user,1,0,0,0 +access_extra_time_manager,extra_time_manager,extra_time_application.model_extra_time_application,extra_time_application.group_extra_time_manager,1,1,1,1 \ No newline at end of file diff --git a/extra_time_application/test/__init__.py b/extra_time_application/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/extra_time_application/test/test_extra_time.py b/extra_time_application/test/test_extra_time.py new file mode 100644 index 00000000..e69de29b diff --git a/extra_time_application/test/test_project_task_save.py b/extra_time_application/test/test_project_task_save.py new file mode 100644 index 00000000..e69de29b diff --git a/extra_time_application/views/extra_time_approve_view.xml b/extra_time_application/views/extra_time_approve_view.xml index ce7be0ff..fe303902 100644 --- a/extra_time_application/views/extra_time_approve_view.xml +++ b/extra_time_application/views/extra_time_approve_view.xml @@ -1,6 +1,6 @@ - + extra.time.approve.form extra.time.application form @@ -12,7 +12,7 @@ type="object" class="oe_highlight o_expense_submit"/> -
+ @@ -38,11 +38,11 @@ - + extra.time.approve.tree extra.time.application - + diff --git a/extra_time_application/views/project_task_form_inherit.xml b/extra_time_application/views/project_task_form_inherit.xml index c3c88641..e31936fd 100644 --- a/extra_time_application/views/project_task_form_inherit.xml +++ b/extra_time_application/views/project_task_form_inherit.xml @@ -12,10 +12,23 @@ + + project.project.form + project.project + + + +
+ +
+
+
+
\ No newline at end of file diff --git a/extra_time_application/wizard/extra_time_application_wizard.py b/extra_time_application/wizard/extra_time_application_wizard.py index a26f29b6..9447b9be 100644 --- a/extra_time_application/wizard/extra_time_application_wizard.py +++ b/extra_time_application/wizard/extra_time_application_wizard.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (www.elico-corp.com). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import fields, models,api +from openerp import fields, models, api + class TimePromptBox(models.TransientModel): _name = 'extra.time.application.wizard' @@ -13,49 +14,42 @@ def _get_task_no(self): ) submit_user_id = fields.Many2one( - 'res.users','Applicant',help='Applicant', + 'res.users', 'Applicant', help='Applicant', default=lambda self: self.env.user ) - task_no = fields.Many2one('project.task','Task No',help='Task No', + task_no = fields.Many2one('project.task', 'Task No', help='Task No', default=_get_task_no ) reason = fields.Text('Reason', help='the reason of apply') - apply_hours = fields.Float('Apply Hours',help='the length of apply time') + apply_hours = fields.Float('Apply Hours', help='the length of apply time') state = fields.Selection([ - ('to_approve','To Approve'), - ('approve','Approved'), - ('refused','Refused'), + ('to_approve', 'To Approve'), + ('approve', 'Approved'), + ('refused', 'Refused'), ]) - def subscribe(self): user = self.env.user - is_exist = user.has_group('extra_time_application.group_project_task_manager') + is_exist = user.has_group( + 'extra_time_application.group_project_task_manager') if is_exist: self.env['extra.time.application'].create({ - 'submit_user_id':self.submit_user_id.id, - 'task_no':self.task_no.id, - 'reason':'Automaticity create From PM or Reviewer', - 'apply_hours':self.apply_hours, - 'state':'approve', + 'submit_user_id': self.submit_user_id.id, + 'task_no': self.task_no.id, + 'reason': 'Automaticity create From PM or Reviewer', + 'apply_hours': self.apply_hours, + 'state': 'approve', }) self.task_no.remaining_hours += self.apply_hours self.task_no.sub_extra_time += self.apply_hours - mail = self.env['mail.mail'].create({ - 'body_html': 'apply time:' + str( - self.apply_hours) + '
reason:' - + self.reason + '
Task:' + str(self.task_no.code), - 'email_to': 'test@example.com', - 'subject': 'Apply Time', - }) - mail.send() else: mail = self.env['mail.mail'].create({ 'body_html': 'apply time:' + str( self.apply_hours) + '
reason:' - + self.reason + '
Task:' + self.task_no, - 'email_to': 'test@example.com', + + str(self.reason) + '
Task:' + + str(self.task_no.code), + 'email_to': self.task_no.project_id.user_id.login, 'subject': 'Apply Time', }) mail.send() @@ -66,10 +60,3 @@ def subscribe(self): 'apply_hours': self.apply_hours, 'state': 'to_approve', }) - - - - - - - diff --git a/extra_time_application/wizard/time_prompt_view.xml b/extra_time_application/wizard/time_prompt_view.xml index a7c1e148..d146b793 100644 --- a/extra_time_application/wizard/time_prompt_view.xml +++ b/extra_time_application/wizard/time_prompt_view.xml @@ -10,10 +10,10 @@ - + - + From 1135ecb0e0e8e09399606d27d5defca0436d81a7 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Thu, 14 Dec 2017 18:56:17 +0800 Subject: [PATCH 03/16] [ADD]add test --- extra_time_application/__init__.py | 3 +- .../models/project_task_inherit.py | 56 ++++++++-------- .../models/task_timesheet.py | 32 ++++++++- .../extra_time_application_security.xml | 1 - .../security/ir.model.access.csv | 5 +- extra_time_application/test/__init__.py | 4 ++ .../test/test_extra_time.py | 27 ++++++++ .../test/test_extra_time_wizard.py | 29 ++++++++ .../test/test_project_task_save.py | 67 +++++++++++++++++++ .../views/extra_time_approve_view.xml | 3 +- .../wizard/extra_time_application_wizard.py | 10 +-- 11 files changed, 194 insertions(+), 43 deletions(-) create mode 100644 extra_time_application/test/test_extra_time_wizard.py diff --git a/extra_time_application/__init__.py b/extra_time_application/__init__.py index dc167772..619ab64c 100644 --- a/extra_time_application/__init__.py +++ b/extra_time_application/__init__.py @@ -3,4 +3,5 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models -from . import wizard \ No newline at end of file +from . import wizard +from . import test \ No newline at end of file diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index 412856c3..e8080a9e 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -20,42 +20,42 @@ def write(self, vals): is_exist = user.has_group( 'extra_time_application.group_project_task_manager') remaining = self.remaining_hours - if vals.get('remaining_time'): - self.env['extra.time.application'].create({ - 'submit_user_id': self.submit_user_id.id, - 'task_no': self.task_no.id, - 'reason': 'Automaticity create From PM or Reviewer', - 'apply_hours': self.apply_hours, - 'state': 'approve', - }) - self.task_no.sub_extra_time += \ - vals.get('remaining_hours') - self.apply_hours - for record in vals.get('timesheet_ids', []): - if record[0] == 0: - remaining -= record[2]['unit_amount'] - elif record[0] == 2: - item = self.timesheet_ids.search([ - ('id', '=', record[1]) - ]) - remaining += item['unit_amount'] - if remaining < 0: - raise UserError( - _( - 'The task have no enough time, ' - 'please Apply for more extra time' - )) - if not vals.get('project_id.is_modified'): - if not is_exist and self.project_id.user_id != user: + if not self.env.context.get('flag'): + if vals.get('remaining_hours') and not vals.get('timesheet_ids'): + self.env['extra.time.application'].create({ + 'submit_user_id': user.id, + 'task_no': self.id, + 'reason': 'Automaticity create From PM or Reviewer', + 'apply_hours': vals.get('remaining_hours') - self.remaining_hours, + 'state': 'approve', + }) + self.sub_extra_time += \ + (vals.get('remaining_hours') - self.remaining_hours) + for record in vals.get('timesheet_ids', []): + if record[0] == 0: + remaining -= record[2]['unit_amount'] + elif record[0] == 2: + item = self.timesheet_ids.search([ + ('id', '=', record[1]) + ]) + remaining += item['unit_amount'] + if remaining < 0: raise UserError( _( - 'You do not have permission')) + 'The task have no enough time, ' + 'please Apply for more extra time' + )) + if not vals.get('project_id.is_modified'): + if not is_exist and self.project_id.user_id != user: + raise UserError( + _( + 'You do not have permission')) res = super(ProjectTaskInherit, self).write(vals) return res @api.multi def open_extra_time_line(self): for record in self: - print record domain = [('task_no', '=', record.name)] return { 'name': _('Extra Time Approve'), diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index 7d3e07ec..c18209c4 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -18,15 +18,43 @@ class TaskTimeSheet(models.Model): ('to_approve', 'To Approve'), ('approve', 'Approved'), ('refused', 'Refused'), - ]) + ],track_visibility='onchange',defaule='to_approve') @api.one def approve_function(self): if self.state == 'to_approve': - self.task_no.remaining_hours += self.apply_hours + self.with_context(flag='True').task_no.remaining_hours += self.apply_hours self.task_no.sub_extra_time += self.apply_hours self.state = 'approve' + self.message_post(body=(' Approved:%s'%self.env.user.name)) @api.one def refuse_function(self): self.state = 'refused' + + @api.model + def create(self, vals): + msg_followers = [] + for user in self.env.ref('extra_time_application.group_extra_time_manager').users: + if user != self.env['project.task'].browse(vals.get('task_no')).user_id: + msg_vals = { + 'partner_id': user.partner_id.id, + 'res_model': self._name, + } + msg_followers.append((0, 0, msg_vals)) + + + task_id = self.env['project.task']. \ + browse(vals.get('task_no')) + task_manager = task_id.project_id.user_id + if task_manager not in self.env.ref('extra_time_application.group_extra_time_manager').users and \ + task_manager != task_id.user_id: + msg_vals = { + 'partner_id': task_manager.partner_id.id, + 'res_model': self._name, + } + msg_followers.append((0, 0, msg_vals)) + if msg_followers: + vals['message_follower_ids'] = msg_followers + return super(TaskTimeSheet, self).create(vals) + diff --git a/extra_time_application/security/extra_time_application_security.xml b/extra_time_application/security/extra_time_application_security.xml index 2cb3063a..7a3bd987 100644 --- a/extra_time_application/security/extra_time_application_security.xml +++ b/extra_time_application/security/extra_time_application_security.xml @@ -11,7 +11,6 @@ Extra Time Manager
- extra time rule diff --git a/extra_time_application/security/ir.model.access.csv b/extra_time_application/security/ir.model.access.csv index 63579bdc..e3d905e5 100644 --- a/extra_time_application/security/ir.model.access.csv +++ b/extra_time_application/security/ir.model.access.csv @@ -1,4 +1,5 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" access_project_task_manager,project_task_manager,project.model_project_task,extra_time_application.group_project_task_manager,1,1,1,1 -access_project_task_user,project_task_user,project.model_project_task,extra_time_application.group_project_task_user,1,0,0,0 -access_extra_time_manager,extra_time_manager,extra_time_application.model_extra_time_application,extra_time_application.group_extra_time_manager,1,1,1,1 \ No newline at end of file +access_project_task_user,project_task_user,project.model_project_task,extra_time_application.group_project_task_user,1,1,0,0 +access_extra_time_manager,extra_time_manager,extra_time_application.model_extra_time_application,extra_time_application.group_extra_time_manager,1,1,1,1 +access_extra_time_user,extra_time_user,extra_time_application.model_extra_time_application,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/extra_time_application/test/__init__.py b/extra_time_application/test/__init__.py index e69de29b..36b4fb3b 100644 --- a/extra_time_application/test/__init__.py +++ b/extra_time_application/test/__init__.py @@ -0,0 +1,4 @@ +# -*- coding:utf-8 -*- +from . import test_extra_time +from . import test_project_task_save +from . import test_extra_time_wizard \ No newline at end of file diff --git a/extra_time_application/test/test_extra_time.py b/extra_time_application/test/test_extra_time.py index e69de29b..2d80e7ab 100644 --- a/extra_time_application/test/test_extra_time.py +++ b/extra_time_application/test/test_extra_time.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com) +# Elico Proprietary License v1.0. +# See LICENSE file for full copyright and licensing details. +from odoo.tests import common + + +class TestExtraTime(common.TransactionCase): + + def setUp(self): + super(TestExtraTime, self).setUp() + self.submit_user_id = self.env.ref("base.partner_root") + self.task_no = self.env.ref('project.project_task_9') + + self.extra_time_record = self.env['extra.time.application'].create({ + 'submit_user_id': self.submit_user_id, + 'task_no': self.task_no, + 'reason': 'Automaticity create From PM or Reviewer', + 'apply_hours': 2, + 'state': 'to_approve' + }) + + def test_approve_function(self): + self.extra_time_record.approve_function() + + def test_refuse_function(self): + self.extra_time_record.refuse_function() diff --git a/extra_time_application/test/test_extra_time_wizard.py b/extra_time_application/test/test_extra_time_wizard.py new file mode 100644 index 00000000..7c9232fa --- /dev/null +++ b/extra_time_application/test/test_extra_time_wizard.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com) +# Elico Proprietary License v1.0. +# See LICENSE file for full copyright and licensing details. +from odoo.tests import common + + +class TestExtraTimeWizard(common.TransactionCase): + + def setUp(self): + super(TestExtraTimeWizard, self).setUp() + self.task_no = self.env.ref('project_task_1') + self.submit_user_id = self.env.ref('base.user_demo') + self.extra_time_1 = self.env['extra.time.application'].create({ + 'submit_user_id': self.submit_user_id, + 'task_no': self.task_no, + 'reason': 'system test', + 'apply_hours': 3 + }) + self.extra_time_2 = self.env['extra.time.application'].create({ + 'submit_user_id': self.env.ref('base.res.partner'), + 'task_no': self.task_no, + 'reason': 'system test', + 'apply_hours': 3 + }) + + def test_subscribe(): + self.extra_time_1.subscribe() + self.extra_time_2.subscribe() diff --git a/extra_time_application/test/test_project_task_save.py b/extra_time_application/test/test_project_task_save.py index e69de29b..534fb132 100644 --- a/extra_time_application/test/test_project_task_save.py +++ b/extra_time_application/test/test_project_task_save.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com) +# Elico Proprietary License v1.0. +# See LICENSE file for full copyright and licensing details. +from odoo.tests import common + + +class TestProjectTaskSave(common.TransactionCase): + + def setUp(self): + super(TestProjectTaskSave, self).setUp() + self.name = self.env.ref('project.project_task_9') + self.project_id = self.env.ref('project.project_project_2') + self.user_id = self.env.ref('base.user_demo') + self.sub_extra_time = 0 + self.task_1 = self.env['project.task'].create({ + 'name': self.name, + 'project_id': self.project_id, + 'user_id': self.user_id.id, + 'planned_hours': 18, + 'remaining_hours': 18, + 'timesheet_ids': + [(0, 0, { + 'date': '2017-12-13', + 'name': 'test', + 'unit_amount': 2, + })] + }) + self.task_2 = self.env['project.task'].create({ + 'name': self.name, + 'project_id': self.project_id, + 'user_id': self.user_id.id, + 'planned_hours': 18, + 'remaining_hours': -1, + 'timesheet_ids': + [(0, 0, { + 'date': '2017-12-13', + 'name': 'test', + 'unit_amount': 2, + })] + }) + self.view_id = self.env.ref('project_task_form_inherit_view').id + + def test_save(self): + vals_1 = {'remaining_hours':23} + self.task_1.write(vals_1) + vals_2 = {'timesheet_ids':[[4,20,False],[0,False,{ + 'date_time': '2017-12-13 10:26:54', + 'user_id': 1, + 'name': self.name, + 'unit_amount': 2, + 'date': '2017-12-13', + 'project_id': self.project_id + }]]} + self.task_1.write(vals_2) + self.task_2.write() + + def test_open_extra_time_line(self): + res = self.task_1.open_extra_time_line() + self.assertTrue(res[1], 'error') + return res + + def test_fields_view_get(self): + self.task_1.fields_view_get(view_id=self.view_id, + view_type='form') + + diff --git a/extra_time_application/views/extra_time_approve_view.xml b/extra_time_application/views/extra_time_approve_view.xml index fe303902..133e6e49 100644 --- a/extra_time_application/views/extra_time_approve_view.xml +++ b/extra_time_application/views/extra_time_approve_view.xml @@ -12,9 +12,8 @@ type="object" class="oe_highlight o_expense_submit"/> - + - diff --git a/extra_time_application/wizard/extra_time_application_wizard.py b/extra_time_application/wizard/extra_time_application_wizard.py index 9447b9be..bb0e4cd2 100644 --- a/extra_time_application/wizard/extra_time_application_wizard.py +++ b/extra_time_application/wizard/extra_time_application_wizard.py @@ -15,19 +15,15 @@ def _get_task_no(self): submit_user_id = fields.Many2one( 'res.users', 'Applicant', help='Applicant', - default=lambda self: self.env.user + default=lambda self: self.env.user,readonly="True" ) task_no = fields.Many2one('project.task', 'Task No', help='Task No', - default=_get_task_no + default=_get_task_no,readonly="True" ) reason = fields.Text('Reason', help='the reason of apply') apply_hours = fields.Float('Apply Hours', help='the length of apply time') - state = fields.Selection([ - ('to_approve', 'To Approve'), - ('approve', 'Approved'), - ('refused', 'Refused'), - ]) + @api.multi def subscribe(self): user = self.env.user is_exist = user.has_group( From 4ba428e7073d6eee629a613cc761761ba1687073 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Thu, 14 Dec 2017 19:12:53 +0800 Subject: [PATCH 04/16] [FIX]travis error --- .../models/project_project_inherit.py | 3 ++- .../models/project_task_inherit.py | 3 ++- .../models/task_timesheet.py | 22 ++++++++++--------- .../test/test_project_task_save.py | 11 ++++------ .../wizard/extra_time_application_wizard.py | 10 ++++----- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/extra_time_application/models/project_project_inherit.py b/extra_time_application/models/project_project_inherit.py index 30d7109c..856c654d 100644 --- a/extra_time_application/models/project_project_inherit.py +++ b/extra_time_application/models/project_project_inherit.py @@ -3,7 +3,8 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from openerp import fields, models + class ProjectProjectInherit(models.Model): - _inherit='project.project' + _inherit = 'project.project' is_modified = fields.Boolean() diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index e8080a9e..be55faa7 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -26,7 +26,8 @@ def write(self, vals): 'submit_user_id': user.id, 'task_no': self.id, 'reason': 'Automaticity create From PM or Reviewer', - 'apply_hours': vals.get('remaining_hours') - self.remaining_hours, + 'apply_hours': vals.get('remaining_hours') - \ + self.remaining_hours, 'state': 'approve', }) self.sub_extra_time += \ diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index c18209c4..19019682 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -18,15 +18,16 @@ class TaskTimeSheet(models.Model): ('to_approve', 'To Approve'), ('approve', 'Approved'), ('refused', 'Refused'), - ],track_visibility='onchange',defaule='to_approve') + ], track_visibility='onchange', defaule='to_approve') @api.one def approve_function(self): if self.state == 'to_approve': - self.with_context(flag='True').task_no.remaining_hours += self.apply_hours + self.with_context(flag='True').\ + task_no.remaining_hours += self.apply_hours self.task_no.sub_extra_time += self.apply_hours self.state = 'approve' - self.message_post(body=(' Approved:%s'%self.env.user.name)) + self.message_post(body=(' Approved:%s' % self.env.user.name)) @api.one def refuse_function(self): @@ -35,20 +36,22 @@ def refuse_function(self): @api.model def create(self, vals): msg_followers = [] - for user in self.env.ref('extra_time_application.group_extra_time_manager').users: - if user != self.env['project.task'].browse(vals.get('task_no')).user_id: + for user in self.env.ref( + 'extra_time_application.group_extra_time_manager').users: + if user != self.env['project.task'].browse( + vals.get('task_no')).user_id: msg_vals = { 'partner_id': user.partner_id.id, 'res_model': self._name, } msg_followers.append((0, 0, msg_vals)) - task_id = self.env['project.task']. \ - browse(vals.get('task_no')) + browse(vals.get('task_no')) task_manager = task_id.project_id.user_id - if task_manager not in self.env.ref('extra_time_application.group_extra_time_manager').users and \ - task_manager != task_id.user_id: + if task_manager not in self.env.ref( + 'extra_time_application.group_extra_time_manager').\ + users and task_manager != task_id.user_id: msg_vals = { 'partner_id': task_manager.partner_id.id, 'res_model': self._name, @@ -57,4 +60,3 @@ def create(self, vals): if msg_followers: vals['message_follower_ids'] = msg_followers return super(TaskTimeSheet, self).create(vals) - diff --git a/extra_time_application/test/test_project_task_save.py b/extra_time_application/test/test_project_task_save.py index 534fb132..e860d9a1 100644 --- a/extra_time_application/test/test_project_task_save.py +++ b/extra_time_application/test/test_project_task_save.py @@ -42,11 +42,11 @@ def setUp(self): self.view_id = self.env.ref('project_task_form_inherit_view').id def test_save(self): - vals_1 = {'remaining_hours':23} + vals_1 = {'remaining_hours': 23} self.task_1.write(vals_1) - vals_2 = {'timesheet_ids':[[4,20,False],[0,False,{ + vals_2 = {'timesheet_ids': [[4, 20, False], [0, False, { 'date_time': '2017-12-13 10:26:54', - 'user_id': 1, + 'user_id': 1, 'name': self.name, 'unit_amount': 2, 'date': '2017-12-13', @@ -61,7 +61,4 @@ def test_open_extra_time_line(self): return res def test_fields_view_get(self): - self.task_1.fields_view_get(view_id=self.view_id, - view_type='form') - - + self.task_1.fields_view_get(view_id=self.view_id, view_type='form') diff --git a/extra_time_application/wizard/extra_time_application_wizard.py b/extra_time_application/wizard/extra_time_application_wizard.py index bb0e4cd2..c07cde0a 100644 --- a/extra_time_application/wizard/extra_time_application_wizard.py +++ b/extra_time_application/wizard/extra_time_application_wizard.py @@ -15,10 +15,10 @@ def _get_task_no(self): submit_user_id = fields.Many2one( 'res.users', 'Applicant', help='Applicant', - default=lambda self: self.env.user,readonly="True" + default=lambda self: self.env.user, readonly="True" ) task_no = fields.Many2one('project.task', 'Task No', help='Task No', - default=_get_task_no,readonly="True" + default=_get_task_no, readonly="True" ) reason = fields.Text('Reason', help='the reason of apply') apply_hours = fields.Float('Apply Hours', help='the length of apply time') @@ -42,9 +42,9 @@ def subscribe(self): else: mail = self.env['mail.mail'].create({ 'body_html': 'apply time:' + str( - self.apply_hours) + '
reason:' - + str(self.reason) + '
Task:' - + str(self.task_no.code), + self.apply_hours) + '
reason:' + + str(self.reason) + '
Task:' + + str(self.task_no.code), 'email_to': self.task_no.project_id.user_id.login, 'subject': 'Apply Time', }) From c90884327290353f2622bb01054228cb2d97972c Mon Sep 17 00:00:00 2001 From: xlm609 Date: Fri, 15 Dec 2017 11:54:57 +0800 Subject: [PATCH 05/16] [FIX]fix travis error --- extra_time_application/__init__.py | 2 +- extra_time_application/models/project_task_inherit.py | 4 ++-- extra_time_application/{test => tests}/__init__.py | 3 ++- extra_time_application/{test => tests}/test_extra_time.py | 1 - .../{test => tests}/test_extra_time_wizard.py | 0 .../{test => tests}/test_project_task_save.py | 0 6 files changed, 5 insertions(+), 5 deletions(-) rename extra_time_application/{test => tests}/__init__.py (70%) rename extra_time_application/{test => tests}/test_extra_time.py (99%) rename extra_time_application/{test => tests}/test_extra_time_wizard.py (100%) rename extra_time_application/{test => tests}/test_project_task_save.py (100%) diff --git a/extra_time_application/__init__.py b/extra_time_application/__init__.py index 619ab64c..0aceefd7 100644 --- a/extra_time_application/__init__.py +++ b/extra_time_application/__init__.py @@ -4,4 +4,4 @@ from . import models from . import wizard -from . import test \ No newline at end of file +from . import tests \ No newline at end of file diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index be55faa7..8333af59 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -26,8 +26,8 @@ def write(self, vals): 'submit_user_id': user.id, 'task_no': self.id, 'reason': 'Automaticity create From PM or Reviewer', - 'apply_hours': vals.get('remaining_hours') - \ - self.remaining_hours, + 'apply_hours': + vals.get('remaining_hours') - self.remaining_hours, 'state': 'approve', }) self.sub_extra_time += \ diff --git a/extra_time_application/test/__init__.py b/extra_time_application/tests/__init__.py similarity index 70% rename from extra_time_application/test/__init__.py rename to extra_time_application/tests/__init__.py index 36b4fb3b..7d4880eb 100644 --- a/extra_time_application/test/__init__.py +++ b/extra_time_application/tests/__init__.py @@ -1,4 +1,5 @@ # -*- coding:utf-8 -*- + from . import test_extra_time from . import test_project_task_save -from . import test_extra_time_wizard \ No newline at end of file +from . import test_extra_time_wizard diff --git a/extra_time_application/test/test_extra_time.py b/extra_time_application/tests/test_extra_time.py similarity index 99% rename from extra_time_application/test/test_extra_time.py rename to extra_time_application/tests/test_extra_time.py index 2d80e7ab..ce0855ce 100644 --- a/extra_time_application/test/test_extra_time.py +++ b/extra_time_application/tests/test_extra_time.py @@ -4,7 +4,6 @@ # See LICENSE file for full copyright and licensing details. from odoo.tests import common - class TestExtraTime(common.TransactionCase): def setUp(self): diff --git a/extra_time_application/test/test_extra_time_wizard.py b/extra_time_application/tests/test_extra_time_wizard.py similarity index 100% rename from extra_time_application/test/test_extra_time_wizard.py rename to extra_time_application/tests/test_extra_time_wizard.py diff --git a/extra_time_application/test/test_project_task_save.py b/extra_time_application/tests/test_project_task_save.py similarity index 100% rename from extra_time_application/test/test_project_task_save.py rename to extra_time_application/tests/test_project_task_save.py From 97ded9420bb96f0ef5ddb4272a37462bf6a95609 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Mon, 18 Dec 2017 16:36:03 +0800 Subject: [PATCH 06/16] [FIX]fix test error and some logic error --- extra_time_application/README.rst | 3 +- extra_time_application/__init__.py | 2 +- extra_time_application/__manifest__.py | 2 +- .../models/project_task_inherit.py | 76 ++++++++++--------- .../models/task_timesheet.py | 25 +++--- .../tests/test_extra_time.py | 9 ++- .../tests/test_extra_time_wizard.py | 16 ++-- .../tests/test_project_task_save.py | 57 +++++++------- .../views/extra_time_approve_view.xml | 4 +- .../wizard/extra_time_application_wizard.py | 19 ++--- .../wizard/time_prompt_view.xml | 2 +- 11 files changed, 113 insertions(+), 102 deletions(-) diff --git a/extra_time_application/README.rst b/extra_time_application/README.rst index 62f6c9f3..1014d772 100644 --- a/extra_time_application/README.rst +++ b/extra_time_application/README.rst @@ -4,7 +4,8 @@ ====================== Extra Time Application ====================== - +This module adds functionality to the application time and +will not allow to add new items if the task time is less than 0 Bug Tracker =========== diff --git a/extra_time_application/__init__.py b/extra_time_application/__init__.py index 0aceefd7..4f8fe946 100644 --- a/extra_time_application/__init__.py +++ b/extra_time_application/__init__.py @@ -4,4 +4,4 @@ from . import models from . import wizard -from . import tests \ No newline at end of file +from . import tests diff --git a/extra_time_application/__manifest__.py b/extra_time_application/__manifest__.py index d0765522..c5526894 100644 --- a/extra_time_application/__manifest__.py +++ b/extra_time_application/__manifest__.py @@ -5,7 +5,7 @@ { 'name': 'Extra Time Application', - 'version': '10.0.1.0.0', + 'version': '10.0.0.0.0', 'author': "Elico Corp", 'website': 'https://www.elico-corp.com', 'license': 'Other proprietary', diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index 8333af59..cbc5524f 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -16,53 +16,59 @@ class ProjectTaskInherit(models.Model): @api.multi def write(self, vals): - user = self.env.user - is_exist = user.has_group( - 'extra_time_application.group_project_task_manager') - remaining = self.remaining_hours - if not self.env.context.get('flag'): - if vals.get('remaining_hours') and not vals.get('timesheet_ids'): - self.env['extra.time.application'].create({ - 'submit_user_id': user.id, - 'task_no': self.id, - 'reason': 'Automaticity create From PM or Reviewer', - 'apply_hours': - vals.get('remaining_hours') - self.remaining_hours, - 'state': 'approve', - }) - self.sub_extra_time += \ - (vals.get('remaining_hours') - self.remaining_hours) - for record in vals.get('timesheet_ids', []): - if record[0] == 0: - remaining -= record[2]['unit_amount'] - elif record[0] == 2: - item = self.timesheet_ids.search([ - ('id', '=', record[1]) - ]) - remaining += item['unit_amount'] - if remaining < 0: - raise UserError( - _( - 'The task have no enough time, ' - 'please Apply for more extra time' - )) - if not vals.get('project_id.is_modified'): - if not is_exist and self.project_id.user_id != user: + for log in self: + user = log.env.user + remaining = log.remaining_hours + if not log.env.context.get('flag') and \ + not log.env.context.get('flag_remaine'): + if vals.get('remaining_hours') and not vals.get('timesheet_ids'): + log.env['extra.time.application'].create({ + 'submit_user_id': user.id, + 'task_id': log.id, + 'reason': 'Automaticity create From PM or Reviewer', + 'apply_hours': + vals.get('remaining_hours') - log.remaining_hours, + 'state': 'approve', + }) + log.sub_extra_time += \ + (vals.get('remaining_hours') - log.remaining_hours) + for record in vals.get('timesheet_ids', []): + if record[0] == 0: + remaining -= record[2]['unit_amount'] + elif record[0] == 2: + item = log.timesheet_ids.search([ + ('id', '=', record[1]) + ]) + remaining += item['unit_amount'] + if remaining < 0: raise UserError( _( - 'You do not have permission')) + 'The task have no enough time, ' + 'please Apply for more extra time' + )) res = super(ProjectTaskInherit, self).write(vals) return res + @api.model + def create(self, vals): + user = self.env.user + is_exist = user.has_group( + 'extra_time_application.group_project_task_manager') + if not vals.get('project_id.is_modified'): + if not is_exist and self.project_id.user_id != user: + raise UserError( + _('You do not have permission')) + return super(ProjectTaskInherit, self).create(vals) + @api.multi def open_extra_time_line(self): for record in self: - domain = [('task_no', '=', record.name)] + domain = [('task_id', '=', record.name)] return { 'name': _('Extra Time Approve'), 'type': 'ir.actions.act_window', 'view_type': 'form', - 'view_mode': 'tree', + 'view_mode': 'tree,form', 'res_model': 'extra.time.application', 'target': 'current', 'domain': domain, diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index 19019682..167b8e21 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -11,7 +11,7 @@ class TaskTimeSheet(models.Model): submit_user_id = fields.Many2one( 'res.users', 'Applicant', help='Applicant', ) - task_no = fields.Many2one('project.task', 'Task No', help='Task No') + task_id = fields.Many2one('project.task', 'Task No', help='Task No') reason = fields.Text('Reason', help='the reason of apply') apply_hours = fields.Float('Apply Hours', help='the length of apply time') state = fields.Selection([ @@ -23,11 +23,11 @@ class TaskTimeSheet(models.Model): @api.one def approve_function(self): if self.state == 'to_approve': - self.with_context(flag='True').\ - task_no.remaining_hours += self.apply_hours - self.task_no.sub_extra_time += self.apply_hours + self.with_context(flag='True'). \ + task_id.remaining_hours += self.apply_hours + self.task_id.sub_extra_time += self.apply_hours self.state = 'approve' - self.message_post(body=(' Approved:%s' % self.env.user.name)) + self.message_post(body=('Approved:%s' % self.env.user.name)) @api.one def refuse_function(self): @@ -39,21 +39,20 @@ def create(self, vals): for user in self.env.ref( 'extra_time_application.group_extra_time_manager').users: if user != self.env['project.task'].browse( - vals.get('task_no')).user_id: + vals.get('task_id')).user_id: msg_vals = { - 'partner_id': user.partner_id.id, + 'partner_id': user.id, 'res_model': self._name, } msg_followers.append((0, 0, msg_vals)) - task_id = self.env['project.task']. \ - browse(vals.get('task_no')) + browse(vals.get('task_id')) task_manager = task_id.project_id.user_id - if task_manager not in self.env.ref( - 'extra_time_application.group_extra_time_manager').\ - users and task_manager != task_id.user_id: + if (task_manager not in self.env.ref( + 'extra_time_application.group_extra_time_manager').users) and ( + task_manager != task_id.user_id): msg_vals = { - 'partner_id': task_manager.partner_id.id, + 'partner_id': task_manager.id, 'res_model': self._name, } msg_followers.append((0, 0, msg_vals)) diff --git a/extra_time_application/tests/test_extra_time.py b/extra_time_application/tests/test_extra_time.py index ce0855ce..6db92f3f 100644 --- a/extra_time_application/tests/test_extra_time.py +++ b/extra_time_application/tests/test_extra_time.py @@ -4,16 +4,17 @@ # See LICENSE file for full copyright and licensing details. from odoo.tests import common + class TestExtraTime(common.TransactionCase): def setUp(self): super(TestExtraTime, self).setUp() - self.submit_user_id = self.env.ref("base.partner_root") - self.task_no = self.env.ref('project.project_task_9') + self.submit_user_id = self.env.ref("base.user_demo") + self.task_id = self.env.ref('project.project_task_9') self.extra_time_record = self.env['extra.time.application'].create({ - 'submit_user_id': self.submit_user_id, - 'task_no': self.task_no, + 'submit_user_id': self.submit_user_id.id, + 'task_id': self.task_id.id, 'reason': 'Automaticity create From PM or Reviewer', 'apply_hours': 2, 'state': 'to_approve' diff --git a/extra_time_application/tests/test_extra_time_wizard.py b/extra_time_application/tests/test_extra_time_wizard.py index 7c9232fa..0294b26d 100644 --- a/extra_time_application/tests/test_extra_time_wizard.py +++ b/extra_time_application/tests/test_extra_time_wizard.py @@ -9,21 +9,21 @@ class TestExtraTimeWizard(common.TransactionCase): def setUp(self): super(TestExtraTimeWizard, self).setUp() - self.task_no = self.env.ref('project_task_1') + self.task_id = self.env.ref('project.project_task_9') self.submit_user_id = self.env.ref('base.user_demo') self.extra_time_1 = self.env['extra.time.application'].create({ - 'submit_user_id': self.submit_user_id, - 'task_no': self.task_no, + 'submit_user_id': self.submit_user_id.id, + 'task_id': self.task_id.id, 'reason': 'system test', 'apply_hours': 3 }) self.extra_time_2 = self.env['extra.time.application'].create({ - 'submit_user_id': self.env.ref('base.res.partner'), - 'task_no': self.task_no, + 'submit_user_id': self.submit_user_id.id, + 'task_id': self.task_id.id, 'reason': 'system test', 'apply_hours': 3 }) - def test_subscribe(): - self.extra_time_1.subscribe() - self.extra_time_2.subscribe() + def test_subscribe(self): + self.extra_time_1.subscribe() + self.extra_time_2.subscribe() diff --git a/extra_time_application/tests/test_project_task_save.py b/extra_time_application/tests/test_project_task_save.py index e860d9a1..8b9a04a3 100644 --- a/extra_time_application/tests/test_project_task_save.py +++ b/extra_time_application/tests/test_project_task_save.py @@ -9,37 +9,39 @@ class TestProjectTaskSave(common.TransactionCase): def setUp(self): super(TestProjectTaskSave, self).setUp() - self.name = self.env.ref('project.project_task_9') - self.project_id = self.env.ref('project.project_project_2') - self.user_id = self.env.ref('base.user_demo') + self.name_1 = self.env.ref('project.project_task_9') + self.name_2 = self.env.ref('project.project_task_8') + self.project_id = self.env.ref('project.project_project_4') + self.user_id = self.env.ref('base.user_root') self.sub_extra_time = 0 + self.timesheet_ids = self.env['account.analytic.line'].write([[ + 0, False, { + 'date_time': '2017-12-15', + 'user_id': self.user_id.id, + 'name': 'test', + 'unit_amount': 1, + 'date': '2017-12-15', + 'project_id': self.project_id.id + } + ]]) self.task_1 = self.env['project.task'].create({ - 'name': self.name, - 'project_id': self.project_id, + 'name': self.name_1.id, + 'project_id': self.project_id.id, 'user_id': self.user_id.id, 'planned_hours': 18, 'remaining_hours': 18, - 'timesheet_ids': - [(0, 0, { - 'date': '2017-12-13', - 'name': 'test', - 'unit_amount': 2, - })] + 'timesheet_ids': self.timesheet_ids }) self.task_2 = self.env['project.task'].create({ - 'name': self.name, - 'project_id': self.project_id, + 'name': self.name_2.id, + 'project_id': self.project_id.id, 'user_id': self.user_id.id, 'planned_hours': 18, - 'remaining_hours': -1, - 'timesheet_ids': - [(0, 0, { - 'date': '2017-12-13', - 'name': 'test', - 'unit_amount': 2, - })] + 'remaining_hours': 1, + 'timesheet_ids': self.timesheet_ids }) - self.view_id = self.env.ref('project_task_form_inherit_view').id + self.view_id = self.env.ref( + 'extra_time_application.project_task_form_inherit_view').id def test_save(self): vals_1 = {'remaining_hours': 23} @@ -47,18 +49,19 @@ def test_save(self): vals_2 = {'timesheet_ids': [[4, 20, False], [0, False, { 'date_time': '2017-12-13 10:26:54', 'user_id': 1, - 'name': self.name, + 'name': self.name_2, 'unit_amount': 2, 'date': '2017-12-13', - 'project_id': self.project_id + 'project_id': self.project_id.id }]]} self.task_1.write(vals_2) - self.task_2.write() + try: + self.task_2.write(vals_2) + except Exception: + pass def test_open_extra_time_line(self): - res = self.task_1.open_extra_time_line() - self.assertTrue(res[1], 'error') - return res + self.task_1.open_extra_time_line() def test_fields_view_get(self): self.task_1.fields_view_get(view_id=self.view_id, view_type='form') diff --git a/extra_time_application/views/extra_time_approve_view.xml b/extra_time_application/views/extra_time_approve_view.xml index 133e6e49..6f666fa7 100644 --- a/extra_time_application/views/extra_time_approve_view.xml +++ b/extra_time_application/views/extra_time_approve_view.xml @@ -19,7 +19,7 @@
- + @@ -43,7 +43,7 @@ - + diff --git a/extra_time_application/wizard/extra_time_application_wizard.py b/extra_time_application/wizard/extra_time_application_wizard.py index c07cde0a..bb278e03 100644 --- a/extra_time_application/wizard/extra_time_application_wizard.py +++ b/extra_time_application/wizard/extra_time_application_wizard.py @@ -8,7 +8,7 @@ class TimePromptBox(models.TransientModel): _name = 'extra.time.application.wizard' @api.model - def _get_task_no(self): + def _get_task_id(self): return self.env['project.task'].browse( self._context.get('active_id') ) @@ -17,8 +17,8 @@ def _get_task_no(self): 'res.users', 'Applicant', help='Applicant', default=lambda self: self.env.user, readonly="True" ) - task_no = fields.Many2one('project.task', 'Task No', help='Task No', - default=_get_task_no, readonly="True" + task_id = fields.Many2one('project.task', 'Task No', help='Task No', + default=_get_task_id, readonly="True" ) reason = fields.Text('Reason', help='the reason of apply') apply_hours = fields.Float('Apply Hours', help='the length of apply time') @@ -31,27 +31,28 @@ def subscribe(self): if is_exist: self.env['extra.time.application'].create({ 'submit_user_id': self.submit_user_id.id, - 'task_no': self.task_no.id, + 'task_id': self.task_id.id, 'reason': 'Automaticity create From PM or Reviewer', 'apply_hours': self.apply_hours, 'state': 'approve', }) - self.task_no.remaining_hours += self.apply_hours - self.task_no.sub_extra_time += self.apply_hours + self.with_context(flag_remaine='True'). \ + task_id.remaining_hours += self.apply_hours + self.task_id.sub_extra_time += self.apply_hours else: mail = self.env['mail.mail'].create({ 'body_html': 'apply time:' + str( self.apply_hours) + '
reason:' + str(self.reason) + '
Task:' + - str(self.task_no.code), - 'email_to': self.task_no.project_id.user_id.login, + str(self.task_id.code), + 'email_to': self.task_id.project_id.user_id.login, 'subject': 'Apply Time', }) mail.send() self.env['extra.time.application'].create({ 'submit_user_id': self.submit_user_id.id, - 'task_no': self.task_no.id, + 'task_id': self.task_id.id, 'reason': self.reason, 'apply_hours': self.apply_hours, 'state': 'to_approve', diff --git a/extra_time_application/wizard/time_prompt_view.xml b/extra_time_application/wizard/time_prompt_view.xml index d146b793..eaab55a9 100644 --- a/extra_time_application/wizard/time_prompt_view.xml +++ b/extra_time_application/wizard/time_prompt_view.xml @@ -13,7 +13,7 @@
- + From 6adecceb8e64bfa91cf997701440e6cd79c647b7 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Mon, 18 Dec 2017 17:05:23 +0800 Subject: [PATCH 07/16] [FIX]add lisence file and fix test error --- extra_time_application/LICENSE | 11 +++++++++++ extra_time_application/README.rst | 1 - extra_time_application/models/project_task_inherit.py | 3 ++- .../security/extra_time_application_security.xml | 2 +- extra_time_application/security/ir.model.access.csv | 2 +- .../tests/test_extra_time_wizard.py | 4 ++-- .../views/extra_time_approve_view.xml | 6 +----- .../views/project_task_form_inherit.xml | 2 +- extra_time_application/wizard/time_prompt_view.xml | 6 +----- 9 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 extra_time_application/LICENSE diff --git a/extra_time_application/LICENSE b/extra_time_application/LICENSE new file mode 100644 index 00000000..485a8fa2 --- /dev/null +++ b/extra_time_application/LICENSE @@ -0,0 +1,11 @@ +Elico Proprietary License v1.0 + +This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, via Odoo Apps or direct sale from Elico Corporation, Shanghai Elico Limited or Hong Kong Elico Limited, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). + +You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Elico Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). + +It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. + +The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/extra_time_application/README.rst b/extra_time_application/README.rst index 1014d772..668b68d6 100644 --- a/extra_time_application/README.rst +++ b/extra_time_application/README.rst @@ -55,4 +55,3 @@ Our headquarters are located in Shanghai with branch in Singapore servicing customers from all over Asia Pacific. Contact information: `Sales `__ - diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index cbc5524f..2329da7d 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -21,7 +21,8 @@ def write(self, vals): remaining = log.remaining_hours if not log.env.context.get('flag') and \ not log.env.context.get('flag_remaine'): - if vals.get('remaining_hours') and not vals.get('timesheet_ids'): + if vals.get('remaining_hours') and \ + not vals.get('timesheet_ids'): log.env['extra.time.application'].create({ 'submit_user_id': user.id, 'task_id': log.id, diff --git a/extra_time_application/security/extra_time_application_security.xml b/extra_time_application/security/extra_time_application_security.xml index 7a3bd987..954b8f33 100644 --- a/extra_time_application/security/extra_time_application_security.xml +++ b/extra_time_application/security/extra_time_application_security.xml @@ -16,4 +16,4 @@ [('submit_user_id','=',user.id)]
- \ No newline at end of file + diff --git a/extra_time_application/security/ir.model.access.csv b/extra_time_application/security/ir.model.access.csv index e3d905e5..527e51a2 100644 --- a/extra_time_application/security/ir.model.access.csv +++ b/extra_time_application/security/ir.model.access.csv @@ -2,4 +2,4 @@ access_project_task_manager,project_task_manager,project.model_project_task,extra_time_application.group_project_task_manager,1,1,1,1 access_project_task_user,project_task_user,project.model_project_task,extra_time_application.group_project_task_user,1,1,0,0 access_extra_time_manager,extra_time_manager,extra_time_application.model_extra_time_application,extra_time_application.group_extra_time_manager,1,1,1,1 -access_extra_time_user,extra_time_user,extra_time_application.model_extra_time_application,base.group_user,1,1,1,1 \ No newline at end of file +access_extra_time_user,extra_time_user,extra_time_application.model_extra_time_application,base.group_user,1,1,1,1 diff --git a/extra_time_application/tests/test_extra_time_wizard.py b/extra_time_application/tests/test_extra_time_wizard.py index 0294b26d..74b92915 100644 --- a/extra_time_application/tests/test_extra_time_wizard.py +++ b/extra_time_application/tests/test_extra_time_wizard.py @@ -11,13 +11,13 @@ def setUp(self): super(TestExtraTimeWizard, self).setUp() self.task_id = self.env.ref('project.project_task_9') self.submit_user_id = self.env.ref('base.user_demo') - self.extra_time_1 = self.env['extra.time.application'].create({ + self.extra_time_1 = self.env['extra.time.application.wizard'].create({ 'submit_user_id': self.submit_user_id.id, 'task_id': self.task_id.id, 'reason': 'system test', 'apply_hours': 3 }) - self.extra_time_2 = self.env['extra.time.application'].create({ + self.extra_time_2 = self.env['extra.time.application.wizard'].create({ 'submit_user_id': self.submit_user_id.id, 'task_id': self.task_id.id, 'reason': 'system test', diff --git a/extra_time_application/views/extra_time_approve_view.xml b/extra_time_application/views/extra_time_approve_view.xml index 6f666fa7..e63ac045 100644 --- a/extra_time_application/views/extra_time_approve_view.xml +++ b/extra_time_application/views/extra_time_approve_view.xml @@ -36,7 +36,6 @@ - extra.time.approve.tree extra.time.application @@ -50,7 +49,6 @@ - Extra Time Approve ir.actions.act_window @@ -59,10 +57,8 @@ form,tree - - - \ No newline at end of file + diff --git a/extra_time_application/views/project_task_form_inherit.xml b/extra_time_application/views/project_task_form_inherit.xml index e31936fd..8f2b9a93 100644 --- a/extra_time_application/views/project_task_form_inherit.xml +++ b/extra_time_application/views/project_task_form_inherit.xml @@ -31,4 +31,4 @@ - \ No newline at end of file + diff --git a/extra_time_application/wizard/time_prompt_view.xml b/extra_time_application/wizard/time_prompt_view.xml index eaab55a9..6c8096b7 100644 --- a/extra_time_application/wizard/time_prompt_view.xml +++ b/extra_time_application/wizard/time_prompt_view.xml @@ -1,6 +1,5 @@ - view.time.prompt.form extra.time.application.wizard @@ -31,7 +30,6 @@
- Time Application ir.actions.act_window @@ -41,6 +39,4 @@ new - - -
\ No newline at end of file + From 7bd17b5d64ec86bf21f46d1ed2973ff7fc7bce13 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 19 Dec 2017 13:57:20 +0800 Subject: [PATCH 08/16] [IMP]make some hint morespecific and fix some test error --- extra_time_application/LICENSE | 11 ------- extra_time_application/README.rst | 3 ++ extra_time_application/__manifest__.py | 4 +-- .../models/project_task_inherit.py | 25 ++++++++-------- .../models/task_timesheet.py | 29 ++++++++++++++++--- .../tests/test_extra_time.py | 18 ++++++++---- .../tests/test_extra_time_wizard.py | 3 +- .../tests/test_project_task_save.py | 14 +++++---- .../wizard/extra_time_application_wizard.py | 6 ++-- 9 files changed, 69 insertions(+), 44 deletions(-) delete mode 100644 extra_time_application/LICENSE diff --git a/extra_time_application/LICENSE b/extra_time_application/LICENSE deleted file mode 100644 index 485a8fa2..00000000 --- a/extra_time_application/LICENSE +++ /dev/null @@ -1,11 +0,0 @@ -Elico Proprietary License v1.0 - -This software and associated files (the "Software") may only be used (executed, modified, executed after modifications) if you have purchased a valid license from the authors, via Odoo Apps or direct sale from Elico Corporation, Shanghai Elico Limited or Hong Kong Elico Limited, or if you have received a written agreement from the authors of the Software (see the COPYRIGHT file). - -You may develop Odoo modules that use the Software as a library (typically by depending on it, importing it and using its resources), but without copying any source code or material from the Software. You may distribute those modules under the license of your choice, provided that this license is compatible with the terms of the Elico Proprietary License (For example: LGPL, MIT, or proprietary licenses similar to this one). - -It is forbidden to publish, distribute, sublicense, or sell copies of the Software or modified copies of the Software. - -The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/extra_time_application/README.rst b/extra_time_application/README.rst index 668b68d6..fd7aaa6c 100644 --- a/extra_time_application/README.rst +++ b/extra_time_application/README.rst @@ -27,6 +27,9 @@ Contributors ------------ * Miya Xing +* Eric Caudal +* Sébastien Maillard +* Hulk Liu Maintainer diff --git a/extra_time_application/__manifest__.py b/extra_time_application/__manifest__.py index c5526894..919c43f7 100644 --- a/extra_time_application/__manifest__.py +++ b/extra_time_application/__manifest__.py @@ -5,10 +5,10 @@ { 'name': 'Extra Time Application', - 'version': '10.0.0.0.0', + 'version': '10.0.1.0.0', 'author': "Elico Corp", 'website': 'https://www.elico-corp.com', - 'license': 'Other proprietary', + 'license': 'AGPL-3', 'support': 'https://support@elico-corp.com', 'depends': [ 'project', diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index 2329da7d..938de7b9 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -17,16 +17,16 @@ class ProjectTaskInherit(models.Model): @api.multi def write(self, vals): for log in self: - user = log.env.user + current_user = log.env.user remaining = log.remaining_hours if not log.env.context.get('flag') and \ not log.env.context.get('flag_remaine'): if vals.get('remaining_hours') and \ not vals.get('timesheet_ids'): log.env['extra.time.application'].create({ - 'submit_user_id': user.id, + 'submit_user_id': current_user.id, 'task_id': log.id, - 'reason': 'Automaticity create From PM or Reviewer', + 'reason': 'Automatically create From PM or Reviewer', 'apply_hours': vals.get('remaining_hours') - log.remaining_hours, 'state': 'approve', @@ -44,21 +44,22 @@ def write(self, vals): if remaining < 0: raise UserError( _( - 'The task have no enough time, ' - 'please Apply for more extra time' + 'The task has no enough time left, ' + 'please apply for more extra time.' )) res = super(ProjectTaskInherit, self).write(vals) return res @api.model def create(self, vals): - user = self.env.user - is_exist = user.has_group( + current_user = self.env.user + is_exist = current_user.has_group( 'extra_time_application.group_project_task_manager') if not vals.get('project_id.is_modified'): - if not is_exist and self.project_id.user_id != user: + if not is_exist and self.project_id.user_id != current_user: raise UserError( - _('You do not have permission')) + _('You do not have permission to ' + 'create task belong to this project.')) return super(ProjectTaskInherit, self).create(vals) @api.multi @@ -66,7 +67,7 @@ def open_extra_time_line(self): for record in self: domain = [('task_id', '=', record.name)] return { - 'name': _('Extra Time Approve'), + 'name': _('Extra Time Approval'), 'type': 'ir.actions.act_window', 'view_type': 'form', 'view_mode': 'tree,form', @@ -83,8 +84,8 @@ def fields_view_get(self, view_id=None, view_type='form', submenu=submenu) dom = etree.XML(res['arch']) if view_type == 'form': - user = self.env.user - is_exist = user.has_group( + current_user = self.env.user + is_exist = current_user.has_group( 'extra_time_application.group_project_task_manager') if is_exist or self.project_id.is_modified: for node in dom.xpath("//field[@name='remaining_hours']"): diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index 167b8e21..31bba5bd 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (www.elico-corp.com). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models +from openerp import api, fields, models,_ +from odoo.exceptions import UserError class TaskTimeSheet(models.Model): @@ -22,16 +23,36 @@ class TaskTimeSheet(models.Model): @api.one def approve_function(self): - if self.state == 'to_approve': + task_id = self.task_id + task_manager = task_id.project_id.user_id + if (self.env.user in self.env.ref( + 'extra_time_application.group_extra_time_manager').users) or ( + self.env.user == task_manager.user_id) or \ + task_id.project_id.is_modified: self.with_context(flag='True'). \ task_id.remaining_hours += self.apply_hours self.task_id.sub_extra_time += self.apply_hours self.state = 'approve' - self.message_post(body=('Approved:%s' % self.env.user.name)) + else: + raise UserError( + _( + 'You do not have permission to approve it.' + )) @api.one def refuse_function(self): - self.state = 'refused' + task_id = self.task_id + task_manager = task_id.project_id.user_id + if (self.env.user in self.env.ref( + 'extra_time_application.group_extra_time_manager').users) or ( + self.env.user == task_manager.user_id) or \ + task_id.project_id.is_modified: + self.state = 'refused' + else: + raise UserError( + _( + 'You do not have permission to refuse it.' + )) @api.model def create(self, vals): diff --git a/extra_time_application/tests/test_extra_time.py b/extra_time_application/tests/test_extra_time.py index 6db92f3f..7e6936f3 100644 --- a/extra_time_application/tests/test_extra_time.py +++ b/extra_time_application/tests/test_extra_time.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (www.elico-corp.com) -# Elico Proprietary License v1.0. -# See LICENSE file for full copyright and licensing details. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests import common +from odoo.exceptions import UserError class TestExtraTime(common.TransactionCase): @@ -15,13 +15,21 @@ def setUp(self): self.extra_time_record = self.env['extra.time.application'].create({ 'submit_user_id': self.submit_user_id.id, 'task_id': self.task_id.id, - 'reason': 'Automaticity create From PM or Reviewer', + 'reason': 'Automatically created From PM or Reviewer', 'apply_hours': 2, 'state': 'to_approve' }) def test_approve_function(self): - self.extra_time_record.approve_function() + try: + self.extra_time_record.approve_function() + except UserError: + pass + def test_refuse_function(self): - self.extra_time_record.refuse_function() + try: + self.extra_time_record.refuse_function() + except UserError: + pass + diff --git a/extra_time_application/tests/test_extra_time_wizard.py b/extra_time_application/tests/test_extra_time_wizard.py index 74b92915..b567cb0c 100644 --- a/extra_time_application/tests/test_extra_time_wizard.py +++ b/extra_time_application/tests/test_extra_time_wizard.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (www.elico-corp.com) -# Elico Proprietary License v1.0. -# See LICENSE file for full copyright and licensing details. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests import common diff --git a/extra_time_application/tests/test_project_task_save.py b/extra_time_application/tests/test_project_task_save.py index 8b9a04a3..ba1fcc71 100644 --- a/extra_time_application/tests/test_project_task_save.py +++ b/extra_time_application/tests/test_project_task_save.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (www.elico-corp.com) -# Elico Proprietary License v1.0. -# See LICENSE file for full copyright and licensing details. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests import common +from datetime import datetime +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo.exceptions import UserError class TestProjectTaskSave(common.TransactionCase): @@ -16,7 +18,8 @@ def setUp(self): self.sub_extra_time = 0 self.timesheet_ids = self.env['account.analytic.line'].write([[ 0, False, { - 'date_time': '2017-12-15', + 'date_time': datetime.today(). + strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'user_id': self.user_id.id, 'name': 'test', 'unit_amount': 1, @@ -47,7 +50,8 @@ def test_save(self): vals_1 = {'remaining_hours': 23} self.task_1.write(vals_1) vals_2 = {'timesheet_ids': [[4, 20, False], [0, False, { - 'date_time': '2017-12-13 10:26:54', + 'date_time': datetime.today(). + strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'user_id': 1, 'name': self.name_2, 'unit_amount': 2, @@ -57,7 +61,7 @@ def test_save(self): self.task_1.write(vals_2) try: self.task_2.write(vals_2) - except Exception: + except UserError: pass def test_open_extra_time_line(self): diff --git a/extra_time_application/wizard/extra_time_application_wizard.py b/extra_time_application/wizard/extra_time_application_wizard.py index bb278e03..28b2ab98 100644 --- a/extra_time_application/wizard/extra_time_application_wizard.py +++ b/extra_time_application/wizard/extra_time_application_wizard.py @@ -25,14 +25,14 @@ def _get_task_id(self): @api.multi def subscribe(self): - user = self.env.user - is_exist = user.has_group( + current_user = self.env.user + is_exist = current_user.has_group( 'extra_time_application.group_project_task_manager') if is_exist: self.env['extra.time.application'].create({ 'submit_user_id': self.submit_user_id.id, 'task_id': self.task_id.id, - 'reason': 'Automaticity create From PM or Reviewer', + 'reason': 'Automatically created From PM or Reviewer', 'apply_hours': self.apply_hours, 'state': 'approve', }) From c64767c56be9168a6b2de1b1310f73d9af9f7c37 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 19 Dec 2017 14:03:55 +0800 Subject: [PATCH 09/16] [FIX]travis error --- extra_time_application/models/task_timesheet.py | 2 +- extra_time_application/tests/test_extra_time.py | 2 -- extra_time_application/tests/test_project_task_save.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index 31bba5bd..3764a98f 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (www.elico-corp.com). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import api, fields, models,_ +from openerp import api, fields, models, _ from odoo.exceptions import UserError diff --git a/extra_time_application/tests/test_extra_time.py b/extra_time_application/tests/test_extra_time.py index 7e6936f3..934376dd 100644 --- a/extra_time_application/tests/test_extra_time.py +++ b/extra_time_application/tests/test_extra_time.py @@ -26,10 +26,8 @@ def test_approve_function(self): except UserError: pass - def test_refuse_function(self): try: self.extra_time_record.refuse_function() except UserError: pass - diff --git a/extra_time_application/tests/test_project_task_save.py b/extra_time_application/tests/test_project_task_save.py index ba1fcc71..04a4625d 100644 --- a/extra_time_application/tests/test_project_task_save.py +++ b/extra_time_application/tests/test_project_task_save.py @@ -51,7 +51,7 @@ def test_save(self): self.task_1.write(vals_1) vals_2 = {'timesheet_ids': [[4, 20, False], [0, False, { 'date_time': datetime.today(). - strftime(DEFAULT_SERVER_DATETIME_FORMAT), + strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'user_id': 1, 'name': self.name_2, 'unit_amount': 2, From b7f03f6e282e7194cd7cecb52e44af89970b912c Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 19 Dec 2017 14:08:11 +0800 Subject: [PATCH 10/16] [FIX]travis error --- extra_time_application/tests/test_project_task_save.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extra_time_application/tests/test_project_task_save.py b/extra_time_application/tests/test_project_task_save.py index 04a4625d..bc7f49e4 100644 --- a/extra_time_application/tests/test_project_task_save.py +++ b/extra_time_application/tests/test_project_task_save.py @@ -18,8 +18,8 @@ def setUp(self): self.sub_extra_time = 0 self.timesheet_ids = self.env['account.analytic.line'].write([[ 0, False, { - 'date_time': datetime.today(). - strftime(DEFAULT_SERVER_DATETIME_FORMAT), + 'date_time': datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT), 'user_id': self.user_id.id, 'name': 'test', 'unit_amount': 1, @@ -50,8 +50,8 @@ def test_save(self): vals_1 = {'remaining_hours': 23} self.task_1.write(vals_1) vals_2 = {'timesheet_ids': [[4, 20, False], [0, False, { - 'date_time': datetime.today(). - strftime(DEFAULT_SERVER_DATETIME_FORMAT), + 'date_time': datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT), 'user_id': 1, 'name': self.name_2, 'unit_amount': 2, From 2a88b15d553db8940c11828229875d3a67cdc848 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 19 Dec 2017 14:13:49 +0800 Subject: [PATCH 11/16] [FIX]license and init --- extra_time_application/__init__.py | 2 -- extra_time_application/__manifest__.py | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/extra_time_application/__init__.py b/extra_time_application/__init__.py index 4f8fe946..30ac26c2 100644 --- a/extra_time_application/__init__.py +++ b/extra_time_application/__init__.py @@ -1,6 +1,4 @@ # -*-coding: utf-8 -*- -# © 2016-2017 Elico Corp (https://www.elico-corp.com). -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models from . import wizard diff --git a/extra_time_application/__manifest__.py b/extra_time_application/__manifest__.py index 919c43f7..13c9031a 100644 --- a/extra_time_application/__manifest__.py +++ b/extra_time_application/__manifest__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # © 2017 Elico Corp (https://www.elico-corp.com) -# Elico Proprietary License v1.0. -# See LICENSE file for full copyright and licensing details. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { 'name': 'Extra Time Application', From 223aceb61759846975bd29f239903911897f493e Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 19 Dec 2017 17:09:20 +0800 Subject: [PATCH 12/16] [IMP]add message_post --- extra_time_application/models/task_timesheet.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index 3764a98f..387a8dc8 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -33,6 +33,8 @@ def approve_function(self): task_id.remaining_hours += self.apply_hours self.task_id.sub_extra_time += self.apply_hours self.state = 'approve' + self.message_post( + body=_(" %s Approved.") % (self.env.user.name)) else: raise UserError( _( @@ -48,6 +50,8 @@ def refuse_function(self): self.env.user == task_manager.user_id) or \ task_id.project_id.is_modified: self.state = 'refused' + self.message_post( + body=_(" %s Refused.") % (self.env.user.name)) else: raise UserError( _( From 05012ca4e5503472e945feda6382651d65e92c49 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 19 Dec 2017 17:50:15 +0800 Subject: [PATCH 13/16] [FIX]add field instruction --- extra_time_application/models/project_project_inherit.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/extra_time_application/models/project_project_inherit.py b/extra_time_application/models/project_project_inherit.py index 856c654d..6cbbaabd 100644 --- a/extra_time_application/models/project_project_inherit.py +++ b/extra_time_application/models/project_project_inherit.py @@ -7,4 +7,8 @@ class ProjectProjectInherit(models.Model): _inherit = 'project.project' - is_modified = fields.Boolean() + is_modified = fields.Boolean( + string='Is modified', + help='If this field is true,everyone can create the corresponding ' + 'task,and if it is false, only the person in the manager group ' + 'can create the corresponding task') From 4896596889d05e7d83f5e26465ced4fa960b04c3 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Tue, 19 Dec 2017 17:55:34 +0800 Subject: [PATCH 14/16] [DEL]del tests file to test --- extra_time_application/tests/__init__.py | 5 -- .../tests/test_extra_time.py | 33 --------- .../tests/test_extra_time_wizard.py | 28 -------- .../tests/test_project_task_save.py | 71 ------------------- 4 files changed, 137 deletions(-) delete mode 100644 extra_time_application/tests/__init__.py delete mode 100644 extra_time_application/tests/test_extra_time.py delete mode 100644 extra_time_application/tests/test_extra_time_wizard.py delete mode 100644 extra_time_application/tests/test_project_task_save.py diff --git a/extra_time_application/tests/__init__.py b/extra_time_application/tests/__init__.py deleted file mode 100644 index 7d4880eb..00000000 --- a/extra_time_application/tests/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# -*- coding:utf-8 -*- - -from . import test_extra_time -from . import test_project_task_save -from . import test_extra_time_wizard diff --git a/extra_time_application/tests/test_extra_time.py b/extra_time_application/tests/test_extra_time.py deleted file mode 100644 index 934376dd..00000000 --- a/extra_time_application/tests/test_extra_time.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Elico Corp (www.elico-corp.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests import common -from odoo.exceptions import UserError - - -class TestExtraTime(common.TransactionCase): - - def setUp(self): - super(TestExtraTime, self).setUp() - self.submit_user_id = self.env.ref("base.user_demo") - self.task_id = self.env.ref('project.project_task_9') - - self.extra_time_record = self.env['extra.time.application'].create({ - 'submit_user_id': self.submit_user_id.id, - 'task_id': self.task_id.id, - 'reason': 'Automatically created From PM or Reviewer', - 'apply_hours': 2, - 'state': 'to_approve' - }) - - def test_approve_function(self): - try: - self.extra_time_record.approve_function() - except UserError: - pass - - def test_refuse_function(self): - try: - self.extra_time_record.refuse_function() - except UserError: - pass diff --git a/extra_time_application/tests/test_extra_time_wizard.py b/extra_time_application/tests/test_extra_time_wizard.py deleted file mode 100644 index b567cb0c..00000000 --- a/extra_time_application/tests/test_extra_time_wizard.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Elico Corp (www.elico-corp.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests import common - - -class TestExtraTimeWizard(common.TransactionCase): - - def setUp(self): - super(TestExtraTimeWizard, self).setUp() - self.task_id = self.env.ref('project.project_task_9') - self.submit_user_id = self.env.ref('base.user_demo') - self.extra_time_1 = self.env['extra.time.application.wizard'].create({ - 'submit_user_id': self.submit_user_id.id, - 'task_id': self.task_id.id, - 'reason': 'system test', - 'apply_hours': 3 - }) - self.extra_time_2 = self.env['extra.time.application.wizard'].create({ - 'submit_user_id': self.submit_user_id.id, - 'task_id': self.task_id.id, - 'reason': 'system test', - 'apply_hours': 3 - }) - - def test_subscribe(self): - self.extra_time_1.subscribe() - self.extra_time_2.subscribe() diff --git a/extra_time_application/tests/test_project_task_save.py b/extra_time_application/tests/test_project_task_save.py deleted file mode 100644 index bc7f49e4..00000000 --- a/extra_time_application/tests/test_project_task_save.py +++ /dev/null @@ -1,71 +0,0 @@ -# -*- coding: utf-8 -*- -# © 2017 Elico Corp (www.elico-corp.com) -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests import common -from datetime import datetime -from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT -from odoo.exceptions import UserError - - -class TestProjectTaskSave(common.TransactionCase): - - def setUp(self): - super(TestProjectTaskSave, self).setUp() - self.name_1 = self.env.ref('project.project_task_9') - self.name_2 = self.env.ref('project.project_task_8') - self.project_id = self.env.ref('project.project_project_4') - self.user_id = self.env.ref('base.user_root') - self.sub_extra_time = 0 - self.timesheet_ids = self.env['account.analytic.line'].write([[ - 0, False, { - 'date_time': datetime.today().strftime( - DEFAULT_SERVER_DATETIME_FORMAT), - 'user_id': self.user_id.id, - 'name': 'test', - 'unit_amount': 1, - 'date': '2017-12-15', - 'project_id': self.project_id.id - } - ]]) - self.task_1 = self.env['project.task'].create({ - 'name': self.name_1.id, - 'project_id': self.project_id.id, - 'user_id': self.user_id.id, - 'planned_hours': 18, - 'remaining_hours': 18, - 'timesheet_ids': self.timesheet_ids - }) - self.task_2 = self.env['project.task'].create({ - 'name': self.name_2.id, - 'project_id': self.project_id.id, - 'user_id': self.user_id.id, - 'planned_hours': 18, - 'remaining_hours': 1, - 'timesheet_ids': self.timesheet_ids - }) - self.view_id = self.env.ref( - 'extra_time_application.project_task_form_inherit_view').id - - def test_save(self): - vals_1 = {'remaining_hours': 23} - self.task_1.write(vals_1) - vals_2 = {'timesheet_ids': [[4, 20, False], [0, False, { - 'date_time': datetime.today().strftime( - DEFAULT_SERVER_DATETIME_FORMAT), - 'user_id': 1, - 'name': self.name_2, - 'unit_amount': 2, - 'date': '2017-12-13', - 'project_id': self.project_id.id - }]]} - self.task_1.write(vals_2) - try: - self.task_2.write(vals_2) - except UserError: - pass - - def test_open_extra_time_line(self): - self.task_1.open_extra_time_line() - - def test_fields_view_get(self): - self.task_1.fields_view_get(view_id=self.view_id, view_type='form') From 794b7b8e680c6f6941b000cf006f4be836a4df88 Mon Sep 17 00:00:00 2001 From: xlm609 Date: Wed, 20 Dec 2017 10:18:01 +0800 Subject: [PATCH 15/16] [IMP]add test file --- .../models/task_timesheet.py | 4 +- extra_time_application/tests/__init__.py | 5 ++ .../tests/test_extra_time.py | 33 +++++++++ .../tests/test_extra_time_wizard.py | 28 ++++++++ .../tests/test_project_task_save.py | 71 +++++++++++++++++++ 5 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 extra_time_application/tests/__init__.py create mode 100644 extra_time_application/tests/test_extra_time.py create mode 100644 extra_time_application/tests/test_extra_time_wizard.py create mode 100644 extra_time_application/tests/test_project_task_save.py diff --git a/extra_time_application/models/task_timesheet.py b/extra_time_application/models/task_timesheet.py index 387a8dc8..de6329d2 100644 --- a/extra_time_application/models/task_timesheet.py +++ b/extra_time_application/models/task_timesheet.py @@ -66,7 +66,7 @@ def create(self, vals): if user != self.env['project.task'].browse( vals.get('task_id')).user_id: msg_vals = { - 'partner_id': user.id, + 'partner_id': user.partner_id.id, 'res_model': self._name, } msg_followers.append((0, 0, msg_vals)) @@ -77,7 +77,7 @@ def create(self, vals): 'extra_time_application.group_extra_time_manager').users) and ( task_manager != task_id.user_id): msg_vals = { - 'partner_id': task_manager.id, + 'partner_id': task_manager.partner_id.id, 'res_model': self._name, } msg_followers.append((0, 0, msg_vals)) diff --git a/extra_time_application/tests/__init__.py b/extra_time_application/tests/__init__.py new file mode 100644 index 00000000..7d4880eb --- /dev/null +++ b/extra_time_application/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding:utf-8 -*- + +from . import test_extra_time +from . import test_project_task_save +from . import test_extra_time_wizard diff --git a/extra_time_application/tests/test_extra_time.py b/extra_time_application/tests/test_extra_time.py new file mode 100644 index 00000000..934376dd --- /dev/null +++ b/extra_time_application/tests/test_extra_time.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.tests import common +from odoo.exceptions import UserError + + +class TestExtraTime(common.TransactionCase): + + def setUp(self): + super(TestExtraTime, self).setUp() + self.submit_user_id = self.env.ref("base.user_demo") + self.task_id = self.env.ref('project.project_task_9') + + self.extra_time_record = self.env['extra.time.application'].create({ + 'submit_user_id': self.submit_user_id.id, + 'task_id': self.task_id.id, + 'reason': 'Automatically created From PM or Reviewer', + 'apply_hours': 2, + 'state': 'to_approve' + }) + + def test_approve_function(self): + try: + self.extra_time_record.approve_function() + except UserError: + pass + + def test_refuse_function(self): + try: + self.extra_time_record.refuse_function() + except UserError: + pass diff --git a/extra_time_application/tests/test_extra_time_wizard.py b/extra_time_application/tests/test_extra_time_wizard.py new file mode 100644 index 00000000..b567cb0c --- /dev/null +++ b/extra_time_application/tests/test_extra_time_wizard.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.tests import common + + +class TestExtraTimeWizard(common.TransactionCase): + + def setUp(self): + super(TestExtraTimeWizard, self).setUp() + self.task_id = self.env.ref('project.project_task_9') + self.submit_user_id = self.env.ref('base.user_demo') + self.extra_time_1 = self.env['extra.time.application.wizard'].create({ + 'submit_user_id': self.submit_user_id.id, + 'task_id': self.task_id.id, + 'reason': 'system test', + 'apply_hours': 3 + }) + self.extra_time_2 = self.env['extra.time.application.wizard'].create({ + 'submit_user_id': self.submit_user_id.id, + 'task_id': self.task_id.id, + 'reason': 'system test', + 'apply_hours': 3 + }) + + def test_subscribe(self): + self.extra_time_1.subscribe() + self.extra_time_2.subscribe() diff --git a/extra_time_application/tests/test_project_task_save.py b/extra_time_application/tests/test_project_task_save.py new file mode 100644 index 00000000..bc7f49e4 --- /dev/null +++ b/extra_time_application/tests/test_project_task_save.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# © 2017 Elico Corp (www.elico-corp.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from odoo.tests import common +from datetime import datetime +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo.exceptions import UserError + + +class TestProjectTaskSave(common.TransactionCase): + + def setUp(self): + super(TestProjectTaskSave, self).setUp() + self.name_1 = self.env.ref('project.project_task_9') + self.name_2 = self.env.ref('project.project_task_8') + self.project_id = self.env.ref('project.project_project_4') + self.user_id = self.env.ref('base.user_root') + self.sub_extra_time = 0 + self.timesheet_ids = self.env['account.analytic.line'].write([[ + 0, False, { + 'date_time': datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT), + 'user_id': self.user_id.id, + 'name': 'test', + 'unit_amount': 1, + 'date': '2017-12-15', + 'project_id': self.project_id.id + } + ]]) + self.task_1 = self.env['project.task'].create({ + 'name': self.name_1.id, + 'project_id': self.project_id.id, + 'user_id': self.user_id.id, + 'planned_hours': 18, + 'remaining_hours': 18, + 'timesheet_ids': self.timesheet_ids + }) + self.task_2 = self.env['project.task'].create({ + 'name': self.name_2.id, + 'project_id': self.project_id.id, + 'user_id': self.user_id.id, + 'planned_hours': 18, + 'remaining_hours': 1, + 'timesheet_ids': self.timesheet_ids + }) + self.view_id = self.env.ref( + 'extra_time_application.project_task_form_inherit_view').id + + def test_save(self): + vals_1 = {'remaining_hours': 23} + self.task_1.write(vals_1) + vals_2 = {'timesheet_ids': [[4, 20, False], [0, False, { + 'date_time': datetime.today().strftime( + DEFAULT_SERVER_DATETIME_FORMAT), + 'user_id': 1, + 'name': self.name_2, + 'unit_amount': 2, + 'date': '2017-12-13', + 'project_id': self.project_id.id + }]]} + self.task_1.write(vals_2) + try: + self.task_2.write(vals_2) + except UserError: + pass + + def test_open_extra_time_line(self): + self.task_1.open_extra_time_line() + + def test_fields_view_get(self): + self.task_1.fields_view_get(view_id=self.view_id, view_type='form') From e18439d9cb83e875b68449334e2cc0a86b546a2c Mon Sep 17 00:00:00 2001 From: xlm609 Date: Fri, 22 Dec 2017 10:51:11 +0800 Subject: [PATCH 16/16] [FIX]the bug that when input timesheet and edit remainig_hours do not automatic create a extra time record --- .../models/project_task_inherit.py | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/extra_time_application/models/project_task_inherit.py b/extra_time_application/models/project_task_inherit.py index 938de7b9..94321a01 100644 --- a/extra_time_application/models/project_task_inherit.py +++ b/extra_time_application/models/project_task_inherit.py @@ -19,28 +19,33 @@ def write(self, vals): for log in self: current_user = log.env.user remaining = log.remaining_hours + spending_hours = 0 if not log.env.context.get('flag') and \ not log.env.context.get('flag_remaine'): + for record in vals.get('timesheet_ids', []): + if record[0] == 0: + remaining -= record[2]['unit_amount'] + spending_hours += record[2]['unit_amount'] + elif record[0] == 2: + item = log.timesheet_ids.search([ + ('id', '=', record[1]) + ]) + remaining += item['unit_amount'] + spending_hours -= item['unit_amount'] if vals.get('remaining_hours') and \ - not vals.get('timesheet_ids'): + (vals.get('remaining_hours') != remaining): log.env['extra.time.application'].create({ 'submit_user_id': current_user.id, 'task_id': log.id, 'reason': 'Automatically create From PM or Reviewer', 'apply_hours': - vals.get('remaining_hours') - log.remaining_hours, + vals.get('remaining_hours') - + log.remaining_hours + spending_hours, 'state': 'approve', }) log.sub_extra_time += \ - (vals.get('remaining_hours') - log.remaining_hours) - for record in vals.get('timesheet_ids', []): - if record[0] == 0: - remaining -= record[2]['unit_amount'] - elif record[0] == 2: - item = log.timesheet_ids.search([ - ('id', '=', record[1]) - ]) - remaining += item['unit_amount'] + (vals.get('remaining_hours') - + log.remaining_hours + spending_hours) if remaining < 0: raise UserError( _(