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

How to write a many2many field from a wizard to Project member (Team)field in Odoo

By
Odoo
on 4/2/16, 6:02 AM 681 views

I am Creating a wizard in Project More Button for allocating projects into Project For users Batch Allocation

My issue is when i click on the Allocate button from this project wizard selected users

should allocate the Corresponding projects as (like we select Add from Project Team)

This is my code ...Need a help...


-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

project_batch class (osv.Model)

_name = 'project.batch'

_columns = {

'Members_batch': fields.many2many ( 'res.users', 'project_userbatch_rel', 'project_id', 'uid', 'Project Members')

}


#EDIT -- Working Code

def batch_allocate(self, cr, uid, ids, context=None):        project_obj = self.pool.get('project.project')        if context.get('active_model') == 'project.project' and context.get('active_ids'):            for rec in self.browse(cr, uid, ids, context=context):                for user in rec.members_batch:                    # raise osv.except_osv(_('Warning'), _('Please Enter a valid Phone Number'+str(user.id)))                    project_obj.write(cr, uid, context.get('active_ids'), {'members': [(4, user.id)]})        return True

#Here I want to create the selected users from wizard should write to all the project as Team

xml

---------------------------------------------------------------------------------------------------------------------------------------

<Act_window id = "action_project_batch_confirm1"

Multi = "True"

key2 = "client_action_multi" name = "Batch Project Allocation"

res_model = "project.batch" src_model = "project.project"

view_mode = "form" target = "new" view_type = "form" />

<Record id = "project_batch_allocation_test" model = "ir.ui.view">

<Field name = "name"> project.project.confirm.form </ field>

<Field name = "model"> project.batch </ field>

<Field name = "arch" type = "xml">

<Form string = "Batch Project Allocation">

<Sheet>

<Group>

<Field name = "members_batch" widget = "many2many_tags" context = "{ 'default_groups_ref': [ 'base.group_user', 'base.group_partner_manager', 'project.group_project_user']}" />

</ Group>

</ Sheet>

<Footer>

<Button string = "Allocate" name = "batch_allocate" type = "object" default_focus = "1" class = "oe_highlight" />

gold

<Button string = "Cancel" class = "oe_link" special = "cancel" />

</ Footer>

</ Form>

</ Field>

</ Record>





------------------------------------------------------------------------------------------------------------------------------------------------


I am attaching the screen shots here

1)http://prntscr.com/an538n


2)http://prntscr.com/an53pk


3)http://prntscr.com/an53te

2

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

Sudhir Arya (SA)
On 4/2/16, 3:03 PM

Hi Deep,

What you are doing wrong is that, you are creating a new project instead of adding members in selected projects.

Try following code:

def batch_allocate(self, cr, uid, ids, context=None):
if context is None:
context = {}
project_obj = self.pool.get('project.project')
if context.get('active_model') == 'project.project' and context.get('active_ids'):
for rec in self.browse(cr, uid, ids, context=context):
for user in rec.your_user_field: # your wizard field in which you have selected the users as members
project_obj.write(cr, uid, context.get('active_ids'), {'members_batch': [(4, user.id)]})
return True

Reference: Many2Many write codes


Thanks sudhir. .....

Odoo
on 4/3/16, 12:41 AM

Did that work?

Sudhir Arya (SA)
on 4/3/16, 6:43 AM

No its not working... I checked now

Odoo
on 4/4/16, 12:17 AM

I edited code as per your answer ,but its not working...

Odoo
on 4/4/16, 12:27 AM

Make some changes..Now its working

Odoo
on 4/4/16, 1:04 AM

Glad to know that it's working.

Sudhir Arya (SA)
on 4/4/16, 1:09 AM

Thanks..

Odoo
on 4/4/16, 1:21 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

1 follower(s)

Stats

Asked: 4/2/16, 6:02 AM
Seen: 681 times
Last updated: 4/4/16, 1:06 AM