From f3999314af3a81c0886fcbedca571ee2e1845fad Mon Sep 17 00:00:00 2001 From: Geoffroy Larue Date: Tue, 30 Apr 2019 13:27:21 +0000 Subject: [PATCH] [ADD] sale_timesheet_purchase: bridge module Add two smart buttons in project overview : purchase orders and vendor bills, linking purchases and bills pointing to the project's analytic account. Task-1975022 --- addons/sale_timesheet_purchase/__init__.py | 4 ++ .../sale_timesheet_purchase/__manifest__.py | 17 +++++++++ .../models/__init__.py | 4 ++ .../models/project_overview.py | 38 +++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 addons/sale_timesheet_purchase/__init__.py create mode 100644 addons/sale_timesheet_purchase/__manifest__.py create mode 100644 addons/sale_timesheet_purchase/models/__init__.py create mode 100644 addons/sale_timesheet_purchase/models/project_overview.py 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