修改模板模型结构
This commit is contained in:
@@ -54,29 +54,38 @@ class PropertyModel(models.Model):
|
||||
# 控件配置模型
|
||||
class ConfigModel(models.Model):
|
||||
_name = 'config.model'
|
||||
_rec_name = "title"
|
||||
|
||||
control_id = fields.Many2one('wxwork.approval.template.controls', string='控件')
|
||||
# 在此添加其他字段以存储不同控件类型的附加类型和属性
|
||||
date_type = fields.Selection([('day', '日期'), ('hour', '日期+时间')], string='日期类型')
|
||||
|
||||
selector_type = fields.Selection([('single', '单选'), ('multi', '多选')], string='选择器类型')
|
||||
options = fields.One2many('config.option', 'config_id', string='选项')
|
||||
|
||||
contact_type = fields.Selection(
|
||||
[('single', '单选'), ('multi', '多选')],
|
||||
string='联系人类型')
|
||||
contact_mode = fields.Selection(
|
||||
[('user', '成员'), ('department', '部门')],
|
||||
string='联系人模式')
|
||||
|
||||
# table_children = fields.One2many('config.child', 'config_id', string='明细子控件')
|
||||
table_children = fields.One2many('property.model', 'child_control_id', string='明细子控件')
|
||||
|
||||
attendance_type = fields.Selection([('1', '请假'), ('3', '出差'), ('4', '外出'), ('5', '加班')], string='假勤组件类型')
|
||||
attendance_date_range_type = fields.Selection([('hour', '分钟'), ('halfday', '上午/下午')], string='假勤时间刻度')
|
||||
|
||||
vacation_list = fields.One2many('config.option', 'config_id', string='假期类型列表')
|
||||
# # 在此添加其他字段以存储不同控件类型的附加类型和属性
|
||||
# date_type = fields.Selection([('day', '日期'), ('hour', '日期+时间')], string='日期类型')
|
||||
#
|
||||
# selector_type = fields.Selection([('single', '单选'), ('multi', '多选')], string='选择器类型')
|
||||
# options = fields.One2many('config.option', 'config_id', string='选项')
|
||||
#
|
||||
# contact_type = fields.Selection(
|
||||
# [('single', '单选'), ('multi', '多选')],
|
||||
# string='联系人类型')
|
||||
# contact_mode = fields.Selection(
|
||||
# [('user', '成员'), ('department', '部门')],
|
||||
# string='联系人模式')
|
||||
#
|
||||
# # table_children = fields.One2many('config.child', 'config_id', string='明细子控件')
|
||||
# table_children = fields.One2many('property.model', 'child_control_id', string='明细子控件')
|
||||
#
|
||||
# attendance_type = fields.Selection([('1', '请假'), ('3', '出差'), ('4', '外出'), ('5', '加班')], string='假勤组件类型')
|
||||
# attendance_date_range_type = fields.Selection([('hour', '分钟'), ('halfday', '上午/下午')], string='假勤时间刻度')
|
||||
#
|
||||
# vacation_list = fields.One2many('config.option', 'config_id', string='假期类型列表')
|
||||
# 增加一个wxwork.approval.date.config的关联字段
|
||||
date_type = fields.One2many('wxwork.approval.date.config', 'config_id', string='日期控件配置')
|
||||
# 增加一个与wxwork.approval.selector.config的关联字段
|
||||
selector_type = fields.One2many('wxwork.approval.selector.config', 'config_id', string='选择器控件配置')
|
||||
# 增加一个与wxwork.approval.contact.config的关联字段
|
||||
contact_type = fields.One2many('wxwork.approval.contact.config', 'config_id', string='联系人控件配置')
|
||||
# 增加一个与wxwork.approval.table.config的关联字段
|
||||
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='假勤控件配置')
|
||||
|
||||
|
||||
class ConfigOption(models.Model):
|
||||
@@ -96,10 +105,74 @@ class ConfigChild(models.Model):
|
||||
# 其他属性...
|
||||
|
||||
|
||||
class VacationType(models.Model):
|
||||
_name = 'vacation.type'
|
||||
# Date控件config
|
||||
class DateConfig(models.Model):
|
||||
_name = 'wxwork.approval.date.config'
|
||||
|
||||
config_id = fields.Many2one('config.model', string='配置')
|
||||
# 增加一个与config.model的关联字段
|
||||
config_id = fields.Many2one('config.model', string='控件')
|
||||
date_type = fields.Selection([('day', '日期'), ('hour', '日期+时间')], string='日期类型')
|
||||
|
||||
|
||||
# Selector控件(单选/多选控件)config
|
||||
class SelectorConfig(models.Model):
|
||||
_name = 'wxwork.approval.selector.config'
|
||||
|
||||
# 增加一个与config.model的关联字段
|
||||
config_id = fields.Many2one('config.model', string='控件')
|
||||
selector_type = fields.Selection([('single', '单选'), ('multi', '多选')], string='选择器类型')
|
||||
options = fields.One2many('selector.option', 'config_id', string='选项')
|
||||
|
||||
|
||||
# Selector控件(单选/多选控件)选项
|
||||
class SelectorOption(models.Model):
|
||||
_name = 'selector.option'
|
||||
|
||||
key = fields.Char(string='选项Key')
|
||||
text = fields.Char(string='选项Text')
|
||||
lang = fields.Char(string='语言')
|
||||
config_id = fields.Many2one('wxwork.approval.selector.config', string='配置')
|
||||
|
||||
|
||||
# Contact控件(成员/部门控件)config
|
||||
class ContactConfig(models.Model):
|
||||
_name = 'wxwork.approval.contact.config'
|
||||
|
||||
# 增加一个与config.model的关联字段
|
||||
config_id = fields.Many2one('config.model', string='控件')
|
||||
contact_type = fields.Selection([('single', '单选'), ('multi', '多选')], string='选择器类型')
|
||||
contact_mode = fields.Selection([('user', '成员'), ('department', '部门')], string='联系人类型')
|
||||
|
||||
|
||||
# Table控件(明细控件)config
|
||||
class TableConfig(models.Model):
|
||||
_name = 'wxwork.approval.table.config'
|
||||
|
||||
# 增加一个与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='明细子控件')
|
||||
# stat_field = fields.Many2one('config.model', string='统计字段')
|
||||
|
||||
|
||||
# Attendance控件(假勤控件)config
|
||||
class AttendanceConfig(models.Model):
|
||||
_name = 'wxwork.approval.attendance.config'
|
||||
|
||||
# 增加一个与config.model的关联字段
|
||||
config_id = fields.Many2one('config.model', string='控件')
|
||||
attendance_type = fields.Selection([('1', '请假'), ('3', '出差'), ('4', '外出'), ('5', '加班')], string='假勤组件类型')
|
||||
attendance_date_range_type = fields.Selection([('hour', '分钟'), ('halfday', '上午/下午')], string='假勤时间刻度')
|
||||
|
||||
|
||||
# Vacation控件(假勤控件)config
|
||||
class VacationConfig(models.Model):
|
||||
_name = 'wxwork.approval.vacation.config'
|
||||
|
||||
# 增加一个与wxwork.approval.template的关联字段
|
||||
template_id = fields.Many2one('wxwork.approval.template', string='模板')
|
||||
# control_id = fields.Many2one('wxwork.approval.template.controls', string='控件')
|
||||
# vacation_list = fields.One2many('config.option', 'config_id', string='假期类型列表')
|
||||
vacation_id = fields.Integer(string='假期ID')
|
||||
name = fields.Char(string='假期名称')
|
||||
lang = fields.Char(string='语言')
|
||||
|
||||
@@ -38,7 +38,7 @@ class WxSettings(models.Model):
|
||||
# print(json.dumps(temp_dict))
|
||||
# aa = json.dumps(temp_dict)
|
||||
template_detail = wx.get_template_detail(temp_dict)
|
||||
# print('template_detail%s' % template_detail)
|
||||
print('template_detail%s' % template_detail)
|
||||
#
|
||||
# # 准备用于创建记录的字段值
|
||||
# values = {
|
||||
@@ -54,11 +54,78 @@ class WxSettings(models.Model):
|
||||
# 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)
|
||||
# print('control_data', control_data)
|
||||
property_data = control_data['property']
|
||||
config_values = {}
|
||||
|
||||
# print(property_data)
|
||||
# # print(property_data)
|
||||
# # 准备用于创建记录的字段值
|
||||
# property_values = {
|
||||
# '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),
|
||||
# # 'un_replace': template_detail['template_names'][0]['text'],
|
||||
# # 如果需要设置content_ids,请按照正确格式添加关联数据
|
||||
# }
|
||||
# # print('property_values', property_values)
|
||||
# # config_data = None
|
||||
#
|
||||
# if 'config' in control_data:
|
||||
#
|
||||
# config_data = control_data['config']
|
||||
# # print('config_data===', config_data)
|
||||
# if '"date":' in config_data:
|
||||
# # config_values = {
|
||||
# # 'date_type': config_data.get('type', ''),
|
||||
# # }
|
||||
# config_values['date_type'] = config_data.get('type', '')
|
||||
# if '"selector":' in config_data:
|
||||
# # config_values = {
|
||||
# # 'selector_type': config_data.get('type', ''),
|
||||
# # # 'options': config_data['title'][0]['text'] if 'title' in property_data else '',
|
||||
# # }
|
||||
# config_values['selector_type'] = config_data.get('type', '')
|
||||
# if '"contact":' in config_data:
|
||||
# # config_values = {
|
||||
# # 'contact_type': config_data.get('type', ''),
|
||||
# # 'contact_mode': config_data.get('mode', ''),
|
||||
# #
|
||||
# # }
|
||||
# config_values['contact_type'] = config_data.get('type', '')
|
||||
# config_values['contact_mode'] = config_data.get('mode', '')
|
||||
# if '"table":' in config_data:
|
||||
# pass
|
||||
# # config_values = {
|
||||
# # 'table_children': config_data.get('un_print', None),
|
||||
# # }
|
||||
# if '"attendance":' in config_data:
|
||||
# pass
|
||||
# # config_values = {
|
||||
# # 'attendance_type': config_data.get('un_replace', None),
|
||||
# # 'attendance_date_range_type': config_data.get('display', None),
|
||||
# # # 如果需要设置content_ids,请按照正确格式添加关联数据
|
||||
# # }
|
||||
# if '"vacation_list":' in config_data:
|
||||
# pass
|
||||
# # config_values = {
|
||||
# # 'vacation_list': config_data['template_names'][0]['text'],
|
||||
# # # 如果需要设置content_ids,请按照正确格式添加关联数据
|
||||
# # }
|
||||
#
|
||||
# content_data_list.append((0, 0, {
|
||||
# 'property_id': [(0, 0, property_values)],
|
||||
# 'config_id': [(0, 0, config_values)],
|
||||
# }))
|
||||
# else:
|
||||
# content_data_list.append((0, 0, {
|
||||
# 'property_id': [(0, 0, property_values)],
|
||||
# # 'config_id': [(0, 0, config_values)],
|
||||
# }))
|
||||
# 准备用于创建记录的字段值
|
||||
property_values = {
|
||||
'control_type': property_data.get('control', ''),
|
||||
@@ -69,63 +136,67 @@ class WxSettings(models.Model):
|
||||
'un_print': property_data.get('un_print', None),
|
||||
'un_replace': property_data.get('un_replace', None),
|
||||
'display': property_data.get('display', None),
|
||||
# 'un_replace': template_detail['template_names'][0]['text'],
|
||||
# 如果需要设置content_ids,请按照正确格式添加关联数据
|
||||
}
|
||||
# print('property_values', property_values)
|
||||
# config_data = None
|
||||
|
||||
if 'config' in control_data:
|
||||
|
||||
config_data = control_data['config']
|
||||
# print('config_data===', config_data)
|
||||
if '"date":' in config_data:
|
||||
# config_values = {
|
||||
# 'date_type': config_data.get('type', ''),
|
||||
# }
|
||||
config_values['date_type'] = config_data.get('type', '')
|
||||
if '"selector":' in config_data:
|
||||
# config_values = {
|
||||
# 'selector_type': config_data.get('type', ''),
|
||||
# # 'options': config_data['title'][0]['text'] if 'title' in property_data else '',
|
||||
# }
|
||||
config_values['selector_type'] = config_data.get('type', '')
|
||||
if '"contact":' in config_data:
|
||||
# config_values = {
|
||||
# 'contact_type': config_data.get('type', ''),
|
||||
# 'contact_mode': config_data.get('mode', ''),
|
||||
#
|
||||
# }
|
||||
config_values['contact_type'] = config_data.get('type', '')
|
||||
config_values['contact_mode'] = config_data.get('mode', '')
|
||||
if '"table":' in config_data:
|
||||
pass
|
||||
# config_values = {
|
||||
# 'table_children': config_data.get('un_print', None),
|
||||
# }
|
||||
if '"attendance":' in config_data:
|
||||
pass
|
||||
# config_values = {
|
||||
# 'attendance_type': config_data.get('un_replace', None),
|
||||
# 'attendance_date_range_type': config_data.get('display', None),
|
||||
# # 如果需要设置content_ids,请按照正确格式添加关联数据
|
||||
# }
|
||||
if '"vacation_list":' in config_data:
|
||||
pass
|
||||
# config_values = {
|
||||
# 'vacation_list': config_data['template_names'][0]['text'],
|
||||
# # 如果需要设置content_ids,请按照正确格式添加关联数据
|
||||
# }
|
||||
|
||||
content_data_list.append((0, 0, {
|
||||
'property_id': [(0, 0, property_values)],
|
||||
'config_id': [(0, 0, config_values)],
|
||||
}))
|
||||
else:
|
||||
content_data_list.append((0, 0, {
|
||||
'property_id': [(0, 0, property_values)],
|
||||
# 'config_id': [(0, 0, config_values)],
|
||||
}))
|
||||
# 根据config_data为config.model的One2many字段(如options和table_children)构建命令列表
|
||||
option_vals = [
|
||||
(0, 0, {'key': 'option_key_1', 'text': 'option_text_1', 'lang': 'zh_CN'}),
|
||||
(0, 0, {'key': 'option_key_2', 'text': 'option_text_2', 'lang': 'zh_CN'})
|
||||
]
|
||||
vacation_vals = [{'key': 'vacation_key_1', 'text': 'vacation_text_1', 'lang': 'zh_CN'},
|
||||
{'key': 'vacation_key_2', 'text': 'vacation_text_2', 'lang': 'zh_CN'}]
|
||||
table_children_vals = [
|
||||
(0, 0, {
|
||||
'control_type': 'Text',
|
||||
'unique_control_id': 'control_id_1',
|
||||
'title': '控件名称1',
|
||||
'placeholder': '控件说明1',
|
||||
'require': True
|
||||
}),
|
||||
(0, 0, {
|
||||
'control_type': 'Number',
|
||||
'unique_control_id': 'control_id_2',
|
||||
'title': '控件名称2',
|
||||
'placeholder': '控件说明2',
|
||||
'require': False
|
||||
})
|
||||
]
|
||||
|
||||
# property_vals = [
|
||||
# (0, 0, {
|
||||
# 'control_type': 'Text',
|
||||
# 'unique_control_id': 'control_id_1',
|
||||
# 'title': '控件名称1',
|
||||
# 'placeholder': '控件说明1',
|
||||
# 'require': True
|
||||
# }),
|
||||
# (0, 0, {
|
||||
# 'control_type': 'Number',
|
||||
# 'unique_control_id': 'control_id_2',
|
||||
# 'title': '控件名称2',
|
||||
# 'placeholder': '控件说明2',
|
||||
# 'require': False
|
||||
# })
|
||||
# ]
|
||||
|
||||
config_values = {
|
||||
'date_type': config_data.get('type', '') if '"date":' in config_data else '',
|
||||
'selector_type': config_data.get('type', '') if '"selector":' in config_data else '',
|
||||
'contact_type': config_data.get('type', '') if '"contact":' in config_data else '',
|
||||
'contact_mode': config_data.get('mode', '') if '"contact":' in config_data else '',
|
||||
'options': option_vals if '"selector":' in config_data else [(6, 0, [])], # 使用示例中的option_vals
|
||||
'table_children': table_children_vals if '"table":' in config_data else [(6, 0, [])],
|
||||
# 使用示例中的property_vals
|
||||
'vacation_list': vacation_vals if '"vacation_list":' in config_data else [] # 添加vacation_vals
|
||||
}
|
||||
|
||||
content_data_list.append((0, 0, {
|
||||
'property_id': [(0, 0, property_values)],
|
||||
'config_id': [(0, 0, config_values)] if 'config' in control_data else [(6, 0, [])],
|
||||
}))
|
||||
|
||||
# 准备用于创建记录的字段值,包括content_ids数据
|
||||
values = {
|
||||
|
||||
@@ -10,7 +10,7 @@ access_wxwork_template_settings,wxwork.template.settings,model_wxwork_template_s
|
||||
access_property_model,property.model,model_property_model,base.group_user,1,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_vacation_type,vacation.type,model_vacation_type,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
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -26,6 +26,7 @@
|
||||
<field name="name"/>
|
||||
<field name="process_code"/>
|
||||
<field name="content_ids"/>
|
||||
<field name="vacation_config_id"/>
|
||||
<field name="company_id"/>
|
||||
<field name="choose_department"/>
|
||||
<field name="use_template_approver"/>
|
||||
@@ -57,7 +58,7 @@
|
||||
</strong>
|
||||
</div>
|
||||
</div>
|
||||
<field name="company_id" options="{'color_field': 'color'}"/>
|
||||
<!-- <field name="company_id" options="{'color_field': 'color'}"/> -->
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
@@ -137,13 +138,17 @@
|
||||
<field name="control_id"/>
|
||||
<field name="date_type"/>
|
||||
<field name="selector_type"/>
|
||||
<field name="options"/>
|
||||
<field name="contact_type"/>
|
||||
<field name="contact_mode"/>
|
||||
<field name="table_children"/>
|
||||
<field name="table_type"/>
|
||||
<field name="attendance_type"/>
|
||||
<field name="attendance_date_range_type"/>
|
||||
<field name="vacation_list"/>
|
||||
|
||||
<!-- <field name="options"/> -->
|
||||
<!-- <field name="contact_type"/> -->
|
||||
<!-- <field name="contact_mode"/> -->
|
||||
<!-- <field name="table_children"/> -->
|
||||
<!-- <field name="attendance_type"/> -->
|
||||
<!-- <field name="attendance_date_range_type"/> -->
|
||||
<!-- <field name="vacation_list"/> -->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -156,13 +161,18 @@
|
||||
<field name="control_id"/>
|
||||
<field name="date_type"/>
|
||||
<field name="selector_type"/>
|
||||
<field name="options"/>
|
||||
<field name="contact_type"/>
|
||||
<field name="contact_mode"/>
|
||||
<field name="table_children"/>
|
||||
<field name="table_type"/>
|
||||
<field name="attendance_type"/>
|
||||
<field name="attendance_date_range_type"/>
|
||||
<field name="vacation_list"/>
|
||||
<!-- <field name="date_type"/> -->
|
||||
<!-- <field name="selector_type"/> -->
|
||||
<!-- <field name="options"/> -->
|
||||
<!-- <field name="contact_type"/> -->
|
||||
<!-- <field name="contact_mode"/> -->
|
||||
<!-- <field name="table_children"/> -->
|
||||
<!-- <field name="attendance_type"/> -->
|
||||
<!-- <field name="attendance_date_range_type"/> -->
|
||||
<!-- <field name="vacation_list"/> -->
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user