diff --git a/attachment_category/README.rst b/attachment_category/README.rst new file mode 100644 index 00000000..4bf9f8c2 --- /dev/null +++ b/attachment_category/README.rst @@ -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 +`_. 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 `_. + +Contributors +------------ + +* Firstname Lastname +* Second Person + +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. diff --git a/attachment_category/__init__.py b/attachment_category/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/attachment_category/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/attachment_category/__manifest__.py b/attachment_category/__manifest__.py new file mode 100644 index 00000000..e8039ece --- /dev/null +++ b/attachment_category/__manifest__.py @@ -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', + ], +} diff --git a/attachment_category/models/__init__.py b/attachment_category/models/__init__.py new file mode 100644 index 00000000..6858a37c --- /dev/null +++ b/attachment_category/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_attachment_category +from . import ir_attachment diff --git a/attachment_category/models/ir_attachment.py b/attachment_category/models/ir_attachment.py new file mode 100644 index 00000000..ed39c917 --- /dev/null +++ b/attachment_category/models/ir_attachment.py @@ -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, + ) diff --git a/attachment_category/models/ir_attachment_category.py b/attachment_category/models/ir_attachment_category.py new file mode 100644 index 00000000..b0bc8527 --- /dev/null +++ b/attachment_category/models/ir_attachment_category.py @@ -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 diff --git a/attachment_category/security/ir_attachment_category.xml b/attachment_category/security/ir_attachment_category.xml new file mode 100644 index 00000000..4eba438c --- /dev/null +++ b/attachment_category/security/ir_attachment_category.xml @@ -0,0 +1,17 @@ + + + + + + + Attachment Category User + + + + + + + + + diff --git a/attachment_category/static/description/icon.png b/attachment_category/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/attachment_category/static/description/icon.png differ diff --git a/attachment_category/views/ir_attachment.xml b/attachment_category/views/ir_attachment.xml new file mode 100644 index 00000000..66196d80 --- /dev/null +++ b/attachment_category/views/ir_attachment.xml @@ -0,0 +1,40 @@ + + + + + + + ir.attachment.form (in attachment_category) + ir.attachment + + + + + + + + + + ir.attachment.search (in attachment_category) + ir.attachment + + + + + + + + + + ir.attachment.tree (in attachment_category) + ir.attachment + + + + + + + + + diff --git a/attachment_category/views/ir_attachment_category.xml b/attachment_category/views/ir_attachment_category.xml new file mode 100644 index 00000000..4b1fc7fe --- /dev/null +++ b/attachment_category/views/ir_attachment_category.xml @@ -0,0 +1,71 @@ + + + + + + + ir.attachment.category.form (in document_category) + ir.attachment.category + +
+
+ +
+ +
+ +
+ + + + +
+
+
+
+ + + ir.attachment.category.search (in document_category) + ir.attachment.category + + + + + + + + + ir.attachment.category.tree (in document_category) + ir.attachment.category + + + + + + + + + Attachment Categories + ir.attachment.category + tree,form + +

+ Create a new document +

+

+ Also you will find here all the related document categories. +

+
+
+ + + Attachment Categories + + + + + +
diff --git a/setup/attachment_category/odoo/addons/attachment_category b/setup/attachment_category/odoo/addons/attachment_category new file mode 120000 index 00000000..c8c075cf --- /dev/null +++ b/setup/attachment_category/odoo/addons/attachment_category @@ -0,0 +1 @@ +../../../../attachment_category \ No newline at end of file diff --git a/setup/attachment_category/setup.py b/setup/attachment_category/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/attachment_category/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)