2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2009-12-01 07:19:53 +00:00
#
2009-02-04 09:46:57 +00:00
# OpenERP, Open Source Management Solution
2012-05-22 08:14:13 +00:00
# Copyright (C) 2004-today OpenERP SA (<http://www.openerp.com>)
2008-06-16 11:00:21 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2006-12-07 13:41:40 +00:00
#
2008-11-03 19:18:56 +00:00
# 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
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2006-12-07 13:41:40 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-12-01 07:19:53 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
2014-07-08 15:33:00 +00:00
from openerp . osv import osv , fields
from openerp . http import request
2009-09-24 10:46:21 +00:00
2006-12-07 13:41:40 +00:00
AVAILABLE_PRIORITIES = [
2014-02-14 11:49:37 +00:00
( ' 0 ' , ' Very Low ' ) ,
( ' 1 ' , ' Low ' ) ,
( ' 2 ' , ' Normal ' ) ,
( ' 3 ' , ' High ' ) ,
( ' 4 ' , ' Very High ' ) ,
2006-12-07 13:41:40 +00:00
]
2014-07-08 15:33:00 +00:00
class crm_tracking_medium ( osv . Model ) :
# OLD crm.case.channel
_name = " crm.tracking.medium "
2011-08-27 23:31:30 +00:00
_description = " Channels "
_order = ' name '
_columns = {
2014-05-21 09:52:05 +00:00
' name ' : fields . char ( ' Channel Name ' , required = True ) ,
2011-08-27 23:31:30 +00:00
' active ' : fields . boolean ( ' Active ' ) ,
}
_defaults = {
' active ' : lambda * a : 1 ,
}
2014-07-08 15:33:00 +00:00
class crm_tracking_campaign ( osv . Model ) :
# OLD crm.case.resource.type
_name = " crm.tracking.campaign "
_description = " Campaign "
_rec_name = " name "
_columns = {
' name ' : fields . char ( ' Campaign Name ' , required = True , translate = True ) ,
' section_id ' : fields . many2one ( ' crm.case.section ' , ' Sales Team ' ) ,
}
class crm_tracking_source ( osv . Model ) :
_name = " crm.tracking.source "
_description = " Source "
_rec_name = " name "
_columns = {
' name ' : fields . char ( ' Source Name ' , required = True , translate = True ) ,
}
class crm_tracking_mixin ( osv . AbstractModel ) :
""" Mixin class for objects which can be tracked by marketing. """
_name = ' crm.tracking.mixin '
_columns = {
' campaign_id ' : fields . many2one ( ' crm.tracking.campaign ' , ' Campaign ' , # old domain ="['|',('section_id','=',section_id),('section_id','=',False)]"
2014-07-29 15:10:03 +00:00
help = " This is a name that helps you keep track of your different campaign efforts Ex: Fall_Drive, Christmas_Special " ) ,
' source_id ' : fields . many2one ( ' crm.tracking.source ' , ' Source ' , help = " This is the source of the link Ex: Search Engine, another domain, or name of email list " ) ,
2014-11-21 14:03:12 +00:00
' medium_id ' : fields . many2one ( ' crm.tracking.medium ' , ' Channel ' , help = " This is the method of delivery. Ex: Postcard, Email, or Banner Ad " , oldname = ' channel_id ' ) ,
2014-07-08 15:33:00 +00:00
}
def tracking_fields ( self ) :
return [ ( ' utm_campaign ' , ' campaign_id ' ) , ( ' utm_source ' , ' source_id ' ) , ( ' utm_medium ' , ' medium_id ' ) ]
def tracking_get_values ( self , cr , uid , vals , context = None ) :
[IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns. This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...
This commit contains the following changes:
- adapt several methods of BaseModel to use fields instead of columns and
_all_columns
- copy all semantic-free attributes of related fields from their source
- add attribute 'group_operator' on integer and float fields
- base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
payment_acquirer, share, website, website_crm, website_mail: simply use
_fields instead of _all_columns
- base, decimal_precision, website: adapt qweb rendering methods to use fields
instead of columns
2014-11-03 15:00:50 +00:00
for key , fname in self . tracking_fields ( ) :
field = self . _fields [ fname ]
value = vals . get ( fname ) or ( request and request . httprequest . cookies . get ( key ) ) # params.get should be always in session by the dispatch from ir_http
if field . type == ' many2one ' and isinstance ( value , basestring ) :
# if we receive a string for a many2one, we search/create the id
2014-07-08 15:33:00 +00:00
if value :
[IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns. This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...
This commit contains the following changes:
- adapt several methods of BaseModel to use fields instead of columns and
_all_columns
- copy all semantic-free attributes of related fields from their source
- add attribute 'group_operator' on integer and float fields
- base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
payment_acquirer, share, website, website_crm, website_mail: simply use
_fields instead of _all_columns
- base, decimal_precision, website: adapt qweb rendering methods to use fields
instead of columns
2014-11-03 15:00:50 +00:00
Model = self . pool [ field . comodel_name ]
2014-07-08 15:33:00 +00:00
rel_id = Model . name_search ( cr , uid , value , context = context )
2014-07-29 12:46:45 +00:00
if rel_id :
2014-07-29 15:10:03 +00:00
rel_id = rel_id [ 0 ] [ 0 ]
2014-07-29 12:46:45 +00:00
else :
2014-07-08 15:33:00 +00:00
rel_id = Model . create ( cr , uid , { ' name ' : value } , context = context )
[IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns. This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...
This commit contains the following changes:
- adapt several methods of BaseModel to use fields instead of columns and
_all_columns
- copy all semantic-free attributes of related fields from their source
- add attribute 'group_operator' on integer and float fields
- base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
payment_acquirer, share, website, website_crm, website_mail: simply use
_fields instead of _all_columns
- base, decimal_precision, website: adapt qweb rendering methods to use fields
instead of columns
2014-11-03 15:00:50 +00:00
vals [ fname ] = rel_id
2014-07-08 15:33:00 +00:00
else :
[IMP] use model._fields instead of model._all_columns to cover all fields
The old-api model._all_columns contains information about model._columns and
inherited columns. This dictionary is missing new-api computed non-stored
fields, and the new field objects provide a more readable api...
This commit contains the following changes:
- adapt several methods of BaseModel to use fields instead of columns and
_all_columns
- copy all semantic-free attributes of related fields from their source
- add attribute 'group_operator' on integer and float fields
- base, base_action_rule, crm, edi, hr, mail, mass_mailing, pad,
payment_acquirer, share, website, website_crm, website_mail: simply use
_fields instead of _all_columns
- base, decimal_precision, website: adapt qweb rendering methods to use fields
instead of columns
2014-11-03 15:00:50 +00:00
# Here the code for others cases that many2one
vals [ fname ] = value
2014-07-08 15:33:00 +00:00
return vals
def _get_default_track ( self , cr , uid , field , context = None ) :
return self . tracking_get_values ( cr , uid , { } , context = context ) . get ( field )
_defaults = {
' source_id ' : lambda self , cr , uid , ctx : self . _get_default_track ( cr , uid , ' source_id ' , ctx ) ,
' campaign_id ' : lambda self , cr , uid , ctx : self . _get_default_track ( cr , uid , ' campaign_id ' , ctx ) ,
' medium_id ' : lambda self , cr , uid , ctx : self . _get_default_track ( cr , uid , ' medium_id ' , ctx ) ,
}
2011-08-25 04:10:37 +00:00
class crm_case_stage ( osv . osv ) :
2012-05-22 08:14:13 +00:00
""" Model for case stages. This models the main stages of a document
2012-10-02 10:29:15 +00:00
management flow . Main CRM objects ( leads , opportunities , project
2012-05-22 08:14:13 +00:00
issues , . . . ) will now use only stages , instead of state and stages .
Stages are for example used to display the kanban view of records .
"""
2011-08-25 04:10:37 +00:00
_name = " crm.case.stage "
_description = " Stage of case "
_rec_name = ' name '
_order = " sequence "
_columns = {
2014-05-21 09:52:05 +00:00
' name ' : fields . char ( ' Stage Name ' , required = True , translate = True ) ,
2012-05-22 08:14:13 +00:00
' sequence ' : fields . integer ( ' Sequence ' , help = " Used to order stages. Lower is better. " ) ,
2011-08-25 04:10:37 +00:00
' 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 = " Setting this stage will change the probability automatically on the opportunity. " ) ,
' requirements ' : fields . text ( ' Requirements ' ) ,
2013-07-16 15:10:03 +00:00
' section_ids ' : fields . many2many ( ' crm.case.section ' , ' section_stage_rel ' , ' stage_id ' , ' section_id ' , string = ' Sections ' ,
2014-07-29 15:10:03 +00:00
help = " Link between stages and sales teams. When set, this limitate the current stage to the selected sales teams. " ) ,
2012-12-16 15:58:43 +00:00
' case_default ' : fields . boolean ( ' Default to New Sales Team ' ,
2014-07-29 15:10:03 +00:00
help = " If you check this field, this stage will be proposed by default on each sales team. It will not assign this stage to existing teams. " ) ,
2013-10-18 13:21:20 +00:00
' fold ' : fields . boolean ( ' Folded in Kanban View ' ,
help = ' This stage is folded in the kanban view when '
' there are no records in that stage to display. ' ) ,
2014-07-29 15:10:03 +00:00
' type ' : fields . selection ( [ ( ' lead ' , ' Lead ' ) , ( ' opportunity ' , ' Opportunity ' ) , ( ' both ' , ' Both ' ) ] ,
string = ' Type ' , required = True ,
help = " This field is used to distinguish stages related to Leads from stages related to Opportunities, or to specify stages available for both types. " ) ,
2011-08-25 04:10:37 +00:00
}
_defaults = {
2013-10-23 16:30:29 +00:00
' sequence ' : 1 ,
' probability ' : 0.0 ,
2013-07-16 15:10:03 +00:00
' on_change ' : True ,
2012-05-22 14:11:27 +00:00
' fold ' : False ,
2012-05-24 09:10:24 +00:00
' type ' : ' both ' ,
2012-08-28 11:32:41 +00:00
' case_default ' : True ,
2011-08-25 04:10:37 +00:00
}
2014-07-29 15:10:03 +00:00
2011-08-25 04:10:37 +00:00
class crm_case_categ ( osv . osv ) :
""" Category of Case """
_name = " crm.case.categ "
_description = " Category of Case "
_columns = {
2014-05-21 09:52:05 +00:00
' name ' : fields . char ( ' Name ' , required = True , translate = True ) ,
2011-08-25 04:10:37 +00:00
' section_id ' : fields . many2one ( ' crm.case.section ' , ' Sales Team ' ) ,
' object_id ' : fields . many2one ( ' ir.model ' , ' Object Name ' ) ,
}
2014-07-29 15:10:03 +00:00
2011-08-25 04:10:37 +00:00
def _find_object_id ( self , cr , uid , context = None ) :
2011-08-27 21:19:48 +00:00
""" Finds id for case object """
2012-12-08 13:14:49 +00:00
context = context or { }
object_id = context . get ( ' object_id ' , False )
2014-07-29 15:10:03 +00:00
ids = self . pool . get ( ' ir.model ' ) . search ( cr , uid , [ ' | ' , ( ' id ' , ' = ' , object_id ) , ( ' model ' , ' = ' , context . get ( ' object_name ' , False ) ) ] )
2011-11-14 21:33:19 +00:00
return ids and ids [ 0 ] or False
2011-08-25 04:10:37 +00:00
_defaults = {
2014-07-29 15:10:03 +00:00
' object_id ' : _find_object_id
2011-08-25 04:10:37 +00:00
}
2014-07-29 15:10:03 +00:00
2012-08-01 06:44:42 +00:00
class crm_payment_mode ( osv . osv ) :
""" Payment Mode for Fund """
_name = " crm.payment.mode "
_description = " CRM Payment Mode "
2010-01-08 11:05:05 +00:00
_columns = {
2014-05-21 09:52:05 +00:00
' name ' : fields . char ( ' Name ' , required = True ) ,
2012-08-01 06:44:42 +00:00
' section_id ' : fields . many2one ( ' crm.case.section ' , ' Sales Team ' ) ,
2010-02-01 08:21:18 +00:00
}
2011-02-18 09:54:19 +00:00
2011-11-22 08:51:38 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: