~eduardo-bayardo-bias/openobject-addons/bias_trunk_v8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2012 OpenERP SA (<http://openerp.com>)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import fields, osv
from openerp.tools.translate import _


class crm_zone(osv.Model):
    _name = "crm.zone"
    _description = "CRM Zone"
    _order = 'name'
    _columns = {
        'name': fields.char('Name', size=1),
        'description': fields.char('Description', size=32),
    }

class crm_brand(osv.Model):
    _name = "crm.brand"
    _description = "CRM Brand"
    _order = 'name'
    _columns = {
        'name': fields.char('Name', size=32),
    }

class crm_category(osv.Model):
    _name = "crm.category"
    _description = "CRM category"
    _order = 'name'
    _columns = {
        'name': fields.char('Name', size=32),
    }

class crm_lead(osv.Model):
    _inherit = 'crm.lead'

    def _get_default_group_id(self, cr, uid, context=None):
        return self.get_obj(cr, uid, 'res.groups', 'crm_extra.group_assign_user')

    _columns = {
        'number': fields.char('Number', size=16),
        'number_view': fields.char('Number', size=16),
        'sequence': fields.char('Number', size=16),
        'date_ing': fields.date('Date'),
        'assigned_id': fields.many2one('res.users', 'Assigned To'),
        'zone_id': fields.many2one('crm.zone', 'Zone'),
        'project_type': fields.selection([('p','Proyecto'),('l','Licitacion'),('i','Invitacion'),('r','RFP'),('c','Concurso')],'Comertial Type'),
        'type_cable': fields.boolean('CABLEADO'),
        'type_equipment': fields.boolean('EQUIPO ACTIVO'),
        'type_video': fields.boolean('VIDEO CONFERENCIA'),
        'type_scurity': fields.boolean('SEGURIDAD FISICA'),
        'type_data': fields.boolean('DATA CENTER'),


        'date_publication': fields.date('Publication'),
        'date_visit': fields.date('Site Visit'),
        'date_meeting': fields.date('Clarification Meeting'),
        'date_delivery': fields.date('Technical Delivery'),
        'date_decision': fields.date('Decision Date'),
        'date_presentation': fields.date('Presentation Date'),
        'asigner_group_id': fields.many2one('res.groups', 'Assigner Group'),
        'project_description': fields.text('Project Description'),

        'copper': fields.boolean('Copper'),
        'optic_fiber': fields.boolean('Optic Fiber'),
        'coper_brand': fields.many2one('crm.brand', 'Brand'),
        'optic_brand': fields.many2one('crm.brand', 'Brand'),
        'cable_category': fields.many2one('crm.category', 'Category'),
        'copper_mo': fields.char('M.O.', size=64),
        'optic_mo': fields.char('M.O.', size=64),
        'project_notes': fields.text('Notes'),

        'switches': fields.boolean('Switches'),
        'routings': fields.boolean('Routings'),
        'switches_brand': fields.many2one('crm.brand', 'Brand'),
        'routings_brand': fields.many2one('crm.brand', 'Brand'),
        'switches_mo': fields.char('M.O.', size=64),
        'routings_mo': fields.char('M.O.', size=64),

        'codec': fields.boolean('Codec'),
        'mcu': fields.boolean('MCU'),
        'software': fields.boolean('Software'),
        'codec_brand': fields.many2one('crm.brand', 'Brand'),
        'mcu_brand': fields.many2one('crm.brand', 'Brand'),
        'software_brand': fields.many2one('crm.brand', 'Brand'),
        'codec_mo': fields.char('M.O.', size=64),
        'mcu_mo': fields.char('M.O.', size=64),
        'software_mo': fields.char('M.O.', size=64),

        'access_control': fields.boolean('Access Control'),
        'cctv': fields.boolean('CCTV'),
        'access_brand': fields.many2one('crm.brand', 'Brand'),
        'cctv_brand': fields.many2one('crm.brand', 'Brand'),
        'access_mo': fields.char('M.O.', size=64),
        'cctv_mo': fields.char('M.O.', size=64),

        'ups': fields.boolean('UPS'),
        'monitoring': fields.boolean('Monitoring'),
        'camera': fields.boolean('Camera'),
        'fire_detector': fields.boolean('Fire Detector'),
        'emergency_power': fields.boolean('Emergency Power'),
        'ups_brand': fields.many2one('crm.brand', 'Brand'),
        'monitoring_brand': fields.many2one('crm.brand', 'Brand'),
        'camera_brand': fields.many2one('crm.brand', 'Brand'),
        'fire_brand': fields.many2one('crm.brand', 'Brand'),
        'emergency_brand': fields.many2one('crm.brand', 'Brand'),
        'ups_mo': fields.char('M.O.', size=64),
        'monitoring_mo': fields.char('M.O.', size=64),
        'camera_mo': fields.char('M.O.', size=64),
        'fire_mo': fields.char('M.O.', size=64),
        'emergency_mo': fields.char('M.O.', size=64),
        'civil_works': fields.text('Civil Works Notes'),

        'information_gathering': fields.selection([('y','Yes'),('n','No'),('m','Maybe')],'Information Gathering'),
        'date_gathering': fields.datetime('Date'),
        'gatering_contact': fields.char('Contact', size=64),
        'gatering_address': fields.char('Address', size=128),
        'gatering_phone': fields.char('Phone', size=16),
        'gatering_email': fields.char('Email', size=16),
        'special_request': fields.text('Special Request'),
        'request_notes': fields.text('Notes'),

        'request_document': fields.binary('Request Document'),
    }
    _defaults = {
        'date_ing': fields.date.context_today,
        'asigner_group_id': lambda s, cr, uid, c: s._get_default_group_id(cr, uid, c),
    }
    
    def get_obj(self, cr, uid, model, external_id):
        # Return id from Model and External ID
        obj_id = False
        try:
            external_id = external_id.split('.')[1]
        except:
            osv.except_osv(_('Warning!'), _('Such External ID does not Exist!'))
        model_data_pool = self.pool.get('ir.model.data')
        ir_model_data_id = model_data_pool.search(cr, uid, [('model', '=', model), ('name', '=', external_id)])
        if ir_model_data_id:
            ir_model_data_obj = model_data_pool.browse(cr, uid, ir_model_data_id)[0]
            obj = self.pool.get(model).browse(cr, uid, ir_model_data_obj.res_id)
            obj_id = obj and obj.id
        else:
            osv.except_osv(_('Warning!'), _('Such External ID does not Exist!'))
        return obj_id

    def on_change_user(self, cr, uid, ids, user_id, number=False, project_type='', context=None):
        res = super(crm_lead, self).on_change_user(cr, uid, ids, user_id, context=context)        
        if user_id and project_type:
            employee = (self.pool.get('res.users').browse(cr, uid, user_id).ref or '')[:2].rjust(2,'0')
            if number:
                return {'value': {'sequence': employee + number, 'number_view': employee + number}}
            number = self.pool.get('ir.sequence').get(cr, uid, 'oportunity.sequence', context)
            res['value'].update({'number':number, 'sequence': employee + number, 'number_view': employee + number})
        else:
            res['value'].update({'sequence':'', 'number_view':''})
        return res

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: