[IMP] project_{account,purchase,hr_expense}: extend form and panel
This commit extends project form and panel in order to add buttons which allow user to view documents linked to the project analytic account. This commit adds bridge modules in order to handle those extensions. PR : #72736 See odoo/upgrade#2706 task-2545084
This commit is contained in:
committed by
Laurent Stukkens (LTU)
parent
0df93da823
commit
2b3e3a44a9
@@ -0,0 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
{
|
||||
'name': 'Project Accounting',
|
||||
'version': '1.0',
|
||||
'category': 'Project/account',
|
||||
'summary': 'Project accounting',
|
||||
'description': 'Bridge created to remove the profitability setting if the account module is installed',
|
||||
'depends': ['project', 'account'],
|
||||
'data': [
|
||||
'views/project_project_templates.xml',
|
||||
],
|
||||
'demo': [],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
'license': 'OEEL-1',
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit.project</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="inherit_id" ref="project.res_config_settings_view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='analytic']/div" position="replace"/>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
@@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
{
|
||||
'name': 'Project Expenses',
|
||||
'version': '1.0',
|
||||
'category': 'Project/expenses',
|
||||
'summary': 'Project expenses',
|
||||
'description': 'Bridge created to add the number of expenses linked to an AA to a project form',
|
||||
'depends': ['project', 'hr_expense'],
|
||||
'data': [
|
||||
'views/project_project_views.xml',
|
||||
],
|
||||
'demo': [],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
'license': 'OEEL-1',
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import project
|
||||
@@ -0,0 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
class Project(models.Model):
|
||||
_inherit = 'project.project'
|
||||
|
||||
expenses_count = fields.Integer('# Expenses', compute='_compute_expenses_count')
|
||||
|
||||
@api.depends('analytic_account_id')
|
||||
def _compute_expenses_count(self):
|
||||
expenses_data = self.env['hr.expense'].read_group([
|
||||
('analytic_account_id', '!=', False),
|
||||
('analytic_account_id', 'in', self.analytic_account_id.ids)
|
||||
],
|
||||
['analytic_account_id'], ['analytic_account_id'])
|
||||
mapped_data = {data['analytic_account_id'][0]: data['analytic_account_id_count'] for data in expenses_data}
|
||||
for project in self:
|
||||
project.expenses_count = mapped_data.get(project.analytic_account_id.id, 0)
|
||||
|
||||
# ----------------------------
|
||||
# Actions
|
||||
# ----------------------------
|
||||
|
||||
def action_open_project_expenses(self):
|
||||
expenses = self.env['hr.expense'].search([
|
||||
('analytic_account_id', '!=', False),
|
||||
('analytic_account_id', 'in', self.analytic_account_id.ids)
|
||||
])
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("hr_expense.hr_expense_actions_all")
|
||||
action.update({
|
||||
'display_name': _('Expenses'),
|
||||
'views': [[False, 'tree'], [False, 'form'], [False, 'kanban'], [False, 'graph'], [False, 'pivot']],
|
||||
'context': {'default_analytic_account_id': self.analytic_account_id.id},
|
||||
'domain': [('id', 'in', expenses.ids)]
|
||||
})
|
||||
if(len(expenses) == 1):
|
||||
action["views"] = [[False, 'form']]
|
||||
action["res_id"] = expenses.id
|
||||
return action
|
||||
|
||||
# ----------------------------
|
||||
# Project Updates
|
||||
# ----------------------------
|
||||
|
||||
def _get_stat_buttons(self):
|
||||
buttons = super(Project, self)._get_stat_buttons()
|
||||
buttons.append({
|
||||
'icon': 'money',
|
||||
'text': _('Expenses'),
|
||||
'number': self.expenses_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_open_project_expenses',
|
||||
'show': self.user_has_groups('hr_expense.group_hr_expense_team_approver') and self.expenses_count > 0,
|
||||
'sequence': 10,
|
||||
})
|
||||
return buttons
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="project_project_view_form" model="ir.ui.view">
|
||||
<field name="name">project.project.form.inherit</field>
|
||||
<field name="model">project.project</field>
|
||||
<field name="inherit_id" ref="project.edit_project"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='%(project.action_project_task_burndown_chart_report)d']" position="after">
|
||||
<button name="action_open_project_expenses" type="object" class="oe_stat_button" icon="fa-money" attrs="{'invisible': [('expenses_count', '=', 0)]}" groups="hr_expense.group_hr_expense_team_approver">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value">
|
||||
<field name="expenses_count" nolabel="1"/>
|
||||
</span>
|
||||
<span class="o_stat_text">
|
||||
Expenses
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -1,14 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
_inherit = "project.project"
|
||||
|
||||
purchase_order_count = fields.Integer(related="analytic_account_id.purchase_order_count")
|
||||
purchase_orders_count = fields.Integer('# Purchase Orders', compute='_compute_purchase_orders_count')
|
||||
|
||||
def action_view_purchase_orders(self):
|
||||
self.ensure_one()
|
||||
return self.analytic_account_id.action_view_purchase_orders()
|
||||
@api.depends('analytic_account_id')
|
||||
def _compute_purchase_orders_count(self):
|
||||
purchase_orders_data = self.env['purchase.order.line'].read_group([
|
||||
('account_analytic_id', '!=', False),
|
||||
('account_analytic_id', 'in', self.analytic_account_id.ids)
|
||||
], ['account_analytic_id', 'order_id:count_distinct'], ['account_analytic_id'])
|
||||
mapped_data = dict([(data['account_analytic_id'][0], data['order_id']) for data in purchase_orders_data])
|
||||
for project in self:
|
||||
project.purchase_orders_count = mapped_data.get(project.analytic_account_id.id, 0)
|
||||
|
||||
# ----------------------------
|
||||
# Actions
|
||||
# ----------------------------
|
||||
|
||||
def action_open_project_purchase_orders(self):
|
||||
purchase_orders = self.env['purchase.order'].search([
|
||||
('order_line.account_analytic_id', '!=', False),
|
||||
('order_line.account_analytic_id', 'in', self.analytic_account_id.ids)
|
||||
])
|
||||
action_window = {
|
||||
'name': _('Purchase Orders'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'purchase.order',
|
||||
'views': [[False, 'tree'], [False, 'form']],
|
||||
'domain': [('id', 'in', purchase_orders.ids)],
|
||||
'context': {
|
||||
'create': False,
|
||||
}
|
||||
}
|
||||
if len(purchase_orders) == 1:
|
||||
action_window['views'] = [[False, 'form']]
|
||||
action_window['res_id'] = purchase_orders.id
|
||||
return action_window
|
||||
|
||||
# ----------------------------
|
||||
# Project Updates
|
||||
# ----------------------------
|
||||
|
||||
def _get_stat_buttons(self):
|
||||
buttons = super(Project, self)._get_stat_buttons()
|
||||
buttons.append({
|
||||
'icon': 'credit-card',
|
||||
'text': _('Purchase Orders'),
|
||||
'number': self.purchase_orders_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_open_project_purchase_orders',
|
||||
'show': self.user_has_groups('purchase.group_purchase_user') and self.purchase_orders_count > 0,
|
||||
'sequence': 13,
|
||||
})
|
||||
return buttons
|
||||
|
||||
@@ -3,13 +3,18 @@
|
||||
<record id="project_project_form_view_inherited" model="ir.ui.view">
|
||||
<field name="name">project.project.view.inherited</field>
|
||||
<field name="model">project.project</field>
|
||||
<field name="inherit_id" ref="project.edit_project" />
|
||||
<field name="priority">20</field>
|
||||
<field name="inherit_id" ref="project.edit_project"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='action_view_analytic_account_entries']" position="after">
|
||||
<button class="oe_stat_button" type="object" name="action_view_purchase_orders"
|
||||
icon="fa-shopping-cart" attrs="{'invisible': [('purchase_order_count', '=', 0)]}">
|
||||
<field string="Purchase Orders" name="purchase_order_count" widget="statinfo"/>
|
||||
<xpath expr="//button[@name='%(project.action_project_task_burndown_chart_report)d']" position="after">
|
||||
<button name="action_open_project_purchase_orders" type="object" class="oe_stat_button" icon="fa-credit-card" attrs="{'invisible': [('purchase_orders_count', '=', 0)]}" groups="purchase.group_purchase_user">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value">
|
||||
<field name="purchase_orders_count" nolabel="1"/>
|
||||
</span>
|
||||
<span class="o_stat_text">
|
||||
Purchase Orders
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user