Setting default value at Form

I have this record block in module xml:

      <!-- RPA Projects -->
      <!-- Menu entry -->
      <record model="ir.action.act_window" id="act_rpa_project_form">
         <field name="name">RPA Projects</field>
         <field name="res_model">afx.project</field>
      </record>
      <record model="ir.action.act_window.view" id="act_rpa_project_form_view1">
         <field name="sequence" eval="10"/>
         <field name="view" ref="project_view_list"/>
         <field name="act_window" ref="act_rpa_project_form"/>
      </record>
      <record model="ir.action.act_window.view" id="act_rpa_project_form_view2">
         <field name="sequence" eval="20"/>
         <field name="view" ref="project_view_form"/>
         <field name="act_window" ref="act_rpa_project_form"/>
      </record>
      <!--/ End of Menu entry -->
      <!-- Tabs definitions -->
      <record model="ir.action.act_window.domain" id="act_rpa_project_domain_rpa">
         <field name="name">RPA</field>
         <field name="sequence" eval="10"/>
         <field name="domain"
               eval="[('team', '=', 'RPA')]"
               pyson="1"/>
         <field name="count" eval="False"/>
         <field name="act_window" ref="act_rpa_project_form"/>
      </record>
      <!--/ End of Tabs definitions -->
      <!--/ End of RPA Projects -->

So when a person click on RPA Projects nav button, it will open a list only projects that assigned to “RPA” team. As below:

But now, my boss want me to set default team’s name on the creation of a project tobe “RPA” without needed the user to choose from clicking the search button at project form as below:

My question, is there a way to di this from XML file? If there isn’t then I will try via class level.
Thanks in advance :slight_smile:

Bromo

You can use something like (taken from account_invoice module)

@staticmethod
def default_company():
    Company = Pool().get('company.company')
    if Transaction().context.get('company'):
        company = Company(Transaction().context['company'])
        return company.currency.id

For example you can get the user from the context and search for the team the user is in and return that team. So you have to do some pre-configuration to get this to work.

1 Like

I think you are having difficulties because you do not embrasse the Tryton design fully.
Instead of hard-coding the team name in the domain of the menu, you should instead perform the action in two steps. The menu opens the list of teams and click on the teams open the project of this domain (using a domain like [('team', '=', Eval('active_id', -1))]). This way thanks to the domain inversion, the team field will be filled automatically.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.