add next_action and next_action_date functional fields
This commit is contained in:
parent
ca626189d4
commit
4a6445c184
36
activity.py
36
activity.py
|
@ -1,5 +1,7 @@
|
|||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from datetime import datetime
|
||||
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.pyson import Eval
|
||||
|
@ -18,17 +20,49 @@ class SaleOpportunity:
|
|||
}, depends=['party'])
|
||||
last_action_date = fields.Function(fields.DateTime('Last Action'),
|
||||
'get_last_action_date')
|
||||
next_action_date = fields.Function(fields.DateTime('Next Action Date',
|
||||
format="%H:%M"),
|
||||
'get_next_action_fields')
|
||||
next_action = fields.Function(fields.Many2One('activity.activity',
|
||||
'Next Activity'),
|
||||
'get_next_action_fields')
|
||||
|
||||
def get_last_action_date(self, name=None):
|
||||
if not self.activities:
|
||||
return None
|
||||
Activity = Pool().get('activity.activity')
|
||||
act = Activity.search([
|
||||
('resource', '=', 'sale.opportunity,%s' % self.id)
|
||||
('resource', '=', 'sale.opportunity,%s' % self.id),
|
||||
('state', '=', 'held'),
|
||||
],
|
||||
order=[('dtstart', 'desc')], limit=1)
|
||||
return act and act[0].dtstart or None
|
||||
|
||||
@classmethod
|
||||
def get_next_action_fields(cls, opportunities, names):
|
||||
pool = Pool()
|
||||
Activity = pool.get('activity.activity')
|
||||
|
||||
today = datetime.now()
|
||||
res = dict((n, {}.fromkeys([o.id for o in opportunities]))
|
||||
for n in names)
|
||||
for opportunity in opportunities:
|
||||
if not opportunity.activities:
|
||||
continue
|
||||
activities = Activity.search([
|
||||
('resource', '=', 'sale.opportunity,%s' % opportunity.id),
|
||||
('state', '=', 'planned'),
|
||||
('dtstart', '>=', today),
|
||||
],
|
||||
order=[('dtstart', 'asc')], limit=1)
|
||||
if not activities:
|
||||
continue
|
||||
if 'next_action_date' in names:
|
||||
res['next_action_date'][opportunity.id] = activities[0].dtstart
|
||||
if 'next_action' in names:
|
||||
res['next_action'][opportunity.id] = activities[0].id
|
||||
return res
|
||||
|
||||
|
||||
class Activity:
|
||||
__name__ = 'activity.activity'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--The COPYRIGHT file at the top level of this repository
|
||||
contains the full copyright notices and license terms. -->
|
||||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/notebook"
|
||||
|
@ -15,6 +15,9 @@ contains the full copyright notices and license terms. -->
|
|||
position="after">
|
||||
<label name="last_action_date"/>
|
||||
<field name="last_action_date"/>
|
||||
<label name="next_action_date"/>
|
||||
<field name="next_action_date"/>
|
||||
<label name="next_action"/>
|
||||
<field name="next_action"/>
|
||||
</xpath>
|
||||
|
||||
</data>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--The COPYRIGHT file at the top level of this repository
|
||||
contains the full copyright notices and license terms. -->
|
||||
<?xml version="1.0"?>
|
||||
<!-- The COPYRIGHT file at the top level of this repository contains the full
|
||||
copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath
|
||||
expr="/tree/field[@name='probability']"
|
||||
position="after">
|
||||
<field name="last_action_date"/>
|
||||
<field name="next_action_date"/>
|
||||
<field name="next_action"/>
|
||||
</xpath>
|
||||
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue