0

我在对 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.

在不保存表单的情况下,我仍然没有得到更改表单状态所需的内容。任何评论都非常值得赞赏。

4

2 回答 2

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.

很抱歉这么晚才回复,但这是我从支持人员那里得到的回复。谢谢

于 2013-07-23T12:03:38.627 回答
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,})

我试过这个,这工作正常

于 2013-06-14T06:13:58.220 回答