I try to make this 2 buttons on the hr.timesheet.sheet view.
My hr_timesheet.py looks like this:
# -*- coding: utf-8 -*-
import openerp
from openerp.osv import fields, osv
class hr_timesheet_sheet(osv.osv):
_inherit = ["hr_timesheet_sheet.sheet"]
_columns = {
'testfield1': fields.char(''),
'project_field': fields.many2one('project.project', 'name'),
}
class project(osv.osv):
_inherit = "project.project"
def test(self, cr, uid, vals, context=None):
return super(project.project, self)._get_attached_docs(cr, uid, vals, context=context)
def attachment_tree_view(self, cr, uid, ids, context):
task_ids = self.pool.get('project.task').search(cr, uid, [('project_id', 'in', ids)])
domain = [
'|',
'&', ('res_model', '=', 'project.project'), ('res_id', 'in', ids),
'&', ('res_model', '=', 'project.task'), ('res_id', 'in', task_ids)]
res_id = ids and ids[0] or False
return {
'name': _('Attachments'),
'domain': domain,
'res_model': 'ir.attachment',
'type': 'ir.actions.act_window',
'view_id': False,
'view_mode': 'kanban,tree,form',
'view_type': 'form',
'limit': 80,
'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, res_id)
}
_columns = {
'doc_count': fields.function(test, string="Number of documents attached",type='integer')
}
My XML file like this: hr_timesheet_view_test.xml:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="hr_timesheet_sheet_tree_test_buttons" model="ir.ui.view">
<field name="name">hr.test.button.tree</field>
<field name="model">hr_timesheet_sheet.sheet</field>
<field name="inherit_id" ref="hr_timesheet_sheet.hr_timesheet_sheet_form"/> <!-- "hr_presence.hr_timesheet_sheet_form_presence" -->
<field name="arch" type="xml">
<xpath expr="//notebook" position="before">
<button class="oe_inline oe_stat_button" name="attachment_tree_view" type="object" icon="fa-files-o">
<field string="Documents" name="doc_count" widget="statinfo"/>
</button>
</xpath>
</field>
</record>
</data>
</openerp>
This is not working , I get the error that the field : doc_count does not exist.