تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
6013 أدوات العرض

Reference Image

When I click the checkbox in activity "Tick if you are a vegetarian", a custom Boolean field I made named vegetarian in that employee's record should be active. How can I achieve this?

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

You can achieve this by using BeautifulSoup python library to check if the activity was ticked or not inside the html field of activity.
If it is ticked, the class will be changed to "o_checked".
We can then change the boolean field "Vegetarian" to true or false based on this.
Kindly refer the code,

from odoo import api, fields, models, _from bs4 import BeautifulSoup​
class HrEmployee(models.Model):

_inherit = 'hr.employee'
vegetarian = fields.Boolean("Vegetarian", default=False, readonly=True)


class HrPlanActivityType(models.Model):
_inherit = 'mail.activity'
def action_close_dialog(self):
"""
function used to check if the employee can be
rehire by the checkbox
"""
res = super(HrPlanActivityType, self).action_close_dialog()
employee_id = self.env['hr.employee'].search([('id', '=', self._context['default_res_id'])])
for line in employee_id.activity_ids:
if line.note:
soup = BeautifulSoup(line.note, 'html.parser')
if soup.find(id="checklist-re_hide-id-4", class_="o_checked"):
employee_id.write({"vegetarian": True})
else:
employee_id.write({"vegetarian": False})
return res

Regards

الصورة الرمزية
إهمال
الكاتب

This works. Thanks

المنشورات ذات الصلة الردود أدوات العرض النشاط
7
نوفمبر 20
25261
11
يناير 19
10218
1
يونيو 24
1722
1
ديسمبر 22
4378
1
نوفمبر 22
4112