我几乎尝试了所有可能的组合而没有成功。我设计了一个树视图:
<record model="ir.ui.view" id="simple_timesheet_tree">
<field name="name">Simple time sheet</field>
<field name="model">account.analytic.line</field>
<field name="arch" type="xml">
<tree editable="top" string="Timesheet Activities" default_order='project_id'>
<field name="name"/>
<field name="project_id" required="1"/>
<field name="task_id" required="1" context="{'default_project_id': project_id}" domain="[('project_id', '=', project_id)]"/>
<button
type="object"
name="action_clone_timesheetentry"
icon="fa-play-circle"
string=""
groups="base.group_user"
attrs="{'invisible': [('task_id', '=', True)], 'tree_invisible': [('task_id', '=', True)]}">
</button>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="act_odoo_simple_timesheet">
<field name="name">Sime time sheet</field>
<field name="res_model">account.analytic.line</field>
<field name="domain">[('project_id', '!=', False)]</field>
<field name="context">{"search_default_today":1}</field>
<field name="search_view_id" ref="hr_timesheet.hr_timesheet_line_search"/>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
Click to record activities.
</p><p>
You can register and track your workings hours by project every
day. Every time spent on a project will become a cost and can be re-invoiced to
customers if required.
</p>
</field>
</record>
<record model="ir.actions.act_window.view" id="act_odoo_simple_timesheet_view_tree">
<field name="view_mode">tree</field>
<field name="sequence">1</field>
<field name="view_id" ref="odoo_simple_timesheet.simple_timesheet_tree"/>
<field name="act_window_id" ref="act_odoo_simple_timesheet"/>
</record>
<menuitem name="Simple timesheet" action="act_odoo_simple_timesheet" id="menu_simple_timesheet" parent="project.menu_project_management" sequence="-1"/>
当克隆时间表时出现问题,然后视图不刷新,所以我写了一个像这样的python动作:
@api.multi
def action_clone_timesheetentry(self):
copy = self.copy()
# model_obj = self.env['ir.model.data']
# module_name = 'odoo_simple_timesheet'
# view_name = 'simple_timesheet_tree' # Script error
# data_id = model_obj._get_id(module_name, view_name)
# view_id = model_obj.browse(data_id).res_id
view_id = self.env.ref('odoo_simple_timesheet.simple_timesheet_tree').id
return {
'_name': _('Simple time sheet'),
'view_type': 'tree',
'view_mode': 'tree',
'res_model': 'account.analytic.line',
'type': 'ir.actions.act_window',
'target': 'main',
# 'view_id': False,
# 'view_id': view_id,
# "views": [[view_id, "tree"], [False, "form"]],
'view_id': view_id,
'nodestroy' : True,
}
# return {
# 'type': 'ir.actions.client',
# 'tag': 'reload',
# }
唯一有效的是重新加载整个窗口的ir.actions.client
,这不是我想要的,我只想重新加载当前视图...
请帮助,我已被困在这里好几个小时......
修改
它似乎与树视图中按钮的错误有关。
如果按钮中没有字符串,则web.assets_common.js
中的这一行会引发错误:
r.push(dict['field_value'].attrs.string || dict['fields'][dict['field'].attrs.name].string)
由于空字符串而dict['field_value'].attrs.string
为false且dict['fields'][dict['field'].attrs.name]
不存在,因此尝试访问未定义的.string
。
所以我把按钮改为:
<button
type="object"
name="action_clone_timesheetentry"
icon="fa-play-circle"
string="&zwnj;"
groups="base.group_user"
</button>
然后错误出现在另一行:
(dict['class']) + ' ' + (dict['rank']) + ' ' + ((dict['fields'][dict['field'].attrs.name].type === 'float') || (dict['fields'][dict['field'].attrs.name].type === 'integer') || (dict['fields'][dict['field'].attrs.name].type === 'monetary')? 'oe_number' : '')
再次dict['fields'][dict['field'].attrs.name]
不存在:dict['field'].attrs.name === action_clone_timesheetentry
显然没有名为action_clone_timesheetentry
的字段,因此它试图获取未定义的.type
... Don& #39;知道如何从这里继续......也许:
有没有办法创建虚拟字段?