Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Get and write: where is the problem?

By
Uillino
on 9/10/15, 6:36 AM 461 views

I have two models:

class 1st_model(models.Model):  
 
scode = fields.Char('Code', size=3)

field_to_update = fields.Char('Updated')

and

class 2nd_model(models.Model):

_inherits = {'1st_model': 'id_1st_model'}
id_1st_model = fields.Many2one('1st_model', 'Code', widget="many2one_list")

name = fields.Char(string='Name', size=100, required=True)  
 
def update_field_to_update(self, cr, uid, ids, context=None):
context = context or {}
assignment_obj = self.pool.get('1st_model')
for record in self.browse(cr, uid, ids, context=context):
if record.id_1st_model:
assignment_ids = assignment_obj.search(cr, uid, [('id_1st_model', '=', record.id_1st_model)], context=context)
if assignment_ids:
assignment_obj.write(cr, uid, assignment_ids, {'field_to_update': 'ok'}, context=context)
return True

When I create a new entry in 2nd_model, I would like to wite 'ok' in 'field_to_update' of 1st_model. But this code doesn't work.

Any idea?

Who is calling update_field_to_update method?

Axel Mendoza
on 9/10/15, 10:27 AM

Thank you for your reply. Where I Have to call this method? In the view? And how I can do?

Uillino
on 9/10/15, 10:35 AM

in the write method. This will do your required update

Tarek Mohamed Ibrahim
on 9/10/15, 11:34 AM

Sorry, but I'm not good enough with Python. Could you make me an example, please?

Uillino
on 9/11/15, 4:17 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 9/10/15, 6:36 AM
Seen: 461 times
Last updated: 9/11/15, 4:17 AM