mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-27 02:48:41 -06:00
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.
This commit is contained in:
parent
8fab04e6b6
commit
9b7799d749
1
document_type/__init__.py
Normal file
1
document_type/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import models
|
@ -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,
|
||||
}
|
||||
|
1
document_type/models/__init__.py
Normal file
1
document_type/models/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import document_type
|
18
document_type/models/document_type.py
Normal file
18
document_type/models/document_type.py
Normal file
@ -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')
|
40
document_type/static/src/js/sidebar.js
Normal file
40
document_type/static/src/js/sidebar.js
Normal file
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
10
document_type/templates/web.xml
Normal file
10
document_type/templates/web.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<template id="assets_backend" name="document_type backend assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/document_type/static/src/js/sidebar.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</odoo>
|
30
document_type/views/attachment.xml
Normal file
30
document_type/views/attachment.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="ir_attachment_view_form_upload" model="ir.ui.view">
|
||||
<field name="name">Attachment form view for type selection after upload</field>
|
||||
<field name="model">ir.attachment</field>
|
||||
<!-- higher priority needed to make sure this isn't used as default form view -->
|
||||
<field name="priority" eval="32"/>
|
||||
<field name="arch" type="xml">
|
||||
<form create="false">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="document_type_id"/>
|
||||
<field name="description"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="ir_attachment_action_upload_type" model="ir.actions.act_window">
|
||||
<field name="name">Attachment upload typle selection action</field>
|
||||
<field name="res_model">ir.attachment</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="ir_attachment_view_form_upload"/>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
42
document_type/views/document_type.xml
Normal file
42
document_type/views/document_type.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="document_type_action_main" model="ir.actions.act_window">
|
||||
<field name="name">Document Types</field>
|
||||
<field name="res_model">document.type</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
</record>
|
||||
|
||||
<record id="document_type_view_form" model="ir.ui.view">
|
||||
<field name="name">Document types list view</field>
|
||||
<field name="model">document.type</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="ir_model_id"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="document_type_view_tree" model="ir.ui.view">
|
||||
<field name="name">Document types list view</field>
|
||||
<field name="model">document.type</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="ir_model_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
id="document_type_menu"
|
||||
name="Document Types"
|
||||
action="document_type_action_main"
|
||||
parent="knowledge.menu_document_configuration"/>
|
||||
|
||||
</odoo>
|
Loading…
Reference in New Issue
Block a user