Professional Documents
Culture Documents
EXPERIENCE
Xavier Morel
generic visualisation
non-technical customisation(-ish)
integration
Why a view?
Why a view instead of a client action?
class View(models.Model):
_inherit = 'ir.ui.view'
type = fields.Selection(
selection_add=[('myview', "MyView")]
)
class ActWindowView(models.Model):
_inherit = 'ir.actions.act_window.view'
view_mode = fields.Selection(
selection_add=[('myview', "MyView")]
)
Congratulation your server-side work is done and you can create your view.
Which means its not that useful, so youre not actually done
Server: <field>
groups
attributes/attrs/modifiers
fields_get filtering
@view_validation.validate('myview')
def validate_thing(arch):
""" Validates a thing
"""
if arch.find(".//field[@name='charlie']"):
return True
return False
Server validation
def validate_thing(arch):
with misc.file_open(os.path.join('my_module', 'views',
'myview.rng')) as f:
validator = etree.RelaxNG(etree.parse(f))
if validator.validate(arch):
return True
LXML validators
Anything includes LXMLs various validators, such as RelaxNG (used by Odoo for
XML import validation)
class Base(models.AbstractModel):
_inherit = 'base'
@api.multi
def myread(self):
""" ...
"""
});
Action name
View switcher if multiple views of the same category (multi v mono record)
Search view
Client: Search View
multi_record: false
mobile_friendly: true
require_fields: true
this.do_push_state({});
do_show: function() {
this.do_push_state({});
return this._super();
}
reload_content: function () {
// ...
this.do_push_state({
min: this.current_min,
limit: this._limit
});
}
do_push_state (method of View) will add a new state item to the stack
ViewManager automatically adds current view *type*
Which is why pushing an empty state is useful (adds new state
transitioning to current view type)
Usually called on do_show to update current view_type
Can pass map of additional values to store in the URL (and history) e.g.
pagination info in list view (when updating list)
current record id in form view (when loading record)
Can call at any moment to further update values
Client: Control Panel
render_buttons: function($node) {
var $buttons = $('<div/>');
$buttons.append(
QWeb.render("MyView.buttons", {'widget': this})
).on('click', '.my_button_create', this.on_create)
.on('click', '.my_button_import', this.on_import);
$node.append($buttons);
}
Buttons zone
render_sidebar: function($node) {
var sidebar = new Sidebar(this, {});
sidebar.appendTo($node);
}
Sidebar section
render_pager: function($node) {
var pager = new Pager(this, size, low, page, options);
pager.on('pager_changed', this, function (new_state) {
// ...
});
pager.appendTo($node);
}
Pager area
fields_view
model
dataset
do_execute_action
do_switch_view
do_show
About it
Aside from these, view ~ regular widget
regular widgets lifecycle
Regular widgets tools (willStart/start/$el)
Regular web client API (QWeb, RPC)
Regular JS object (vdom)
Caveats
access rights
this.is_action_enabled('edit')
is_action_enabled
Basic access rights information
Can current user create/write/delete object of the model
does not work as server-side information only provided to whitelist of
view types
Drop-in structures
Validation mixins
Client helpers/handlers
No API for Studio integration yet, no Studio for non-standard view types
API
format_date
en_US Sat, Oct 8
format_date
en_US Sat, Oct 8
es_ES sb., oct. 8
fr_FR sam., oct. 8
hi_IN , 8
pt_BR sb, out 8
zh_CN , 10 8
format_date format_skeleton
en_US Sat, Oct 8 Sat, Oct 8
es_ES sb., oct. 8 sb., 8 oct.
fr_FR sam., oct. 8 sam. 8 oct.
hi_IN , 8 , 8
pt_BR sb, out 8 sb, 8 de out
zh_CN , 10 8 108