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

modify record values of other class while saving a record

By
Praveen Upadhyaya
on 8/16/14, 8:01 AM 1,206 views

Hi, Everybody
I have created two classes project and block
In module project i have a field block which is related as many2many with a class block, we can add records of block class to the project.
Class block have a field project many2one to the project class
I want when ever a record of block is create it should automatically add to the related project in that project from

I tried with this but does not work

class real_estate_project(osv.osv):
    _name = 'real.estate.project'

    _columns = {
        'name':fields.char("Project :"),
        'block_id':fields.many2many('blocks.sector', "project_blocks_ref", "project_id", "block_id", string="Blocks"),
    }    
real_estate_project()

class blocks_sector(osv.osv):
    _name="blocks.sector"

    def create(self,cr,user,vals,context=None):
        res = {}
        proj_obj = self.pool.get('real.estate.project')
        proj_ids = proj_obj.search(cr,user, [('id','=',vals['re_project'])])
        values = {'name': vals['name'], 're_no_tower': vals['re_no_tower'], 're_no_flats': vals['re_no_flats'] }
        proj_obj.write(cr, user, proj_ids, {'block_id':[(0,0, vals)]})
        res = super(blocks_sector,self).create(cr, user, vals)
        return res

    _columns = {
            'block_id':fields.many2many('real.estate.project', "project_block_ref", "block_id", "project_id", string="project"),
            're_project':fields.many2one('real.estate.project', "Project:"),
            'name':fields.char("Block:"),
               }

   

 

using the Create and Write method to modify record of other class or related field add the data.

Praveen Upadhyaya
on 8/17/14, 3:05 AM
0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 8/18/14, 2:09 AM

https://doc.odoo.com/v6.0/developer/2_5_Objects_Fields_Methods/methods.html/#osv.osv.osv.write

To Create or Write Many2Many Field:  [(6, 0, [ids])]

Example,

    def create(self,cr,user,vals,context=None):
        res = {}
        proj_obj = self.pool.get('real.estate.project')
        proj_ids = proj_obj.search(cr,user, [('id','=',vals['re_project'])])
        values = {'name': vals['name'], 're_no_tower': vals['re_no_tower'], 're_no_flats': vals['re_no_flats'], 'block_id':[(6,0,proj_ids)] }
        proj_obj.write(cr, user, proj_ids, values)
        res = super(blocks_sector,self).create(cr, user, vals)
        return res

 

 

 

0
Praveen Upadhyaya
On 8/18/14, 12:23 AM

Thank you for your reply I am getting error while trying to modify or write (cr, user, proj_ids, {'block_id':[(0,0, vals)]}) RuntimeError: maximum recursion depth exceeded But if I change the field to some other field like write(cr, user, proj_ids, {'city:"Mathura"}) It works out and change the name of city in the project form But when I try to modify the ids of many2many field it gives error as said above

I do have a another field tower_id many2many to the class tower in the block form 

0
klacus
On 8/17/14, 5:27 AM

The create methode is runing?

Do you have any error message, or just not runing?

If you have any error pls. post it, if you do not have just try to change the code layout like this:

_columns = {

}

def create(self,...

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

3 follower(s)

Stats

Asked: 8/16/14, 8:01 AM
Seen: 1206 times
Last updated: 3/16/15, 8:10 AM