Browse Source

[IMP] sort record list as daily agenda

pull/1/head
Ivan Yelizariev 10 years ago
parent
commit
ad1e313413
  1. 53
      models.py
  2. 24
      static/src/css/main.css
  3. 4
      static/src/js/main.js
  4. 11
      static/src/xml/main.xml
  5. 3
      views.xml

53
models.py

@ -4,6 +4,9 @@ from openerp.tools.safe_eval import safe_eval
from openerp.addons.email_template.email_template import mako_template_env from openerp.addons.email_template.email_template import mako_template_env
import copy import copy
from openerp.tools.translate import _ from openerp.tools.translate import _
from datetime import date, datetime, timedelta
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
class mail_wall_widgets_widget(models.Model): class mail_wall_widgets_widget(models.Model):
_name = 'mail.wall.widgets.widget' _name = 'mail.wall.widgets.widget'
@ -22,7 +25,6 @@ class mail_wall_widgets_widget(models.Model):
], help=''' ], help='''
Slice - use "domain" for total and "won_domain" for target Slice - use "domain" for total and "won_domain" for target
'''), '''),
'description': old_fields.text('Description', translate=True), 'description': old_fields.text('Description', translate=True),
'group_ids': old_fields.many2many('res.groups', relation='mail_wall_widgets_widget_group', column1='widget_id', column2='group_id', string='Groups', help="User groups to show widget"), 'group_ids': old_fields.many2many('res.groups', relation='mail_wall_widgets_widget_group', column1='widget_id', column2='group_id', string='Groups', help="User groups to show widget"),
'model_id': old_fields.many2one('ir.model', string='Model', help='The model object for the field to evaluate'), 'model_id': old_fields.many2one('ir.model', string='Model', help='The model object for the field to evaluate'),
@ -52,6 +54,7 @@ Slice - use "domain" for total and "won_domain" for target
'sequence': old_fields.integer('Sequence', help='Sequence number for ordering'), 'sequence': old_fields.integer('Sequence', help='Sequence number for ordering'),
} }
precision = fields.Float('Precision', help='round(Value/precision) * precision. E.g. 12345,333333 will be rounded to 12345,33 for precision=0.01, and to 12000 for precision=1000', default=0.01) precision = fields.Float('Precision', help='round(Value/precision) * precision. E.g. 12345,333333 will be rounded to 12345,33 for precision=0.01, and to 12000 for precision=1000', default=0.01)
agenda = fields.Boolean('Agenda', help='Split records by date: overdue, today, tomorrow, later')
_defaults = { _defaults = {
'active': True, 'active': True,
'cache': False, 'cache': False,
@ -81,10 +84,49 @@ Slice - use "domain" for total and "won_domain" for target
obj = self.env[self.model_id.model] obj = self.env[self.model_id.model]
if self.type == 'list': if self.type == 'list':
total_count = obj.search_count(domain) total_count = obj.search_count(domain)
groups = [{'test': lambda r: True}]
if self.agenda:
today = date.today()
tomorrow = today + timedelta(days=1)
def r2date(r):
d = getattr(r, field_date_name)
d = datetime.strptime(d, self.field_date_id.ttype=='date' and DEFAULT_SERVER_DATE_FORMAT or DEFAULT_SERVER_DATETIME_FORMAT)
d = d.date()
return d
groups = [
{
'label': _('Overdue'),
'class': 'overdue',
'test': lambda r: r2date(r) < today,
'mandatory': False,
},
{
'label': _('Today'),
'class': 'today',
'test': lambda r: r2date(r) == today,
'mandatory': True,
},
{
'label': _('Tomorrow'),
'class': 'tomorrow',
'test': lambda r: r2date(r) == tomorrow,
'mandatory': False,
},
{
'label': _('Later'),
'class': 'later',
'test': lambda r: r2date(r) == later,
'mandatory': False,
},
]
for g in groups:
g['lines'] = []
res.update({ res.update({
'more': self.limit and self.limit < total_count, 'more': self.limit and self.limit < total_count,
'total_count': total_count, 'total_count': total_count,
'lines': [],
'agenda': self.agenda,
'groups': groups,
}) })
for r in obj.search(domain, limit=self.limit, order=self.order): for r in obj.search(domain, limit=self.limit, order=self.order):
mako = mako_template_env.from_string(tools.ustr(self.content)) mako = mako_template_env.from_string(tools.ustr(self.content))
@ -102,7 +144,12 @@ Slice - use "domain" for total and "won_domain" for target
r_json['current'] = getattr(r, self.value_field_id.name) r_json['current'] = getattr(r, self.value_field_id.name)
if self.value_field_monetary: if self.value_field_monetary:
r_json['monetary'] = 1 r_json['monetary'] = 1
res['lines'].append(r_json)
for g in groups:
if g['test'](r):
g['lines'].append(r_json)
break
for g in groups:
del g['test']
elif self.type == 'funnel': elif self.type == 'funnel':
stage_ids = [] # [key] stage_ids = [] # [key]
for group in obj.read_group(domain, [], [self.stage_field_id.name]): for group in obj.read_group(domain, [], [self.stage_field_id.name]):

24
static/src/css/main.css

@ -32,3 +32,27 @@
.oe_open_record:hover, .oe_open_record_list_funnel:hover{ .oe_open_record:hover, .oe_open_record_list_funnel:hover{
cursor:pointer; cursor:pointer;
} }
.openerp .oe_mail_wall .list_group{
margin-bottom:0.6em;
}
.openerp .oe_mail_wall .list_group .group_label{
padding: 0 0 0.1em 1em;
font-size:120%;
}
.openerp .oe_mail_wall .list_group.overdue .group_label{
color:red;
}
.openerp .oe_mail_wall .list_group.today .group_label{
font-weight:bold;
}
.openerp .oe_mail_wall .list_group.later .group_label{
color:grey;
}
.openerp .oe_mail_wall .list_group .empty_list{
background-color:white;
padding:10px 0;
color:grey;
text-align:center;
}

4
static/src/js/main.js

@ -19,11 +19,11 @@ openerp.mail_wall_widgets = function(instance) {
this.do_action({ this.do_action({
'name': _t('Details'), 'name': _t('Details'),
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'res_model': $t.parent().attr('data-model'),
'res_model': $t.parent().parent().attr('data-model'),
'res_id': parseInt($t.attr('data-id')), 'res_id': parseInt($t.attr('data-id')),
'target': 'current', 'target': 'current',
'views': [[false, 'form'],[false, 'list']], 'views': [[false, 'form'],[false, 'list']],
'domain': $t.parent().attr('data-domain'),
'domain': $t.parent().parent().attr('data-domain'),
}) })
}, },
'click .oe_open_record_list': function(event){ 'click .oe_open_record_list': function(event){

11
static/src/xml/main.xml

@ -13,7 +13,11 @@
<t t-if="info.model=='mail.wall.widgets.widget' and info.data.type == 'list'"> <t t-if="info.model=='mail.wall.widgets.widget' and info.data.type == 'list'">
<div class="oe_table oe_goals_list" t-att-data-model="info.data.model" t-att-data-domain="info.data.domain"> <div class="oe_table oe_goals_list" t-att-data-model="info.data.model" t-att-data-domain="info.data.domain">
<div t-foreach="info.data.lines" t-as="line" t-attf-class="oe_row oe_goal_outer_box oe_open_record record #{line.state == 'reached' ? 'oe_goal_reached' : ''} #{line.display_mode != 'progress' ? 'oe_no_progress' : ''}" t-att-data-id="line.id" >
<div t-foreach="info.data.groups" t-as="group" t-if="group.lines.length or group.mandatory" t-attf-class="list_group #{group.class or ''}">
<div t-if="group.label" class="group_label">
<t t-esc="group.label"/>
</div>
<div t-foreach="group.lines" t-as="line" t-attf-class="oe_row oe_goal_outer_box oe_open_record record #{line.state == 'reached' ? 'oe_goal_reached' : ''} #{line.display_mode != 'progress' ? 'oe_no_progress' : ''}" t-att-data-id="line.id" >
<t t-if="line.display_mode == 'progress'"> <t t-if="line.display_mode == 'progress'">
<div class="oe_goal_progress_background"></div> <div class="oe_goal_progress_background"></div>
<div class="oe_goal_progress" t-attf-style="#{line.display_mode == 'progress' ? 'width: '+line.completeness+'%;' : 'width:0;'}"></div> <div class="oe_goal_progress" t-attf-style="#{line.display_mode == 'progress' ? 'width: '+line.completeness+'%;' : 'width:0;'}"></div>
@ -23,6 +27,11 @@
<span t-att-title="line.description"><t t-raw="line.name" /></span> <span t-att-title="line.description"><t t-raw="line.name" /></span>
</div> </div>
</div> </div>
<t t-if="!group.lines.length">
<div class="empty_list">No records</div>
</t>
</div>
<div t-if="info.data.more" class="oe_row oe_goal_outer_box oe_open_record_list"> <div t-if="info.data.more" class="oe_row oe_goal_outer_box oe_open_record_list">
<div class="oe_goal_progress_background"></div> <div class="oe_goal_progress_background"></div>
<div class="more"> <div class="more">

3
views.xml

@ -58,7 +58,7 @@
<field name="model_id" class="oe_inline"/> <field name="model_id" class="oe_inline"/>
<field name="domain" /> <field name="domain" />
<field name="won_domain" attrs="{'invisible':[('type', 'not in', ['funnel','slice'])]}" /> <field name="won_domain" attrs="{'invisible':[('type', 'not in', ['funnel','slice'])]}" />
<field name="field_date_id"/>
<field name="field_date_id" attrs="{'required':[('agenda','=',True)]}"/>
<field name="start_date"/> <field name="start_date"/>
<field name="end_date"/> <field name="end_date"/>
</group> </group>
@ -73,6 +73,7 @@
<field name="content" attrs="{'invisible':[('type', 'not in', ['list'])]}"/> <field name="content" attrs="{'invisible':[('type', 'not in', ['list'])]}"/>
<field name="limit" attrs="{'invisible':[('type', 'not in', ['list'])]}" class="oe_inline"/> <field name="limit" attrs="{'invisible':[('type', 'not in', ['list'])]}" class="oe_inline"/>
<field name="order" attrs="{'invisible':[('type', 'not in', ['list'])]}" class="oe_inline"/> <field name="order" attrs="{'invisible':[('type', 'not in', ['list'])]}" class="oe_inline"/>
<field name="agenda" attrs="{'invisible':[('type', 'not in', ['list'])]}" class="oe_inline"/>
</group> </group>
<group string="Other"> <group string="Other">
<field name="sequence" class="oe_inline"/> <field name="sequence" class="oe_inline"/>

Loading…
Cancel
Save