4
votes

I have a wizard in which there is a one2many field. I made a button in each line of the one2many which calls another wizard made by me. This wizard is for modifying some values of the selected line.

My purpose is to return the first wizard, with the new changes, when you click on the Apply button of my wizard.

Example:

The first wizard has a one2many field with three records:

  • Product A | 1 ud | Source location X | Dest location Y | Lot A1
  • Product B | 2 ud | Source location X | Dest location Y | Lot B1
  • Product C | 3 ud | Source location X | Dest location Y | Lot C1

Now, I click on the first line button I made (each line has one), and my wizard is opened. Here I can modify the lot of the first line (the one with the Product A). Imagine I set Lot A0 and click on Apply.

I should return to the parent wizard, and see the same data except for the changes made. So the result will be:

  • Product A | 1 ud | Source location X | Dest location Y | Lot A0
  • Product B | 2 ud | Source location X | Dest location Y | Lot B1
  • Product C | 3 ud | Source location X | Dest location Y | Lot C1

Does anyone know how to achieve this? How could I preserve the first wizard data?

1
How do you open the "line" wizard with the button: by returning an action dictionary? If so, just return the parent wizard as action dictionary (target "new") by clicking "Apply", what should be a button type "object" like the other button.CZoellner
Is there any feedback on given answer ?Bhavesh Odedra

1 Answers

2
votes

First you need to browse current record of Wizard and it's line. Afterward write value as you want.

Return that current id with wizard object.

Try with following trick:

#apply button method logic
def apply_data(self, cr, uid, ids, context=None):
    if not context:
        context = {}

    ctx = context.copy()
    for wizard in self.browse(cr, uid, ids[0], context=context):
        for line in wizard.one2many_field:
            line.write({
                'field_name': field_value
            })

    dummy, view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'module_name', 'wizard_form_view_name')
    return {
        'name':_("Name of your Wizard"),
        'view_mode': 'form',
        'view_id': view_id,
        'view_type': 'form',
        'res_id': ids and ids[0] or False,
        'res_model': 'wizard.object.name',
        'type': 'ir.actions.act_window',
        'nodestroy': True,
        'target': 'new',
        'context': ctx
    }

NOTE:

You can also update context value as well.

Apply button type must be object to execute method logic.