-
-class crm_case_stage(osv.osv):
- """ Stage of case """
-
- _name = "crm.case.stage"
- _description = "Stage of case"
- _rec_name = 'name'
- _order = "sequence"
-
-
-
- def _get_type_value(self, cr, user, context):
- return [('lead','Lead'),('opportunity','Opportunity')]
-
-
- _columns = {
- 'name': fields.char('Stage Name', size=64, required=True, translate=True),
- 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of case stages."),
- 'probability': fields.float('Probability (%)', required=True, help="This percentage depicts the default/average probability of the Case for this stage to be a success"),
- 'on_change': fields.boolean('Change Probability Automatically', \
- help="Change Probability on next and previous stages."),
- 'requirements': fields.text('Requirements'),
- 'type': fields.selection(_get_type_value, 'Type'),
- }
-
-
- def _find_stage_type(self, cr, uid, context=None):
- """Finds type of stage according to object.
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param context: A standard dictionary for contextual values
- """
- type = context and context.get('type', '') or ''
- return type
-
- _defaults = {
- 'sequence': lambda *args: 1,
- 'probability': lambda *args: 0.0,
- 'type': _find_stage_type,
- }
-
-crm_case_stage()
-
-
-class crm_case_section(osv.osv):
- """Sales Team"""
-
- _name = "crm.case.section"
- _description = "Sales Teams"
- _order = "complete_name"
-
- def get_full_name(self, cr, uid, ids, field_name, arg, context=None):
- return dict(self.name_get(cr, uid, ids, context=context))
-
- _columns = {
- 'name': fields.char('Sales Team', size=64, required=True, translate=True),
- 'complete_name': fields.function(get_full_name, method=True, type='char', size=256, readonly=True, store=True),
- 'code': fields.char('Code', size=8),
- 'active': fields.boolean('Active', help="If the active field is set to "\
- "true, it will allow you to hide the sales team without removing it."),
- 'allow_unlink': fields.boolean('Allow Delete', help="Allows to delete non draft cases"),
- 'change_responsible': fields.boolean('Change Responsible', help="Thick this box if you want that on escalation, the responsible of this sale team automatically becomes responsible of the lead/opportunity escaladed"),
- 'user_id': fields.many2one('res.users', 'Responsible User'),
- 'member_ids':fields.many2many('res.users', 'sale_member_rel', 'section_id', 'member_id', 'Team Members'),
- 'reply_to': fields.char('Reply-To', size=64, help="The email address put in the 'Reply-To' of all emails sent by OpenERP about cases in this sales team"),
- 'parent_id': fields.many2one('crm.case.section', 'Parent Team'),
- 'child_ids': fields.one2many('crm.case.section', 'parent_id', 'Child Teams'),
- 'resource_calendar_id': fields.many2one('resource.calendar', "Working Time"),
- 'note': fields.text('Description'),
- 'working_hours': fields.float('Working Hours', digits=(16,2 )),
- 'stage_ids': fields.many2many('crm.case.stage', 'section_stage_rel', 'section_id', 'stage_id', 'Stages'),
- }
-
- _defaults = {
- 'active': lambda *a: 1,
- 'allow_unlink': lambda *a: 1,
- }
-
- _sql_constraints = [
- ('code_uniq', 'unique (code)', 'The code of the sales team must be unique !')
- ]
-
- def _check_recursion(self, cr, uid, ids, context=None):
-
- """
- Checks for recursion level for sales team
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param ids: List of Sales team ids
- """
- level = 100
-
- while len(ids):
- cr.execute('select distinct parent_id from crm_case_section where id IN %s', (tuple(ids),))
- ids = filter(None, map(lambda x: x[0], cr.fetchall()))
- if not level:
- return False
- level -= 1
-
- return True
-
- _constraints = [
- (_check_recursion, 'Error ! You cannot create recursive Sales team.', ['parent_id'])
- ]
-
- def name_get(self, cr, uid, ids, context=None):
- """Overrides orm name_get method
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param ids: List of sales team ids
- """
- if context is None:
- context = {}
-
- res = []
- if not ids:
- return res
- reads = self.read(cr, uid, ids, ['name', 'parent_id'], context)
-
- for record in reads:
- name = record['name']
- if record['parent_id']:
- name = record['parent_id'][1] + ' / ' + name
- res.append((record['id'], name))
- return res
-
-crm_case_section()
-
-
-class crm_case_categ(osv.osv):
- """ Category of Case """
- _name = "crm.case.categ"
- _description = "Category of Case"
- _columns = {
- 'name': fields.char('Name', size=64, required=True, translate=True),
- 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
- 'object_id': fields.many2one('ir.model', 'Object Name'),
- }
-
- def _find_object_id(self, cr, uid, context=None):
- """Finds id for case object
- @param self: The object pointer
- @param cr: the current row, from the database cursor,
- @param uid: the current user’s ID for security checks,
- @param context: A standard dictionary for contextual values
- """
-
- object_id = context and context.get('object_id', False) or False
- ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', object_id)])
- return ids and ids[0]
-
- _defaults = {
- 'object_id' : _find_object_id
-
- }
-crm_case_categ()
-
-
-class crm_case_stage(osv.osv):
- _inherit = "crm.case.stage"
- _columns = {
- 'section_ids':fields.many2many('crm.case.section', 'section_stage_rel', 'stage_id', 'section_id', 'Sections'),
- }
-
-crm_case_stage()
-
-
-class crm_case_resource_type(osv.osv):
- """ Resource Type of case """
- _name = "crm.case.resource.type"
- _description = "Campaign"
- _rec_name = "name"
- _columns = {
- 'name': fields.char('Campaign Name', size=64, required=True, translate=True),
- 'section_id': fields.many2one('crm.case.section', 'Sales Team'),
- }
-crm_case_resource_type()
-
-