diff options
| author | Robot Odoo <xmo+roboto@odoo.com> | 2019-05-24 14:15:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-24 14:15:52 +0200 |
| commit | 079fcd6232e0c0338c353e6281dc5a930aa91e3a (patch) | |
| tree | f577b36b18513ba3c2bee63cb2085d2a20695356 | |
| parent | af86bc7288d252c6e1c3fe9b4fae3121ef459190 (diff) | |
| parent | 3ab9b5192c71073a5c3d629ce598d5bafd3407a5 (diff) | |
[MERGE][IMP] project, *_timesheet: link analytic account and project
Impacted modules: hr_timesheet, project, sale_timesheet and sale_timesheet_purchase
Currently, the link between the Analytic Account and the Project is non existant if
Timesheets is not installed, and we track any cost linked to the AA set on the Project,
but we only track the revenues linked to Timesheets.
The purpose of this merge is to allow simple project (no timesheet installed or
activated) to track their costs and revenues. This is done through the analytic account; indeed, all
purchase order, sales order, invoices and vendor bills can generate analytic entries. It could
then be interessting for user to see the costs and revenues for a project.
We decided to redirect user from the project dashboard to the "costs/revenues" action of the analytic
account itself, or (if timesheet is allowed on project) to the overview.
This commit also integrates purchase orders on the project overview.
Implementation:
This PR aims to improve the link between Project and Analytic Accounting, by several actions:
* Move all the analytic account business to project
* Add an Other Revenues field in Project Overview, which represent the positive analytic entries
from the AA set on the Project AND that are not linked
to a Timesheet
* Add two smart buttons on Project Overview to Purchase Orders and Vendor Bill of the project's AA
* Add the results (Sales Orders and Timesheets) linked to the project's AA in the respective smart
buttons of Project Overview
* Add a "Profitability" link on the Kanban card of the Project bringing to the Costs & Revenues of
the AA set on the Project to allow profitability tracking when there are no Timesheets.
To do so, it was required to move back the analytic dependency from hr_timesheet to project, like
before 3dd3e2648329995ddc309081787e19005d48ccd0 (but without the inheritS).
Limitation:
This will only make sense for project having a "one-to-one" relation with analytic account. If 2 projects
are linked to the same AA, we have no way to deduce from which project the cost entry is linked.
Task-1975022
closes odoo/odoo#33237
Signed-off-by: Jérome Maes (jem) <jem@openerp.com>
| -rw-r--r-- | addons/hr_timesheet/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hr_timesheet/models/project.py | 33 | ||||
| -rw-r--r-- | addons/hr_timesheet/security/ir.model.access.csv | 4 | ||||
| -rw-r--r-- | addons/hr_timesheet/views/hr_timesheet_views.xml | 18 | ||||
| -rw-r--r-- | addons/hr_timesheet/views/project_views.xml | 6 | ||||
| -rw-r--r-- | addons/project/__manifest__.py | 2 | ||||
| -rw-r--r-- | addons/project/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/project/models/analytic_account.py (renamed from addons/hr_timesheet/models/analytic_account.py) | 1 | ||||
| -rw-r--r-- | addons/project/models/project.py | 57 | ||||
| -rw-r--r-- | addons/project/security/ir.model.access.csv | 6 | ||||
| -rw-r--r-- | addons/project/views/analytic_views.xml | 21 | ||||
| -rw-r--r-- | addons/project/views/project_views.xml | 7 | ||||
| -rw-r--r-- | addons/sale_timesheet/views/hr_timesheet_templates.xml | 4 | ||||
| -rw-r--r-- | addons/sale_timesheet_purchase/__init__.py | 4 | ||||
| -rw-r--r-- | addons/sale_timesheet_purchase/__manifest__.py | 17 | ||||
| -rw-r--r-- | addons/sale_timesheet_purchase/models/__init__.py | 4 | ||||
| -rw-r--r-- | addons/sale_timesheet_purchase/models/project_overview.py | 38 |
17 files changed, 158 insertions, 66 deletions
diff --git a/addons/hr_timesheet/models/__init__.py b/addons/hr_timesheet/models/__init__.py index ce7d853abca..5e18c694d32 100644 --- a/addons/hr_timesheet/models/__init__.py +++ b/addons/hr_timesheet/models/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import analytic_account from . import hr from . import hr_timesheet from . import ir_http diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 3e7a5fc3668..8c6d21eab92 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -9,9 +9,6 @@ class Project(models.Model): _inherit = "project.project" allow_timesheets = fields.Boolean("Allow timesheets", default=True, help="Enable timesheeting on the project.") - analytic_account_id = fields.Many2one('account.analytic.account', string="Analytic Account", copy=False, ondelete='set null', - help="Analytic account to which this project is linked for financial management." - "Use an analytic account to record cost and revenue on your project.") @api.onchange('partner_id') def _onchange_partner_id(self): @@ -47,12 +44,7 @@ class Project(models.Model): """ allow_timesheets = values['allow_timesheets'] if 'allow_timesheets' in values else self.default_get(['allow_timesheets'])['allow_timesheets'] if allow_timesheets and not values.get('analytic_account_id'): - analytic_account = self.env['account.analytic.account'].create({ - 'name': values.get('name', _('Unknown Analytic Account')), - 'company_id': values.get('company_id', self.env.company_id.id), - 'partner_id': values.get('partner_id'), - 'active': True, - }) + analytic_account = self._create_analytic_account_from_values(values) values['analytic_account_id'] = analytic_account.id return super(Project, self).create(values) @@ -66,31 +58,14 @@ class Project(models.Model): result = super(Project, self).write(values) return result - @api.multi - def unlink(self): - """ Delete the empty related analytic account """ - analytic_accounts_to_delete = self.env['account.analytic.account'] - for project in self: - if project.analytic_account_id and not project.analytic_account_id.line_ids: - analytic_accounts_to_delete |= project.analytic_account_id - result = super(Project, self).unlink() - analytic_accounts_to_delete.unlink() - return result + # --------------------------------------------------- + # Business Methods + # --------------------------------------------------- @api.model def _init_data_analytic_account(self): self.search([('analytic_account_id', '=', False), ('allow_timesheets', '=', True)])._create_analytic_account() - def _create_analytic_account(self): - for project in self: - analytic_account = self.env['account.analytic.account'].create({ - 'name': project.name, - 'company_id': project.company_id.id, - 'partner_id': project.partner_id.id, - 'active': True, - }) - project.write({'analytic_account_id': analytic_account.id}) - class Task(models.Model): _inherit = "project.task" diff --git a/addons/hr_timesheet/security/ir.model.access.csv b/addons/hr_timesheet/security/ir.model.access.csv index c6776df9364..96723f93935 100644 --- a/addons/hr_timesheet/security/ir.model.access.csv +++ b/addons/hr_timesheet/security/ir.model.access.csv @@ -2,10 +2,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink access_account_analytic_line_user,analytic.account.analytic.line.timesheet.user,analytic.model_account_analytic_line,hr_timesheet.group_hr_timesheet_user,1,1,1,1
access_account_analytic_line_portal,access_timesheets_portal,analytic.model_account_analytic_line,base.group_portal,1,0,0,0
access_account_analytic_user,analytic.account.analytic.timesheet.user,analytic.model_account_analytic_account,hr_timesheet.group_hr_timesheet_user,1,1,0,0
-access_account_analytic_account_user,account.analytic.account,analytic.model_account_analytic_account,project.group_project_user,1,0,0,0
-access_account_analytic_account_manager,account.analytic.account,analytic.model_account_analytic_account,project.group_project_manager,1,1,1,1
-access_account_analytic_account_portal,account_analytic_account,analytic.model_account_analytic_account,base.group_portal,1,0,0,0
-access_account_analytic_line_project,account.analytic.line project,analytic.model_account_analytic_line,project.group_project_manager,1,1,1,1
access_uom_uom_hr_timesheet,uom.uom.timesheet.user,uom.model_uom_uom,hr_timesheet.group_hr_timesheet_user,1,0,0,0
access_project_project,project.project.timesheet.user,model_project_project,hr_timesheet.group_hr_timesheet_user,1,0,0,0
access_project_task,project.task.timesheet.user,model_project_task,hr_timesheet.group_hr_timesheet_user,1,1,0,0
diff --git a/addons/hr_timesheet/views/hr_timesheet_views.xml b/addons/hr_timesheet/views/hr_timesheet_views.xml index f5a5c8a1929..700feb230fe 100644 --- a/addons/hr_timesheet/views/hr_timesheet_views.xml +++ b/addons/hr_timesheet/views/hr_timesheet_views.xml @@ -1,24 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <odoo> <data> - <!-- - Analytic Accounts with project - --> - <record id="account_analytic_account_view_form_inherit" model="ir.ui.view"> - <field name="name">account.analytic.account.form.inherit</field> - <field name="model">account.analytic.account</field> - <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/> - <field eval="18" name="priority"/> - <field name="arch" type="xml"> - <xpath expr="//button[@name='toggle_active']" position="before"> - <button class="oe_stat_button" type="object" name="action_view_projects" - icon="fa-puzzle-piece" attrs="{'invisible': [('project_count', '=', 0)]}"> - <field string="Projects" name="project_count" widget="statinfo"/> - </button> - </xpath> - </field> - </record> - <!-- Timesheet root menus --> <menuitem id="timesheet_menu_root" diff --git a/addons/hr_timesheet/views/project_views.xml b/addons/hr_timesheet/views/project_views.xml index 1b17e29d25c..c8a061b5ad0 100644 --- a/addons/hr_timesheet/views/project_views.xml +++ b/addons/hr_timesheet/views/project_views.xml @@ -45,9 +45,6 @@ <xpath expr="//group[@name='extra_settings']" position="inside"> <field name="allow_timesheets"/> </xpath> - <xpath expr="//field[@name='partner_id']" position="after"> - <field name="analytic_account_id" groups="analytic.group_analytic_accounting" /> - </xpath> </field> </record> @@ -178,6 +175,9 @@ </div> </a> </xpath> + <xpath expr="//a[@name='action_view_account_analytic_line']" position="attributes"> + <attribute name="t-if">record.analytic_account_id.raw_value and !record.allow_timesheets.raw_value</attribute> + </xpath> </field> </record> diff --git a/addons/project/__manifest__.py b/addons/project/__manifest__.py index 3620923b452..e71a47d8286 100644 --- a/addons/project/__manifest__.py +++ b/addons/project/__manifest__.py @@ -9,6 +9,7 @@ 'sequence': 10, 'summary': 'Organize and schedule your projects ', 'depends': [ + 'analytic', 'base_setup', 'mail', 'portal', @@ -23,6 +24,7 @@ 'security/project_security.xml', 'security/ir.model.access.csv', 'report/project_report_views.xml', + 'views/analytic_views.xml', 'views/digest_views.xml', 'views/rating_views.xml', 'views/project_views.xml', diff --git a/addons/project/models/__init__.py b/addons/project/models/__init__.py index c796777486b..22a31e4bc71 100644 --- a/addons/project/models/__init__.py +++ b/addons/project/models/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import analytic_account from . import project from . import res_config_settings from . import res_partner diff --git a/addons/hr_timesheet/models/analytic_account.py b/addons/project/models/analytic_account.py index 574e73962d9..f61059058be 100644 --- a/addons/hr_timesheet/models/analytic_account.py +++ b/addons/project/models/analytic_account.py @@ -9,7 +9,6 @@ class AccountAnalyticAccount(models.Model): _inherit = 'account.analytic.account' _description = 'Analytic Account' - company_uom_id = fields.Many2one('uom.uom', related='company_id.project_time_mode_id', string="Company UOM", readonly=False) project_ids = fields.One2many('project.project', 'analytic_account_id', string='Projects') project_count = fields.Integer("Project Count", compute='_compute_project_count') diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 4e53288d2a8..627ec77b643 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -80,13 +80,6 @@ class Project(models.Model): values['alias_defaults'] = {'project_id': self.id} return values - @api.multi - def unlink(self): - for project in self: - if project.tasks: - raise UserError(_('You cannot delete a project containing tasks. You can either archive it or first delete all of its tasks.')) - return super(Project, self).unlink() - def _compute_attached_docs_count(self): Attachment = self.env['ir.attachment'] for project in self: @@ -180,6 +173,9 @@ class Project(models.Model): partner_id = fields.Many2one('res.partner', string='Customer', auto_join=True, tracking=True) company_id = fields.Many2one('res.company', string='Company', required=True, default=lambda self: self.env.company_id) currency_id = fields.Many2one('res.currency', related="company_id.currency_id", string="Currency", readonly=True) + analytic_account_id = fields.Many2one('account.analytic.account', string="Analytic Account", copy=False, ondelete='set null', + help="Analytic account to which this project is linked for financial management. " + "Use an analytic account to record cost and revenue on your project.") favorite_user_ids = fields.Many2many( 'res.users', 'project_favorite_user_rel', 'project_id', 'user_id', @@ -325,6 +321,21 @@ class Project(models.Model): return res @api.multi + def unlink(self): + # Check project is empty + for project in self: + if project.tasks: + raise UserError(_('You cannot delete a project containing tasks. You can either archive it or first delete all of its tasks.')) + # Delete the empty related analytic account + analytic_accounts_to_delete = self.env['account.analytic.account'] + for project in self: + if project.analytic_account_id and not project.analytic_account_id.line_ids: + analytic_accounts_to_delete |= project.analytic_account_id + result = super(Project, self).unlink() + analytic_accounts_to_delete.unlink() + return result + + @api.multi def message_subscribe(self, partner_ids=None, channel_ids=None, subtype_ids=None): """ Subscribe to all existing active tasks when subscribing to a project """ res = super(Project, self).message_subscribe(partner_ids=partner_ids, channel_ids=channel_ids, subtype_ids=subtype_ids) @@ -365,6 +376,13 @@ class Project(models.Model): action = self.env['ir.actions.act_window'].for_xml_id('project', 'act_project_project_2_project_task_all') return dict(action, context=ctx) + def action_view_account_analytic_line(self): + """ return the action to see all the analytic lines of the project's analytic account """ + action = self.env.ref('analytic.account_analytic_line_action').read()[0] + action['context'] = {'default_account_id': self.analytic_account_id.id} + action['domain'] = [('account_id', '=', self.analytic_account_id.id)] + return action + @api.multi def action_view_all_rating(self): """ return the action to see all the rating of the project, and activate default filters """ @@ -384,6 +402,31 @@ class Project(models.Model): return dict(action, context=action_context) # --------------------------------------------------- + # Business Methods + # --------------------------------------------------- + + @api.model + def _create_analytic_account_from_values(self, values): + analytic_account = self.env['account.analytic.account'].create({ + 'name': values.get('name', _('Unknown Analytic Account')), + 'company_id': values.get('company_id', self.env.user.company_id.id), + 'partner_id': values.get('partner_id'), + 'active': True, + }) + return analytic_account + + @api.multi + def _create_analytic_account(self): + for project in self: + analytic_account = self.env['account.analytic.account'].create({ + 'name': project.name, + 'company_id': project.company_id.id, + 'partner_id': project.partner_id.id, + 'active': True, + }) + project.write({'analytic_account_id': analytic_account.id}) + + # --------------------------------------------------- # Rating business # --------------------------------------------------- diff --git a/addons/project/security/ir.model.access.csv b/addons/project/security/ir.model.access.csv index ed22a1b4da7..f7bf080c5cf 100644 --- a/addons/project/security/ir.model.access.csv +++ b/addons/project/security/ir.model.access.csv @@ -19,4 +19,8 @@ access_project_tags_all,project.project_tags_all,model_project_tags,,1,0,0,0 access_project_tags_manager,project.project_tags_manager,model_project_tags,project.group_project_manager,1,1,1,1 access_project_tags_portal,project_tags_portal,project.model_project_tags,base.group_portal,1,0,0,0 access_mail_alias,mail.alias,mail.model_mail_alias,project.group_project_manager,1,1,1,1 -access_mail_activity_type_project_manager,mail.activity.type.project.manager,mail.model_mail_activity_type,project.group_project_manager,1,1,1,1
\ No newline at end of file +access_mail_activity_type_project_manager,mail.activity.type.project.manager,mail.model_mail_activity_type,project.group_project_manager,1,1,1,1 +access_account_analytic_account_user,account.analytic.account,analytic.model_account_analytic_account,project.group_project_user,1,0,0,0 +access_account_analytic_account_manager,account.analytic.account,analytic.model_account_analytic_account,project.group_project_manager,1,1,1,1 +access_account_analytic_account_portal,account_analytic_account,analytic.model_account_analytic_account,base.group_portal,1,0,0,0 +access_account_analytic_line_project,account.analytic.line project,analytic.model_account_analytic_line,project.group_project_manager,1,1,1,1
\ No newline at end of file diff --git a/addons/project/views/analytic_views.xml b/addons/project/views/analytic_views.xml new file mode 100644 index 00000000000..bf6809dc5c4 --- /dev/null +++ b/addons/project/views/analytic_views.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <!-- + Analytic Accounts with project + --> + <record id="account_analytic_account_view_form_inherit" model="ir.ui.view"> + <field name="name">account.analytic.account.form.inherit</field> + <field name="model">account.analytic.account</field> + <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/> + <field eval="18" name="priority"/> + <field name="arch" type="xml"> + <xpath expr="//button[@name='toggle_active']" position="before"> + <button class="oe_stat_button" type="object" name="action_view_projects" + icon="fa-puzzle-piece" attrs="{'invisible': [('project_count', '=', 0)]}"> + <field string="Projects" name="project_count" widget="statinfo"/> + </button> + </xpath> + </field> + </record> + +</odoo> diff --git a/addons/project/views/project_views.xml b/addons/project/views/project_views.xml index 54eb70b7935..da0d1921500 100644 --- a/addons/project/views/project_views.xml +++ b/addons/project/views/project_views.xml @@ -140,6 +140,7 @@ </group> <group> <field name="partner_id" string="Customer"/> + <field name="analytic_account_id" context="{'default_partner_id': partner_id}" groups="analytic.group_analytic_accounting"/> <label for="rating_status" groups="project.group_project_rating"/> <div groups="project.group_project_rating"> <field name="rating_status" widget="radio"/> @@ -303,6 +304,7 @@ <field name="is_favorite"/> <field name="rating_percentage_satisfaction"/> <field name="rating_status"/> + <field name="analytic_account_id"/> <templates> <t t-name="kanban-box"> <div t-attf-class="#{kanban_color(record.color.raw_value)} oe_kanban_global_click o_has_icon"> @@ -359,6 +361,11 @@ <span class="o_label"><t t-esc="record.label_tasks.value"/></span> </div> </a> + <a t-if="record.analytic_account_id.raw_value" class="o_project_kanban_box o_project_timesheet_box" name="action_view_account_analytic_line" type="object" groups="analytic.group_analytic_accounting"> + <div> + <span class="o_label">Profitability</span> + </div> + </a> </div> </div> </t> diff --git a/addons/sale_timesheet/views/hr_timesheet_templates.xml b/addons/sale_timesheet/views/hr_timesheet_templates.xml index 7f999d9e27c..200d9af637d 100644 --- a/addons/sale_timesheet/views/hr_timesheet_templates.xml +++ b/addons/sale_timesheet/views/hr_timesheet_templates.xml @@ -71,7 +71,7 @@ <td class="o_timesheet_plan_dashboard_cell"> <t t-esc="dashboard['profit']['invoiced']" t-options='{"widget": "monetary", "display_currency": currency}'/> </td> - <td>Invoiced</td> + <td>Time invoiced</td> </tr> <tr> <td class="o_timesheet_plan_dashboard_cell"> @@ -85,7 +85,7 @@ <td class="o_timesheet_plan_dashboard_cell"> <t t-esc="dashboard['profit']['to_invoice']" t-options='{"widget": "monetary", "display_currency": currency}'/> </td> - <td>To invoice</td> + <td>Time to invoice</td> </tr> <tr> <td class="o_timesheet_plan_dashboard_cell"> diff --git a/addons/sale_timesheet_purchase/__init__.py b/addons/sale_timesheet_purchase/__init__.py new file mode 100644 index 00000000000..dc5e6b693d1 --- /dev/null +++ b/addons/sale_timesheet_purchase/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/sale_timesheet_purchase/__manifest__.py b/addons/sale_timesheet_purchase/__manifest__.py new file mode 100644 index 00000000000..2acf83b5cd8 --- /dev/null +++ b/addons/sale_timesheet_purchase/__manifest__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Sales Timesheet Purchase', + 'category': 'Hidden', + 'summary': 'Bridge module between Sales Timesheet and Purchase', + 'description': """ +Allows to access purchase orders from Project Overview +====================================================== +""", + 'depends': ['sale_timesheet', 'purchase'], + 'data': [], + 'demo': [], + 'auto_install': True, + 'uninstall_hook': 'uninstall_hook', +} diff --git a/addons/sale_timesheet_purchase/models/__init__.py b/addons/sale_timesheet_purchase/models/__init__.py new file mode 100644 index 00000000000..2e9481d9165 --- /dev/null +++ b/addons/sale_timesheet_purchase/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import project_overview diff --git a/addons/sale_timesheet_purchase/models/project_overview.py b/addons/sale_timesheet_purchase/models/project_overview.py new file mode 100644 index 00000000000..600bf28094d --- /dev/null +++ b/addons/sale_timesheet_purchase/models/project_overview.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from odoo import _, models +from odoo.addons.sale_timesheet.models.project_overview import _to_action_data + + +class Project(models.Model): + _inherit = 'project.project' + + def _plan_get_stat_button(self): + stat_buttons = super(Project, self)._plan_get_stat_button() + if self.env.user.has_group('purchase.group_purchase_user'): + accounts = self.mapped('analytic_account_id.id') + purchase_order_lines = self.env['purchase.order.line'].search([('account_analytic_id', 'in', accounts)]) + purchase_orders = purchase_order_lines.mapped('order_id') + if purchase_orders: + stat_buttons.append({ + 'name': _('Purchase Orders'), + 'count': len(purchase_orders), + 'icon': 'fa fa-shopping-cart', + 'action': _to_action_data('purchase.order', + domain=[('id', 'in', purchase_orders.ids)], + context={'create': False, 'edit': False, 'delete': False} + ) + }) + account_invoice_lines = self.env['account.invoice.line'].search([('account_analytic_id', 'in', accounts)]) + account_invoices = account_invoice_lines.mapped('invoice_id') + if account_invoices: + stat_buttons.append({ + 'name': _('Vendor Bills'), + 'count': len(account_invoices), + 'icon': 'fa pencil-square-o', + 'action': _to_action_data( + action=self.env.ref('purchase.action_invoice_pending'), + domain=[('id', 'in', account_invoices.ids)], + context={'create': False, 'edit': False, 'delete': False} + )}) + + return stat_buttons |
