From 71a801dc2b43bd2fb13fadf1b5c8e6546f131759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Taymans?= Date: Sat, 17 Mar 2018 13:38:20 +0100 Subject: [PATCH] [ADD] emc_document: Management of documents Allow you to store documents and organize them in categories. Access right is not managed yet. It must be solved in further commit. --- easy_my_coop_document/__init__.py | 2 + easy_my_coop_document/__openerp__.py | 32 ++++++ easy_my_coop_document/models/__init__.py | 2 + easy_my_coop_document/models/document.py | 80 +++++++++++++ .../security/ir.model.access.csv | 3 + .../views/easy_my_coop_document_menu.xml | 39 +++++++ .../views/easy_my_coop_document_views.xml | 105 ++++++++++++++++++ 7 files changed, 263 insertions(+) create mode 100644 easy_my_coop_document/__init__.py create mode 100644 easy_my_coop_document/__openerp__.py create mode 100644 easy_my_coop_document/models/__init__.py create mode 100644 easy_my_coop_document/models/document.py create mode 100644 easy_my_coop_document/security/ir.model.access.csv create mode 100644 easy_my_coop_document/views/easy_my_coop_document_menu.xml create mode 100644 easy_my_coop_document/views/easy_my_coop_document_views.xml diff --git a/easy_my_coop_document/__init__.py b/easy_my_coop_document/__init__.py new file mode 100644 index 0000000..447df70 --- /dev/null +++ b/easy_my_coop_document/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf8 -*- +import models diff --git a/easy_my_coop_document/__openerp__.py b/easy_my_coop_document/__openerp__.py new file mode 100644 index 0000000..bee59f8 --- /dev/null +++ b/easy_my_coop_document/__openerp__.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Rémy Taymans +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Easy My Coop Document', + + 'summary': """ + Manage the documents of your cooperative. + """, + 'description': """ + """, + + 'author': 'Rémy Taymans', + 'license': 'AGPL-3', + 'version': '9.0.1.0', + 'website': "https://github.com/houssine78/vertical-cooperative", + + 'category': 'Cooperative Management', + + 'depends': [ + 'base', + 'web', + ], + + 'data': [ + 'security/ir.model.access.csv', + 'views/easy_my_coop_document_menu.xml', + 'views/easy_my_coop_document_views.xml', + ] +} diff --git a/easy_my_coop_document/models/__init__.py b/easy_my_coop_document/models/__init__.py new file mode 100644 index 0000000..c4914fe --- /dev/null +++ b/easy_my_coop_document/models/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf8 -*- +from . import document diff --git a/easy_my_coop_document/models/document.py b/easy_my_coop_document/models/document.py new file mode 100644 index 0000000..b509bf8 --- /dev/null +++ b/easy_my_coop_document/models/document.py @@ -0,0 +1,80 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Rémy Taymans +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + + +from openerp import models, fields, api + + +class Document(models.Model): + _name = 'easy_my_coop.document' + _description = "Document" + _order = 'document_date desc, name' + + name = fields.Char("Name", required=True) + description = fields.Text("Description") + document = fields.Binary('Document', attachment=True, required=True) + filename = fields.Char("Document File Name") + mimetype = fields.Char("Mime-Type", compute='_mimetype') + file_size = fields.Integer("File Size", compute='_file_size') + document_date = fields.Date("Document Date", + default=fields.Date.today()) + category = fields.Many2one('easy_my_coop.document.category', + string="Category") + published = fields.Boolean("Published?") + publication_date = fields.Datetime("Publication Date", + compute='_publication_date', + store=True) + public = fields.Boolean("Public?") + + @api.depends('document') + def _mimetype(self): + for doc in self: + attachment_mgr = self.env['ir.attachment'].sudo() + attachment = attachment_mgr.search_read( + [('res_model', '=', self._name), + ('res_id', '=', doc.id), + ('res_field', '=', 'document')], + fields=['mimetype', 'file_size'], + limit=1, + )[0] + doc.mimetype = attachment['mimetype'] + + @api.depends('document') + def _file_size(self): + for doc in self: + attachment_mgr = self.env['ir.attachment'].sudo() + attachment = attachment_mgr.search_read( + [('res_model', '=', self._name), + ('res_id', '=', doc.id), + ('res_field', '=', 'document')], + fields=['mimetype', 'file_size'], + limit=1, + )[0] + doc.file_size = attachment['file_size'] + + @api.depends('published') + def _publication_date(self): + for doc in self: + if doc.published and not doc.publication_date: + doc.publication_date = fields.Datetime.now() + if not doc.published: + doc.publication_date = False + + +class Category(models.Model): + _name = 'easy_my_coop.document.category' + _description = "Category" + _order = 'name' + + name = fields.Char("Name", required=True) + description = fields.Text("Description") + parent_id = fields.Many2one('easy_my_coop.document.category', + string="Parent Category") + child_ids = fields.One2many('easy_my_coop.document.category', + 'parent_id', + string="Child Categories") + document_ids = fields.One2many('easy_my_coop.document', + 'category', + string="Documents") diff --git a/easy_my_coop_document/security/ir.model.access.csv b/easy_my_coop_document/security/ir.model.access.csv new file mode 100644 index 0000000..ed7eaa0 --- /dev/null +++ b/easy_my_coop_document/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_easy_my_coop_document,access_easy_my_coop_document,model_easy_my_coop_document,,1,0,0,0 +access_easy_my_coop_document_category,access_easy_my_coop_document_category,model_easy_my_coop_document_category,,1,0,0,0 diff --git a/easy_my_coop_document/views/easy_my_coop_document_menu.xml b/easy_my_coop_document/views/easy_my_coop_document_menu.xml new file mode 100644 index 0000000..a8e6e93 --- /dev/null +++ b/easy_my_coop_document/views/easy_my_coop_document_menu.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/easy_my_coop_document/views/easy_my_coop_document_views.xml b/easy_my_coop_document/views/easy_my_coop_document_views.xml new file mode 100644 index 0000000..bd89d60 --- /dev/null +++ b/easy_my_coop_document/views/easy_my_coop_document_views.xml @@ -0,0 +1,105 @@ + + + + + + + + Document Form + easy_my_coop.document + +
+ + + + + + + + + + + +
+
+
+ + + + Document Tree + easy_my_coop.document + + + + + + + + + + + + + + + + + Document Search + easy_my_coop.document + + + + + + + + + + + + + + Category Form + easy_my_coop.document.category + +
+ + + + + +
+
+
+ + + + Category Tree + easy_my_coop.document.category + + + + + + + + + + + + Category Search + easy_my_coop.document.category + + + + + + + + +
+