Skip to Content
Menu
This question has been flagged
2 Replies
6804 Views

Hi !

 
I have my button that is available from tree view and when it's clicked it opens the form view of the label in edit mode. I would like to use the active_id parameter from my tree view to place it in a many2many field of my form view.
 
I tried things in my python function that opens the form view but can't manage to achieve my purpose.
 
Thank you !

Avatar
Discard
Author

I would like the record not to be saved this way, but just replace fields like if the user added them manually and was about to save it.

Author Best Answer

Here is my code :

     

    <!-- ================================ -->

    <!-- Create a matching from a product -->

    <!-- ================================ -->

    

    <record model="ir.values" id="product.product_link_to_label">

        <field name="name">Create Matching</field>

        <field name="key2">client_action_multi</field>

        <field name="type">object</field>

        <field name="value" eval="'ir.actions.act_window,' + str(ref('action_create_matching_tree'))" />

        <field name="key">action</field>

        <field name="model">product.product</field>

    </record>

    

    <record model="ir.ui.view" id="label.tree_new_match">

      <field name="name">Create Matching</field>

      <field name="model">label.label</field>

      <field name="view_type">form</field>

      <field name="view_mode">tree</field>

      <field name="arch" type="xml">

        <tree colors="green:len(products)==0;red:len(products)!=0" default_order='len_products, real_id' create='false' delete='false'>

          <button string="New" type="object" name="new_match"/> <==== THIS Button where i got trouble to pass values trough context

          <field name="nom" string="Name"/>

          <field name="real_id"/>

          <field name="type"/>

          <field name="products"/>

          <field name="len_products" invisible="context.get('len_products')!=1000"/>

        </tree>

      </field>

    </record>     

    

    <record id="action_create_matching_tree" model="ir.actions.act_window">

        <field name="name">Create Matching</field>

        <field name="res_model">label.label</field>

        <field eval="0" name="sequence"/>

        <field name="view_mode">tree</field>

        <field name="view_id" ref="label.tree_new_match" />

    </record>

 

Python fun in my label model:
 

def new_match(self):

self = self.with_context(products=self._context.get('active_ids'))

return {

            'name':_("Save a new matching"),

            'view_mode': 'form',

            'view_type': 'form',

            'view_id': False,

            'res_model': 'label.label',

            'res_id': self.id,

            'type': 'ir.actions.act_window',

            'target': 'current',

            'domain': '[]',

'flags': {'initial_mode': 'edit'},

            }

Avatar
Discard
Related Posts Replies Views Activity
3
May 20
6256
3
Apr 24
423
0
Aug 23
766
1
Dec 22
3519
4
Dec 23
76360