[IMP] crm: salesteams, add target_invoice_duration attribute

bzr revid: chm@openerp.com-20130416134520-znocwh73q6x3nk1r
This commit is contained in:
Christophe Matthieu 2013-04-16 15:45:20 +02:00
parent 7394f41f83
commit f6b6035922
2 changed files with 56 additions and 14 deletions

View File

@ -19,8 +19,10 @@
#
##############################################################################
from datetime import datetime
from datetime import date
from dateutil.relativedelta import relativedelta
from openerp.osv import osv, fields
from openerp.tools.translate import _
class sale_order(osv.osv):
@ -35,14 +37,35 @@ class sale_order(osv.osv):
class crm_case_section(osv.osv):
_inherit = 'crm.case.section'
def _get_sum_month_invoice(self, cr, uid, ids, field_name, arg, context=None):
def _get_sum_duration_invoice(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, 0)
obj = self.pool.get('account.invoice.report')
when = datetime.today()
for section_id in ids:
invoice_ids = obj.search(cr, uid, [("section_id", "=", section_id), ('state', 'not in', ['draft', 'cancel']), ('year', '=', when.year), ('month', '=', when.month > 9 and when.month or "0%s" % when.month)], context=context)
previous_month = {
"monthly": 0,
"semesterly": 2,
"semiannually": 5,
"annually": 11
}
for section in self.browse(cr, uid, ids, context=context):
when = date.today().replace(day=1) + relativedelta(months=-previous_month[section.target_invoice_duration])
invoice_ids = obj.search(cr, uid, [("section_id", "=", section.id), ('state', 'not in', ['draft', 'cancel']), ('date', '>=', when)], context=context)
for invoice in obj.browse(cr, uid, invoice_ids, context=context):
res[section_id] += invoice.price_total
res[section.id] += invoice.price_total
return res
def _get_target_invoice_duration_txt(self, cr, uid, ids, field_name, arg, context=None):
res = dict.fromkeys(ids, "")
duration_txt = {
"monthly": _("this month"),
"semesterly": _("this semester"),
"semiannually": _("this semi"),
"annually": _("this year")
}
for section in self.browse(cr, uid, ids, context=context):
res[section.id] = duration_txt[section.target_invoice_duration]
return res
_columns = {
@ -55,11 +78,19 @@ class crm_case_section(osv.osv):
'invoice_ids': fields.one2many('account.invoice', 'section_id',
string='Invoices', readonly=True,
domain=[('state', 'not in', ['draft', 'cancel'])]),
'sum_month_invoice': fields.function(_get_sum_month_invoice,
string='Total invoiced this month',
'sum_duration_invoice': fields.function(_get_sum_duration_invoice,
string='Total invoiced',
type='integer', readonly=True),
'forcasted': fields.integer(string='Total forcasted'),
'target_invoice': fields.integer(string='Target Invoice'),
'target_invoice_duration': fields.selection([("monthly", "Monthly"), ("semesterly", "Semesterly"), ("semiannually", "Semiannually"), ("annually", "Annually")],
string='Report duration view', required=True),
'target_invoice_duration_txt': fields.function(_get_target_invoice_duration_txt,
string='Duration',
type="string", readonly=True),
}
_defaults = {
'target_invoice_duration': "monthly",
}
def action_forcasted(self, cr, uid, id, value, context=None):

View File

@ -213,9 +213,12 @@
<field name="inherit_id" ref="crm.crm_case_section_view_form"/>
<field name="arch" type="xml">
<data>
<field name="active" position="before">
<field name="target_invoice"/>
</field>
<xpath expr="//notebook" position="before">
<group col="4">
<field name="target_invoice_duration" widget="radio"/>
<field name="target_invoice"/>
</group>
</xpath>
</data>
</field>
</record>
@ -230,9 +233,10 @@
<field name="quotation_ids"/>
<field name="sale_order_ids"/>
<field name="invoice_ids"/>
<field name="sum_month_invoice"/>
<field name="sum_duration_invoice"/>
<field name="forcasted"/>
<field name="target_invoice"/>
<field name="target_invoice_duration_txt"/>
</xpath>
<xpath expr="//div[@class='oe_items_list']" position="inside">
<a name="%(action_quotations_salesteams)d" type="action">
@ -253,8 +257,15 @@
</xpath>
<xpath expr="//div[@class='oe_items_list']" position="after">
<div class="oe_center">
<div class="oe_justgage" style="width:160px; height: 120px;" t-att-data-value="record.sum_month_invoice.raw_value" t-att-data-max="record.target_invoice.raw_value" data-label="this month">Invoiced</div>
<div class="oe_justgage" style="width:160px; height: 120px;" t-att-data-value="record.forcasted.raw_value" t-att-data-max="record.target_invoice.raw_value" data-label="this month" data-action="action_forcasted">Forcasted</div>
<div class="oe_justgage" style="width:160px; height: 120px;"
t-att-data-value="record.sum_duration_invoice.raw_value"
t-att-data-max="record.target_invoice.raw_value"
t-att-data-label="record.target_invoice_duration_txt.raw_value">Invoiced</div>
<div class="oe_justgage" style="width:160px; height: 120px;"
t-att-data-value="record.forcasted.raw_value"
t-att-data-max="record.target_invoice.raw_value"
t-att-data-label="record.target_invoice_duration_txt.raw_value"
data-action="action_forcasted">Forcasted</div>
</div>
</xpath>
</data>