Browse Source
[ADD] emc_document: Management of documents
[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.pull/1/head
Rémy Taymans
7 years ago
7 changed files with 263 additions and 0 deletions
-
2easy_my_coop_document/__init__.py
-
32easy_my_coop_document/__openerp__.py
-
2easy_my_coop_document/models/__init__.py
-
80easy_my_coop_document/models/document.py
-
3easy_my_coop_document/security/ir.model.access.csv
-
39easy_my_coop_document/views/easy_my_coop_document_menu.xml
-
105easy_my_coop_document/views/easy_my_coop_document_views.xml
@ -0,0 +1,2 @@ |
|||
# -*- coding: utf8 -*- |
|||
import models |
@ -0,0 +1,32 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
# Copyright 2018 Rémy Taymans <remytaymans@gmail.com> |
|||
# 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', |
|||
] |
|||
} |
@ -0,0 +1,2 @@ |
|||
# -*- coding: utf8 -*- |
|||
from . import document |
@ -0,0 +1,80 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
# Copyright 2018 Rémy Taymans <remytaymans@gmail.com> |
|||
# 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") |
@ -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 |
@ -0,0 +1,39 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- |
|||
Copyright 2018 Rémy Taymans <remytaymans@gmail.com> |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
--> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<!-- Action to open document list --> |
|||
<act_window id="action_easy_my_coop_document" |
|||
name="Document" |
|||
res_model="easy_my_coop.document" |
|||
view_mode="tree,form" /> |
|||
|
|||
<!-- Action to open category list --> |
|||
<act_window id="action_easy_my_coop_document_category" |
|||
name="Categories" |
|||
res_model="easy_my_coop.document.category" |
|||
view_mode="tree,form" /> |
|||
|
|||
<!-- Root menu for document --> |
|||
<menuitem id="menu_main_easy_my_coop_document" |
|||
name="Documents" |
|||
sequence="45" /> |
|||
|
|||
<!-- Menu item to open Document list --> |
|||
<menuitem id="menu_document" |
|||
name="Documents" |
|||
parent="menu_main_easy_my_coop_document" |
|||
action="action_easy_my_coop_document" /> |
|||
|
|||
<!-- Menu item to open Category list --> |
|||
<menuitem id="menu_category" |
|||
name="Categories" |
|||
parent="menu_main_easy_my_coop_document" |
|||
action="action_easy_my_coop_document_category" /> |
|||
|
|||
</data> |
|||
</openerp> |
@ -0,0 +1,105 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- |
|||
Copyright 2018 Rémy Taymans <remytaymans@gmail.com> |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
--> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<!-- Document form view --> |
|||
<record id="view_form_document" model="ir.ui.view"> |
|||
<field name="name">Document Form</field> |
|||
<field name="model">easy_my_coop.document</field> |
|||
<field name="arch" type="xml"> |
|||
<form string="Documents"> |
|||
<group> |
|||
<field name="name"/> |
|||
<field name="filename" invisible="1"/> |
|||
<field name="document" filename="filename"/> |
|||
<field name="document_date"/> |
|||
<field name="description"/> |
|||
<field name="public"/> |
|||
<field name="category"/> |
|||
<field name="published"/> |
|||
<field name="publication_date" readonly="True"/> |
|||
</group> |
|||
</form> |
|||
</field> |
|||
</record> |
|||
|
|||
<!-- Document tree view --> |
|||
<record id="view_tree_document" model="ir.ui.view"> |
|||
<field name="name">Document Tree</field> |
|||
<field name="model">easy_my_coop.document</field> |
|||
<field name="arch" type="xml"> |
|||
<tree decoration-muted="not published"> |
|||
<field name="name"/> |
|||
<field name="document" filename="filename"/> |
|||
<field name="document_date"/> |
|||
<field name="description"/> |
|||
<field name="public"/> |
|||
<field name="category"/> |
|||
<field name="published"/> |
|||
<field name="publication_date"/> |
|||
</tree> |
|||
</field> |
|||
</record> |
|||
|
|||
<!-- Document search view --> |
|||
<record id="view_search_document" model="ir.ui.view"> |
|||
<field name="name">Document Search</field> |
|||
<field name="model">easy_my_coop.document</field> |
|||
<field name="arch" type="xml"> |
|||
<search> |
|||
<field name="name"/> |
|||
<field name="category"/> |
|||
<filter string="Public" domain="[('public', '=', True)]"/> |
|||
<filter string="Published" domain="[('published', '=', True)]"/> |
|||
<filter string="Category" context="{'group_by': 'category'}"/> |
|||
</search> |
|||
</field> |
|||
</record> |
|||
|
|||
<!-- Category form view --> |
|||
<record id="view_form_category" model="ir.ui.view"> |
|||
<field name="name">Category Form</field> |
|||
<field name="model">easy_my_coop.document.category</field> |
|||
<field name="arch" type="xml"> |
|||
<form string="Categories"> |
|||
<group> |
|||
<field name="name"/> |
|||
<field name="description"/> |
|||
<field name="parent_id"/> |
|||
</group> |
|||
</form> |
|||
</field> |
|||
</record> |
|||
|
|||
<!-- Category tree view --> |
|||
<record id="view_tree_category" model="ir.ui.view"> |
|||
<field name="name">Category Tree</field> |
|||
<field name="model">easy_my_coop.document.category</field> |
|||
<field name="arch" type="xml"> |
|||
<tree> |
|||
<field name="name"/> |
|||
<field name="description"/> |
|||
<field name="parent_id"/> |
|||
</tree> |
|||
</field> |
|||
</record> |
|||
|
|||
<!-- Category search view --> |
|||
<record id="view_search_category" model="ir.ui.view"> |
|||
<field name="name">Category Search</field> |
|||
<field name="model">easy_my_coop.document.category</field> |
|||
<field name="arch" type="xml"> |
|||
<search> |
|||
<field name="name"/> |
|||
<filter string="Parent Category" |
|||
context="{'group_by': 'parent_id'}"/> |
|||
</search> |
|||
</field> |
|||
</record> |
|||
|
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue