diff --git a/addons/crm_fundraising/__openerp__.py b/addons/crm_fundraising/__openerp__.py index 292325f1084..5c0c7907c3d 100644 --- a/addons/crm_fundraising/__openerp__.py +++ b/addons/crm_fundraising/__openerp__.py @@ -21,28 +21,29 @@ { - 'name': 'CRM Fundraising', - 'version': '1.0', - 'category': 'Generic Modules/CRM & SRM', - 'description': """Fundraising""", - 'author': 'Tiny', - 'website': 'http://www.openerp.com', - 'depends': ['crm'], + 'name': 'CRM Fundraising', + 'version': '1.0', + 'category': 'Generic Modules/CRM & SRM', + 'description': """Fundraising""", + 'author': 'Tiny', + 'website': 'http://www.openerp.com', + 'depends': ['crm'], 'init_xml': [ - 'crm_fundraising_data.xml', - ], + 'crm_fundraising_data.xml', + ], 'update_xml': [ - 'crm_fundraising_view.xml', - 'crm_fundraising_menu.xml', - 'security/ir.model.access.csv', - 'report/crm_fundraising_report_view.xml', - ], + 'crm_fundraising_view.xml', + 'crm_fundraising_menu.xml', + 'security/ir.model.access.csv', + 'report/crm_fundraising_report_view.xml', + ], 'demo_xml': [ - 'crm_fundraising_demo.xml', - ], - 'installable': True, - 'active': False, + 'crm_fundraising_demo.xml', + ], + 'test': ['test/test_crm_fund.yml'], + 'installable': True, + 'active': False, } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm_fundraising/crm_fundraising.py b/addons/crm_fundraising/crm_fundraising.py index 850e088d6b6..3790985075c 100644 --- a/addons/crm_fundraising/crm_fundraising.py +++ b/addons/crm_fundraising/crm_fundraising.py @@ -22,7 +22,7 @@ from osv import fields, osv, orm from crm import crm -class crm_fundraising(osv.osv): +class crm_fundraising(osv.osv, crm.crm_case): """ Fund Raising Cases """ _name = "crm.fundraising" @@ -31,6 +31,23 @@ class crm_fundraising(osv.osv): _inherit ='mailgate.thread' _columns = { + 'name': fields.char('Name', size=128, required=True), + 'description': fields.text('Description'), + 'create_date': fields.datetime('Creation Date' , readonly=True), + 'write_date': fields.datetime('Update Date' , readonly=True), + 'date_deadline': fields.date('Deadline'), + 'user_id': fields.many2one('res.users', 'Responsible'), + 'section_id': fields.many2one('crm.case.section', 'Sales Team', \ + select=True, help='Sales team to which Case belongs to.\ + Define Responsible user and Email account for mail gateway.'), + '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."), 'date_closed': fields.datetime('Closed', readonly=True), 'date': fields.datetime('Date'), 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'), @@ -63,13 +80,26 @@ class crm_fundraising(osv.osv): "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 10 (Extremely satisfied)."), + '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 = { - 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], - 'probability':lambda *a:0.0, - 'planned_cost':lambda *a:0.0, - 'planned_revenue':lambda *a:0.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], + 'probability': lambda *a:0.0, + 'planned_cost': lambda *a:0.0, + 'planned_revenue': lambda *a:0.0, + } crm_fundraising() diff --git a/addons/crm_fundraising/crm_fundraising_view.xml b/addons/crm_fundraising/crm_fundraising_view.xml index 70cc477af98..af6c37a7041 100644 --- a/addons/crm_fundraising/crm_fundraising_view.xml +++ b/addons/crm_fundraising/crm_fundraising_view.xml @@ -182,7 +182,7 @@ - +
diff --git a/addons/crm_fundraising/report/crm_fundraising_report.py b/addons/crm_fundraising/report/crm_fundraising_report.py index af867ea0008..5c19689257c 100644 --- a/addons/crm_fundraising/report/crm_fundraising_report.py +++ b/addons/crm_fundraising/report/crm_fundraising_report.py @@ -22,16 +22,75 @@ from osv import fields,osv import tools +AVAILABLE_STATES = [ + ('draft','Draft'), + ('open','Open'), + ('cancel', 'Cancelled'), + ('done', 'Closed'), + ('pending','Pending') +] class crm_fundraising_report(osv.osv): """CRM Fundraising Report""" _name = "crm.fundraising.report" _auto = False - _inherit = "crm.case.report" _description = "CRM Fundraising 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 user’s ID for security checks, + @param ids: List of case and section Data’s 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 = { + '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), 'categ_id': fields.many2one('crm.case.categ', 'Category', \ domain="[('section_id','=',section_id),\ ('object_id.model', '=', 'crm.fundraising')]"), diff --git a/addons/crm_fundraising/report/crm_fundraising_report_view.xml b/addons/crm_fundraising/report/crm_fundraising_report_view.xml index dc759d0bf1c..fad9c7eb93d 100644 --- a/addons/crm_fundraising/report/crm_fundraising_report_view.xml +++ b/addons/crm_fundraising/report/crm_fundraising_report_view.xml @@ -33,15 +33,20 @@ crm.fundraising.report.form crm.fundraising.report - form - + + + + + + - + + @@ -62,20 +67,108 @@ - - crm.fundraising.report.select + + crm.fundraising.report.selectt crm.fundraising.report - search - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/addons/crm_fundraising/test/test_crm_fund.yml b/addons/crm_fundraising/test/test_crm_fund.yml index 4bcacbe148e..e310dfa4d47 100644 --- a/addons/crm_fundraising/test/test_crm_fund.yml +++ b/addons/crm_fundraising/test/test_crm_fund.yml @@ -7,14 +7,14 @@ I make payment by Cheque so I make sure that the mode on fund is selected as cheque - !record {model: crm.fundraising, id: crm_fundraising_donationforbookstopoorschoolchildren0}: - categ_id: crm.categ_fund2 + categ_id: crm_fundraising.categ_fund2 email_from: info@balmerinc.be name: Donation for books to poor school children partner_address_id: base.res_partner_address_1 partner_id: base.res_partner_9 planned_cost: 500000.0 section_id: crm.section_sales_department - type_id: crm.type_fund2 + type_id: crm_fundraising.type_fund2 - | I check that the Funds is in 'draft' state. -