[IMP] project_timesheet: code cleanup for project kanban view

bzr revid: rco@openerp.com-20120509081955-2p5u2z4xkycbmpdd
This commit is contained in:
Raphael Collet 2012-05-09 10:19:55 +02:00
parent 479d600986
commit 85e4f9c4f2
2 changed files with 66 additions and 86 deletions

View File

@ -29,41 +29,34 @@ from tools.translate import _
class project_project(osv.osv):
_inherit = 'project.project'
def _to_invoice(self, cr, uid, ids,field_name, arg, context=None):
def _to_invoice(self, cr, uid, ids, field_name, arg, context=None):
account_analytic_line = self.pool.get("account.analytic.line")
res = {}
aal_pool = self.pool.get("account.analytic.line")
for project in self.browse(cr,uid,ids,context=context):
line_ids = aal_pool.search(cr, uid, [('account_id','=',project.analytic_account_id.id),('to_invoice','=',1),('invoice_id','=',False)])
line_ids = account_analytic_line.search(cr, uid, [('account_id', '=', project.analytic_account_id.id), ('to_invoice','=',1), ('invoice_id','=',False)])
lines = account_analytic_line.browse(cr, uid, line_ids, context)
res[project.id] = {
'amt_to_invoice': 0.0,
'hrs_to_invoice': 0.0,
}
if line_ids:
amt_to_invoice,hrs_to_invoice = 0.0,0.0
for line in aal_pool.browse(cr,uid,line_ids,context=context):
amt_to_invoice += line.amount
hrs_to_invoice += line.unit_amount
res[project.id]['amt_to_invoice'] = (amt_to_invoice)*-1
res[project.id]['hrs_to_invoice'] = hrs_to_invoice
'amt_to_invoice': sum(line.amount for line in lines),
'hrs_to_invoice': sum(line.unit_amount for line in lines),
}
return res
def _timesheet_count(self, cr, uid, ids, field_name, arg, context=None):
res={}
aal_pool=self.pool.get('account.analytic.line')
for project in self.browse(cr, uid, ids, context=context):
timesheet = aal_pool.search(cr, uid, [("account_id","=", project.analytic_account_id.id)])
res[project.id] = len(timesheet)
account_analytic_line = self.pool.get('account.analytic.line')
res = {}
for project in self.browse(cr, uid, ids, context):
line_ids = account_analytic_line.search(cr, uid, [('account_id', '=', project.analytic_account_id.id)])
res[project.id] = len(line_ids)
return res
_columns = {
'use_timesheets' : fields.boolean('Timesheets',help = "If you check this field timesheets appears in kanban view"),
'amt_to_invoice': fields.function(_to_invoice,string="Amount to Invoice",multi="sums"),
'hrs_to_invoice': fields.function(_to_invoice,string="Hours to Invoice",multi="sums"),
'timesheet_count': fields.function(_timesheet_count , type='integer',string="Issue"),
'use_timesheets': fields.boolean('Timesheets', help="Check this field if this project manages timesheets"),
'amt_to_invoice': fields.function(_to_invoice, string="Amount to Invoice", multi="sums"),
'hrs_to_invoice': fields.function(_to_invoice, string="Time to Invoice", multi="sums"),
'timesheet_count': fields.function(_timesheet_count, type='integer', string="Issue"),
}
_defaults = {
'use_timesheets' : True,
'use_timesheets': True,
}
def onchange_partner_id(self, cr, uid, ids, part=False, context=None):
@ -77,40 +70,27 @@ class project_project(osv.osv):
res['value'].update({'to_invoice': factor_id})
return res
def getAnalyticJournal(self, cr, uid, context=None):
md = self.pool.get('ir.model.data')
try:
result = md.get_object_reference(cr, uid, 'hr_timesheet', 'analytic_journal')
return result[1]
except ValueError:
pass
return False
def open_timesheets(self, cr, uid, ids, context=None):
#Open the View for the Timesheet of the project
"""
This opens Timesheets views
@return :Dictionary value for timesheet view
"""
if context is None:
context = {}
if ids:
project = self.browse(cr, uid, ids[0], context=context)
context = dict(context,
search_default_account_id = project.analytic_account_id.id,
default_account_id = project.analytic_account_id.id,
default_journal_id = self.getAnalyticJournal(cr, uid, context)
)
""" open Timesheets view """
project = self.browse(cr, uid, ids[0], context)
try:
journal_id = self.pool.get('ir.model.data').get_object(cr, uid, 'hr_timesheet', 'analytic_journal').id
except ValueError:
journal_id = False
view_context = {
'search_default_account_id': [project.analytic_account_id.id],
'default_account_id': project.analytic_account_id.id,
'default_journal_id': journal_id,
}
return {
'name': _('Bill Tasks Works'),
'context': context,
'view_type': 'form',
'view_mode': 'tree,form',
'res_model': 'account.analytic.line',
'view_id': False,
'type': 'ir.actions.act_window',
'nodestroy': True
}
'type': 'ir.actions.act_window',
'name': _('Bill Tasks Works'),
'res_model': 'account.analytic.line',
'view_type': 'form',
'view_mode': 'tree,form',
'context': view_context,
'nodestroy': True,
}
project_project()

