-
-
Notifications
You must be signed in to change notification settings - Fork 767
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG][9.0]purchase_order_analytic_search
- Loading branch information
Showing
6 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
|
||
============================== | ||
Purchase Order Analytic Search | ||
============================== | ||
|
||
Organizations often require to quickly find the purchase orders associated to | ||
an analytic account, searching by it's code, name or project/account manager. | ||
|
||
This module introduces the possibility to search purchase orders by analytic | ||
account. | ||
|
||
It also introduces a new menu entry in Purchasing to list purchase order lines. | ||
|
||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Set 'Analytic Accounting' and 'Analytic Accounting for | ||
Purchases' user rights. | ||
|
||
|
||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas | ||
:alt: Try me on Runbot | ||
:target: https://runbot.odoo-community.org/runbot/142/9.0 | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please | ||
check there if your issue has already been reported. If you spotted it first, | ||
help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Eficent Business and IT Consulting Services S.L. <contact@eficent.com> | ||
|
||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015-17 Eficent Business and IT Consulting Services S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015-17 Eficent Business and IT Consulting Services S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
{ | ||
"name": "Purchase Order Analytic Search", | ||
"summary": """" | ||
Search purchase orders by analytic account. New menu entry in | ||
Purchasing to list purchase order lines. | ||
""", | ||
"version": "9.0.1.0.0", | ||
"website": "https://odoo-community.org/", | ||
"category": "Purchase Workflow", | ||
"author": "Eficent, Odoo Community Association (OCA)", | ||
"license": "LGPL-3", | ||
"installable": True, | ||
"depends": ["analytic", "purchase"], | ||
"data": ["views/purchase_order_view.xml"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015-17 Eficent Business and IT Consulting Services S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from . import purchase_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2015 Eficent Business and IT Consulting Services S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
||
from openerp import models, fields, api | ||
|
||
|
||
class PurchaseOrder(models.Model): | ||
|
||
_inherit = "purchase.order" | ||
|
||
@api.multi | ||
@api.depends('order_line.account_analytic_id') | ||
def _get_analytic_accounts(self): | ||
res = {} | ||
for purchase in self: | ||
res[purchase.id] = [] | ||
for po_line in purchase.order_line: | ||
if po_line.account_analytic_id: | ||
res[purchase.id].append(po_line.account_analytic_id.id) | ||
return res | ||
|
||
@api.model | ||
def _search_analytic_accounts(self, operator, value): | ||
|
||
po_line_obj = self.env['purchase.order.line'] | ||
res = [] | ||
po_lines = po_line_obj.search( | ||
[('account_analytic_id', operator, value)]) | ||
order_ids = [po_line.order_id and po_line.order_id.id for po_line in | ||
po_lines] | ||
res.append(('id', 'in', order_ids)) | ||
return res | ||
|
||
account_analytic_ids = \ | ||
fields.Many2many(comodel_name='account.analytic.account', | ||
string='Analytic Account', | ||
compute=_get_analytic_accounts, | ||
search=_search_analytic_accounts, | ||
readonly=True) |
67 changes: 67 additions & 0 deletions
67
purchase_order_analytic_search/views/purchase_order_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
#--------------------------------------------------------------------------------------------------------- | ||
# Add analytic account id to purchase orders | ||
#--------------------------------------------------------------------------------------------------------- | ||
|
||
<record id="view_purchase_order_filter_analytic" model="ir.ui.view"> | ||
<field name="name">purchase.order.list.select</field> | ||
<field name="model">purchase.order</field> | ||
<field name="inherit_id" ref="purchase.view_purchase_order_filter"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//search/field[@name='product_id']" position="after"> | ||
<field name="account_analytic_ids" groups="analytic.group_analytic_accounting"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="purchase_order_line_tree_analytic" model="ir.ui.view"> | ||
<field name="name">purchase.order.line.tree</field> | ||
<field name="model">purchase.order.line</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_line_tree"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//tree//field[@name='name']" position="after"> | ||
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"/> | ||
<field name="state"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
<record id="purchase_order_line_search_analytic" model="ir.ui.view"> | ||
<field name="name">purchase.order.line.search</field> | ||
<field name="model">purchase.order.line</field> | ||
<field name="inherit_id" ref="purchase.purchase_order_line_search"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//search/field[@name='partner_id']" position="after"> | ||
<field name="account_analytic_id" groups="analytic.group_analytic_accounting"/> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
|
||
#--------------------------------------------------------------------------------------------------------- | ||
# Extend menus | ||
#--------------------------------------------------------------------------------------------------------- | ||
|
||
<record id="purchase_line_form_action_3" model="ir.actions.act_window"> | ||
<field name="name">Purchase Order Lines</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">purchase.order.line</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="search_view_id" ref="purchase_order_line_search_analytic"/> | ||
</record> | ||
<record id="purchase_line_form_action_tree3" model="ir.actions.act_window.view"> | ||
<field eval="1" name="sequence"/> | ||
<field name="view_mode">tree</field> | ||
<field name="view_id" ref="purchase_order_line_tree_analytic"/> | ||
<field name="act_window_id" ref="purchase_line_form_action_3"/> | ||
</record> | ||
<menuitem | ||
action="purchase_line_form_action_3" | ||
id="menu_purchase_line_order_analytic" | ||
parent="purchase.menu_procurement_management" | ||
sequence="7"/> | ||
|
||
</odoo> |