Add total label to tree footer odoo 12 - treeview

I need to add a Total label on the last row from a tree, the last row is for sum values, how can I edit a tree footer?
view.xml
<xpath expr="//field[#name='field_list']/tree/field[#name='name']" position="after">
<field name="field1" sum="Total Field 1"/>
<field name="field2" sum="Total Field 2"/>
<field name="field3" sum="Total Field 3"/>
</xpath>
screenshot
Is there a way to edit the tree footer?

The list footer is used to show aggregates (sum, avg), it is rendered in _renderFooter of the ListRenderer.
The method docstring:
/**
* Render the footer. It is a <tfoot> with a single row, containing all
* aggregates, if applicable.
*
* #private
* #returns {jQueryElement} a <tfoot> element
*/
The method that computes aggregates will check for the field type, the computation will be ignored if the field type is not one of the following integer, float or monetary.
You can alter the _renderFooter to be able to provide a static text to display in the footer using a field attribute.
Example:
var ListRenderer = require("web.ListRenderer");
ListRenderer.include({
_renderFooter: function () {
var res = this._super();
_.each(this.columns, function (column) {
if(!('aggregate' in column) && column.attrs.text) {
res.find('.'+column.attrs.name).text(column.attrs.text);
}
});
return res;
},
});
To add the above code, check the Assets Management documentation.
To display the text in the footer of the corresponding column, set the text attribute in the field tag ( if the field contain an aggregate, the text will be ignored).
<field name="total" text="Total"/>

Related

Odoo duplicate many2many fields

A model [m] with a many2many field [m2m]
Field [m2m] have attribute [copy=False]
A form view [v] display the [m] and the field [m2m] with widget [many2many_tags]
I have tested that the python object did return a with False on field [m2m]
but the javascript, keep render the tags on web.
model.py
class model(models.Model):
_name = "m"
m2m = fields.Many2many('sale.order', string="SO", copy=False)
XML File
<record ...>
<form>
<group>
<field name="name"/>
<field name="ref"/>
<field name="so_m2m" widget="many2many_tags" options="{'no_create_edit': True}"/>
</group>
</form>
</record>
When I duplicate the current record, the field [m2m] is keeps the old tag from old record which is not expected.
After clicking the save button, the old tag will disappear.
Try one thing here :
Whatever your third table is there, both fields used in many2many relation, from third table keep them as a copy false.
i.e.
m2m = fields.Many2many('sale.order','sale_order_another_table_rel', 'sale_order_field','antother_table_field', string="SO", copy=False)
Into new table :
_name = 'sale.order.another.table.rel'
sale_order_field_id = // copy=false
another_table_field_id = //copy = false
Hopefully work.

Odoo 9.0 C How to add a new many2one field from an inherited view?

Could you guy please show me what is the right steps to follow when we want to add a new many2one field to an inherited view like account.invoice.order.
It's like the same :
<template id="new_id" inherit_id="module_name.qweb_template_id" name="Template name as you want">
<!-- specify the target that you want to add the many2one field
than the place after,before or inside -->
<xpath expr="//target_where_you_want_to_add" position="after/before/inside">
<field name="your_one_to_many_field_name" />
</xpath>
</template>
the hard part is targeting the write place
like if you want to add the the field to a div tag inside a div with id ="div_id" and the div contain a class="class_name"
<xpath expr="//div[#id='div_id']/div[#class='class_name']" position="inside">
or a after a field inside that div named field1
<xpath expr="//div[#id='div_id']/div[#class='class_name']/field[#name='field1']" position="after">
or after a field that named field1
<!-- // is like a shortcut -->
<xpath expr="//field[#name='field1']" position="after">
so see who can you target the place that you want to put the field using tag names and properties like id,class,... (string is not supported in odoo 9)

Update a value on redux form

