The function "Write" after new o2m record don't update form and don't be saved

Asked by David Diz

class A(osv.osv):
    _name="A"

    def write(self, cr, uid, ids, vals, context=None):
        eval = vals.get('b_ids', 0)
        for item in eval:
            vals['state_a'] = eval[i][2]['state_b']
        return super(A, self).write(cr, uid, ids, vals, context)

    _columns={
        "name": fields.char('Name', size=25 ),
        "b_ids": fields.one2many('B', 'a_id', 'Evals' ),
        "state_a": fields.selection([("O","Open"), ("C","Close")], 'State'),
        }
A()

class B(osv.osv):
    _name='B'

    _columns={
        "name": fields.char('Name', size=25 ),
        "a_id": fields.many2one('A'),
        "state_b": fields.selection([("O","Open"), ("C","Close")], 'State'),
        }

    _defaults = {
        'a_id': lambda self, cr, uid, context: context.get('a', False),
    }

B()

-In the form of the A object i have a o2m grid with its B objects.
-Now i create a new B object from the grid.
-The write function of the A object is called and the new value of "state" is stored in the database but not displayed in the form.
-If i press the cancel button of the form the new value of the "state" field is displayed but if i press the save button the new value is deleted from the database and not displayed in the saved form.

This behavior does not happen in the GTK client.

Question information

Language:
English Edit question
Status:
Answered
For:
Odoo Web Client Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
DBR (OpenERP) (dbr-openerp) said :
#1

class A(osv.osv):
    _name="A"

    def write(self, cr, uid, ids, vals, context=None):
        eval = vals.get('b_ids', 0)
        for item in eval:
            vals['state_a'] = eval[i][2]['state_b']
        return super(A, self).write(cr, uid, ids, vals, context)

    _columns={
        "name": fields.char('Name', size=25 ),
        "b_ids": fields.one2many('B', 'a_id', 'Evals' ),
        "state_a": fields.selection([("O","Open"), ("C","Close")], 'State'),
        }
A()

class B(osv.osv):
    _name='B'

    _columns={
        "name": fields.char('Name', size=25 ),
        "a_id": fields.many2one('A'),
        "state_b": fields.selection([("O","Open"), ("C","Close")], 'State'),
        }

    _defaults = {
        'a_id': lambda self, cr, uid, context: context.get('a', False),
    }

B()

-In the form of the A object i have a o2m grid with its B objects.
-Now i create a new B object from the grid.
-The write function of the A object is called and the new value of "state" is stored in the database but not displayed in the form.
-If i press the cancel button of the form the new value of the "state" field is displayed but if i press the save button the new value is deleted from the database and not displayed in the saved form.

This behavior does not happen in the GTK client.

Revision history for this message
DBR (OpenERP) (dbr-openerp) said :
#2

Hello David Diz,

Please consider the following help link before developing module.

   http://doc.openerp.com/developer/index.html#book-develop-link

I have made some following code improvement:

class a_a(osv.osv):
    _name="a.a"

    def write(self, cr, uid, ids, vals, context=None):
        eval = vals.get('b_ids', 0)
        for item in eval:
            vals['state_a'] = eval[i][2]['state_b']
        return super(a, self).write(cr, uid, ids, vals, context)

    _columns={
        "name": fields.char('Name', size=25 ),
        "b_ids": fields.one2many('b.b', 'a_id', 'Evals' ),
        "state_a": fields.selection([("openerp","Open"), ("C","Close")], 'State'),
        }
a_a()

class b_b(osv.osv):
    _name='b.b'

    _columns={
        "name": fields.char('Name', size=25 ),
        "a_id": fields.many2one('a.a','A_id'),
        "state_b": fields.selection([("O","Open"), ("C","Close")], 'State'),
        }

    _defaults = {
        'a_id': lambda self, cr, uid, context: context.get('a', False),
    }
b_b()

Thanks.

Can you help with this problem?

Provide an answer of your own, or ask David Diz for more information if necessary.

To post a message you must log in.