From 3eb717baecb590580bb3a098308822a6ed70cd42 Mon Sep 17 00:00:00 2001 From: vbh-odoo Date: Mon, 27 Jul 2015 13:00:08 +0530 Subject: [PATCH] [MOV] project_issue: split project_issue.py and project_issue_view files --- addons/project_issue/__openerp__.py | 7 +- ...data.xml => mail_message_subtype_data.xml} | 0 addons/project_issue/models/__init__.py | 3 + .../models/account_analytic_account.py | 35 +++++ addons/project_issue/models/project_issue.py | 120 ------------------ .../project_issue/models/project_project.py | 72 +++++++++++ addons/project_issue/models/res_partner.py | 21 +++ .../views/account_analytic_account_view.xml | 17 +++ .../views/project_issue_view.xml | 103 +++------------ .../views/project_project_view.xml | 36 ++++++ .../project_issue/views/res_partner_view.xml | 24 ++++ 11 files changed, 232 insertions(+), 206 deletions(-) rename addons/project_issue/data/{project_issue_data.xml => mail_message_subtype_data.xml} (100%) create mode 100644 addons/project_issue/models/account_analytic_account.py create mode 100644 addons/project_issue/models/project_project.py create mode 100644 addons/project_issue/models/res_partner.py create mode 100644 addons/project_issue/views/account_analytic_account_view.xml create mode 100644 addons/project_issue/views/project_project_view.xml create mode 100644 addons/project_issue/views/res_partner_view.xml diff --git a/addons/project_issue/__openerp__.py b/addons/project_issue/__openerp__.py index 5cdd6aec9bb..7637a61e7ce 100644 --- a/addons/project_issue/__openerp__.py +++ b/addons/project_issue/__openerp__.py @@ -10,7 +10,7 @@ 'description': """ Track Issues/Bugs Management for Projects ========================================= -This application allows you to manage the issues you might face in a project like bugs in a system, client complaints or material breakdowns. +This application allows you to manage the issues you might face in a project like bugs in a system, client complaints or material breakdowns. It allows the manager to quickly check the issues, assign them and decide on their status quickly as they evolve. """, @@ -21,11 +21,14 @@ It allows the manager to quickly check the issues, assign them and decide on the 'data': [ 'views/project_issue_view.xml', 'views/project_issue_config_settings_views.xml', + 'views/account_analytic_account_view.xml', + 'views/project_project_view.xml', + 'views/res_partner_view.xml', 'views/project_issue_menu.xml', 'report/project_issue_report_view.xml', 'security/project_issue_security.xml', 'security/ir.model.access.csv', - 'data/project_issue_data.xml', + 'data/mail_message_subtype_data.xml', 'views/project_dashboard.xml', ], 'demo': ['data/project_issue_demo.xml'], diff --git a/addons/project_issue/data/project_issue_data.xml b/addons/project_issue/data/mail_message_subtype_data.xml similarity index 100% rename from addons/project_issue/data/project_issue_data.xml rename to addons/project_issue/data/mail_message_subtype_data.xml diff --git a/addons/project_issue/models/__init__.py b/addons/project_issue/models/__init__.py index 7bb2eddb06b..859bb01a7b3 100644 --- a/addons/project_issue/models/__init__.py +++ b/addons/project_issue/models/__init__.py @@ -2,5 +2,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import project_issue +import account_analytic_account +import project_project import project_task_type +import res_partner import project_issue_config_settings diff --git a/addons/project_issue/models/account_analytic_account.py b/addons/project_issue/models/account_analytic_account.py new file mode 100644 index 00000000000..3dc67c26f6f --- /dev/null +++ b/addons/project_issue/models/account_analytic_account.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp.osv import fields, osv +from openerp.tools.translate import _ +from openerp.exceptions import UserError + + +class account_analytic_account(osv.Model): + _inherit = 'account.analytic.account' + _description = 'Analytic Account' + + _columns = { + 'use_issues': fields.boolean('Use Issues', help="Check this box to manage customer activities through this project"), + } + + def on_change_template(self, cr, uid, ids, template_id, date_start=False, context=None): + res = super(account_analytic_account, self).on_change_template(cr, uid, ids, template_id, date_start=date_start, context=context) + if template_id and 'value' in res: + template = self.browse(cr, uid, template_id, context=context) + res['value']['use_issues'] = template.use_issues + return res + + def _trigger_project_creation(self, cr, uid, vals, context=None): + if context is None: + context = {} + res = super(account_analytic_account, self)._trigger_project_creation(cr, uid, vals, context=context) + return res or (vals.get('use_issues') and not 'project_creation_in_progress' in context) + + def unlink(self, cr, uid, ids, context=None): + proj_ids = self.pool['project.project'].search(cr, uid, [('analytic_account_id', 'in', ids)]) + has_issues = self.pool['project.issue'].search(cr, uid, [('project_id', 'in', proj_ids)], count=True, context=context) + if has_issues: + raise UserError(_('Please remove existing issues in the project linked to the accounts you want to delete.')) + return super(account_analytic_account, self).unlink(cr, uid, ids, context=context) diff --git a/addons/project_issue/models/project_issue.py b/addons/project_issue/models/project_issue.py index 9302bf45d57..bc929a67352 100644 --- a/addons/project_issue/models/project_issue.py +++ b/addons/project_issue/models/project_issue.py @@ -457,123 +457,3 @@ class project_issue(osv.Model): headers['X-Odoo-Tags'] = ','.join([tag.name for tag in current_issue.tag_ids]) res['headers'] = repr(headers) return res - - -class project(osv.Model): - _inherit = "project.project" - - def _get_alias_models(self, cr, uid, context=None): - res = super(project, self)._get_alias_models(cr, uid, context=context) - res.append(("project.issue", "Issues")) - return res - - def _issue_count(self, cr, uid, ids, field_name, arg, context=None): - Issue = self.pool['project.issue'] - return { - project_id: Issue.search_count(cr,uid, [('project_id', '=', project_id), '|', ('stage_id.fold', '=', False), ('stage_id', '=', False)], context=context) - for project_id in ids - } - - def _issue_needaction_count(self, cr, uid, ids, field_name, arg, context=None): - Issue = self.pool['project.issue'] - res = dict.fromkeys(ids, 0) - projects = Issue.read_group(cr, uid, [('project_id', 'in', ids), ('message_needaction', '=', True)], ['project_id'], ['project_id'], context=context) - res.update({project['project_id'][0]: int(project['project_id_count']) for project in projects}) - return res - - _columns = { - 'issue_count': fields.function(_issue_count, type='integer', string="Issues",), - 'issue_ids': fields.one2many('project.issue', 'project_id', string="Issues", - domain=['|', ('stage_id.fold', '=', False), ('stage_id', '=', False)]), - 'issue_needaction_count': fields.function(_issue_needaction_count, type='integer', string="Issues",), - } - - @api.multi - def write(self, vals): - res = super(project, self).write(vals) - if 'active' in vals: - # archiving/unarchiving a project does it on its issues, too - issues = self.with_context(active_test=False).mapped('issue_ids') - issues.write({'active': vals['active']}) - return res - - -class account_analytic_account(osv.Model): - _inherit = 'account.analytic.account' - _description = 'Analytic Account' - - _columns = { - 'use_issues': fields.boolean('Use Issues', help="Check this box to manage customer activities through this project"), - } - - def on_change_template(self, cr, uid, ids, template_id, date_start=False, context=None): - res = super(account_analytic_account, self).on_change_template(cr, uid, ids, template_id, date_start=date_start, context=context) - if template_id and 'value' in res: - template = self.browse(cr, uid, template_id, context=context) - res['value']['use_issues'] = template.use_issues - return res - - def _trigger_project_creation(self, cr, uid, vals, context=None): - if context is None: - context = {} - res = super(account_analytic_account, self)._trigger_project_creation(cr, uid, vals, context=context) - return res or (vals.get('use_issues') and not 'project_creation_in_progress' in context) - - def unlink(self, cr, uid, ids, context=None): - proj_ids = self.pool['project.project'].search(cr, uid, [('analytic_account_id', 'in', ids)]) - has_issues = self.pool['project.issue'].search(cr, uid, [('project_id', 'in', proj_ids)], count=True, context=context) - if has_issues: - raise UserError(_('Please remove existing issues in the project linked to the accounts you want to delete.')) - return super(account_analytic_account, self).unlink(cr, uid, ids, context=context) - - -class project_project(osv.Model): - _inherit = 'project.project' - - _columns = { - 'label_issues': fields.char('Use Issues as', help="Customize the issues label, for example to call them cases."), - } - - _defaults = { - 'use_issues': True, - 'label_issues': 'Issues', - } - - def _check_create_write_values(self, cr, uid, vals, context=None): - """ Perform some check on values given to create or write. """ - # Handle use_tasks / use_issues: if only one is checked, alias should take the same model - if vals.get('use_tasks') and not vals.get('use_issues'): - vals['alias_model'] = 'project.task' - elif vals.get('use_issues') and not vals.get('use_tasks'): - vals['alias_model'] = 'project.issue' - - def on_change_use_tasks_or_issues(self, cr, uid, ids, use_tasks, use_issues, context=None): - values = {} - if use_tasks and not use_issues: - values['alias_model'] = 'project.task' - elif not use_tasks and use_issues: - values['alias_model'] = 'project.issue' - return {'value': values} - - def create(self, cr, uid, vals, context=None): - self._check_create_write_values(cr, uid, vals, context=context) - return super(project_project, self).create(cr, uid, vals, context=context) - - def write(self, cr, uid, ids, vals, context=None): - self._check_create_write_values(cr, uid, vals, context=context) - return super(project_project, self).write(cr, uid, ids, vals, context=context) - -class res_partner(osv.osv): - def _issue_count(self, cr, uid, ids, field_name, arg, context=None): - Issue = self.pool['project.issue'] - partners = {id: self.search(cr, uid, [('id', 'child_of', ids)]) for id in ids} - return { - partner_id: Issue.search_count(cr, uid, [('partner_id', 'in', partners[partner_id])]) - for partner_id in partners.keys() - } - - """ Inherits partner and adds Issue information in the partner form """ - _inherit = 'res.partner' - _columns = { - 'issue_count': fields.function(_issue_count, string='# Issues', type='integer'), - } diff --git a/addons/project_issue/models/project_project.py b/addons/project_issue/models/project_project.py new file mode 100644 index 00000000000..490c837f700 --- /dev/null +++ b/addons/project_issue/models/project_project.py @@ -0,0 +1,72 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp.osv import fields, osv +from openerp import api + + +class project_project(osv.Model): + _inherit = 'project.project' + + def _get_alias_models(self, cr, uid, context=None): + res = super(project, self)._get_alias_models(cr, uid, context=context) + res.append(("project.issue", "Issues")) + return res + + + def _issue_count(self, cr, uid, ids, field_name, arg, context=None): + Issue = self.pool['project.issue'] + return { + project_id: Issue.search_count(cr,uid, [('project_id', '=', project_id), '|', ('stage_id.fold', '=', False), ('stage_id', '=', False)], context=context) + for project_id in ids + } + + def _issue_needaction_count(self, cr, uid, ids, field_name, arg, context=None): + Issue = self.pool['project.issue'] + res = dict.fromkeys(ids, 0) + projects = Issue.read_group(cr, uid, [('project_id', 'in', ids), ('message_needaction', '=', True)], ['project_id'], ['project_id'], context=context) + res.update({project['project_id'][0]: int(project['project_id_count']) for project in projects}) + return res + + _columns = { + 'issue_count': fields.function(_issue_count, type='integer', string="Issues",), + 'issue_ids': fields.one2many('project.issue', 'project_id', string="Issues", + domain=['|', ('stage_id.fold', '=', False), ('stage_id', '=', False)]), + 'issue_needaction_count': fields.function(_issue_needaction_count, type='integer', string="Issues",), + 'label_issues': fields.char('Use Issues as', help="Customize the issues label, for example to call them cases."), + } + + _defaults = { + 'use_issues': True, + 'label_issues': 'Issues', + } + + def _check_create_write_values(self, cr, uid, vals, context=None): + """ Perform some check on values given to create or write. """ + # Handle use_tasks / use_issues: if only one is checked, alias should take the same model + if vals.get('use_tasks') and not vals.get('use_issues'): + vals['alias_model'] = 'project.task' + elif vals.get('use_issues') and not vals.get('use_tasks'): + vals['alias_model'] = 'project.issue' + + def on_change_use_tasks_or_issues(self, cr, uid, ids, use_tasks, use_issues, context=None): + values = {} + if use_tasks and not use_issues: + values['alias_model'] = 'project.task' + elif not use_tasks and use_issues: + values['alias_model'] = 'project.issue' + return {'value': values} + + def create(self, cr, uid, vals, context=None): + self._check_create_write_values(cr, uid, vals, context=context) + return super(project_project, self).create(cr, uid, vals, context=context) + + @api.multi + def write(self, vals): + self._check_create_write_values(vals) + res = super(project_project, self).write(vals) + if 'active' in vals: + # archiving/unarchiving a project does it on its issues, too + issues = self.with_context(active_test=False).mapped('issue_ids') + issues.write({'active': vals['active']}) + return res diff --git a/addons/project_issue/models/res_partner.py b/addons/project_issue/models/res_partner.py new file mode 100644 index 00000000000..7e9655a41c9 --- /dev/null +++ b/addons/project_issue/models/res_partner.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from openerp.osv import fields, osv + + +class res_partner(osv.osv): + """ Inherits partner and adds Issue information in the partner form """ + _inherit = 'res.partner' + + def _issue_count(self, cr, uid, ids, field_name, arg, context=None): + Issue = self.pool['project.issue'] + partners = {id: self.search(cr, uid, [('id', 'child_of', ids)]) for id in ids} + return { + partner_id: Issue.search_count(cr, uid, [('partner_id', 'in', partners[partner_id])]) + for partner_id in partners.keys() + } + + _columns = { + 'issue_count': fields.function(_issue_count, string='# Issues', type='integer'), + } diff --git a/addons/project_issue/views/account_analytic_account_view.xml b/addons/project_issue/views/account_analytic_account_view.xml new file mode 100644 index 00000000000..c1f787abecb --- /dev/null +++ b/addons/project_issue/views/account_analytic_account_view.xml @@ -0,0 +1,17 @@ + + + + + account.analytic.account.issue.form.inherit + account.analytic.account + + + + + + + + + + diff --git a/addons/project_issue/views/project_issue_view.xml b/addons/project_issue/views/project_issue_view.xml index 7d20e4b9055..6bd3295c085 100644 --- a/addons/project_issue/views/project_issue_view.xml +++ b/addons/project_issue/views/project_issue_view.xml @@ -257,52 +257,6 @@ - - - project.project.form.inherited - project.project - - - - on_change_use_tasks_or_issues(use_tasks, use_issues) - - - 0 - - -
- -
-
-
- -
- - {'on_change': 'on_change_use_tasks_or_issues(use_tasks, use_issues)'} - -
-
- - - account.analytic.account.issue.form.inherit - account.analytic.account - - - - - - - - - project.issue form @@ -317,47 +271,28 @@ - - - res.partner.issues.button.view - res.partner - - - - -
- -
+ + + Issues + project.issue + form + tree,form + + + {"search_default_user_id":'', "search_default_draft":'', "search_default_todo":'', "portal":'True'} + + current + +