I have a react-bootstrap class of a form. The code is something like that:
class MyReactClass extends Component {
// ....
render() {
return (
<div>
<Field name="combobox1" component={ComboBox} options={options} ></Field>
<Field name="textField2" component={My_TextField}></Field>
<Field name="textField3" component={My_TextField}></Field>
<Field name="textField4" component={My_TextField}></Field>
</div>
}
}
export default reduxForm({
form: 'myReactClass ',
}
)(MyReactClass );
I added an initialization to initialize some values:
componentDidMount() {
this.props.initialize({textField2:'blabla'});
}
Now I want that when the user selects a value from the combobox, it'll automatically change the value of textfield3. I have a WORKING onChange function for the combobox, but I can't find a way to change textfield3's value. I tried to use "initialize" again -
this.props.initialize({textField3: this.getUpdatedValue()});
but it initialize the whole form and the form gets cleared and have only the value for textfield3.
I tried to access this.props.textField3 but I got undefined.
How can I update the form's value?
this.props.change('textField3', this.getUpdatedValue()) would work.
Optionally, if you need the user to understand that the value was autofilled but can be manually changed, you can use:
this.props.autofill('textField3', this.getUpdatedValue())
These are described in the docs here.

Display tag external sort overriden?

I am using display tag and spring mvc.
Basically, i have a simple table like this. Note the use of external.
<display:table id="tableId" name="data" sort="external" defaultsort="1" sort="external">
<display:column property="id" title="ID" sortable="true" sortName="id" />
<display:column property="firstName" sortable="true" sortName="firstName" title="First Name" />
<display:column property="lastName" sortable="true" sortName="lastName" title="Last Name" />
<display:column property="address" sortable="true" sortName="address" title="Email Address"/>
</display:table>
On the controller side, i get the sorted column index and the sort order.
String c = request.getAttribute(new ParamEncoder("tableId").encodeParameterName(TableTagParameters.PARAMETER_SORT));
To get the order (ASC/DESC):
String order = request.getAttribute(new ParamEncoder("tableId").encodeParameterName(TableTagParameters.PARAMETER_ORDER)));
All this is working fine. For the last step i used customized comparator to sort my list and put it back into the attribute "data" mapped himself to the table (see display tag "name" property).
public void populateModel(Model model, HttpRequest request){
String c = request.getAttribute(new ParamEncoder("tableId").encodeParameterName(TableTagParameters.PARAMETER_SORT));
// here the comparator is computed with column and order value eg
Comparator comp = new DefaultComparator();
if(c == 1){
comp = new NumericComparator();
}
List<Employe> list = Collection.sort(dao.getEmployee(), comp );
model.addAttribute("data", list);
// here the list is sorted properly
return "mypage";
}
Unfortunatly the display in the final jsp does not care about order in the list. It seem's something is overriding to a default and alphanumeric sorter...so even if i use my NumericComparator the column is still wrong sorted and i assume the "list" object has been sorted back by the librairie before the display.
To summup:
Get display tag indexes : ok
Sort the list and put it back to jsp : ok (list is sorted depending on display tag params in the controller)
Display the sorted list in the jsp side with display tag : KO (the library do not care about list order, sorting it with default sort)
Display the sorted list in the jsp side without display tag : OK
Any got the explanation about this, is there something wrong or missing ?

Update smart table after content changed

I have an array of objects, which I display using st-table directive.
I filter the table by a value of a certain field in the objects.
The problem is, once a value of a field in these objects has been changed, the filtering is not performed.
I believe the reason for it is that smart-table watches the array's length, but doesn't perform deep comparison to see whether or not the values inside any of the objects changed.
What can I do to solve this?
edit: added code:
angular.module('myApp', ['smart-table'])
.controller('mainCtrl', ['$scope', '$timeout',
function ($scope, $timeout) {
$scope.rowCollection = [
{
name: "sth odd",
number: 1
},
{
name: "sth even",
number: 1
}
];
$scope.displayedCollection = [].concat($scope.rowCollection);
function changeNumber(){
$timeout(function(){
$scope.rowCollection[1].number = $scope.rowCollection[1].number === 1 ? 2 : 1;
changeNumber();
}, 1000);
}
changeNumber();
}
]);
http://plnkr.co/edit/IVYy5WrsiEJSRXZCqY9z?p=preview
Notice how when you search e.g number "2", the view isn't updated even though the property of the second item sometimes is "2" and sometimes not.
Found a solution for you, instead of using st-search use a plain ng-model and then filter by the ng-model value. then in the ng-repeat filter by that value
so instead of this
<input st-search="number" placeholder="search for number" class="input-sm form-control" type="search"/>
...
<tr ng-repeat="row in displayedCollection">
<td>{{row.name}}</td>
<td>{{row.number}}</td>
</tr>
do this
<input ng-model="searchMe" placeholder="search for number" class="input-sm form-control" type="search"/>
....
<tr ng-repeat="row in filterd = (displayedCollection | filter: searchMe)">
<td>{{row.name}}</td>
<td>{{row.number}}</td>
</tr>
here's a plunker, enter 2 and see how it redos the filtering each time
To refresh the smart-table you can add or remove items as you know or use a new array.. so just recreate the array.
$scope.rowCollection = [].concat($scope.rowCollection);

Resources