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

« back to all changes in this revision

Viewing changes to crm_protocol/crm.py

  • Committer: Eduardo Bayardo
  • Date: 2016-10-06 21:28:13 UTC
  • Revision ID: eduardo.bayardo@bias.com.mx-20161006212813-z4utlenj8qtt3dlg
update crm protocol module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2012 OpenERP SA (<http://openerp.com>)
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU General Public License as published by
 
9
#    the Free Software Foundation, either version 3 of the License, or
 
10
#    (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from openerp.osv import fields, osv
 
23
from openerp.tools.translate import _
 
24
import openerp.addons.decimal_precision as dp
 
25
 
 
26
class crm_lead(osv.Model):
 
27
    _inherit = 'crm.lead'
 
28
 
 
29
    def _is_asigned(self, cr, uid, ids, name, args, context=None):
 
30
        result = {}
 
31
        for rec in self.browse(cr, uid, ids, context=context):
 
32
            result[rec.id] = not rec.final_close and rec.asigned_by and (rec.asigned_by.id == uid)
 
33
        return result
 
34
 
 
35
 
 
36
    _columns = {
 
37
        ################# SALES #################
 
38
        'partner_invoice': fields.char('Invoice Address', size=200),
 
39
        'partner_shipping': fields.char('Delivery Address', size=200),
 
40
        'delivery_time': fields.char('Delivery time', size=150),
 
41
        'operating_conditions': fields.char('Operating Conditions', size=200),
 
42
        'main_contact': fields.char('Main Contact', size=150),
 
43
        'technical_contact': fields.char('Technical Contact', size=150),
 
44
        'invoice_contact': fields.char('Invoice Contact', size=150),
 
45
        'payment_contact': fields.char('Payment Contact', size=150),
 
46
        'purchase_contact': fields.char('Purchase Contact', size=150),
 
47
        'leadime': fields.char('Leadtime', size=150),
 
48
        'date_start': fields.date('Date Start'),
 
49
        'date_stop': fields.date('Date Stop'),
 
50
        'conditions': fields.char('Terms and conditions', size=200),
 
51
        'payment_terms': fields.integer('Payment Terms'),
 
52
        'advance': fields.char('Advance', size=150),
 
53
        'travel_expenses': fields.float('Travel Expenses', digits_compute= dp.get_precision('Account') ),
 
54
        'm_o': fields.float('M.O.', digits_compute= dp.get_precision('Account')),
 
55
        'other': fields.char('Other', size=200),
 
56
        'po_contract_1': fields.binary('Purchase Order / Decision / Contract'),
 
57
        'po_contract_2': fields.binary('Purchase Order / Decision / Contract'),
 
58
        'quotation': fields.binary('Quotation'),
 
59
        'authorization_evidence': fields.char('Authorization Evidence', size=100),
 
60
        'evidence': fields.text('Evidence'),
 
61
        'sale_observations': fields.text('Sale Observations'),
 
62
        'sale_state': fields.selection([('authorized','Sale Autorized'), ('rejected','Sale Rejected')], 'Sale State', track_visibility='onchange'),
 
63
        ################# FINANCIAL #################
 
64
        'purchase_order': fields.boolean('Purchase Order'),
 
65
        'billing': fields.boolean('Billing'),
 
66
        'billing_support': fields.boolean('Billing Support'),
 
67
        'credit_terms': fields.boolean('Credit Terms'),
 
68
        'commertial_terms': fields.boolean('Commertial Terms'),
 
69
        'financial_notes': fields.text('Financial Notes'),
 
70
        'nt_purchase_order': fields.text('Purchase Order'),
 
71
        'nt_billing': fields.text('Billing'),
 
72
        'nt_billing_support': fields.text('Billing Support'),
 
73
        'nt_credit_terms': fields.text('Credit Terms'),
 
74
        'nt_commertial_terms': fields.text('Commertial Terms'),
 
75
        'financial_state': fields.selection([('authorized','Financial Autorized'), ('rejected','Financial Rejected')], 'Financial State', track_visibility='onchange'),
 
76
        ################# ENGINEERING #################
 
77
        'design_by': fields.related('assigned_id', type='many2one', relation='res.users', string='Design by', readonly=True),
 
78
        'validated_by': fields.many2one('res.users', 'Validated by'),
 
79
        'asigned_by': fields.many2one('res.users', 'Asigned by'),
 
80
        'validated_notes': fields.text('Validation Notes'),
 
81
        'gang_allocation': fields.char('Gang Allocation', size=300),
 
82
        'mo_allocation': fields.char('Amount/Gang/MO Allocation ', size=200),
 
83
        'gang_travel_expenses': fields.float('Gang Travel Expenses', digits_compute= dp.get_precision('Account') ),
 
84
        'ap_travel_expenses': fields.float('AP Travel Expenses', digits_compute= dp.get_precision('Account') ),
 
85
        'vobo': fields.boolean('Vo.Bo.'),
 
86
        'nt_change_control': fields.text('Change Control Notes'),
 
87
        'change_control': fields.binary('Change Control'),
 
88
        'material_chart': fields.binary('Material Chart'),
 
89
        'material_return': fields.binary('Material Return'),
 
90
        'technical_memory': fields.binary('Technical Memory'),
 
91
        'delivery_report': fields.binary('Delivery Report'),
 
92
        'blueprints': fields.binary('Blueprints'),
 
93
        'photos': fields.binary('Photos'),
 
94
        'diagrams': fields.binary('Diagrams'),
 
95
        'fluke_test': fields.binary('Fluke Test'),
 
96
        'certifications': fields.binary('Certifications'),
 
97
        'operative_close': fields.date('Opertive Close'),
 
98
        'operative_documentry': fields.date('Operative Documentary'),
 
99
        'final_close': fields.date('Final Close'),
 
100
        'is_asigned': fields.function(_is_asigned, type='boolean', string="Is Assigned"),
 
101
    }   
 
102
 
 
103
    def get_obj(self, cr, uid, model, external_id):
 
104
        # Return id from Model and External ID
 
105
        obj_id = False
 
106
        try:
 
107
            external_id = external_id.split('.')[1]
 
108
        except:
 
109
            osv.except_osv(_('Warning!'), _('Such External ID does not Exist!'))
 
110
        model_data_pool = self.pool.get('ir.model.data')
 
111
        ir_model_data_id = model_data_pool.search(cr, uid, [('model', '=', model), ('name', '=', external_id)])
 
112
        if ir_model_data_id:
 
113
            ir_model_data_obj = model_data_pool.browse(cr, uid, ir_model_data_id)[0]
 
114
            obj = self.pool.get(model).browse(cr, uid, ir_model_data_obj.res_id)
 
115
            obj_id = obj and obj.id
 
116
        else:
 
117
            osv.except_osv(_('Warning!'), _('Such External ID does not Exist!'))
 
118
        return obj_id
 
119
 
 
120
    def is_manager(self, cr, uid, context=None):
 
121
        usr_groups = []
 
122
        groups_id = [x.id for x in self.pool.get('res.users').browse(cr, uid, uid).groups_id]
 
123
        groups =  [{'external_id':'group_account_manager','rol':'financial'}]
 
124
        groups += [{'external_id':'group_sale_manager','rol':'sale'}] 
 
125
        groups += [{'external_id':'group_operation_supervisor_user','rol':'operation'}]
 
126
        model = 'res.groups'
 
127
        for item in groups:
 
128
            external_id = item['external_id'] 
 
129
            obj_id = self.get_obj(cr, uid, model, external_id)
 
130
            if obj_id in groups_id:
 
131
                usr_groups.append(item['rol'])
 
132
        return usr_groups
 
133
 
 
134
    def button_authorize(self, cr, uid, ids, context=None):
 
135
        if 'financial' not in self.is_manager(cr, uid, context):
 
136
            raise osv.except_osv(_('Error!'), _("Only Financial Manager can authorize this document."))
 
137
        oportunity_id = ids[0]
 
138
        self.write(cr, uid, oportunity_id, {'financial_state':'authorized'})
 
139
        return True
 
140
    
 
141
    def button_reject(self, cr, uid, ids, context=None):
 
142
        if 'financial' not in self.is_manager(cr, uid, context):
 
143
            raise osv.except_osv(_('Error!'), _("Only Financial Manager can reject this document."))
 
144
        oportunity_id = ids[0]
 
145
        self.write(cr, uid, oportunity_id, {'financial_state':'rejected'})
 
146
        return True
 
147
 
 
148
    def button_authorize_sale(self, cr, uid, ids, context=None):
 
149
        if 'sale' not in self.is_manager(cr, uid, context):
 
150
            raise osv.except_osv(_('Error!'), _("Only Sale Manager can authorize this document."))
 
151
        oportunity_id = ids[0]
 
152
        self.write(cr, uid, oportunity_id, {'sale_state':'authorized'})
 
153
        return True
 
154
    
 
155
    def button_reject_sale(self, cr, uid, ids, context=None):
 
156
        if 'sale' not in self.is_manager(cr, uid, context):
 
157
            raise osv.except_osv(_('Error!'), _("Only Sale Manager can reject this document."))
 
158
        oportunity_id = ids[0]
 
159
        self.write(cr, uid, oportunity_id, {'sale_state':'rejected'})
 
160
        return True
 
161
 
 
162
    def button_po(self, cr, uid, ids, context=None):
 
163
        return True
 
164
 
 
165
    def button_picking_in(self, cr, uid, ids, context=None):
 
166
        return True
 
167
 
 
168
    def button_supplier_invoice(self, cr, uid, ids, context=None):
 
169
        return True
 
170
 
 
171
    def button_picking_out(self, cr, uid, ids, context=None):
 
172
        return True
 
173
 
 
174
    def button_payment(self, cr, uid, ids, context=None):
 
175
        return True
 
176
 
 
177
    def button_cost_chart(self, cr, uid, ids, context=None):
 
178
        return True
 
179
 
 
180
 
 
181
    
 
182
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: