I am facing a problem to do some simple calculation on the Allocation requests in the leaves section in Menu . I have added a button in the view xml file:
<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>
and in .py file
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'),
}
Here I just want to calculate the monthly quota of the leaves on the click of the button . suppose if I enter 12 in allocation(number_of_days_temp) then I should get monthly as 1. Every thing is working just fine as expected , except the state of the record. after the click of the button the state of the record changes from "To Submit" i.e draft to "To Approve" i.e confirm. before saving the form the state of the form changes itself, Ideally the state of the form should only change after we hit the save button. I have read the openerp 7.0 documentation there it says that
After a button has been clicked, the record should always be reloaded.
I did not still get what is required to change the state of the form without saving it. Any comments highly appreciable.