This commit is contained in:
Giovanni Capalbo (Therp) 2017-09-26 08:57:17 +00:00 committed by GitHub
commit f45cd8adc8
7 changed files with 187 additions and 0 deletions

View File

@ -0,0 +1,46 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=====================
Terms and definitions
=====================
Installs a new document_definition model for dictionary-style word archive and
definition. Adds Searchable view for terms and definitions in the Knowledge menu.
Has a search view per term and per definition and a dictionary Style Alphabetical grouping view.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/knowledge/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Giovanni Francesco Capalbo <giovanni@therp.nl>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

View File

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

View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Terms and Definitions",
"version": "8.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Knowledge",
"depends": [
'knowledge',
],
"data": [
'views/templates.xml',
'security/ir.model.access.csv',
],
"installable": True,
}

View File

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

View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
class DocumentDefinition(models.Model):
_name = 'document.definition'
term = fields.Char(help='Term', 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 one or more whitespaces we trim
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

@ -0,0 +1,2 @@
"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

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<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>
</openerp>