How to add one2many field of custom model to the tree view in Openerp? - odoo

I want to add a selection field to the form view and show the selection in tree view.
I first tried adding a custom selection field to the model but since I have many values to add to the selection field I bumped to the char(128) limit of the selection field of ir.model model.
Second I created a new custom model named x_newmodel with 3 fiedls with names x_name, x_code, x_description
added a one2many field x_newfield connecting to the x_newmodel solved the problem with the form view.
However when I try to add the new field x_newfield to the tree view I cannot get to show the data on the view.
My question is how can I add the field one2many relationship of the custom field to the tree view?

AFAIK, it is not supported.
What you could do is add a function field on your model which would compute
','.join(elem.name for elem in obj.x_newfield)
and use this in your tree display.
If you need to add a filter, you can implement the search function for your function field.

Related

default values on a related model

From my model I have a many2one relationship to res.partner
Such relationship "feeds" a dropdown field (menu)
Such dropdown field contains a list of partners and the last item is "Start writing", to create a new partner (see this picture; "Inizia a scrivere is the Italian for "Start writing")
I'd like the new partner being created to have some fields automatically assigned with some default values
I've been suggested to use an action with a context but in this case I'm not starting the creation of a new partner from a menu or button and I'm not sure how to call my action from the last item of the dropdown menu
you can apply a context attribute on a related field in a view
Like this
<field name="some_related_field_id"
context="{'default_field_to_be_set_on_the_related_model': 'some_value'}"/>
Please notice that the name of the field to be set is not
default_field_to_be_set_on_the_related_model
it is
field_to_be_set_on_the_related_model
The initial default_ is a convention to set default values
That's required, if you don't prefix the name of your field with default_ the thing won't work

How to add a checkbox to the CDS view's filter bar

I would like to add a simple checkbox to a Fiori app based on a CDS view. Clicking it would restrict the data using a parameterized table function that would return "true" or "false" for each row.
I'm unable to find any info on checkboxes in the filter bar. Is this possible using CDS annotations ?
Please check the relevant ODATA metadata, if the field of the entity is of type 'Edm.Boolean', in the Fiori, it will automatically rendered as a checkbox. You can also cast the field to ABAP boolean in CDS view if necessary.

Does mvc 4 application need another model to return aggregate data on an existing table and model

I have a table (and model) with the following properties in an asp.net MVC 4 application:
TV Table
height
width
depth
type
brand
cost
When the user answes a question about the space that they have for the TV I then do an ajax call to determine which types are possible to fit into the space they have specified. Which type of TV type they want is the following question, so some options may need to be disabled. The SQL for what types fit in the space is "select distinct type from TV where height < #height and width < #width and depth < #depth".
Should I:
1. create a new model that I call from the TV controller just to return the distinct types
2. add a method to the TV model that I call from the TV controller that just returns a list of string with the types that fit
Depends on what you want to display to the user based on her selection' e. g.
If you want to display TV name + its description then returning a list of TV model will make sense.
If you are just going to display a list of TV names in combo box, then returning a list of string will suffice.
Calling a new action make sense in both cases IMHO.
EDIT:
For 2 - I want to return a list of string - should I create a new data model for this, or add a method in the existing TV data model that returns a list of string?
To expand on above query, since its not clear (at least I do not visualize it) from your question i will assume few things.
Case 1: You are displaying a view say "TVSelection" to the user that does not contain list of TVModels. In this view you are expecting user to enter three values i.e. Width, Height, Depth. Now when user enter these values, she can submit the form or you can fetch the TV Brand name list on Lost Focus event as well. In any case, the question would be are you updating existing view by populating the combo box or you are displaying a new view. I am assuming you are updating existing "TVSelection" view by the means of making an AJAX call. In that case you can just call a method on your controller (which displayed the "TVSelection" view) that returns a list of TV Brand names.
Case 2: You are displaying "TVSelection" view that already has a list of TVModel objects and you update it dynamically on selection of required field (filtering). In this case you can add a method in the TVModel itself to filter names only that matches the user selection.
I found these links relevant 1 & 2.
Hope that make sense.
Please add more details to your question if this does not answer your question.

Yii booster: how to render a cgridview inside a relation table row?

I'm using boostrap library on Yii via yii-booster
I've created a relation table view
The related view is a TbGriView itself
Vhen in a row i click on the link on the 'related' column, the row expands itself, and render a TbGridview inside it.
The problem is that the internal gridview cannot be sorte, paged or filtered, because each action on it causes that the entire container grid will empty
Note
- external grid as a id of 'extenalgrid'
- each internal grid has as id like 'internalgrid-$rowId' , so every internal grid as differnt id on div, table and table row elements.
- the action called from "render related tabel" link is using renderPartial without the postProcess option. If i use potProcess, the row will be empty
So is it not possible to rendere a full working gridview/tbgridview into a related table ?
Use different css classes for the filters, buttons and headers for the different tables. From the jquery.yiigridview.js file events are bound to selectors as $('#table-id .selector-class') so elements in your internal gridView still trigger the events bound to the external gridView. You also have to specify a different url for the internal gridView by setting it's ajaxUrl.

Sencha Touch 2: Insert into TreeStore/NestedList

I'm using a NestedList with a underlying TreeStore. Now I want to add items to the NestedList as leafs.
How can I do this?
Currently my code (Controller, onAddButtonTapped) looks like this:
var store = Ext.getStore('menuStore');
var customerAreaNode = store.getRoot().getChildAt(1);
customerAreaNode.appendChild({name: "text", leaf:true});
customerAreaNode.expand();
store.sync();
This code results in two new empty listentries on leaf level (behind the correct node) and one new listentry on node level.
Every new entry has no names shown in the NestedList but every item contains "text" in their name field. Curiously one of the new entries at leaf level is not typed to the underlying Model. So the model-corresponding methods could't be found:
Uncaught TypeError: Cannot call method 'getSelectedName' of undefined
Does anybody know a easy tutorial how to add data into NestedList/TreeStore? I could not find one good example in the sencha touch docs.
The default display field for leaf items is "text". You can get the information from here. If you want to use "text" as display field, then you need to change this line to
customerAreaNode.appendChild({text: "text", leaf:true});
Or you can change your nested list's display field, so your model do not need to change for this time.
yournestedlist.setDisplayField('name');
Hope this helps.
In my case i used to update root and child nodes like the following way
Ext.getStore('Contactsstore').getAt(1).getChildAt(0).set('Email',contactemail);
Ext.getStore('Contactsstore').getAt(1).set('ContactTitle',contacttitle);