mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-17 04:32:55 -06:00
[IMP] document_page_reference: add option to create a new page from a non-existing reference
This commit is contained in:
parent
28be8f7258
commit
6fa16d937c
@ -74,21 +74,25 @@ class DocumentPage(models.Model):
|
|||||||
document = self.search([('reference', '=', code)])
|
document = self.search([('reference', '=', code)])
|
||||||
if document:
|
if document:
|
||||||
return document
|
return document
|
||||||
return False
|
else:
|
||||||
|
return self.env[self._name]
|
||||||
|
|
||||||
def get_reference(self, code):
|
def get_reference(self, code):
|
||||||
element = self._get_document(code)
|
element = self._get_document(code)
|
||||||
if not element:
|
|
||||||
return code
|
|
||||||
if self.env.context.get('raw_reference', False):
|
if self.env.context.get('raw_reference', False):
|
||||||
return html_escape(element.display_name)
|
return html_escape(element.display_name)
|
||||||
text = '<a href="#" class="oe_direct_line" ' \
|
text = """<a href="#" class="oe_direct_line"
|
||||||
'name="%s" data-id="%s">%s</a>'
|
data-oe-model="%s" data-oe-id="%s" name="%s">%s</a>
|
||||||
return text % (
|
"""
|
||||||
|
if not element:
|
||||||
|
text = '<i>%s</i>' % text
|
||||||
|
res = text % (
|
||||||
element._name,
|
element._name,
|
||||||
element.id,
|
element and element.id or '',
|
||||||
html_escape(element.display_name)
|
code,
|
||||||
|
html_escape(element.display_name or code),
|
||||||
)
|
)
|
||||||
|
return res
|
||||||
|
|
||||||
def _get_template_variables(self):
|
def _get_template_variables(self):
|
||||||
return {'ref': self.get_reference}
|
return {'ref': self.get_reference}
|
||||||
|
@ -14,11 +14,18 @@ odoo.define('document_page_reference.backend', function (require) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
var element = $(event.target).closest('.oe_direct_line')[0];
|
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({
|
this._rpc({
|
||||||
model: element.name,
|
model: model,
|
||||||
method: 'get_formview_action',
|
method: 'get_formview_action',
|
||||||
args: [[parseInt(element.dataset.id)]],
|
args: [[parseInt(id)]],
|
||||||
context: this.record.getContext(this.recordParams),
|
context: context,
|
||||||
})
|
})
|
||||||
.then(function (action) {
|
.then(function (action) {
|
||||||
self.trigger_up('do_action', {action: action});
|
self.trigger_up('do_action', {action: action});
|
||||||
|
Loading…
Reference in New Issue
Block a user