[IMP] document_page_reference: add option to create a new page from a non-existing reference

This commit is contained in:
Jordi Ballester Alomar 2019-11-29 14:31:58 +01:00 committed by Anusha
parent 958c70d670
commit 51ddc0a45b
5 changed files with 99 additions and 15 deletions

View File

@ -7,9 +7,9 @@ Document Page Reference
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
@ -28,6 +28,11 @@ Document Page Reference
This module allows to add a reference name on documents and simplifies the link
between document pages.
.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_
**Table of contents**
.. contents::
@ -76,6 +81,14 @@ 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.
.. |maintainer-etobella| image:: https://github.com/etobella.png?size=40px
:target: https://github.com/etobella
:alt: etobella
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
|maintainer-etobella|
This module is part of the `OCA/knowledge <https://github.com/OCA/knowledge/tree/11.0/document_page_reference>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -0,0 +1,52 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * document_page_reference
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: document_page_reference
#: model:ir.model.fields,field_description:document_page_reference.field_document_page_content_parsed
msgid "Content Parsed"
msgstr ""
#. module: document_page_reference
#: model:ir.model,name:document_page_reference.model_document_page
msgid "Document Page"
msgstr ""
#. module: document_page_reference
#: model:ir.model.fields,field_description:document_page_reference.field_document_page_reference
msgid "Reference"
msgstr ""
#. module: document_page_reference
#: code:addons/document_page_reference/models/document_page.py:65
#, python-format
msgid "Reference is not valid"
msgstr ""
#. module: document_page_reference
#: code:addons/document_page_reference/models/document_page.py:70
#, python-format
msgid "Reference must be unique"
msgstr ""
#. module: document_page_reference
#: model:ir.model.fields,help:document_page_reference.field_document_page_reference
msgid "Used to find the document, it can contain letters, numbers and _"
msgstr ""
#. module: document_page_reference
#: model:ir.ui.view,arch_db:document_page_reference.document_page_form_view
msgid "internal_reference"
msgstr ""

View File

@ -74,21 +74,25 @@ class DocumentPage(models.Model):
document = self.search([('reference', '=', code)])
if document:
return document
return False
else:
return self.env[self._name]
def get_reference(self, code):
element = self._get_document(code)
if not element:
return code
if self.env.context.get('raw_reference', False):
return html_escape(element.display_name)
text = '<a href="#" class="oe_direct_line" ' \
'name="%s" data-id="%s">%s</a>'
return text % (
text = """<a href="#" class="oe_direct_line"
data-oe-model="%s" data-oe-id="%s" name="%s">%s</a>
"""
if not element:
text = '<i>%s</i>' % text
res = text % (
element._name,
element.id,
html_escape(element.display_name)
element and element.id or '',
code,
html_escape(element.display_name or code),
)
return res
def _get_template_variables(self):
return {'ref': self.get_reference}

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Document Page Reference</title>
<style type="text/css">
@ -367,9 +367,15 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/11.0/document_page_reference"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-11-0/knowledge-11-0-document_page_reference"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/knowledge/tree/11.0/document_page_reference"><img alt="OCA/knowledge" src="https://img.shields.io/badge/github-OCA%2Fknowledge-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/knowledge-11-0/knowledge-11-0-document_page_reference"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/118/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows to add a reference name on documents and simplifies the link
between document pages.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
<a class="reference external" href="https://odoo-community.org/page/development-status">More details on development status</a></p>
</div>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
@ -418,6 +424,8 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/etobella"><img alt="etobella" src="https://github.com/etobella.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/knowledge/tree/11.0/document_page_reference">OCA/knowledge</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>

View File

@ -14,11 +14,18 @@ odoo.define('document_page_reference.backend', function (require) {
event.preventDefault();
event.stopPropagation();
var element = $(event.target).closest('.oe_direct_line')[0];
var default_reference = element.name;
var model = $(event.target).data('oe-model');
var id = $(event.target).data('oe-id');
var context = this.record.getContext(this.recordParams);
if (default_reference){
context['default_reference'] = default_reference
}
this._rpc({
model: element.name,
model: model,
method: 'get_formview_action',
args: [[parseInt(element.dataset.id)]],
context: this.record.getContext(this.recordParams),
args: [[parseInt(id)]],
context: context,
})
.then(function (action) {
self.trigger_up('do_action', {action: action});