first version

This commit is contained in:
Giovanni Francesco Capalbo 2017-09-22 12:36:40 +02:00
parent a5a01ecfcd
commit 1b56ee20bd
8 changed files with 109 additions and 40 deletions

View File

@ -2,5 +2,3 @@
# © 2017 Therp BV <http://therp.nl> # © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models from . import models
from . import wizards
from . import controllers

View File

@ -2,31 +2,17 @@
# © 2017 Therp BV <http://therp.nl> # © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Term", "name": "Terms and Definitions",
"version": "8.0.1.0.0", "version": "8.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)", "author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"category": "", "category": "Knowledge",
"summary": "",
"depends": [ "depends": [
'knowledge',
], ],
"data": [ "data": [
'views/templates.xml', 'views/templates.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
], ],
"qweb": [
],
"test": [
],
"images": [
],
"pre_init_hook": False,
"post_init_hook": False,
"uninstall_hook": False,
"auto_install": False,
"installable": True, "installable": True,
"application": False,
"external_dependencies": {
'python': [],
},
} }

View File

@ -4,8 +4,36 @@
from openerp import api, fields, models from openerp import api, fields, models
class document_definition(models.Model): class DocumentDefinition(models.Model):
_inherit = 'document_definition' _name = 'document.definition'
_name = 'document_definition'
_description = ''
term = fields.Char(help='Term to define', required=True)
definition = fields.Text(help='Definition of term', required=True)
# stored compute field used for making the letter grouping
# need to be stored in order to use grouping
first_letter = fields.Char()
def _get_first_letter(self, text):
# if somehow the user starts with a blank space we trim it
return text.lstrip()[:1].upper() or 'Blank Term'
@api.model
def create(self, vals):
vals['first_letter'] = self._get_first_letter(vals['term'])
res = super(DocumentDefinition, self).create(vals=vals)
return res
@api.multi
def write(self, vals):
for this in self:
if vals.get('term'):
vals['first_letter'] = this._get_first_letter(vals['term'])
res = super(DocumentDefinition, this).write(vals=vals)
return res
# constraint of uniqueness on term, two terms can't have different
# definitions
_sql_constraints = [('term_uniq', 'UNIQUE(term)',
'Every term must be unique')]

View File

@ -1 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
document_definition_all,document.definition,model_document_definition,,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 document_definition_all document.definition model_document_definition 1 1 1 1
3

View File

@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_document_definition

View File

@ -1,9 +0,0 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase
class TestDocumentDefinition(TransactionCase):
def test_document_definition(self):
pass

View File

@ -3,9 +3,80 @@
<data> <data>
<template id="assets_backend" name="document_definition assets" inherit_id="web.assets_backend"> <template id="assets_backend" name="document_definition assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/document_definition/static/src/js/document_definition.js"></script> <script type="text/javascript" src="/document_definition/static/src/js/document_definition.js"/>
<link rel="stylesheet" href="/document_definition/static/src/css/document_definition.css"/> <link rel="stylesheet" href="/document_definition/static/src/css/document_definition.css"/>
</xpath> </xpath>
</template> </template>
<record id="view_definition_tree" model="ir.ui.view">
<field name="name">document.definition.tree</field>
<field name="model">document.definition</field>
<field name="priority">100</field>
<field name="arch" type="xml">
<tree string="Definitions" editable="top">
<field name="term"/>
<field name="definition"/>
</tree>
</field>
</record>
<record id="view_definition_form" model="ir.ui.view">
<field name="name">document.definition.form</field>
<field name="model">document.definition</field>
<field name="priority">100</field>
<field name="arch" type="xml">
<form string="Definitions">
<sheet>
<h1>
<field name="term"/>
</h1>
<field name="definition"/>
</sheet>
</form>
</field>
</record>
<!-- filters to group by alphabetical order, and search by term or in
definition -->
<record id="view_definition_filter" model="ir.ui.view">
<field name="name">document.definition.search</field>
<field name="model">document.definition</field>
<field name="arch" type="xml">
<search string="Definitions">
<field name="term" string="Search Term" filter_domain="[('term','ilike',self)]"/>
<field name="definition" string="Search in definition" filter_domain="[('definition','ilike',self)]"/>
<field name="write_uid"/>
<group expand="1" string="Group By...">
<filter string="Alphabetical" domain="[]" context="{'group_by':'first_letter'}"/>
<filter string="Author" domain="[]" context="{'group_by':'create_uid'}"/>
<filter string="Last Contributor" domain="[]" context="{'group_by':'write_uid'}"/>
</group>
</search>
</field>
</record>
<record id="action_definition" model="ir.actions.act_window">
<field name="name">Terms and definitions</field>
<field name="res_model">document.definition</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_definition_tree"/>
<field name="search_view_id" ref="view_definition_filter"/>
</record>
<menuitem
id="menu_definition_top"
parent="knowledge.menu_document"
name="Definitions"
sequence="10" />
<menuitem
id="menu_definition"
parent="menu_definition_top"
name="Definitions"
action="action_definition"
sequence="10" />
</data> </data>
</openerp> </openerp>

View File

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).