콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
5185 화면

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:



아바타
취소
베스트 답변

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.

아바타
취소
작성자

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.

작성자

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

작성자 베스트 답변

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.

아바타
취소

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.

작성자

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.

작성자

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.

작성자

make the hr_timesheet.py to project.py ?

and make the hr_timesheet_view_test.xml to project_view.xml?

작성자

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

관련 게시물 답글 화면 활동
0
9월 19
4185
1
11월 16
3583
2
7월 16
4631
1
6월 16
3297
0
6월 16
3607