2013-06-13 33 views
0

我面臨一個問題,要對菜單中葉子部分的分配請求做一些簡單的計算。 我在視圖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. 

我沒仍然得到需要什麼來改變表單的狀態,但不保存。 任何意見都非常可觀。

回答

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,}) 

我嘗試這樣做,這是工作的罰款

+0

沒有得到的回答是,其實你沒有得到什麼,我問了.... 我做了計算後的狀態說表單更改爲「批准」,但保存表單後應該更改。 –

+0

我想你需要在hr_holidays表的狀態中搜索,因爲他們提到了提交,批准,驗證,雙重驗證等狀態。我認爲你的問題是你沒有返回正確的狀態....讓我知道如果你得到解決方案...謝謝 – vaibhav

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. 

我的回答這麼晚對不起,這是我從support.Thanks

相關問題