我面臨一個問題,要對菜單中葉子部分的分配請求做一些簡單的計算。 我在視圖xml文件添加一個按鈕:如何使用OEv7中的按鈕進行計算?
<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 documentation 有它說,
After a button has been clicked, the record should always be reloaded.
我沒仍然得到需要什麼來改變表單的狀態,但不保存。 任何意見都非常可觀。
沒有得到的回答是,其實你沒有得到什麼,我問了.... 我做了計算後的狀態說表單更改爲「批准」,但保存表單後應該更改。 –
我想你需要在hr_holidays表的狀態中搜索,因爲他們提到了提交,批准,驗證,雙重驗證等狀態。我認爲你的問題是你沒有返回正確的狀態....讓我知道如果你得到解決方案...謝謝 – vaibhav