Skip to Content
Menu
This question has been flagged
1 Reply
7775 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

Avatar
Discard
Best Answer

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


Avatar
Discard
Author

Thanks sudhir. .....

Author

No its not working... I checked now

Author

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

Author

Make some changes..Now its working

Glad to know that it's working.

Author

Thanks..