def insert_record(self, request, model, values, custom, meta=None): model_name = model.sudo().model record = request.env[model_name].sudo().with_context( mail_create_nosubscribe=True).create(values) if custom or meta: _custom_label = "%s\n___________\n\n" % _( "Other Information:") # Title for custom fields if model_name == 'mail.mail': _custom_label = "%s\n___________\n\n" % _( "This message has been posted on your website!") default_field = model.website_form_default_field_id default_field_data = values.get(default_field.name, '') custom_content = (default_field_data + "\n\n" if default_field_data else '') \ + (_custom_label + custom + "\n\n" if custom else '') \ + (self._meta_label + meta if meta else '') # If there is a default field configured for this model, use it. # If there isn't, put the custom data in a message instead if default_field.name: if default_field.ttype == 'html' or model_name == 'mail.mail': custom_content = nl2br(custom_content) record.update({default_field.name: custom_content}) else: values = { 'body': nl2br(custom_content), 'model': model_name, 'message_type': 'comment', 'no_auto_thread': False, 'res_id': record.id, } mail_id = request.env['mail.message'].sudo().create(values) return record.id
def insert_record(self, request, model, values, custom, meta=None): record = request.env[model.model].sudo().with_context(mail_create_nosubscribe=True).create(values) if custom or meta: default_field = model.website_form_default_field_id default_field_data = values.get(default_field.name, '') custom_content = (default_field_data + "\n\n" if default_field_data else '') \ + (self._custom_label + custom + "\n\n" if custom else '') \ + (self._meta_label + meta if meta else '') # If there is a default field configured for this model, use it. # If there isn't, put the custom data in a message instead if default_field.name: if default_field.ttype == 'html' or model.model == 'mail.mail': custom_content = nl2br(custom_content) record.update({default_field.name: custom_content}) else: values = { 'body': nl2br(custom_content), 'model': model.model, 'message_type': 'comment', 'no_auto_thread': False, 'res_id': record.id, } mail_id = request.env['mail.message'].sudo().create(values) return record.id
def insert_record(self, request, model, values, custom, meta=None): if model.model == 'crm.lead': if 'company_id' not in values: values['company_id'] = request.website.company_id.id model_name = model.sudo().model record = request.env[model_name].sudo().with_context( mail_create_nosubscribe=True).create(values) if custom or meta: default_field = model.website_form_default_field_id default_field_data = values.get(default_field.name, '') custom_content = (default_field_data + "\n\n" if default_field_data else '') \ + (self._custom_label + custom + "\n\n" if custom else '') \ + (self._meta_label + meta if meta else '') # If there is a default field configured for this model, use it. # If there isn't, put the custom data in a message instead if default_field.name: if default_field.ttype == 'html' or model_name == 'mail.mail': custom_content = nl2br(custom_content) record.update({default_field.name: custom_content}) else: values = { 'body': nl2br(custom_content), 'model': model_name, 'message_type': 'comment', 'no_auto_thread': False, 'res_id': record.id, } mail_id = request.env['mail.message'].sudo().create(values) return record.id
def website_form_saleorder(self, **kwargs): model_record = request.env.ref('sale.model_sale_order') try: data = self.extract_data(model_record, kwargs) except ValidationError as e: return json.dumps({'error_fields': e.args[0]}) order = request.website.sale_get_order() if data['record']: order.write(data['record']) if data['custom']: values = { 'body': nl2br(data['custom']), 'model': 'sale.order', 'message_type': 'comment', 'no_auto_thread': False, 'res_id': order.id, } request.env['mail.message'].sudo().create(values) if data['attachments']: self.insert_attachment(model_record, order.id, data['attachments']) return json.dumps({'id': order.id})
def website_form_saleorder(self, **kwargs): model_record = request.env.ref('sale.model_sale_order') try: data = self.extract_data(model_record, kwargs) except ValidationError as e: return json.dumps({'error_fields': e.args[0]}) order = request.website.sale_get_order() if data['record']: order.write(data['record']) if data['custom']: values = { 'body': nl2br(data['custom']), 'model': 'sale.order', 'message_type': 'comment', 'no_auto_thread': False, 'res_id': order.id, } request.env['mail.message'].sudo().create(values) if data['attachments']: self.insert_attachment(model_record, order.id, data['attachments']) return json.dumps({'id': order.id})
def value_to_html(self, value, options): if not value: return False value = value.sudo().display_name if not value: return False return nl2br(html_escape(value, options)) if value else ''
def _default_company_details(self): company = self.env.company address_format, company_data = company.partner_id._prepare_display_address() # company_name may *still* be missing from prepared address in case commercial_company_name is falsy if 'company_name' not in address_format: address_format = '%(company_name)s\n' + address_format company_data['company_name'] = company_data['company_name'] or company.name return Markup(nl2br(address_format)) % company_data
def _default_company_details(self): company = self.env.company default_address_format = "%(company_name)s\n%(street)s\n%(city)s %(state_code)s %(zip)s\n%(country_name)s" address_format = company.country_id.address_format or default_address_format if 'company_name' not in address_format: address_format = '%(company_name)s\n' + address_format company_data = { "company_name": company.name or "", "street": company.street or "", "street2": "", "city": company.city or "", "state_code": company.state_id.name or "", "zip": company.zip or "", "country_name": company.country_id.name or "", } return Markup(nl2br(address_format)) % company_data
def value_to_html(self, value, options): """ Escapes the value and converts newlines to br. This is bullshit. """ return nl2br(html_escape(value, options)) if value else ''
def insert_record(self, request, model, values, custom, meta=None): print("model") print(model) print("Request") print(request) print("values") print(values) national_id = values['national_id'] is_egyption = "true" date_from = "2020-12-01" date_to = "2021-03-18" model_name = model.sudo().model if model_name == 'mail.mail': values.update({'reply_to': values.get('email_from')}) if model_name == 'hr.applicant': if values['partner_phone'].isnumeric() == False: raise ValidationError( _("Mobile Number Must Contain numbers only.")) return emp = request.env['hr.employee'].sudo().search([ ('identification_id', '=', values['national_id']) ]) kpi_average = emp.kpi_average Applicable = emp.Applicable print("ccccccccccccccccccccccccccccc") print("ccccccccccccccccccccccccccccc") print("ccccccccccccccccccccccccccccc") print("ccccccccccccccccccccccccccccc") print(kpi_average) print(emp) print("ccccccccccccccccccccccccccccc") print("ccccccccccccccccccccccccccccc") if kpi_average: if int(kpi_average) < 51: raise ValidationError( _("Your KPI doesnt meet the Requirements. ")) return if emp.employee_grade: job_obj = request.env['hr.job'].sudo().search([ ('id', '=', values['job_id']) ]) grade_obj = request.env['employee.grade'].sudo().search([ ('id', '=', emp.employee_grade.id) ]) max_emp_grade = int(grade_obj.garde) + int( grade_obj.grade_level_exception) max_job_grade = int( job_obj.employee_grade.garde ) # int(job_obj.employee_grade.grade_level_exception) if max_emp_grade < max_job_grade: raise ValidationError( _("Your Grade doesn't meet the Requirements")) return if emp: conn = clientapi.HTTPSConnection("recruitment-api.rayacx.com") payload = '' headers = { 'Authorization': 'Bearer UUvQxe3uvXDTMH7lriK6le0IeLkw3hkZC7Kn_eErH6o2SROhFAXj2TKR-bwYZ3O0OCoc7x08LHYdPxyk8VkO_5t3tLHoJoJzEj_AswoDDazBwdqhAZ2q6t2rw1Jvn9ytMC5lCd8KHbfdbvWoj-_X79Fkzm-mL9PRu_LWpC6vjssExpAWtT_EePWcD3zQPYIISelMaGA0XE-z3n291ZMAoA' } conn.request( "GET", "/api/cz/GetEmpMisconduct?IsEgyptian=" + is_egyption + "&RefId=" + national_id, payload, headers) ress = conn.getresponse() print(ress) dataa = ress.read() dict_data = json.loads(dataa.decode('utf-8')) GetEmpMisconduct = 0 print("Misconduct") print("Misconduct") print(ress) print(conn) print(dict_data) print("Misconduct") print("Misconduct") if dict_data: for i in dict_data: print(dict_data) last_emp_miconduct_count = str(i["date"]) emp_misconduct_date = str(i["date"]).split('T')[0] if i["type"] == "Warning": if last_emp_miconduct_count: #misconduct_period = last_emp_miconduct_count.misconduct_type_id.applying_restriction miconduct_employee_date = datetime.strptime( emp_misconduct_date, '%Y-%m-%d') emp_misconduct_date = miconduct_employee_date + timedelta( days=+90) if emp_misconduct_date > datetime.now(): raise ValidationError( _("You have Misconducts that contradicts with the Requirements" )) return False if i["type"] == "Fine": if last_emp_miconduct_count: #misconduct_period = last_emp_miconduct_count.misconduct_type_id.applying_restriction miconduct_employee_date = datetime.strptime( emp_misconduct_date, '%Y-%m-%d') emp_misconduct_date = miconduct_employee_date + timedelta( days=+30) if emp_misconduct_date > datetime.now(): raise ValidationError( _("You have Misconducts that contradicts with the Requirements" )) return False if i["type"] == "Pay attention": if last_emp_miconduct_count: #misconduct_period = last_emp_miconduct_count.misconduct_type_id.applying_restriction miconduct_employee_date = datetime.strptime( emp_misconduct_date, '%Y-%m-%d') emp_misconduct_date = miconduct_employee_date + timedelta( days=+30) if emp_misconduct_date > datetime.now(): raise ValidationError( _("You have Misconducts that contradicts with the Requirements" )) return False # Misconduct Online Restriction if emp: #KPI conn = clientapi.HTTPSConnection("recruitment-api.rayacx.com") payload = '' headers = { 'Authorization': 'Bearer UUvQxe3uvXDTMH7lriK6le0IeLkw3hkZC7Kn_eErH6o2SROhFAXj2TKR-bwYZ3O0OCoc7x08LHYdPxyk8VkO_5t3tLHoJoJzEj_AswoDDazBwdqhAZ2q6t2rw1Jvn9ytMC5lCd8KHbfdbvWoj-_X79Fkzm-mL9PRu_LWpC6vjssExpAWtT_EePWcD3zQPYIISelMaGA0XE-z3n291ZMAoA' } conn.request( "GET", "/api/cz/GetEmpHeadcount?IsEgyptian=" + is_egyption + "&RefId=" + national_id, payload, headers) ress = conn.getresponse() data = ress.read() dict_data = json.loads(data.decode('utf-8')) GetEmpHeadcount = 0 print("HEAD Count ") print("HEAD Count ") print("HEAD Count ") print("HEAD Count ") print(dict_data) print("Head Count") print("HEAD Count ") print("HEAD Count ") print("HEAD Count ") print("HEAD Count ") if dict_data: #for i in dict_data: job_head_count = request.env['hr.job'].sudo().search([ ('id', '=', values['job_id']) ]).head_count_restriction print("i") print("i") last_emp_head_count = dict_data["headcount_Date"] emp_head_count_date = dict_data["headcount_Date"].split( 'T')[0] if last_emp_head_count: emp_head_count_date = datetime.strptime( emp_head_count_date, '%Y-%m-%d') print(emp_head_count_date) print(emp_head_count_date) print(emp_head_count_date) emp_head_count_date = emp_head_count_date + timedelta( days=(int(job_head_count) * 30)) print(emp_head_count_date) if emp_head_count_date > datetime.now(): raise ValidationError( _("Your Last Head Count doesn't meet the Requirements" )) return False else: job_head_count = request.env['hr.job'].search([ ('id', '=', values['job_id']) ]).head_count_restriction last_emp_head_count = request.env[ 'head.count.line'].search([('emp_id', '=', emp.id)], order='id desc', limit=1) if last_emp_head_count: emp_head_count_date = last_emp_head_count.date + relativedelta( months=+int(job_head_count)) if emp_head_count_date > date.today(): raise ValidationError( _("Your Last Head Count doesn't meet the Requirements" )) return False record = request.env[model_name].sudo().create(values) print("RECORD") print(record) print("RECORD") if custom or meta: _custom_label = "%s\n___________\n\n" % _( "Other Information:") # Title for custom fields if model_name == 'mail.mail': _custom_label = "%s\n___________\n\n" % _( "This message has been posted on your website!") default_field = model.website_form_default_field_id default_field_data = values.get(default_field.name, '') custom_content = (default_field_data + "\n\n" if default_field_data else '') \ + (_custom_label + custom + "\n\n" if custom else '') \ + (self._meta_label + meta if meta else '') # If there is a default field configured for this model, use it. # If there isn't, put the custom data in a message instead if default_field.name: if default_field.ttype == 'html' or model_name == 'mail.mail': custom_content = nl2br(custom_content) print(record) record.update({default_field.name: custom_content}) else: values = { 'body': nl2br(custom_content), 'model': model_name, 'message_type': 'comment', 'no_auto_thread': False, 'res_id': record.id, } mail_id = request.env['mail.message'].with_user( SUPERUSER_ID).create(values) return record.id