Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
5150 Vistas

I try to inherit this button in hr.timesheet.sheet.form:

<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>

On my python I have this:

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)
_columns = {
'doc_count': fields.function(
test, string="Number of documents attached", type='integer'
)
}

Now I get all time an error. What am I making wrong with the import of the function get_attached_docs ? How can I import this simple function to my field? and then put it on the button?


I want this 2 buttons from project.project on the hr.timesheet.sheet form with the same links behind that in project:



Avatar
Descartar
Mejor respuesta

In your .py file you have to define the function that is called by the button "attachment_tree_view"

EDITED:

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):
tasks_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.project'),('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')
 }

...


With this you inherit original function, now just modify as you need (remember to set super if you modify before or after the original functions returns the values).


Kind regards.

Avatar
Descartar
Autor

How can I inherit this function from project.project - project.py to my module ?

I've modified my answer. see if this fits your needs.

Autor

How Can I display that in the hr.timesheet.sheet view? I want the button there, not in project.project. :)

Autor Mejor respuesta

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.

Avatar
Descartar

in your py file, you define field doc_count for model 'project.project'

in ypur view you have set model hr_timesheet_sheet.sheet

Kind regards.

Autor

now when I try to install that I get this error: attendance_count does not exist.

I don't have a field like that.

If I change the model in view to project.project it give me this error. I want this button in the timesheet view.

in py.file remove 'project.project' inherited class and define doc_count and the functions in hr_timesheet_sheet class.

the modify functions to match your requeriments.

kind regards.

Autor

I have made that but it's not working . I don't understand how I can use this buttons in an other model view.

you have to redefine, the views and py files in your model.

Autor

make the hr_timesheet.py to project.py ?

and make the hr_timesheet_view_test.xml to project_view.xml?

Autor

please can you give me the right example that this works...

Publicaciones relacionadas Respuestas Vistas Actividad
0
sept 19
4167
1
nov 16
3569
2
jul 16
4617
1
jun 16
3285
0
jun 16
3598