我在对 Menu 的叶子部分的分配请求进行一些简单的计算时遇到了问题。我在视图 xml 文件中添加了一个按钮:
<record model="ir.ui.view" id="view_edit_holiday_allocation_form">
<field name="name">allocation</field>
<field name="model">hr.holidays</field>
<field name="inherit_id" ref="hr_holidays.allocation_leave_new"/>
<field name="arch" type="xml">
<data>
<field name="department_id" position="after">
<field name="monthly_quota"/>
<field name="refusal_date"/>
<button name="calc_monthly_quota" type="object" string="Calculate Monthly Quota"/>
</field>
</data>
</field>
</record>
并在 .py 文件中
class hr_holidays(osv.osv):
_inherit = "hr.holidays"
def calc_monthly_quota(self, cr, uid, ids, context=None):
for record in self.browse(cr, uid, ids):
if record.state :
self.write(cr, uid, [record.id],{'monthly_quota':\
record.number_of_days_temp/12})
return True
_columns = {
"monthly_quota": fields.float("Monthly Quota", readonly=True,
states={'draft':[('readonly',False)]}, help="If monthly leave \
limit is more then xero then employee can not take leave more \
then monthly allocation in total allocation. If monthly quota \
is zero user can take leave as per his allocation limit."),
"refusal_date" : fields.date('Date of Refusal'),
"create_date" : fields.date('Create Date'),
}
在这里我只想计算点击按钮的每月叶子配额。假设如果我在分配(number_of_days_temp)中输入 12,那么我应该每月获得 1。除了记录的状态外,每件事都按预期工作。单击按钮后,记录状态从“提交”即草稿变为“批准”即确认。在保存表单之前,表单的状态会自行改变,理想情况下,表单的状态应该只在我们点击保存按钮后才会改变。我已经阅读了openerp 7.0 文档 ,它说
After a button has been clicked, the record should always be reloaded.
在不保存表单的情况下,我仍然没有得到更改表单状态所需的内容。任何评论都非常值得赞赏。