+ Click to create an issue. +

+ You can track your issues from this menu and the action we + will take. +

- - - Issues - project.issue - form - tree,form - - - {"search_default_user_id":'', "search_default_draft":'', "search_default_todo":'', "portal":'True'} - - current - -

- Click to create an issue. -

- You can track your issues from this menu and the action we - will take. -

-
-
- - diff --git a/addons/project_issue/views/project_project_view.xml b/addons/project_issue/views/project_project_view.xml new file mode 100644 index 00000000000..35e0f140f1b --- /dev/null +++ b/addons/project_issue/views/project_project_view.xml @@ -0,0 +1,36 @@ + + + + + project.project.form.inherited + project.project + + + + on_change_use_tasks_or_issues(use_tasks, use_issues) + + + 0 + + +
+ +
+
+
+ +
+ + {'on_change': 'on_change_use_tasks_or_issues(use_tasks, use_issues)'} + +
+
+
+
diff --git a/addons/project_issue/views/res_partner_view.xml b/addons/project_issue/views/res_partner_view.xml new file mode 100644 index 00000000000..d018464c01b --- /dev/null +++ b/addons/project_issue/views/res_partner_view.xml @@ -0,0 +1,24 @@ + + + + + + res.partner.issues.button.view + res.partner + + + + +
+ +
+
+
+ +
+