diff --git a/attachment_category/README.rst b/attachment_category/README.rst new file mode 100644 index 00000000..14af0a2f --- /dev/null +++ b/attachment_category/README.rst @@ -0,0 +1,78 @@ +================== +Atachment Category +================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github + :target: https://github.com/OCA/knowledge/tree/13.0/attachment_category + :alt: OCA/knowledge +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/knowledge-13-0/knowledge-13-0-attachment_category + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/118/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a document category to help classification. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +* Go to Attachments, and set categories as tags. + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Denis Roussel + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/knowledge `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. 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..5a09a117 --- /dev/null +++ b/attachment_category/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2020 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": "13.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..5c6f144f --- /dev/null +++ b/attachment_category/models/ir_attachment.py @@ -0,0 +1,18 @@ +# Copyright 2020 ACSONE SA/NV +# 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..e2671fe0 --- /dev/null +++ b/attachment_category/models/ir_attachment_category.py @@ -0,0 +1,55 @@ +# Copyright 2020 ACSONE SA/NV +# 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 = "{}/{}".format( + 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/readme/CONTRIBUTORS.rst b/attachment_category/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9179ee4b --- /dev/null +++ b/attachment_category/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Denis Roussel diff --git a/attachment_category/readme/DESCRIPTION.rst b/attachment_category/readme/DESCRIPTION.rst new file mode 100644 index 00000000..60554088 --- /dev/null +++ b/attachment_category/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds a document category to help classification. diff --git a/attachment_category/readme/USAGE.rst b/attachment_category/readme/USAGE.rst new file mode 100644 index 00000000..2ca9eb6c --- /dev/null +++ b/attachment_category/readme/USAGE.rst @@ -0,0 +1 @@ +* Go to Attachments, and set categories as tags. diff --git a/attachment_category/security/ir_attachment_category.xml b/attachment_category/security/ir_attachment_category.xml new file mode 100644 index 00000000..354d0f54 --- /dev/null +++ b/attachment_category/security/ir_attachment_category.xml @@ -0,0 +1,14 @@ + + + + + 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/static/description/index.html b/attachment_category/static/description/index.html new file mode 100644 index 00000000..f6e343da --- /dev/null +++ b/attachment_category/static/description/index.html @@ -0,0 +1,426 @@ + + + + + + +Atachment Category + + + +
+

Atachment Category

+ + +

Beta License: AGPL-3 OCA/knowledge Translate me on Weblate Try me on Runbot

+

This module adds a document category to help classification.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to Attachments, and set categories as tags.
  • +
+
+
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/knowledge project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/attachment_category/views/ir_attachment.xml b/attachment_category/views/ir_attachment.xml new file mode 100644 index 00000000..c61f047a --- /dev/null +++ b/attachment_category/views/ir_attachment.xml @@ -0,0 +1,35 @@ + + + + + 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..37135529 --- /dev/null +++ b/attachment_category/views/ir_attachment_category.xml @@ -0,0 +1,69 @@ + + + + + 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, +)