diff --git a/sf_wxwork_approval/models/wxwork_approval_template.py b/sf_wxwork_approval/models/wxwork_approval_template.py index f60663c0..2757188b 100644 --- a/sf_wxwork_approval/models/wxwork_approval_template.py +++ b/sf_wxwork_approval/models/wxwork_approval_template.py @@ -14,12 +14,15 @@ class WxWorkApprovalTemplate(models.Model): name = fields.Char(string='模板名称') # content_ids = fields.Many2many('wxwork.approval.template.controls', string='模板内容') content_ids = fields.One2many('wxwork.approval.template.controls', 'template_id', string='模板内容') + # 增加一个与wxwork.approval.vacation.config的关联字段 + vacation_config_id = fields.One2many('wxwork.approval.vacation.config', 'template_id', string='控件配置') + company_id = fields.Many2one('res.company', '公司', default=lambda self: self.env.user.company_id.id) creator_userid = fields.Many2one('res.users', '创建者', default=lambda self: self.env.user.id) use_template_approver = fields.Selection([ ('0', '自选审批人'), ('1', '预设审批人') - ], string='审批人模式', default='0') + ], string='审批人模式', default='1') choose_department = fields.Char(string='提单部门') approver = fields.One2many('wxwork.approval.approver_line', 'main_id', string='审批流程') notifyer = fields.Many2many('res.users', string='抄送人userid列表') diff --git a/sf_wxwork_approval/models/wxwork_approval_template_controls.py b/sf_wxwork_approval/models/wxwork_approval_template_controls.py index da43ab52..bfdc5873 100644 --- a/sf_wxwork_approval/models/wxwork_approval_template_controls.py +++ b/sf_wxwork_approval/models/wxwork_approval_template_controls.py @@ -48,7 +48,7 @@ class PropertyModel(models.Model): un_print = fields.Boolean(string='是否参与打印') un_replace = fields.Boolean(string='不替换') display = fields.Boolean(string='显示') - child_control_id = fields.Many2one('config.model', string='明细子控件') + child_control_id = fields.Many2one('wxwork.approval.table.config', string='明细子控件') # 控件配置模型 @@ -86,6 +86,10 @@ class ConfigModel(models.Model): table_type = fields.One2many('wxwork.approval.table.config', 'config_id', string='明细控件配置') # 增加一个与wxwork.approval.attendance.config的关联字段 attendance_type = fields.One2many('wxwork.approval.attendance.config', 'config_id', string='假勤控件配置') + # 增加一个与wxwork.approval.file.config的关联字段 + file_type = fields.One2many('wxwork.approval.file.config', 'config_id', string='附件控件配置') + # 增加一个与wxwork.approval.table.config的Many2one关联字段 + table_child = fields.Many2one('wxwork.approval.table.config', string='明细子控件配置') class ConfigOption(models.Model): @@ -121,6 +125,7 @@ class SelectorConfig(models.Model): # 增加一个与config.model的关联字段 config_id = fields.Many2one('config.model', string='控件') selector_type = fields.Selection([('single', '单选'), ('multi', '多选')], string='选择器类型') + selector_exp_type = fields.Integer(string='选择器表达式类型', default=0) options = fields.One2many('selector.option', 'config_id', string='选项') @@ -151,7 +156,9 @@ class TableConfig(models.Model): # 增加一个与config.model的关联字段 config_id = fields.Many2one('config.model', string='控件') # table_children = fields.One2many('config.child', 'config_id', string='明细子控件') - table_children = fields.One2many('property.model', 'child_control_id', string='明细子控件') + table_children = fields.One2many('property.model', 'child_control_id', string='明细属性控件') + # 增加一个与config.model的One2many关联字段 + table_children_config = fields.One2many('config.model', 'table_child', string='明细配置控件') # stat_field = fields.Many2one('config.model', string='统计字段') @@ -177,6 +184,19 @@ class VacationConfig(models.Model): name = fields.Char(string='假期名称') lang = fields.Char(string='语言') +# file控件(文件控件)config +class FileConfig(models.Model): + _name = 'wxwork.approval.file.config' + + # 增加一个与config.model的关联字段 + config_id = fields.Many2one('config.model', string='控件') + # control_id = fields.Many2one('wxwork.approval.template.controls', string='控件') + # vacation_list = fields.One2many('config.option', 'config_id', string='假期类型列表') + # file_id = fields.Integer(string='文件ID') + # name = fields.Char(string='文件名称') + # lang = fields.Char(string= + is_only_photo = fields.Boolean(string='是否只能上传图片') + class ApproverLine(models.Model): _name = 'wxwork.approval.approver_line' diff --git a/sf_wxwork_approval/models/wxwork_settings.py b/sf_wxwork_approval/models/wxwork_settings.py index 54cd7726..1be0f354 100644 --- a/sf_wxwork_approval/models/wxwork_settings.py +++ b/sf_wxwork_approval/models/wxwork_settings.py @@ -32,6 +32,9 @@ class WxSettings(models.Model): # 删除所有记录 all_records.unlink() all_records1.unlink() + content_data_list = [] + template_data = {} + controls_data = [] for template in template_list: print('====================') temp_dict = {'template_id': template} @@ -50,54 +53,225 @@ class WxSettings(models.Model): # new_record = self.env['wxwork.approval.template'].create(values) # 解析template_detail中的内容数据 - content_data_list = [] + # print('jjjjjjjj', template_detail['template_content']) # print('jjjjjjjjjj', template_detail['template_content']['controls']) for control_data in template_detail['template_content']['controls']: # print('control_data', control_data) property_data = control_data['property'] + # print('property_data', property_data) config_values = {} - # 创建一个字典,包含wxwork.approval.template.controls和wxwork.approval.vacation.config记录的数据 - template_data = { - 'process_code': template, - 'name': template_detail['template_names'][0]['text'], - 'content_ids': [(0, 0, { - 'property_id': [(0, 0, { - 'control_type': property_data.get('control', ''), - 'unique_control_id': property_data.get('id', ''), - 'title': property_data['title'][0]['text'] if 'title' in property_data else '', - 'placeholder': property_data['placeholder'][0]['text'] if 'placeholder' in property_data else '', - 'require': property_data.get('require', None), - 'un_print': property_data.get('un_print', None), - 'un_replace': property_data.get('un_replace', None), - 'display': property_data.get('display', None), - })], - 'config_id': [(0, 0, { - 'date_type': [(0, 0, {'date_type': 'day'})], + if 'config' in control_data: + config_data = control_data['config'] + print('config_data', config_data) + + # 先提取table_children数据 + table_children_data = config_data.get('table', {}).get('children', []) + + # 创建一个空列表用于存储table_children记录 + table_children_records = [] + + # 遍历table_children_data并为每个子控件创建记录 + for child_data in table_children_data: + print('child_data====================', child_data) + # 提取property相关数据 + child_property_data = { + # 'control_type': child_data.get('property', {}).get('control', None), + # 'unique_control_id': child_data.get('property', {}).get('id', None), + # 'title': child_data.get('property', {}).get('title', [{}])[0].get('text', None), + # 'placeholder': child_data.get('property', {}).get('placeholder', [{}])[0].get('text', None), + # 'require': child_data.get('property', {}).get('require', None), + # 'un_print': child_data.get('property', {}).get('un_print', None), + # 'un_replace': child_data.get('property', {}).get('un_replace', None), + # 'display': child_data.get('property', {}).get('display', None), + 'control_type': child_data.get('property', {}).get('control', None), + 'unique_control_id': child_data.get('property', {}).get('id', None), + 'title': child_data.get('property', {}).get('title', [{}])[0].get('text', None), + 'placeholder': child_data.get('property', {}).get('placeholder', [{}])[0].get('text', None), + 'require': child_data.get('property', {}).get('require', None), + 'un_print': child_data.get('property', {}).get('un_print', None), + 'un_replace': child_data.get('property', {}).get('un_replace', None), + 'display': child_data.get('property', {}).get('display', None), + } + + # 在这里根据控件类型为每个子控件创建相应的config_id数据 + # 例如: + config_id_data = { + 'date_type': [(0, 0, {'date_type': child_data.get('config', {}).get('date', {}).get('type', + None)})] if 'date' in child_data.get( + 'config', {}) else [], 'selector_type': [(0, 0, { 'selector_type': 'single', 'options': [(0, 0, {'key': 'opt1', 'text': '选项1'})], - })], - 'contact_type': [(0, 0, {'contact_type': 'single', 'contact_mode': 'user'})], - 'table_type': [(0, 0, { - 'table_children': [ - (0, 0, {'control_type': 'Text', 'unique_control_id': 'text_2', 'title': '文本框2'})], - })], - 'attendance_type': [(0, 0, {'attendance_type': '1', 'attendance_date_range_type': 'hour'})], - })], - })], - 'vacation_config_id': [(0, 0, { - # 在这里添加wxwork.approval.vacation.config模型的字段数据 - 'vacation_id': 1, - 'name': 'value2', - 'lang': 'value2', - # ... - })], - } + })] if 'selector' in child_data.get('config', {}) else [], + 'contact_type': [ + (0, 0, {'contact_type': config_data.get('contact', {}).get('type', None), + 'contact_mode': config_data.get('contact', {}).get('mode', + None)})] if 'contact' in child_data.get( + 'config', {}).get('contact', {}) else [], + 'file_type': [ + (0, 0, {'is_only_photo': config_data.get('file', {}).get('is_only_photo', + None)})] if 'file' in child_data.get( + 'config', {}).get('file', {}) else [], + # 'table_type': [(0, 0, { + # 'table_children': [ + # (0, 0, {'control_type': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('control', None), + # 'unique_control_id': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('id', None), + # 'title': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('title', None)[0].get('text', None), + # 'placeholder': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('placeholder', None)[0].get('text', None), + # 'require': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('require', None), + # 'un_print': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('un_print', None), + # 'un_replace': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('un_replace', None), + # 'display': config_data.get('table', {}).get('children', None)[0].get('property', {}).get('display', None), + # })], + # })] if 'table' in config_data else [], + # 'attendance_type': [(0, 0, {'attendance_type': '1', + # 'attendance_date_range_type': 'hour'})] if 'attendance' in config_data else [], + } - # 调用create方法创建记录 - template_record = self.env['wxwork.approval.template'].create(template_data) + # 将config_id_data添加到property_data中(如果有的话) + if config_id_data: + child_property_data['child_control_id'] = config_id_data + + # 将property_data添加到table_children_records中 + table_children_records.append((0, 0, child_property_data)) + + # 创建一个包含多个wxwork.approval.template.controls的字典列表 + controls_data = [ + (0, 0, { + 'property_id': [(0, 0, { + 'control_type': property_data.get('control', ''), + 'unique_control_id': property_data.get('id', ''), + 'title': property_data['title'][0]['text'] if 'title' in property_data else '', + 'placeholder': property_data['placeholder'][0][ + 'text'] if 'placeholder' in property_data else '', + 'require': property_data.get('require', None), + 'un_print': property_data.get('un_print', None), + 'un_replace': property_data.get('un_replace', None), + 'display': property_data.get('display', None), + })], + 'config_id': [(0, 0, { + 'date_type': [(0, 0, {'date_type': config_data.get('date', {}).get('type', + None)})] if 'date' in config_data else [], + # 'selector_type': [(0, 0, { + # 'selector_type': config_data['table']['children'][0].get('config', {}).get( + # 'selector', {}).get('type', None), + # 'options': [ + # (0, 0, {'key': option['key'], 'text': option['value'][0]['text']}) + # for option in config_data['table']['children'][0].get('config', {}).get('selector', {}).get('options', []) + # ], + # })] if 'selector' in config_data else [], + 'selector_type': [ + (0, 0, { + 'selector_type': child.get('config', {}).get('selector', {}).get('type', None), + 'options': [ + (0, 0, {'key': option['key'], 'text': option['value'][0]['text']}) + for option in child.get('config', {}).get('selector', {}).get('options', []) + ], + }) + for child in config_data.get('table', {}).get('children', []) + if 'selector' in child.get('config', {}) + ], + + 'contact_type': [ + (0, 0, {'contact_type': config_data.get('contact', {}).get('type', None), + 'contact_mode': config_data.get('contact', {}).get('mode', + None)})] if 'contact' in config_data else [], + 'file_type': [ + (0, 0, {'is_only_photo': config_data.get('file', {}).get('is_only_photo', + None)})] if 'file' in config_data else [], + 'table_type': [(0, 0, { + 'table_children': table_children_records, + })] if 'table' in config_data else [], + + # 'contact_type': [ + # (0, 0, {'contact_type': config_data.get('contact', {}).get('type', None)})], + # 'contact_mode': [ + # (0, 0, {'contact_mode': config_data.get('contact', {}).get('mode', None)})], + # 'table_type': [(0, 0, { + # 'table_children': [ + # (0, 0, + # {'control_type': 'Text', 'unique_control_id': 'text_2', 'title': '文本框2'})], + # })], + # # [ + # # (0, 0, {'control_type': config_data.get('table', {}).get('children', {})[0]. + # # get('property', {}).get('control', None), 'unique_control_id': 'text_2', + # # 'title': '文本框2'})] + + 'attendance_type': [(0, 0, {'attendance_type': '1', + 'attendance_date_range_type': 'hour'})] if 'attendance' in config_data else [], + })], + }), + # 在这里添加更多的控件数据 + ] + else: + # 创建一个包含多个wxwork.approval.template.controls的字典列表 + controls_data = [ + (0, 0, { + 'property_id': [(0, 0, { + 'control_type': property_data.get('control', ''), + 'unique_control_id': property_data.get('id', ''), + 'title': property_data['title'][0]['text'] if 'title' in property_data else '', + 'placeholder': property_data['placeholder'][0][ + 'text'] if 'placeholder' in property_data else '', + 'require': property_data.get('require', None), + 'un_print': property_data.get('un_print', None), + 'un_replace': property_data.get('un_replace', None), + 'display': property_data.get('display', None), + })], + }), + # 在这里添加更多的控件数据 + ] + + # 从vacation_list中提取假期类型数据 + vacation_items = [] + vacation_items_data = template_detail.get('vacation_list', []) + # 将假期类型数据转换为适用于vacation_items字段的格式 + if vacation_items_data and 'item' in vacation_items_data: + items = [] + for item in vacation_items_data['item']: + id = item.get('id') + name = item.get('name')[0].get('text') + items.append({'id': id, 'name': name}) + print(items) + + # if vacation_items_data: + # print('vacation_items_data', vacation_items_data) + # print('vacation_items_data', type(vacation_items_data)) + # print('vacation_items_data', vacation_items_data['items']) + # print('vacation_items_data', vacation_items_data[0]) + vacation_items = [(0, 0, { + 'vacation_id': item['id'], + 'name': item['name'], + 'lang': 'zh_CN', + }) for item in items] + + # 创建一个包含WxWorkApprovalTemplate和关联记录数据的字典 + template_data = { + 'process_code': template, + 'name': template_detail['template_names'][0]['text'], + 'content_ids': controls_data, + # 'vacation_config_id': [(0, 0, { + # # 在这里添加wxwork.approval.vacation.config模型的字段数据 + # 'vacation_id': template_detail.get('vacation_id', None), + # 'name': template_detail.get('vacation_name', None), + # 'lang': template_detail.get('vacation_lang', None), + # # ... + # })], + 'vacation_config_id': vacation_items + } + # 检查数据库中是否已经存在具有相同process_code的模板 + existing_template = self.env['wxwork.approval.template'].search( + [('process_code', '=', template)], limit=1) + + if existing_template: + # 如果模板已经存在,更新其content_ids字段(即添加控件记录) + existing_template.write({'content_ids': controls_data}) + else: + # 如果模板不存在,创建一个新的模板及其关联记录 + # 调用create方法创建记录 + template_record = self.env['wxwork.approval.template'].create(template_data) # # print(property_data) # # 准备用于创建记录的字段值 diff --git a/sf_wxwork_approval/security/ir.model.access.csv b/sf_wxwork_approval/security/ir.model.access.csv index 338eee72..b4f4c359 100644 --- a/sf_wxwork_approval/security/ir.model.access.csv +++ b/sf_wxwork_approval/security/ir.model.access.csv @@ -11,6 +11,13 @@ access_property_model,property.model,model_property_model,base.group_user,1,1,1, access_config_model,config.model,model_config_model,base.group_user,1,1,1,1 access_config_option,config.option,model_config_option,base.group_user,1,1,1,1 access_wxwork_approval_vacation_config,wxwork.approval.vacation.config,model_wxwork_approval_vacation_config,base.group_user,1,1,1,1 +access_wxwork_approval_date_config,wxwork.approval.date.config,model_wxwork_approval_date_config,base.group_user,1,1,1,1 +access_wxwork_approval_selector_config,wxwork.approval.selector.config,model_wxwork_approval_selector_config,base.group_user,1,1,1,1 +access_selector_option,selector.option,model_selector_option,base.group_user,1,1,1,1 +access_wxwork_approval_contact_config,wxwork.approval.contact.config,model_wxwork_approval_contact_config,base.group_user,1,1,1,1 +access_wxwork_approval_table_config,wxwork.approval.table.config,model_wxwork_approval_table_config,base.group_user,1,1,1,1 +access_wxwork_approval_attendance_config,wxwork.approval.attendance.config,model_wxwork_approval_attendance_config,base.group_user,1,1,1,1 +access_wxwork_approval_file_config,wxwork.approval.file.config,model_wxwork_approval_file_config,base.group_user,1,1,1,1 diff --git a/sf_wxwork_approval/views/wxwork_approval_template_view.xml b/sf_wxwork_approval/views/wxwork_approval_template_view.xml index af4c74d7..9d00ab6f 100644 --- a/sf_wxwork_approval/views/wxwork_approval_template_view.xml +++ b/sf_wxwork_approval/views/wxwork_approval_template_view.xml @@ -26,15 +26,16 @@ - - - + + + + -