Skip to Content
Menu
This question has been flagged
3970 Views

Hi,

I added a One2many field on res.partner, that appears on child_ids popup. This field is updated with a wizard action, but there is a refresh issue.

My code :

class Param(models.Model):
_name = 'mymodule.param'
name = fields.Char('Name', required=True)
partner_id = fields.Many2one('res.partner', ondelete='cascade', string='Contact'

class ResPartner(models.Model):
_inherit = 'res.partner'
option = fields.Selection([
('option1', 'Option 1'),
('option2', 'Option 2'),
('option3', 'Option 3),
])
param_ids = fields.One2many('mymodule.param', 'partner_id', string='Params')

    @api.multi
def open_wizard(self):
form_id = self.env.ref('mymodule.wizard', False)
return {
'type': 'ir.actions.act_window',
        'target': 'new',
        'view_mode': 'form',
        'view_type': 'form',
        'views': [(form_id.id, 'form)],
        'view_id': form_id.id,
        'res_model': 'res.partner',
        'res_id': self.id,
        'name': _('Add param'),
    }

    @api.multi
    def btn_apply(self):
        self.comment = sef.option
        self.param_ids = [(0, 0, {'name': self.option})]

 And XML:

<record id="wizard" model="ir.ui.view">
    <field name="name">wizard</field>
    <field name="model">res.partner</field>
    <field name="arch" type="xml">
        <form>
            <sheet>
                <group>
                    <field name="option">
                </group>
            </sheet>
            <footer>
                <button name="btn_apply" type="object" string="Confirm" clas="oe_highlight"/>
                or
                <button special="cancel" string="Cancel" class="oe_link"/>
            </footer>
        </form>
    </field>
</record>

<record id="view_partner_form_inherit" model="ir.ui.view">
    <field name="name">base.partner.form.mymodule.inherit</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <xpath expr="//notebook//form/sheet" position="before">
            <header>
                <button name="open_wizard" type="object" string="Open wizard" class="oe_highlight"/>
            </header>
        </xpath>
        <xpath expr="//notebook//form//group/group[2]" position="after">
            <group attrs="{'invisible': [('type', '!=', 'contact')]}">
                <field name="param_ids"/>
            <group>
        </xpath>
    </field>
</record>


After the action, the "comment" field is refreshed, but not the "param_ids" field.

I don't want to reloading all page after the action so I added :

    @api.multi
    def btn_apply(self):
        self.comment = self.option
        self.param_ids = [(0, 0, {'name': self.option})]
return {
            'type': 'ir.actions.client',
            'tag': 'refresh',
        }

And Javascript:

odoo.define('mymodule.refresh', function(require) {
    "use_strict";

    var core = require('web.core')

    function Refresh(parent, action) {
        parent.inner_widget.active_view.controller.reload();
        return {'type': 'ir.actions.act_window_close'}
    }
    core.action_registry.add('refresh', Refresh);
})

And I don't need to reload the page, but I need to close and reopen the popup to refresh param_ids field.

Any idea about that ?

Avatar
Discard
Related Posts Replies Views Activity
2
Dec 24
4264
1
Oct 23
6952
3
Sep 22
5765
1
Aug 22
3491
3
Mar 21
1165