[IMP,FIX]: crm_claim: Improvement in claims for inheriting python class crm case from crm + Improvement in reports, Added missing fields

bzr revid: rpa@tinyerp.com-20100506064400-fws6rmpe6f860enb
This commit is contained in:
rpa (Open ERP) 2010-05-06 12:14:00 +05:30
parent 6c9331f6ea
commit a77041f56b
5 changed files with 235 additions and 60 deletions

View File

@ -40,8 +40,8 @@
], ],
'demo_xml': [ 'demo_xml': [
'crm_claim_demo.xml', 'crm_claim_demo.xml',
'test/test_crm_claim.yml' ],
], 'test': ['test/test_crm_claim.yml'],
'installable': True, 'installable': True,
'active': False, 'active': False,
} }

View File

@ -22,7 +22,7 @@
from osv import fields, osv from osv import fields, osv
from crm import crm from crm import crm
class crm_claim(osv.osv): class crm_claim(osv.osv, crm.crm_case):
""" """
Crm claim Crm claim
""" """
@ -31,41 +31,71 @@ class crm_claim(osv.osv):
_order = "id desc" _order = "id desc"
_inherit = 'mailgate.thread' _inherit = 'mailgate.thread'
_columns = { _columns = {
'date_closed': fields.datetime('Closed', readonly=True), 'id': fields.integer('ID', readonly=True),
'date': fields.datetime('Date'), 'name': fields.char('Name', size=128, required=True),
'ref' : fields.reference('Reference', selection=crm._links_get, size=128), 'description': fields.text('Description'),
'ref2' : fields.reference('Reference 2', selection=crm._links_get, size=128), 'create_date': fields.datetime('Creation Date' , readonly=True),
'canal_id': fields.many2one('res.partner.canal', 'Channel',\ 'write_date': fields.datetime('Update Date' , readonly=True),
'date_deadline': fields.date('Deadline'),
'date_closed': fields.datetime('Closed', readonly=True),
'date': fields.datetime('Date'),
'ref' : fields.reference('Reference', selection=crm._links_get, size=128),
'ref2' : fields.reference('Reference 2', selection=crm._links_get, size=128),
'canal_id': fields.many2one('res.partner.canal', 'Channel', \
help="The channels represent the different communication\ help="The channels represent the different communication\
modes available with the customer." \ modes available with the customer." \
" With each commercial opportunity, you can indicate the\ " With each commercial opportunity, you can indicate the\
canall which is this opportunity source."), canall which is this opportunity source."),
'planned_revenue': fields.float('Planned Revenue'), 'planned_revenue': fields.float('Planned Revenue'),
'planned_cost': fields.float('Planned Costs'), 'planned_cost': fields.float('Planned Costs'),
'som': fields.many2one('res.partner.som', 'State of Mind', \ 'som': fields.many2one('res.partner.som', 'State of Mind', \
help="The minds states allow to define a value scale which represents" \ help="The minds states allow to define a value scale which represents" \
"the partner mentality in relation to our services.The scale has" \ "the partner mentality in relation to our services.The scale has" \
"to be created with a factor for each level from 0 (Very dissatisfied) \ "to be created with a factor for each level from 0 (Very dissatisfied) \
to 10 (Extremely satisfied)."), to 10 (Extremely satisfied)."),
'categ_id': fields.many2one('crm.case.categ', 'Category',\ 'categ_id': fields.many2one('crm.case.categ', 'Category', \
domain="[('section_id','=',section_id),\ domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.claim')]"), ('object_id.model', '=', 'crm.claim')]"),
'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'), 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'),
'type_id': fields.many2one('crm.case.resource.type', 'Claim Type',\ 'type_id': fields.many2one('crm.case.resource.type', 'Claim Type', \
domain="[('section_id','=',section_id),\ domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.claim')]"), ('object_id.model', '=', 'crm.claim')]"),
'user_id': fields.many2one('res.users', 'Responsible'),
'partner_name': fields.char("Employee's Name", size=64), 'section_id': fields.many2one('crm.case.section', 'Sales Team', \
'partner_mobile': fields.char('Mobile', size=32), select=True, help='Sales team to which Case belongs to.\
'partner_phone': fields.char('Phone', size=32), Define Responsible user and Email account for mail gateway.'),
'stage_id': fields.many2one ('crm.case.stage', 'Stage',\ 'company_id': fields.many2one('res.company', 'Company'),
'partner_id': fields.many2one('res.partner', 'Partner'),
'partner_address_id': fields.many2one('res.partner.address', 'Partner Contact', \
domain="[('partner_id','=',partner_id)]"),
'email_cc': fields.text('Watchers Emails', size=252 , help="These people\
will receive a copy of the future" \
" communication between partner and users by email"),
'email_from': fields.char('Email', size=128, help="These people will receive email."),
'partner_name': fields.char("Employee's Name", size=64),
'partner_mobile': fields.char('Mobile', size=32),
'partner_phone': fields.char('Phone', size=32),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
domain="[('section_id','=',section_id),\ domain="[('section_id','=',section_id),\
('object_id.model', '=', 'crm.claim')]"), ('object_id.model', '=', 'crm.claim')]"),
'probability': fields.float('Probability (%)'), 'probability': fields.float('Probability (%)'),
'state': fields.selection(crm.AVAILABLE_STATES, 'State', size=16, readonly=True,
help='The state is set to \'Draft\', when a case is created.\
\nIf the case is in progress the state is set to \'Open\'.\
\nWhen the case is over, the state is set to \'Done\'.\
\nIf the case needs to be reviewed then the state is set to \'Pending\'.'),
} }
_defaults = { _defaults = {
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], 'active': lambda *a: 1,
'user_id': crm.crm_case._get_default_user,
'partner_id': crm.crm_case._get_default_partner,
'partner_address_id': crm.crm_case._get_default_partner_address,
'email_from':crm.crm_case. _get_default_email,
'state': lambda *a: 'draft',
'section_id':crm.crm_case. _get_section,
'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.case', context=c),
'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0],
} }
crm_claim() crm_claim()

