From 9b7799d749a33bd97f902863b365ec6f29fc3efe Mon Sep 17 00:00:00 2001 From: Leonardo Donelli Date: Wed, 1 Feb 2017 19:01:17 +0100 Subject: [PATCH] Initial commit: working document types and attachment upload wizard Define possible document types per model. Then, when uploading attachments, the user is prompted with a simple popup form view where they can select the attachment type and its name and description. --- document_type/__init__.py | 1 + document_type/__manifest__.py | 12 +++++--- document_type/models/__init__.py | 1 + document_type/models/document_type.py | 18 +++++++++++ document_type/static/src/js/sidebar.js | 40 ++++++++++++++++++++++++ document_type/templates/web.xml | 10 ++++++ document_type/views/attachment.xml | 30 ++++++++++++++++++ document_type/views/document_type.xml | 42 ++++++++++++++++++++++++++ 8 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 document_type/__init__.py create mode 100644 document_type/models/__init__.py create mode 100644 document_type/models/document_type.py create mode 100644 document_type/static/src/js/sidebar.js create mode 100644 document_type/templates/web.xml create mode 100644 document_type/views/attachment.xml create mode 100644 document_type/views/document_type.xml diff --git a/document_type/__init__.py b/document_type/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/document_type/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/document_type/__manifest__.py b/document_type/__manifest__.py index 5a72e2bb..1d72d98d 100644 --- a/document_type/__manifest__.py +++ b/document_type/__manifest__.py @@ -2,14 +2,18 @@ # Copyright 2016 MONK Software # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - "name": "Document Types" + "name": "Document Types", "version": "10.0.1.0.0", "author": "MONK Software, Odoo Community Association (OCA)", "category": "Knowledge", "license": "AGPL-3", "website": "https://odoo-community.org/", - "depends": ["knowledge"], - "data": [], - 'installable': True, + "depends": ["document", "knowledge"], + "data": [ + 'views/document_type.xml', + 'views/attachment.xml', + 'templates/web.xml', + ], + "installable": True, "auto_install": False, } diff --git a/document_type/models/__init__.py b/document_type/models/__init__.py new file mode 100644 index 00000000..dc747ec4 --- /dev/null +++ b/document_type/models/__init__.py @@ -0,0 +1 @@ +from . import document_type diff --git a/document_type/models/document_type.py b/document_type/models/document_type.py new file mode 100644 index 00000000..114b11a6 --- /dev/null +++ b/document_type/models/document_type.py @@ -0,0 +1,18 @@ +from odoo import fields, models + + +class DocumentType(models.Model): + _name = 'document.type' + _description = 'Document Type' + + name = fields.Char(required=True) + ir_model_id = fields.Many2one('ir.model', string='Object') + document_ids = fields.One2many( + 'ir.attachment', 'document_type_id', string='Documents') + + +class IrAttachment(models.Model): + _inherit = 'ir.attachment' + + document_type_id = fields.Many2one( + 'document.type', string='Document Type') diff --git a/document_type/static/src/js/sidebar.js b/document_type/static/src/js/sidebar.js new file mode 100644 index 00000000..8844163b --- /dev/null +++ b/document_type/static/src/js/sidebar.js @@ -0,0 +1,40 @@ +odoo.define('document_type.sidebar', function(require) { + "use strict"; + + var core = require('web.core'); + var form_common = require('web.form_common'); + var Sidebar = require('web.Sidebar'); + var Dialog = require('web.Dialog'); + var Model = require('web.Model'); + + var _t = core._t; + + Sidebar.include({ + + do_attachement_update: function(dataset, model_id, args) { + var self = this; + // if args is defined, a new attachment has been added + if (args && !args[0].error) { + var pop = new form_common.FormViewDialog(self, { + res_model: 'ir.attachment', + res_id: args[0].id, + title: _t('Set attachment details'), + view_id: self.attachment_upload_view_id + }).open(); + } + this._super.apply(this, arguments); + }, + + start: function() { + var res = this._super.apply(this, arguments); + var self = this; + new Model('ir.model.data') + .call('xmlid_to_res_id', ['document_type.ir_attachment_view_form_upload']) + .then(function(view_id) { + self.attachment_upload_view_id = view_id; + }); + } + + }); + +}); diff --git a/document_type/templates/web.xml b/document_type/templates/web.xml new file mode 100644 index 00000000..a00e659f --- /dev/null +++ b/document_type/templates/web.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/document_type/views/attachment.xml b/document_type/views/attachment.xml new file mode 100644 index 00000000..810b08d3 --- /dev/null +++ b/document_type/views/attachment.xml @@ -0,0 +1,30 @@ + + + + + Attachment form view for type selection after upload + ir.attachment + + + +
+ + + + + + + +
+
+
+ + + Attachment upload typle selection action + ir.attachment + form + + new + + +
diff --git a/document_type/views/document_type.xml b/document_type/views/document_type.xml new file mode 100644 index 00000000..e42d3906 --- /dev/null +++ b/document_type/views/document_type.xml @@ -0,0 +1,42 @@ + + + + + Document Types + document.type + tree,form + + + + Document types list view + document.type + +
+ + + + + + +
+
+
+ + + Document types list view + document.type + + + + + + + + + + +