diff options
| author | Lucas Lefèvre <lul@odoo.com> | 2019-11-18 10:51:37 +0000 |
|---|---|---|
| committer | Lucas Lefèvre <lul@odoo.com> | 2020-01-31 11:02:14 +0000 |
| commit | ac8c30beec072dd1f52735230eca86195bbeab7b (patch) | |
| tree | 107fe7a3d274525d350c3d49f18d9f5b8acc960d | |
| parent | eafa9f4abc751b07f2ecb67dbe029687278d1d52 (diff) | |
[IMP] hr_timesheet, sale_timesheet: Set task analytic account
Purpose
=======
Currently, it is only possible to set an Analytic Account for a whole Project, there
is no distinction by task. However, if the user has 1 task per customer, he cannot
track the costs and revenues for that specific customer easily. He has to manually
change the AA of the timesheets' analytic lines. An option would be to set a
different AA on the SO generating the task, but the AA of the project takes over
anyway.
Specifications
==============
If the user sets an AA on the SO, it should bypass the one set on the project
Add an AA field below the Email cc one on tasks in debug mode
- should be related to the AA field from the SO
- it should also bypass the AA set on the project
All the timesheets from this task should be related to the AA field set on the SO/Task
closes odoo/odoo#40844
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
| -rw-r--r-- | addons/hr_timesheet/models/project.py | 8 | ||||
| -rw-r--r-- | addons/sale_timesheet/models/account.py | 5 | ||||
| -rw-r--r-- | addons/sale_timesheet/models/project.py | 7 | ||||
| -rw-r--r-- | addons/sale_timesheet/views/project_task_views.xml | 3 |
4 files changed, 22 insertions, 1 deletions
diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index c4404ae1592..c44381ef79a 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -84,7 +84,7 @@ class Task(models.Model): _name = "project.task" _inherit = ["project.task", "timer.mixin"] - analytic_account_active = fields.Boolean("Analytic Account", related='project_id.analytic_account_id.active', readonly=True) + analytic_account_active = fields.Boolean("Active Analytic Account", compute='_compute_analytic_account_active') allow_timesheets = fields.Boolean("Allow timesheets", related='project_id.allow_timesheets', help="Timesheets can be logged on this task.", readonly=True) remaining_hours = fields.Float("Remaining Hours", compute='_compute_remaining_hours', store=True, readonly=True, help="Total remaining time, can be re-estimated periodically by the assignee of the task.") effective_hours = fields.Float("Hours Spent", compute='_compute_effective_hours', compute_sudo=True, store=True, help="Computed using the sum of the task work done.") @@ -133,6 +133,12 @@ class Task(models.Model): 'display_timer_resume': resume, }) + @api.depends('project_id.analytic_account_id.active') + def _compute_analytic_account_active(self): + """ Overridden in sale_timesheet """ + for task in self: + task.analytic_account_active = task.project_id.analytic_account_id.active + @api.depends('timesheet_ids.unit_amount') def _compute_effective_hours(self): for task in self: diff --git a/addons/sale_timesheet/models/account.py b/addons/sale_timesheet/models/account.py index 733b36c20ab..7bba1729ecb 100644 --- a/addons/sale_timesheet/models/account.py +++ b/addons/sale_timesheet/models/account.py @@ -68,6 +68,11 @@ class AccountAnalyticLine(models.Model): @api.model def _timesheet_preprocess(self, values): + if values.get('task_id') and not values.get('account_id'): + task = self.env['project.task'].browse(values.get('task_id')) + if task.analytic_account_id: + values['account_id'] = task.analytic_account_id.id + values['company_id'] = task.analytic_account_id.company_id.id values = super(AccountAnalyticLine, self)._timesheet_preprocess(values) # task implies so line (at create) if 'task_id' in values and not values.get('so_line') and values.get('employee_id'): diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 90e69b533e7..a4a050d9649 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -127,6 +127,7 @@ class ProjectTask(models.Model): # override sale_order_id and make it computed stored field instead of regular field. sale_order_id = fields.Many2one(compute='_compute_sale_order_id', store=True, readonly=False) + analytic_account_id = fields.Many2one('account.analytic.account', related='sale_order_id.analytic_account_id') billable_type = fields.Selection([ ('task_rate', 'At Task Rate'), ('employee_rate', 'At Employee Rate'), @@ -161,6 +162,12 @@ class ProjectTask(models.Model): 'message': message }} + @api.depends('analytic_account_id.active') + def _compute_analytic_account_active(self): + super()._compute_analytic_account_active() + for task in self: + task.analytic_account_active = task.analytic_account_active or task.analytic_account_id.active + @api.depends('sale_line_id', 'project_id', 'billable_type') def _compute_sale_order_id(self): for task in self: diff --git a/addons/sale_timesheet/views/project_task_views.xml b/addons/sale_timesheet/views/project_task_views.xml index 055ddb56dc2..b5c7aa3caba 100644 --- a/addons/sale_timesheet/views/project_task_views.xml +++ b/addons/sale_timesheet/views/project_task_views.xml @@ -81,6 +81,9 @@ <xpath expr="//group[@name='sales_order_group']" position="inside"> <field name="billable_type" invisible="1"/> </xpath> + <xpath expr="//field[@name='email_cc']" position="after"> + <field name="analytic_account_id" groups="base.group_no_one"/> + </xpath> </field> </record> |
