我在菜单中的leaves部分对分配请求进行一些简单计算时遇到问题。 我在视图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'),
}
在这里,我只想计算点击按钮的每月叶子配额。 假设如果我在分配中输入12(number_of_days_temp),那么我应该每月获得1。 除了记录的状态之外,每件事情都按预期工作得很好。 点击按钮后,记录的状态从“提交”变为“草稿”,即“批准”,即确认。 在保存表单之前,表单的状态会自行更改,理想情况下,表单的状态应该只在我们点击“保存”按钮后才会更改。 我看过openerp 7.0 documentation 它说那个
After a button has been clicked, the record should always be reloaded.
我还没有得到更改表单状态而不保存它所需的内容。 任何评论都非常值得赞赏。
答案 0 :(得分:0)
def calc_monthly_quota(self, cr, uid, ids, context=None):
for record in self.browse(cr, uid, ids):
if record.state :
result=record.number_of_days_temp/12
return self.write(cr, uid, [record.id],{'monthly_quota':result,})
我试过这个,这很好用
答案 1 :(得分:0)
我向openerp发送支持电子邮件和视频以帮助我解决这个问题,他们发送邮件作为回复,
I have tested your issue by applying your code at my end and the reason
that the state is 'To Approve' before you save the record is: In Allocation
Request , whenever a record(allocation request) is created , it will be
directly in 'To Approve' state as per the workflow.
According to workflow, an allocation request when created is always in
state confirm i.e 'To Approve' because a request after creating is to be
submited only so it is directly passed to 'To Approve' state.
Now as in your case, when you click on the button 'Calculate Monthly
Quota',first that record is created and saved in the database to perform
further action on that record and then after browsing that record from
database then you write to that record. So even if you don't click on Save,
the record is actually saved to your database and as the record is created
it will be transfered to state 'To Approve' as per the workflow of holidays.
我很抱歉这么晚回复,但这是我从支持中得到的答复。谢谢