Skip to Content
Menu
This question has been flagged
4 Replies
1616 Views

I created an object for show quants of each partner(locate of products that are in the user's hands)
and I set a view  for show this.(a form that have one field "partner_id", and have a action button for show quants with name "emp_open_quants")

class PRQuants(models.Model):
    _name = "product.requisition.emp.quants"
    _description = "Product Requisition Employee's Quants"
    _inherit = ['mail.thread']
    _order = 'partner_id'

    partner_id = fields.Many2one('res.partner', 'Partner')

now, I want when in partner form in my module, click on button"emp_open_quants", I see only this partner's quants.so I do this: (but does'nt work)

    <record model="ir.actions.act_window" id="emp_open_quants">
        <field name="name">Quants</field>
        <field name="context">{'search_default_owner_id': partner_id}</field>
        <field name="res_model">stock.quant</field>
    </record>
    <record id="view_pr_emp_quants_form" model="ir.ui.view">
        <field name="name">pr.emp.quants.form</field>
        <field name="model">product.requisition.emp.quants</field>
        <field name="priority">10</field>
        <field name="arch" type="xml">
            <form string="Employee's Assets(Quants)">
                <sheet>
                <div class="oe_button_box" name="button_box">
                    <button name="%(emp_open_quants)d" icon="fa-arrows" class="oe_stat_button" string="Locatee" type="action" />
                </div>
                <group name="main_group">
                    <group>
                        <field name="partner_id"/>
                    </group>
                </group>
                </sheet>
            </form>
        </field>
    </record>

in below context , I have error that "partner_id" is not defined:

<field name="context">{'search_default_owner_id': partner_id}</field>

how can do this?(when I set a partner id manually, this code work well!!)
{'search_default_owner_id': 23}

Avatar
Discard
Best Answer

hmm there are very few options to pass context from type="action" button. either you can pass a static value or active_id (but in your case active_id is id of product.requisition.emp.quants not partner_id)
like

type="action" context="{'search_default_team_id': active_id}" ...
type="action" context="{'search_default_team_id': 'test'}" .....

so, in this case, define type="object" button and return action from py    

type="object" name="open_stock_qaunt"  ...

 def open_stock_qaunt(self):     
     context = dict(self.env.context)
     context.update({      search_default_partner_id: self.partner_id })
     return {

         .......
        'context': context
         .......

    }

Avatar
Discard
Best Answer

Make sure that the owner_id filter is defined in your related model search view and I think the context should be like,

<field name="context">{'search_default_partner_id': owner_id}</field>
Avatar
Discard
Author

hi, thanks for your answer.

can you say how I should define owner_id filter in serach view?

thanks