View File

@ -169,7 +169,7 @@
<group colspan="4"> <group colspan="4">
<field colspan="4" name="email_cc" string="CC"/> <field colspan="4" name="email_cc" string="CC"/>
</group> </group>
<field name="history_line" colspan="4" nolabel="1" mode="form,tree"> <field name="message_ids" colspan="4" nolabel="1" mode="form,tree">
<form string="Communication history"> <form string="Communication history">
<group col="7" colspan="4"> <group col="7" colspan="4">
<field name="date"/> <field name="date"/>

View File

@ -23,16 +23,75 @@ from osv import fields,osv
import tools import tools
from crm.report import crm_report from crm.report import crm_report
AVAILABLE_STATES = [
('draft','Draft'),
('open','Open'),
('cancel', 'Cancelled'),
('done', 'Closed'),
('pending','Pending')
]
class crm_claim_report(osv.osv): class crm_claim_report(osv.osv):
""" CRM Claim Report""" """ CRM Claim Report"""
_name = "crm.claim.report" _name = "crm.claim.report"
_auto = False _auto = False
_inherit = "crm.case.report"
_description = "CRM Claim Report" _description = "CRM Claim Report"
def _get_data(self, cr, uid, ids, field_name, arg, context={}):
""" @param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of case and section Datas IDs
@param context: A standard dictionary for contextual values """
res = {}
state_perc = 0.0
avg_ans = 0.0
for case in self.browse(cr, uid, ids, context):
if field_name != 'avg_answers':
state = field_name[5:]
cr.execute("select count(*) from crm_opportunity where \
section_id =%s and state='%s'"%(case.section_id.id, state))
state_cases = cr.fetchone()[0]
perc_state = (state_cases / float(case.nbr)) * 100
res[case.id] = perc_state
else:
model_name = self._name.split('report.')
if len(model_name) < 2:
res[case.id] = 0.0
else:
model_name = model_name[1]
cr.execute("select count(*) from crm_case_log l, ir_model m \
where l.model_id=m.id and m.model = '%s'" , model_name)
logs = cr.fetchone()[0]
avg_ans = logs / case.nbr
res[case.id] = avg_ans
return res
_columns = { _columns = {
'name': fields.char('Year', size=64, required=False, readonly=True),
'user_id':fields.many2one('res.users', 'User', readonly=True),
'section_id':fields.many2one('crm.case.section', 'Section', readonly=True),
'nbr': fields.integer('# of Cases', readonly=True),
'state': fields.selection(AVAILABLE_STATES, 'State', size=16, readonly=True),
'avg_answers': fields.function(_get_data, string='Avg. Answers', method=True, type="integer"),
'perc_done': fields.function(_get_data, string='%Done', method=True, type="float"),
'perc_cancel': fields.function(_get_data, string='%Cancel', method=True, type="float"),
'month':fields.selection([('01', 'January'), ('02', 'February'), \
('03', 'March'), ('04', 'April'),\
('05', 'May'), ('06', 'June'), \
('07', 'July'), ('08', 'August'),\
('09', 'September'), ('10', 'October'),\
('11', 'November'), ('12', 'December')], 'Month', readonly=True),
'company_id': fields.many2one('res.company', 'Company', readonly=True),
'create_date': fields.datetime('Create Date', readonly=True),
'day': fields.char('Day', size=128, readonly=True),
'delay_close': fields.float('Delay to close', digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"), 'delay_close': fields.float('Delay to close', digits=(16,2),readonly=True, group_operator="avg",help="Number of Days to close the case"),
'stage_id': fields.many2one ('crm.case.stage', 'Stage', \ 'stage_id': fields.many2one ('crm.case.stage', 'Stage', \
domain="[('section_id','=',section_id),\ domain="[('section_id','=',section_id),\

View File

@ -33,16 +33,21 @@
<record id="view_report_crm_claim_form" model="ir.ui.view"> <record id="view_report_crm_claim_form" model="ir.ui.view">
<field name="name">crm.claim.report.form</field> <field name="name">crm.claim.report.form</field>
<field name="model">crm.claim.report</field> <field name="model">crm.claim.report</field>
<field name="inherit_id" ref="crm.view_crm_case_form"/>
<field name="type">form</field> <field name="type">form</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="nbr" position="after"> <form string="Cases">
<field name="name" select="1"/>
<field name="month" select="1"/>
<field name="user_id" select="1"/>
<field name="section_id" select="1"/>
<field name="nbr" select="1"/>
<field name="delay_close"/> <field name="delay_close"/>
<field name="amount_revenue"/> <field name="amount_revenue"/>
<field name="amount_costs"/> <field name="amount_costs"/>
<field name="amount_revenue_prob"/> <field name="amount_revenue_prob"/>
<field name="probability"/> <field name="probability"/>
</field> <field name="state" select="1"/>
</form>
</field> </field>
</record> </record>
@ -62,40 +67,121 @@
</record> </record>
<!-- CRM Claim Report Search View --> <!-- CRM Claim Report Search View -->
<record id="view_report_crm_claim_filter" model="ir.ui.view"> <record id="view_report_crm_claim_filter" model="ir.ui.view">
<field name="name">crm.claim.report.select</field> <field name="name">crm.claim.report.select</field>
<field name="model">crm.claim.report</field> <field name="model">crm.claim.report</field>
<field name="inherit_id" ref="crm.view_crm_case_filter"/>
<field name="type">search</field> <field name="type">search</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<data> <search string="Search">
<xpath expr='//search[@string="Search"]/group[@string="Extended options..."]/filter[@string="Cancel"]' position='after'> <group col="16" colspan="8">
<group> <!-- <filter string="This Year" name="This Year" icon="terp-hr"
<separator orientation="vertical"/> domain="[('name','=',time.localtime()[0])]"/>-->
<field name="stage_id" widget="selection" domain="[('object_id.model', '=', 'crm.claim')]"/> <filter string="This Year" icon="terp-hr"
<field name="categ_id" widget="selection" domain="[('object_id.model', '=', 'crm.claim')]"/> domain="[('create_date','&lt;=', time.strftime('%%Y-%%m-%%d')), ('create_date','&gt;',(datetime.date.today()-datetime.timedelta(days=365)).strftime('%%Y-%%m-%%d'))]"/>
<separator orientation="vertical"/>
<field name="priority" /> <!-- <filter string="This Month" name="This Year" icon="terp-hr"
<field name="type_id" widget="selection" domain="[('object_id.model', '=', 'crm.claim')]"/> domain="[('month','=',time.strftime('%%m'))]" />-->
</group> <filter string="This Month" icon="terp-hr" name="This Month"
</xpath> domain="[('create_date','&lt;=', time.strftime('%%Y-%%m-%%d')), ('create_date','&gt;',(datetime.date.today()-datetime.timedelta(days=30)).strftime('%%Y-%%m-%%d'))]"/>
<xpath
expr='//search[@string="Search"]/group[@string="Group By..."]/filter[@string="State"]' <filter icon="gtk-media-rewind" string="7 Days" separator="1"
position='after'> domain="[('create_date','&lt;=', time.strftime('%%Y-%%m-%%d')), ('create_date','&gt;',(datetime.date.today()-datetime.timedelta(days=7)).strftime('%%Y-%%m-%%d'))]"/>
<filter string="Stage" icon="terp-sale" domain="[]"
context="{'group_by':'stage_id'}" /> <separator orientation="vertical" />
</xpath> <filter icon="terp-hr"
<xpath string="Draft"
expr='//search[@string="Search"]/group[@string="Group By..."]/filter[@string="Category"]' domain="[('state','=','draft')]"/>
position='after'> <filter icon="terp-hr"
<separator orientation="vertical"/> string="Open"
<filter string="Priority" icon="terp-sale" domain="[]" domain="[('state','=','open')]"/>
context="{'group_by':'priority'}" /> <filter icon="terp-hr"
<filter string="Type" icon="terp-sale" domain="[]" string="Pending"
context="{'group_by':'type_id'}" /> domain="[('state','=','pending')]"/>
</xpath>
</data> <separator orientation="vertical" />
<field name="section_id"
default="context.get('section_id', False)"
widget="selection"
context="{'invisible_section': False}">
<filter icon="terp-crm"
context="{'invisible_section': False}"
domain="[('section_id.user_id','=',uid)]"
help="My section" />
</field>
<field name="company_id" widget="selection">
<filter icon="terp-crm"
context="{'invisible_section': False}"
domain="[('section_id.user_id.company_id','=',uid)]"
help="My company"/>
</field>
<field name="user_id" select="1" widget="selection">
<filter icon="terp-crm" string="My Case" help="My Case" domain="[('user_id','=',uid)]" />
</field>
</group>
<newline/>
<group expand="0" string="Extended options..." colspan="10" col="12">
<filter icon="terp-sale"
string="Done"
domain="[('state','=','done')]"/>
<filter icon="terp-sale"
string="Cancel"
domain="[('state','=','cancel')]"/>
<group>
<separator orientation="vertical"/>
<field name="stage_id" widget="selection" domain="[('object_id.model', '=', 'crm.claim')]"/>
<field name="categ_id" widget="selection" domain="[('object_id.model', '=', 'crm.claim')]"/>
<separator orientation="vertical"/>
<field name="priority" />
<field name="type_id" widget="selection" domain="[('object_id.model', '=', 'crm.claim')]"/>
</group>
</group>
<newline/>
<group expand="1" string="Group By..." colspan="4" col="8">
<filter string="User" name="User" icon="terp-sale"
domain="[]" context="{'group_by':'user_id'}" />
<filter string="Company" icon="terp-sale"
domain="[]"
context="{'group_by':'company_id'}" />
<filter string="Section" icon="terp-sale"
domain="[]"
context="{'group_by':'section_id'}" />
<separator orientation="vertical" />
<filter string="State" icon="terp-sale"
domain="[]" context="{'group_by':'state'}" />
<filter string="Stage" icon="terp-sale" domain="[]"
context="{'group_by':'stage_id'}" />
<filter string="Category" icon="terp-sale"
domain="[]" context="{'group_by':'categ_id'}" />
<separator orientation="vertical"/>
<filter string="Priority" icon="terp-sale" domain="[]"
context="{'group_by':'priority'}" />
<filter string="Type" icon="terp-sale" domain="[]"
context="{'group_by':'type_id'}" />
<separator orientation="vertical" />
<filter string="Day" icon="terp-sale"
domain="[]" context="{'group_by':'day'}"/>
<filter string="Month" icon="terp-sale"
domain="[]" context="{'group_by':'month'}" />
<filter string="Year" icon="terp-sale"
domain="[]" context="{'group_by':'name'}" />
</group>
</search>
</field> </field>
</record> </record>