[IMP] various changes after review

bzr revid: mat@openerp.com-20130306144544-nxtwzbcx600phczf
This commit is contained in:
Martin Trigaux 2013-03-06 15:45:44 +01:00
parent 4409ab2777
commit fca11bc1f1
6 changed files with 53 additions and 39 deletions

View File

@ -9,7 +9,7 @@
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field name="model">gamification.goal.plan</field>
<field name="function">_update_all</field>
<field name="function">_cron_update</field>
<field name="args">()</field>
</record>
</data>

View File

@ -40,6 +40,7 @@ class gamification_goal_type(osv.Model):
_columns = {
'name': fields.char('Type Name', required=True, translate=True),
'description': fields.text('Description'),
'unit': fields.char('Unit', help="The unit of the target and current values", translate=True),
'computation_mode': fields.selection([
('sum','Sum'),
('count','Count'),
@ -64,8 +65,8 @@ class gamification_goal_type(osv.Model):
help="Technical filters rules to apply",
required=True), # how to apply it ?
'condition' : fields.selection([
('minus','<='),
('plus','>=')
('lower','<='),
('higher','>=')
],
string='Validation Condition',
help='A goal is considered as completed when the current value is compared to the value to reach',
@ -78,7 +79,7 @@ class gamification_goal_type(osv.Model):
_order = 'sequence'
_defaults = {
'sequence': 1,
'condition': 'plus',
'condition': 'higher',
'computation_mode':'manually',
'domain':"[]",
}
@ -158,7 +159,6 @@ class gamification_goal(osv.Model):
'current': 0,
'state': 'draft',
'start_date': fields.date.today,
'last_update': fields.date.today,
}
@ -172,12 +172,11 @@ class gamification_goal(osv.Model):
the target value being reached, the goal is set as failed."""
for goal in self.browse(cr, uid, ids, context=context or {}):
if goal.state not in ('inprogress','inprogress_update','reached'):
# skip if goal draft, failed or canceled
if goal.state in ('draft','canceled'):
# skip if goal draft or canceled
continue
if goal.state == 'reached' and goal.end_date and fields.date.today() > goal.end_date:
# only a goal reached but not passed the end date will still be
# checked (to be able to improve the score)
if goal.last_update and goal.end_date and goal.last_update > goal.end_date:
# skip if a goal is finished (updated after the goal end date)
continue
if goal.type_id.computation_mode == 'manually':
@ -220,9 +219,9 @@ class gamification_goal(osv.Model):
towrite = {'current': len(res)}
# check goal target reached
if (goal.type_id.condition == 'plus' \
if (goal.type_id.condition == 'higher' \
and towrite['current'] >= goal.target_goal) \
or (goal.type_id.condition == 'minus' \
or (goal.type_id.condition == 'lower' \
and towrite['current'] <= goal.target_goal):
towrite['state'] = 'reached'

View File

@ -112,6 +112,7 @@ class gamification_goal_plan(osv.Model):
string='Periodicity',
help='Period of automatic goal assigment. If none is selected, should be launched manually.',
required=True),
'start_date' : fields.date('Starting Date', help="The day a new plan will be automatically started. The start and end dates for goals are still defined by the periodicity (eg: weekly goals run from Monday to Sunday)."),
'state': fields.selection([
('draft', 'Draft'),
('inprogress', 'In progress'),
@ -153,7 +154,8 @@ class gamification_goal_plan(osv.Model):
'state': 'draft',
'visibility_mode' : 'progressbar',
'report_message_frequency' : 'onchange',
'last_report_date' : fields.date.today
'last_report_date' : fields.date.today,
'start_date' : fields.date.today,
}
def _check_nonzero_planline(self, cr, uid, ids, context=None):
@ -192,14 +194,19 @@ class gamification_goal_plan(osv.Model):
return write_res
def _update_all(self, cr, uid, context=None, ids=False):
"""Update the plans and goals
def _cron_update(self, cr, uid, context=None, ids=False):
"""Daily cron check.
Start planned plans (in draft and with start_date = today)
Create the goals for planlines not linked to goals (eg: modified the
plan to add planlines)
:param list(int) ids: the ids of the plans to update, if False will
update only plans in progress."""
if not context: context = {}
Update every goal running"""
if not context: context = {}
# start planned plans
planned_plan_ids = self.search(cr, uid, [('state', '=', 'draft'),('start_date','=',fields.date.today())])
self.action_start(cr, uid, planned_plan_ids, context=context)
if not ids:
ids = self.search(cr, uid, [('state', '=', 'inprogress')])
@ -208,15 +215,26 @@ class gamification_goal_plan(osv.Model):
goal_obj = self.pool.get('gamification.goal')
# we use yesterday to update the goals that just ended
yesterday = date.today() - timedelta(days=1)
# TOCHECK conflict with date rule in goal update() function
goal_ids = goal_obj.search(cr, uid, [
'&',
('state', 'in', ('inprogress','inprogress_update', 'reached')),
('state', 'not in', ('draft','canceled')),
'|',
('end_date', '>=', yesterday.isoformat()),
('end_date', '=', False)
], context=context)
goal_obj.update(cr, uid, goal_ids, context=context)
return self._update_all(cr, uid, ids, context=context)
def _update_all(self, cr, uid, ids, context=None):
"""Update the plans and related goals
:param list(int) ids: the ids of the plans to update, if False will
update only plans in progress."""
if not context: context = {}
for plan in self.browse(cr, uid, ids, context=context):
# goals closed but still opened at the last report date
closed_goals_to_report = []
@ -246,15 +264,15 @@ class gamification_goal_plan(osv.Model):
if plan.autojoin_group_id:
self.plan_subscribe_users(cr, uid, ids, [user.id for user in plan.autojoin_group_id.users], context=context)
self.generate_goals_from_plan(cr, uid, ids, context=context)
return self.write(cr, uid, ids, {'state': 'inprogress'}, context=context)
self.write(cr, uid, ids, {'state': 'inprogress'}, context=context)
return self.generate_goals_from_plan(cr, uid, ids, context=context)
def action_check(self, cr, uid, ids, context=None):
"""Check a goal plan
Create goals that haven't been created yet (eg: if added users of planlines)
Recompute the current value for each goal related"""
return self._update_all(cr, uid, ids=ids, context=context)
return self._update_all(cr, uid, ids=ids, context=context)
def action_close(self, cr, uid, ids, context=None):
@ -324,11 +342,10 @@ class gamification_goal_plan(osv.Model):
for plan in self.browse(cr, uid, ids, context):
(start_date, end_date) = start_end_date_for_period(plan.period)
for planline in plan.planline_ids:
for user in plan.user_ids:
#self.create_goal_from_plan(cr, uid, ids, planline.id, user.id, start_date, context=context)
goal_obj = self.pool.get('gamification.goal')
domain = [('planline_id', '=', planline.id),
('user_id', '=', user.id)]

View File

@ -44,7 +44,7 @@
<field name="arch" type="xml">
<form string="Goal types" version="7.0">
<header>
<button string="Start Plan" type="object" name="action_start" states="draft" class="oe_highlight"/>
<button string="Manual Start" type="object" name="action_start" states="draft" class="oe_highlight"/>
<button string="Check Plan" type="object" name="action_check" states="inprogress"/>
<button string="Close Plan" type="object" name="action_close" states="inprogress" class="oe_highlight"/>
<button string="Reset to Draft" type="object" name="action_cancel" states="inprogress"/>
@ -67,6 +67,7 @@
<group>
<group colspan="4">
<field name="start_date" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="period" attrs="{'readonly':[('state','!=','draft')]}"/>
<field name="remind_update_delay"/>

View File

@ -1,16 +1,10 @@
.oe_kanban_goal {
width: 160px;
min-height: 160px;
}
.openerp .oe_kanban_view .oe_kanban_color_reached {
.openerp .oe_kanban_view .oe_kanban_card.oe_kanban_color_reached {
background-color: #A1FF81;
color: #0B1907;
}
.openerp .oe_kanban_view .oe_kanban_color_failed {
.openerp .oe_kanban_view .oe_kanban_card.oe_kanban_color_failed {
background-color: #ffc7c7;
color: #7a3737;
}
.oe_kanban_color_inprogress,.oe_kanban_color_inprogress_update,.oe_kanban_color_draft {
background-color: white;
color: black;
}

View File

@ -12,12 +12,13 @@
<field name="field_date_id" eval="ref('account.field_account_invoice_report_day')" />
<field name="domain">[('state','!=','cancel'),('user_id','=',user_id)]</field>
</record>
<!-- filtre ajout seulement customer -->
<record model="gamification.goal.type" id="type_crm_lead_delay_open">
<field name="name">Delay to Open</field>
<field name="name">Time to Qualify a Lead</field>
<field name="description">The average number of days to open the case (less than)</field>
<field name="computation_mode">sum</field>
<field name="condition">minus</field>
<field name="condition">lower</field>
<field name="model_id" eval="ref('crm.model_crm_lead_report')" />
<field name="field_id" eval="ref('crm.field_crm_lead_report_delay_close')" />
<field name="field_date_id" eval="ref('crm.field_crm_lead_report_date_closed')" />
@ -25,10 +26,10 @@
</record>
<record model="gamification.goal.type" id="type_crm_lead_delay_close">
<field name="name">Delay to Close</field>
<field name="name">Days to Close a Deal</field>
<field name="description">The average number of days to close the case (less than)</field>
<field name="computation_mode">sum</field>
<field name="condition">minus</field>
<field name="condition">lower</field>
<field name="model_id" eval="ref('crm.model_crm_lead_report')" />
<field name="field_id" eval="ref('crm.field_crm_lead_report_delay_open')" />
<field name="field_date_id" eval="ref('crm.field_crm_lead_report_opening_date')" />
@ -95,8 +96,9 @@
<record model="gamification.goal.type" id="type_crm_nbr_customer_refunds">
<field name="name"># Customer Refunds</field>
<field name="description"></field>
<field name="description">Refund the least customers</field>
<field name="computation_mode">count</field>
<field name="condition">lower</field>
<field name="model_id" eval="ref('account.model_account_invoice')" />
<field name="field_date_id" eval="ref('account.field_account_invoice_date_invoice')" />
<field name="domain">[('state','!=','cancel'),('user_id','=',user_id),('type','=','out_refund')]</field>
@ -106,6 +108,7 @@
<field name="name">Total Customer Refunds</field>
<field name="description"></field>
<field name="computation_mode">sum</field>
<field name="condition">higher</field>
<field name="model_id" eval="ref('account.model_account_invoice')" />
<field name="field_id" eval="ref('account.field_account_invoice_amount_total')" />
<field name="field_date_id" eval="ref('account.field_account_invoice_date_invoice')" />