Add line (adding a related record)

83 Views Asked by At

I'm showing a related model by using the

related_model_ids

field in the model form view

The link for adding a record in the related model is

"Add a line" (in the attached image it's "Aggiungi riga", that's the transaltion in Italian) a screenshot of the said string

What's the idiomatic odooish way to change that string ?

Is it by overriding the default_view_get method ?

1

There are 1 best solutions below

2
On

Depends on what you want to achieve.

Change the string for that one case

You can add controls to your tree view and decide what strings will be used. Link to the official doc

For example:

<tree>
  <control>
    <create string="Add a pizza"/>
    <create string="Add some pasta"
        context="{'default_type': 'pasta'}"/>
    <create string="Add some olive oil"
        context="{'default_type': 'oliveoil'}"/>
  </control>
  <field name="name"/>
  <field name="amount"/>
</tree>

Change the string for all default cases

Changing the default string can probably be made by overriding the translation "Add a line" (web module: #: code:addons/web/static/src/js/views/list/list_editable_renderer.js:0) or by extending/changing that part on the list_renderer's JavaScript code which can be found here for Odoo 14.

Edit for atleast Odoo 14: Seems that the controls only work with extra widgets, for example the widget section_and_note_one2many. So you have to change the field node by adding the widget. Then you can use the controls.