mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-27 10:58:41 -06:00
[12.0][ADD] attachment_category
This commit is contained in:
parent
c825b73735
commit
0ed0592a35
91
attachment_category/README.rst
Normal file
91
attachment_category/README.rst
Normal file
@ -0,0 +1,91 @@
|
||||
.. 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
|
||||
|
||||
=================
|
||||
Document Category
|
||||
=================
|
||||
|
||||
Adds a document category to help classification
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
To install this module, you need to:
|
||||
|
||||
#. Do this ...
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
To configure this module, you need to:
|
||||
|
||||
#. Go to ...
|
||||
|
||||
.. figure:: path/to/local/image.png
|
||||
:alt: alternative description
|
||||
:width: 600 px
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
To use this module, you need to:
|
||||
|
||||
#. Go to ...
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}
|
||||
|
||||
.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
|
||||
.. branch is "8.0" for example
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
* ...
|
||||
|
||||
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
|
||||
------------
|
||||
|
||||
* Firstname Lastname <email.address@example.org>
|
||||
* Second Person <second.person@example.org>
|
||||
|
||||
Funders
|
||||
-------
|
||||
|
||||
The development of this module has been financially supported by:
|
||||
|
||||
* Company 1 name
|
||||
* Company 2 name
|
||||
|
||||
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.
|
1
attachment_category/__init__.py
Normal file
1
attachment_category/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import models
|
19
attachment_category/__manifest__.py
Normal file
19
attachment_category/__manifest__.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright 2019 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Atachment Category',
|
||||
'summary': """
|
||||
Adds a document category to help classification""",
|
||||
'version': '12.0.1.0.0',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'ACSONE SA/NV,Odoo Community Association (OCA)',
|
||||
'depends': [
|
||||
"base",
|
||||
],
|
||||
'data': [
|
||||
'views/ir_attachment.xml',
|
||||
'security/ir_attachment_category.xml',
|
||||
'views/ir_attachment_category.xml',
|
||||
],
|
||||
}
|
2
attachment_category/models/__init__.py
Normal file
2
attachment_category/models/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from . import ir_attachment_category
|
||||
from . import ir_attachment
|
18
attachment_category/models/ir_attachment.py
Normal file
18
attachment_category/models/ir_attachment.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright 2019 Denis Roussel
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class IrAttachment(models.Model):
|
||||
|
||||
_inherit = 'ir.attachment'
|
||||
|
||||
category_ids = fields.Many2many(
|
||||
comodel_name="ir.attachment.category",
|
||||
relation="ir_attachment_category_rel",
|
||||
column1="attachment_id",
|
||||
column2="category_id",
|
||||
ondelete="restrict",
|
||||
index=True,
|
||||
)
|
62
attachment_category/models/ir_attachment_category.py
Normal file
62
attachment_category/models/ir_attachment_category.py
Normal file
@ -0,0 +1,62 @@
|
||||
# Copyright 2019 Denis Roussel
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class IrAttachmentCategory(models.Model):
|
||||
|
||||
_name = 'ir.attachment.category'
|
||||
_description = 'Attachment Category'
|
||||
_parent_store = True
|
||||
|
||||
name = fields.Char()
|
||||
display_name = fields.Char(
|
||||
compute="_compute_display_name",
|
||||
store=True,
|
||||
)
|
||||
parent_id = fields.Many2one(
|
||||
"ir.attachment.category",
|
||||
)
|
||||
parent_path = fields.Char(index=True)
|
||||
attachment_ids = fields.Many2many(
|
||||
compute="_compute_attachment_count",
|
||||
comodel_name="ir.attachment"
|
||||
)
|
||||
attachment_count = fields.Integer(
|
||||
compute="_compute_attachment_count",
|
||||
)
|
||||
|
||||
@api.depends('name', 'parent_id.display_name')
|
||||
def _compute_display_name(self):
|
||||
"""
|
||||
|
||||
:return:
|
||||
"""
|
||||
for category in self:
|
||||
if category.parent_id.display_name:
|
||||
category.display_name = '%s/%s' % (
|
||||
category.parent_id.display_name, category.name)
|
||||
else:
|
||||
category.display_name = category.name
|
||||
|
||||
@api.depends()
|
||||
def _compute_attachment_count(self):
|
||||
category_obj = self.env["ir.attachment.category"]
|
||||
attachment_obj = self.env["ir.attachment"]
|
||||
for category in self:
|
||||
child_categories = category_obj.search([
|
||||
("id", "child_of", category.id)])
|
||||
attachment_ids = attachment_obj.search([
|
||||
("category_ids", "in", child_categories.ids)])
|
||||
category.attachment_ids = attachment_ids
|
||||
category.attachment_count = len(attachment_ids)
|
||||
|
||||
def action_attachment_view(self):
|
||||
self.ensure_one()
|
||||
action = self.env.ref('base.action_attachment').read()[0]
|
||||
action["domain"] = [("category_ids", "child_of", self.id)]
|
||||
context = self.env.context.copy()
|
||||
context.update({"default_category_ids": [self.id]})
|
||||
action["context"] = context
|
||||
return action
|
17
attachment_category/security/ir_attachment_category.xml
Normal file
17
attachment_category/security/ir_attachment_category.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 Denis Roussel
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record model="ir.model.access" id="ir_attachment_category_user">
|
||||
<field name="name">Attachment Category User</field>
|
||||
<field name="model_id" ref="model_ir_attachment_category"/>
|
||||
<field name="group_id" ref="base.group_user"/>
|
||||
<field name="perm_read" eval="1"/>
|
||||
<field name="perm_create" eval="1"/>
|
||||
<field name="perm_write" eval="1"/>
|
||||
<field name="perm_unlink" eval="1"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
BIN
attachment_category/static/description/icon.png
Normal file
BIN
attachment_category/static/description/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
40
attachment_category/views/ir_attachment.xml
Normal file
40
attachment_category/views/ir_attachment.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="ir_attachment_form_view">
|
||||
<field name="name">ir.attachment.form (in attachment_category)</field>
|
||||
<field name="model">ir.attachment</field>
|
||||
<field name="inherit_id" ref="base.view_attachment_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="type" position="after">
|
||||
<field name="category_ids" widget="many2many_tags"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="ir_attachment_search_view">
|
||||
<field name="name">ir.attachment.search (in attachment_category)</field>
|
||||
<field name="model">ir.attachment</field>
|
||||
<field name="inherit_id" ref="base.view_attachment_search"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="type" position="after">
|
||||
<field name="category_ids"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="ir_attachment_tree_view">
|
||||
<field name="name">ir.attachment.tree (in attachment_category)</field>
|
||||
<field name="model">ir.attachment</field>
|
||||
<field name="inherit_id" ref="base.view_attachment_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="type" position="after">
|
||||
<field name="category_ids"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
71
attachment_category/views/ir_attachment_category.xml
Normal file
71
attachment_category/views/ir_attachment_category.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 Denis Roussel
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="ir_attachment_category_form_view">
|
||||
<field name="name">ir.attachment.category.form (in document_category)</field>
|
||||
<field name="model">ir.attachment.category</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<!-- TODO -->
|
||||
</header>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
<button name="action_attachment_view" type="object" class="oe_stat_button" icon="fa-align-justify">
|
||||
<field name="attachment_count"/>
|
||||
</button>
|
||||
</div>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="parent_id"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="ir_attachment_category_search_view">
|
||||
<field name="name">ir.attachment.category.search (in document_category)</field>
|
||||
<field name="model">ir.attachment.category</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="display_name"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="ir_attachment_category_tree_view">
|
||||
<field name="name">ir.attachment.category.tree (in document_category)</field>
|
||||
<field name="model">ir.attachment.category</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="display_name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.actions.act_window" id="ir_attachment_category_act_window">
|
||||
<field name="name">Attachment Categories</field>
|
||||
<field name="res_model">ir.attachment.category</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_smiling_face">
|
||||
Create a new document
|
||||
</p>
|
||||
<p>
|
||||
Also you will find here all the related document categories.
|
||||
</p>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.menu" id="ir_attachment_category_menu">
|
||||
<field name="name">Attachment Categories</field>
|
||||
<field name="parent_id" ref="base.next_id_9"/>
|
||||
<field name="action" ref="ir_attachment_category_act_window"/>
|
||||
<field name="sequence" eval="16"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
1
setup/attachment_category/odoo/addons/attachment_category
Symbolic link
1
setup/attachment_category/odoo/addons/attachment_category
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../attachment_category
|
6
setup/attachment_category/setup.py
Normal file
6
setup/attachment_category/setup.py
Normal file
@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
Loading…
Reference in New Issue
Block a user