View File

@ -7,12 +7,11 @@
<field name="type">form</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='use_tasks']" position='after'>
<field name="use_timesheets"/>
<field name="amt_to_invoice" invisible="True"/>
<field name="hrs_to_invoice" invisible="True"/>
</xpath>
<field name="use_tasks" position='after'>
<field name="use_timesheets"/>
<field name="amt_to_invoice" invisible="True"/>
<field name="hrs_to_invoice" invisible="True"/>
</field>
<field name="warn_customer" position="after">
<group colspan="4" col="4">
<separator colspan="4" string="Invoicing Data"/>
@ -31,31 +30,32 @@
<field name="type">kanban</field>
<field name="inherit_id" ref="project.view_project_kanban"/>
<field name="arch" type="xml">
<field name="use_tasks" position="after">
<field name="use_timesheets" context="{'search_default_account_id': project_id, 'default_account_id': project_id}"/>
<field name="use_tasks" position="after">
<field name="use_timesheets"/>
<field name="timesheet_count"/>
<field name="currency_id"/>
<field name="currency_id"/>
<field name="partner_id"/>
</field>
<xpath expr="//div[@id='list']" position="inside">
<t t-if="record.use_timesheets.raw_value">
<a id="3" name="open_timesheets" class="oe_project_buttons" type="object"><t t-if="record.timesheet_count.value &lt;= 1">Timesheet</t><t t-if="record.timesheet_count.value &gt; 1">Timesheets</t>(<t t-esc="record.timesheet_count.value"/>)</a>
</t>
</xpath>
<xpath expr="//tr[@id='deadline']" position="before">
<tr >
<th align="left">Amount to invoice</th>
<td align="left">
<field name="amt_to_invoice"/> <t t-esc="record.currency_id.raw_value[1].split(' ')[1][1]"/>
</td>
</tr>
<tr>
<th align="left">Hours to Invoice</th>
<td align="left">
<field name="hrs_to_invoice"/> h
</td>
</tr>
</xpath>
<xpath expr="//div[@id='list']" position="inside">
<a t-if="record.use_timesheets.raw_value" class="oe_project_buttons"
id="3" name="open_timesheets" type="object">Timesheets(<field name="timesheet_count"/>)</a>
</xpath>
<xpath expr="//tr[@id='deadline']" position="before">
<t t-if="record.partner_id.raw_value">
<tr>
<th align="left">Amount to invoice</th>
<td align="left">
<field name="amt_to_invoice"/> <t t-esc="record.currency_id.raw_value[1].split(' ')[1][1]"/>
</td>
</tr>
<tr>
<th align="left">Time to Invoice</th>
<td align="left">
<field name="hrs_to_invoice"/> <field name="company_uom_id"/>
</td>
</tr>
</t>
</xpath>
</field>
</record>