[FIX] crm_lead, project, project_issue, hr_recruitment: fixed stage_find method.

bzr revid: tde@openerp.com-20120531141930-svw4ax9mfwvnyv07
This commit is contained in:
Thibault Delavallée 2012-05-31 16:19:30 +02:00
parent eb6a0a4ac6
commit 214ba53104
4 changed files with 56 additions and 25 deletions

View File

@ -313,16 +313,29 @@ class crm_lead(base_stage, osv.osv):
"""
if isinstance(cases, (int, long)):
cases = self.browse(cr, uid, cases, context=context)
domain = list(domain)
# collect all section_ids
section_ids = []
types = ['both']
if section_id:
domain += ['|', ('section_ids', '=', section_id)]
domain.append(('case_default', '=', True))
section_ids.append(section_id)
for lead in cases:
domain += ['|', ('type', '=', lead.type), ('type', '=', 'both')]
lead_section_id = lead.section_id.id if lead.section_id else None
if lead_section_id:
domain += ['|', ('section_ids', '=', lead_section_id), ('case_default', '=', True)]
stage_ids = self.pool.get('crm.case.stage').search(cr, uid, domain, order=order, context=context)
if lead.section_id:
section_ids.append(lead.section_id.id)
if lead.type not in types:
types.append(lead.type)
# OR all section_ids and OR with case_default
search_domain = []
if section_ids:
search_domain += [('|')] * len(section_ids)
for section_id in section_ids:
search_domain.append(('section_ids', '=', section_id))
search_domain.append(('case_default', '=', True))
# AND with cases types
search_domain.append(('type', 'in', types))
# AND with the domain in parameter
search_domain += list(domain)
# perform search, return the first found
stage_ids = self.pool.get('crm.case.stage').search(cr, uid, search_domain, order=order, context=context)
if stage_ids:
return stage_ids[0]
return False

View File

@ -273,14 +273,22 @@ class hr_applicant(base_stage, osv.Model):
"""
if isinstance(cases, (int, long)):
cases = self.browse(cr, uid, cases, context=context)
domain = list(domain)
# collect all section_ids
department_ids = []
if section_id:
domain += ['|', ('department_id', '=', section_id), ('department_id', '=', False)]
department_ids.append(section_id)
for case in cases:
case_section_id = case.department_id.id if case.department_id else None
if case_section_id:
domain += ['|', ('department_id', '=', case_section_id), ('department_id', '=', False)]
stage_ids = self.pool.get('hr.recruitment.stage').search(cr, uid, domain, order=order, context=context)
if case.department_id:
department_ids.append(case.department_id.id)
# OR all section_ids and OR with case_default
search_domain = []
if department_ids:
search_domain += ['|', ('department_id', 'in', department_ids)]
search_domain.append(('department_id', '=', False))
# AND with the domain in parameter
search_domain += list(domain)
# perform search, return the first found
stage_ids = self.pool.get('hr.recruitment.stage').search(cr, uid, search_domain, order=order, context=context)
if stage_ids:
return stage_ids[0]
return False

View File

@ -858,7 +858,6 @@ class task(base_stage, osv.osv):
def stage_find(self, cr, uid, cases, section_id, domain=[], order='sequence', context=None):
""" Override of the base.stage method
Parameter of the stage search taken from the lead:
- type: stage type must be the same or 'both'
- section_id: if set, stages must belong to this section or
be a default stage; if not set, stages must be default
stages
@ -872,12 +871,13 @@ class task(base_stage, osv.osv):
for task in cases:
if task.project_id:
section_ids.append(task.project_id.id)
# OR all section_ids
# OR all section_ids and OR with case_default
search_domain = []
if section_ids:
search_domain += [('|')] * (len(section_ids) - 1)
search_domain += [('|')] * len(section_ids)
for section_id in section_ids:
search_domain += [('|'), ('project_ids', '=', section_id), ('case_default', '=', True)]
search_domain.append(('project_ids', '=', section_id))
search_domain.append(('case_default', '=', True))
# AND with the domain in parameter
search_domain += list(domain)
# perform search, return the first found

View File

@ -422,14 +422,24 @@ class project_issue(base_stage, osv.osv):
"""
if isinstance(cases, (int, long)):
cases = self.browse(cr, uid, cases, context=context)
domain = list(domain)
# collect all section_ids
section_ids = []
if section_id:
domain += ['|', ('project_ids', '=', section_id), ('case_default', '=', True)]
for issue in cases:
issue_project_id = issue.project_id.id if issue.project_id else None
if issue_project_id:
domain += ['|', ('project_ids', '=', issue_project_id), ('case_default', '=', True)]
stage_ids = self.pool.get('project.task.type').search(cr, uid, domain, order=order, context=context)
section_ids.append(section_id)
for task in cases:
if task.project_id:
section_ids.append(task.project_id.id)
# OR all section_ids and OR with case_default
search_domain = []
if section_ids:
search_domain += [('|')] * len(section_ids)
for section_id in section_ids:
search_domain.append(('project_ids', '=', section_id))
search_domain.append(('case_default', '=', True))
# AND with the domain in parameter
search_domain += list(domain)
# perform search, return the first found
stage_ids = self.pool.get('project.task.type').search(cr, uid, search_domain, order=order, context=context)
if stage_ids:
return stage_ids[0]
return False