[IMP] project: add analytic tags on project
-if an analytic tags are inserted on the project, it will be added to the timesheet /invoice analytic tag. -In this commit, analytic tags field is added on project in order to gain in granularity.Those tags are passed to the invoice lines generated from the project's SO lines. -set the analytic account and analytic tag of the project by default on its tasks. -added string 'Analytic Tags' analytic_tag_ids field on task. closes #78973 task-2667754
This commit is contained in:
@@ -204,6 +204,10 @@ class AccountAnalyticLine(models.Model):
|
||||
project = self.env['project.project'].browse(vals.get('project_id'))
|
||||
vals['account_id'] = project.analytic_account_id.id
|
||||
vals['company_id'] = project.analytic_account_id.company_id.id or project.company_id.id
|
||||
if vals.get('tag_ids'):
|
||||
vals['tag_ids'] += [Command.link(tag_id.id) for tag_id in project.analytic_tag_ids]
|
||||
else:
|
||||
vals['tag_ids'] = [Command.set(project.analytic_tag_ids.ids)]
|
||||
if not project.analytic_account_id.active:
|
||||
raise UserError(_('You cannot add timesheets to a project linked to an inactive analytic account.'))
|
||||
# employee implies user
|
||||
|
||||
@@ -7,3 +7,4 @@ class AccountAnalyticTag(models.Model):
|
||||
_inherit = 'account.analytic.tag'
|
||||
|
||||
task_ids = fields.Many2many('project.task', string='Tasks')
|
||||
project_ids = fields.Many2many('project.project', string='Projects')
|
||||
|
||||
@@ -225,6 +225,7 @@ class Project(models.Model):
|
||||
help="Analytic account to which this project is linked for financial management. "
|
||||
"Use an analytic account to record cost and revenue on your project.")
|
||||
analytic_account_balance = fields.Monetary(related="analytic_account_id.balance")
|
||||
analytic_tag_ids = fields.Many2many('account.analytic.tag', string='Analytic Tags')
|
||||
|
||||
favorite_user_ids = fields.Many2many(
|
||||
'res.users', 'project_favorite_user_rel', 'project_id', 'user_id',
|
||||
@@ -1111,7 +1112,7 @@ class Task(models.Model):
|
||||
"Use an analytic account to record cost and revenue on your task. "
|
||||
"If empty, the analytic account of the project will be used.")
|
||||
project_analytic_account_id = fields.Many2one('account.analytic.account', string='Project Analytic Account', related='project_id.analytic_account_id')
|
||||
analytic_tag_ids = fields.Many2many('account.analytic.tag',
|
||||
analytic_tag_ids = fields.Many2many('account.analytic.tag', string="Analytic Tags",
|
||||
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", check_company=True)
|
||||
|
||||
@property
|
||||
@@ -1565,6 +1566,12 @@ class Task(models.Model):
|
||||
)
|
||||
if partner_id:
|
||||
vals['partner_id'] = partner_id
|
||||
if vals.get('project_id'):
|
||||
project = self.env['project.project'].browse(vals.get('project_id'))
|
||||
if project.analytic_account_id:
|
||||
vals['analytic_account_id'] = project.analytic_account_id.id
|
||||
if project.analytic_tag_ids:
|
||||
vals['analytic_tag_ids'] = [Command.set(project.analytic_tag_ids.ids)]
|
||||
|
||||
return vals
|
||||
|
||||
|
||||
@@ -417,6 +417,7 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="analytic_account_id" domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]" context="{'default_partner_id': partner_id}" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="analytic_tag_ids" groups="analytic.group_analytic_tags" widget="many2many_tags"/>
|
||||
<field name="privacy_visibility" widget="radio"/>
|
||||
</group>
|
||||
<group>
|
||||
@@ -1029,8 +1030,8 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="analytic_account_id" groups="analytic.group_analytic_accounting" context="{'default_partner_id': partner_id}"/>
|
||||
<field name="parent_id" domain="[('parent_id', '=', False)]" attrs="{'invisible': [('allow_subtasks', '=', False)]}" groups="base.group_no_one"/>
|
||||
<field name="analytic_tag_ids" groups="analytic.group_analytic_tags" widget="many2many_tags"/>
|
||||
<field name="parent_id" domain="[('parent_id', '=', False)]" attrs="{'invisible': [('allow_subtasks', '=', False)]}" groups="base.group_no_one"/>
|
||||
<field name="sequence" groups="base.group_no_one"/>
|
||||
<field name="email_from" invisible="1"/>
|
||||
<field name="email_cc" groups="base.group_no_one"/>
|
||||
|
||||
@@ -201,6 +201,7 @@ class SaleOrderLine(models.Model):
|
||||
return {
|
||||
'name': '%s - %s' % (self.order_id.client_order_ref, self.order_id.name) if self.order_id.client_order_ref else self.order_id.name,
|
||||
'analytic_account_id': account.id,
|
||||
'analytic_tag_ids': [Command.set(self.analytic_tag_ids.ids)],
|
||||
'partner_id': self.order_id.partner_id.id,
|
||||
'sale_line_id': self.id,
|
||||
'active': True,
|
||||
@@ -379,9 +380,11 @@ class SaleOrderLine(models.Model):
|
||||
values['analytic_account_id'] = analytic_account_ids.pop()
|
||||
if self.task_id.analytic_tag_ids:
|
||||
values['analytic_tag_ids'] += [Command.link(tag_id.id) for tag_id in self.task_id.analytic_tag_ids]
|
||||
if self.task_id.analytic_tag_ids or self.task_id.project_id.analytic_tag_ids:
|
||||
values['analytic_tag_ids'] += [Command.link(tag_id.id) for tag_id in self.task_id.analytic_tag_ids | self.task_id.project_id.analytic_tag_ids]
|
||||
elif self.is_service and not self.is_expense:
|
||||
tag_ids = self.env['account.analytic.tag'].search([
|
||||
('task_ids.sale_line_id', '=', self.id)
|
||||
'|', ('task_ids.sale_line_id', '=', self.id), ('project_ids.sale_line_id', '=', self.id)
|
||||
])
|
||||
values['analytic_tag_ids'] += [Command.link(tag_id.id) for tag_id in tag_ids]
|
||||
return values
|
||||
|
||||
Reference in New Issue
Block a user