123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- from odoo import models, fields, api
- from odoo.exceptions import ValidationError
- from odoo.osv import expression
- from odoo.tools import Query
- from odoo.utils import spell
- import logging
- import json
- from lxml import etree
- import re
- COLOR_DIC = {'1': 'red', '2': 'green', '3': 'navy', '4': 'brown', '5': 'pink', '6': 'fuchsia'}
- _logger = logging.getLogger(__name__)
- # ======================== 注意 =======================================
- # =========修改任何内容,需要同步修改所有档案基类文件里的内容。搜索本行即可=========
- class BaseInfo(models.Model):
- _name = 'base_info'
- _description = u'档案基类'
- _module = 'archives'
- # _active_name = 'available'
- name = fields.Char(string=u'名称', required=True)
- spell = fields.Char(string=u'首拼')
- coding = fields.Char(string=u'编码')
- available = fields.Boolean(string=u'是否有效', default=True)
- company_id = fields.Many2one('res.company', string=u'公司',
- domain=lambda self: self.get_company_domain(),
- default=lambda self: self.env['res.company']._company_default_get())
- @api.model
- def get_model_name(self):
- return self._name
- @api.model_create_multi
- @api.returns('self', lambda value: value.id)
- def create(self, values):
- spell.set_spell(values)
- result = super(BaseInfo, self).create(values)
- # self.add_log(u'创建', result)
- return result
- def write(self, values):
- spell.set_spell(values)
- result = super(BaseInfo, self).write(values)
- # self.add_log(u'修改', self)
- return result
- def copy(self, default=None):
- default = dict(default or {})
- copied_count = self.search_count(
- [('name', '=like', u"Copy of {}%".format(self.name))])
- if not copied_count:
- new_name = u"Copy of {}".format(self.name)
- else:
- new_name = u"Copy of {} ({})".format(self.name, copied_count)
- default['name'] = new_name
- self.add_log(u'复制', self)
- return super(BaseInfo, self).copy(default)
- @api.model
- def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
- args = list(args or [])
- if not self._rec_name:
- _logger.warning("Cannot execute name_search, no _rec_name defined on %s", self._name)
- elif not (name == '' and operator == 'ilike'):
- if hasattr(self, 'coding'):
- args += ['|', '|', ('spell', 'ilike', name), (self._rec_name, operator, name),
- ('coding', 'ilike', name)]
- else:
- args += ['|', ('spell', 'ilike', name), (self._rec_name, operator, name), ]
- if hasattr(self, 'company_id'):
- args += ['|', ('company_id', 'in', self.env['res.users'].sudo().browse(self._uid).company_ids.ids),
- ('company_id', '=', False)]
- return self._search(args, limit=limit, access_rights_uid=name_get_uid)
- def unlink(self):
- self.add_log(u'删除', self)
- for bill in self:
- super(BaseInfo, bill).unlink()
- return True
- def add_log(self, operation, bills): # 注意:不要在前面加@api.model,否则添加保存的日志会报错
- self.env['archives.log'].add_log(operation=operation, model_name=bills._name, bill_id=bills.id,
- bill_name=bills.name)
- return
- def set_available(self):
- self.available = True
- self.add_log(u"启用", self)
- def un_set_available(self):
- self.available = False
- self.add_log(u"停用", self)
- @api.model
- def default_get(self, fields_):
- res = super(BaseInfo, self).default_get(fields_)
- _need_set_fields = self.env['archives.set_customer_setting'].get_need_set_fields(self._name)
- self.env['archives.set_customer_setting'].set_default(res, self._name, fields_, _need_set_fields)
- return res
- @api.model
- def _where_calc(self, domain, active_test=True):
- """Computes the WHERE clause needed to implement an OpenERP domain.
- :param domain: the domain to compute
- :type domain: list
- :param active_test: whether the default filtering of records with ``active``
- field set to ``False`` should be applied.
- :return: the query expressing the given domain as provided in domain
- :rtype: osv.query.Query
- """
- if self._active_name and active_test and self._context.get('active_test', True):
- # the item[0] trick below works for domain items and '&'/'|'/'!'
- # operators too
- if not any(item[0] == self._active_name for item in domain):
- domain = [(self._active_name, '=', 1)] + domain
- elif 'available' in self._fields and active_test and self._context.get('active_test', True):
- if not any(item[0] == 'available' for item in domain):
- domain = [('available', '=', True)] + domain
- if domain:
- return expression.expression(domain, self).query
- else:
- return Query(self.env.cr, self._table, self._table_query)
- def set_auxiliary_name(self):
- return self.env['archives.set_auxiliary_name'].send_and_open(self._name, self._description)
- # def modify_field_name(self):
- # return self.env['archives.set_modify_field_name'].get_wizard_page(self._name, self._description)
- #
- # @api.model
- # def load_views(self, views, options=None):
- # res = super(BaseInfo, self).load_views(views, options=None)
- # environment = self.env['archives.set_modify_field_name']
- # environment.modify_field_invisible(res, self._name)
- # return res
- @api.model
- def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
- """
- 增加对中文排序时按拼音排序的支持
- Private implementation of search() method, allowing specifying the uid to use for the access right check.
- This is useful for example when filling in the selection list for a drop-down and avoiding access rights errors,
- by specifying ``access_rights_uid=1`` to bypass access rights check, but not ir.rules!
- This is ok at the security level because this method is private and not callable through XML-RPC.
- :param access_rights_uid: optional user ID to use when checking access rights
- (not for ir.rules, this is only for ir.model.access)
- :return: a list of record ids or an integer (if count is True)
- """
- model = self.with_user(access_rights_uid) if access_rights_uid else self
- model.check_access_rights('read')
- if expression.is_false(self, args):
- # optimization: no need to query, as no record satisfies the domain
- return 0 if count else []
- # the flush must be done before the _where_calc(), as the latter can do some selects
- self._flush_search(args, order=order)
- query = self._where_calc(args)
- self._apply_ir_rules(query, 'read')
- if count:
- # Ignore order, limit and offset when just counting, they don't make sense and could
- # hurt performance
- query_str, params = query.select("count(1)")
- self._cr.execute(query_str, params)
- res = self._cr.fetchone()
- return res[0]
- order_value = self._generate_order_by(order, query).replace('ORDER BY ', '')
- query.order = self._handle_chinese_order(order_value)
- query.limit = limit
- query.offset = offset
- return query
- def _handle_chinese_order(self, order):
- """
- 处理排序字段,如果是按照name排序,则修改为支持拼音排序的形式
- postgresql中汉字默认是按照ASCII进行排序,需使用 convert_to(name, 'GBK')进行字符集转化
- :param order:
- :return:
- """
- order_lst = order.strip().split(' ')
- order_method = ''
- order_field = order_lst[0]
- if len(order_lst) == 2:
- order_method = order_lst[1]
- order_table_name, order_field_name = order_field.strip().split('.')
- if order_field_name.strip() == '"name"':
- return f"convert_to({order_field}, 'GBK') {order_method}"
- return order
- @api.model
- def fields_get(self, all_fields=None, attributes=None):
- res = super(BaseInfo, self).fields_get(all_fields, attributes)
- if 'form_edit' in self.env['ir.module.module']._installed():
- if 'form_edit.modify_field_name' in self.env:
- environment = self.env['form_edit.modify_field_name']
- environment.modify_field_name(res, self._name)
- return res
- @api.model
- def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
- result = super(BaseInfo, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, )
- doc = etree.XML(result.get('arch', ''))
- m = etree.tostring(doc)
- if 'form_edit' in self.env['ir.module.module']._installed():
- if view_type == 'form':
- company = self.env.company.id
- setting = self.env['form_edit.modify_field_name'].sudo().search(
- [('user_id', '=', 2),
- ('table', '=', self._name), ('xml_type', '=', 'form'), ('company_id', '=', company)])
- if not setting:
- # setting = self.update_default_setting(setting, doc, setting.table_show_name)
- # else:
- setting = self.create_default_setting(self._name, doc, self._description)
- # res_dict = self.get_detail_dict(setting)
- head_field_sequence = setting.head_fields_sequence
- other_field_sequence = setting.other_fields_sequence
- second_field_sequence = setting.second_fields_sequence
- third_field_sequence = setting.third_fields_sequence
- fourth_field_sequence = setting.fourth_fields_sequence
- fifth_field_sequence = setting.fifth_fields_sequence
- col = setting.show_col_number
- col_other = setting.show_col_number_other
- col_second = setting.second_col
- col_third = setting.third_col
- col_fourth = setting.fourth_col
- col_fifth = setting.fifth_col
- full_screen = setting.full_screen
- # 表头分列
- if col:
- doc = self.get_col_value(doc, col, 'head')
- # 其它页分列
- if col_other:
- doc = self.get_col_value(doc, col_other, 'other')
- # 第二页分列
- if col_second:
- doc = self.get_col_value(doc, col_second, 'second')
- # 第三页分列
- if col_third:
- doc = self.get_col_value(doc, col_third, 'third')
- # 第四页分列
- if col_fourth:
- doc = self.get_col_value(doc, col_fourth, 'fourth')
- # 第五页页分列
- if col_fifth:
- doc = self.get_col_value(doc, col_fifth, 'fifth')
- # 表头排序
- if head_field_sequence:
- res = self.get_head_field_name(head_field_sequence)
- group_top = "//sheet//group[@name='group_top']"
- doc, result = self.get_sequence_fields(res, group_top, doc, setting.table, modify_setting=setting,
- result=result)
- dd = etree.tostring(doc)
- # 其它页排序
- if other_field_sequence:
- res = self.get_head_field_name(other_field_sequence)
- group_other = "//sheet//group[@name='group_other']"
- doc, result = self.get_sequence_fields(res, group_other, doc, setting.table, result=result,
- modify_setting=setting, flag=True)
- dd = etree.tostring(doc)
- # 第二页页排序
- if second_field_sequence:
- res = self.get_head_field_name(second_field_sequence)
- group_second = "//sheet//group[@name='group_second']"
- doc, result = self.get_sequence_fields(res, group_second, doc, setting.table, result=result,
- modify_setting=setting, flag=True)
- dd = etree.tostring(doc)
- # 第三页排序
- if third_field_sequence:
- res = self.get_head_field_name(third_field_sequence)
- group_third = "//sheet//group[@name='group_third']"
- doc, result = self.get_sequence_fields(res, group_third, doc, setting.table, result=result,
- modify_setting=setting, flag=True)
- dd = etree.tostring(doc)
- # 第四页排序
- if fourth_field_sequence:
- res = self.get_head_field_name(fourth_field_sequence)
- group_fourth = "//sheet//group[@name='group_fourth']"
- doc, result = self.get_sequence_fields(res, group_fourth, doc, setting.table, result=result,
- modify_setting=setting, flag=True)
- dd = etree.tostring(doc)
- # 第五页排序
- if fifth_field_sequence:
- res = self.get_head_field_name(fifth_field_sequence)
- group_fifth = "//sheet//group[@name='group_fifth']"
- doc, result = self.get_sequence_fields(res, group_fifth, doc, setting.table, result=result,
- modify_setting=setting, flag=True)
- dd = etree.tostring(doc)
- # 全屏
- if full_screen:
- exist_style = doc.xpath('//style')
- if exist_style:
- style_text = exist_style[0].text
- if 'o_form_view ' not in style_text.split('.'):
- exist_style[
- 0].text = style_text + "\n .o_form_view .o_form_sheet_bg .o_form_sheet{\n max-width: 99%;\n }\n"
- else:
- node_location = doc.xpath('//form')[0]
- style = etree.Element('style')
- style.text = "\n .o_form_view .o_form_sheet_bg .o_form_sheet{\n max-width: 99%;\n }\n"
- node_location.insert(1, style)
- if not full_screen:
- exist_style = doc.xpath('//style')
- if exist_style:
- style_text = exist_style[0].text
- split_style_text = style_text.split("}\n")[0:-1]
- if 'o_form_view ' in style_text.split('.'):
- style_t = ""
- for _s in split_style_text:
- if 'o_form_view ' not in _s:
- style_t += "\n" + _s + "}\n"
- exist_style[0].text = style_t
- result['arch'] = etree.tostring(doc)
- return result
- # 根据序列中的ids 返回 反向的 字段名称
- def get_head_field_name(self, head_sequence):
- res = []
- result = []
- _l = [int(i) for i in head_sequence.split(',')]
- for _ in _l:
- f = self.env['ir.model.fields'].sudo().search([('id', '=', _)]).name
- res.append(f)
- return res
- def get_col_value(self, doc, col, flag):
- if flag == 'head':
- expr = "//group[@name='group_top']"
- elif flag == 'other':
- expr = "//group[@name='group_other']"
- elif flag == 'second':
- expr = "//group[@name='group_second']"
- elif flag == 'third':
- expr = "//group[@name='group_third']"
- elif flag == 'fourth':
- expr = "//page//group[@name='group_fourth']"
- else:
- expr = "//group[@name='group_fifth']"
- res_list = doc.xpath(expr)
- for res in res_list:
- res.set('col', str(col))
- return doc
- def get_sequence_fields(self, res, expr, doc, setting, result=None, modify_setting=None, flag=False):
- num = 1
- if result and flag:
- _doc = etree.XML(result.get('arch', ''))
- res_dic = {}
- for i in res:
- if not i:
- continue
- i = i
- if self.fields_exist(i, setting):
- node_expr = "//group//field[@name='{}']".format(i)
- if result and flag:
- node = _doc.xpath(node_expr)
- else:
- node = doc.xpath(node_expr)
- if node:
- res_dic[num] = node[-1]
- else:
- _fields = self.env[setting].fields_get().get(i)
- result.get('fields')[i] = _fields
- field = etree.Element('field')
- field.set('modifiers', '{}')
- field.set('name', i)
- field.set('options', json.dumps({'no_open': True, 'no_create': True}))
- res_dic[num] = field
- num += 1
- doc = self.clear_group_data(expr, doc)
- group_new = doc.xpath(expr)
- group_str = etree.tostring(group_new[0])
- for k, v in res_dic.items():
- group_new[0].insert(k, v)
- # 只读、必填、颜色
- res_setting = modify_setting.detail.filtered(lambda a: a.field_name in res)
- for i in res_setting:
- readonly = 1 if i.after_readonly == '1' else 0
- required = 1 if i.after_required == '1' else 0
- color = COLOR_DIC.get(i.select_color, False)
- expr = "//group//field[@name='{}']".format(i.field_name)
- dic = {}
- if doc.xpath(expr):
- if color:
- style_color = 'color:{};'.format(color)
- style = doc.xpath(expr)[0].attrib.get('style')
- if style:
- _style_color = style
- style_color = ';' + _style_color + ';' + style_color
- doc.xpath(expr)[0].set('style', style_color)
- modifiers = doc.xpath(expr)[0].attrib.get('modifiers')
- modifiers_dict = json.loads(modifiers)
- read_val = modifiers_dict.get('readonly', False)
- req_val = modifiers_dict.get('required', False)
- invisible_val = modifiers_dict.get('invisible', False)
- if isinstance(read_val, list):
- dic['readonly'] = read_val
- else:
- dic['readonly'] = readonly
- if isinstance(req_val, list):
- dic['required'] = req_val
- else:
- dic['required'] = required
- if invisible_val:
- dic['invisible'] = invisible_val
- modifiers_val = json.dumps(dic)
- doc.xpath(expr)[0].set('modifiers', modifiers_val)
- return doc, result
- def clear_group_data(self, expr, doc):
- ddd = etree.tostring(doc)
- group = doc.xpath(expr)[0]
- child_node = group.getchildren()
- for i in child_node:
- group.remove(i)
- return doc
- def fields_exist(self, field, setting):
- flag = False
- _fields = self.env[setting].fields_get().keys()
- if field in _fields:
- flag = True
- return flag
- def create_default_setting(self, table, doc, description):
- res_head, res_other, res_second, res_third, res_fourth, res_fifth, second_name, third_name, fourth_name, fifth_name = self.get_head_or_other_sequence(
- table, doc,
- description)
- bill = self.env['form_edit.modify_field_name'].sudo().create(
- {'table': table,
- 'user_id': 2,
- 'table_show_name': description,
- 'sequence_head_fields': [(6, 0, [int(i) for i in res_head])] if res_head else [],
- 'head_fields_sequence': ','.join(res_head) if res_head else '',
- 'sequence_other_fields': [(6, 0, [int(i) for i in res_other])] if res_other else [],
- 'other_fields_sequence': ','.join(res_other) if res_other else '',
- 'sequence_second_fields': [(6, 0, [int(i) for i in res_second])] if res_second else [],
- 'second_fields_sequence': ','.join(res_second) if res_second else '',
- 'second_name': second_name if second_name else '',
- 'sequence_third_fields': [(6, 0, [int(i) for i in res_third])] if res_third else [],
- 'third_fields_sequence': ','.join(res_third) if res_third else '',
- 'third_name': third_name if third_name else '',
- 'sequence_fourth_fields': [(6, 0, [int(i) for i in res_fourth])] if res_fourth else [],
- 'fourth_fields_sequence': ','.join(res_fourth) if res_fourth else '',
- 'fourth_name': fourth_name if fourth_name else '',
- 'sequence_fifth_fields': [(6, 0, [int(i) for i in res_fifth])] if res_fifth else [],
- 'fifth_fields_sequence': ','.join(res_fifth) if res_fifth else '',
- 'fifth_name': fifth_name if fifth_name else '',
- 'parent_table': table,
- 'company_id': self.env.company.id
- }
- )
- return bill
- def update_default_setting(self, setting, doc, description):
- res_head, res_other, res_second, res_third, res_fourth, res_fifth, second_name, third_name, fourth_name, fifth_name = self.get_head_or_other_sequence(
- setting,
- doc)
- head = self.get_invisible(res_head, setting.head_fields_sequence)
- other = self.get_invisible(res_other, setting.other_fields_sequence)
- second = self.get_invisible(res_second, setting.second_fields_sequence)
- third = self.get_invisible(res_third, setting.third_fields_sequence)
- fourth = self.get_invisible(res_fourth, setting.fourth_fields_sequence)
- fifth = self.get_invisible(res_fifth, setting.fifth_fields_sequence)
- val = {}
- if not setting.head_fields_sequence:
- if res_head:
- val['head_fields_sequence'] = ','.join(res_head),
- val['sequence_head_fields'] = [(6, 0, [int(i) for i in res_head])],
- else:
- if head:
- old = head
- head = setting.head_fields_sequence + head
- self.create_m2m(old, setting, 'sequence_head_fields', 'head')
- val['head_fields_sequence'] = head
- if not setting.other_fields_sequence:
- if res_other:
- val['sequence_other_fields'] = [(6, 0, [int(i) for i in res_other])],
- val['other_fields_sequence'] = ','.join(res_other),
- else:
- if other:
- old = other
- other = setting.other_fields_sequence + other
- self.create_m2m(old, setting, 'sequence_other_fields', 'other')
- val['other_fields_sequence'] = other
- if not setting.second_fields_sequence:
- if res_second:
- val['sequence_second_fields'] = [(6, 0, [int(i) for i in res_second])],
- val['second_fields_sequence'] = ','.join(res_second),
- val['second_name'] = second_name if second_name else '',
- else:
- if second:
- old = second
- second = setting.second_fields_sequence + second
- self.create_m2m(old, setting, 'sequence_second_fields', 'second')
- val['second_fields_sequence'] = second,
- val['second_name'] = second_name if second_name else '',
- if not setting.third_fields_sequence:
- if res_third:
- val['sequence_third_fields'] = [(6, 0, [int(i) for i in res_third])],
- val['third_fields_sequence'] = ','.join(res_third),
- val['third_name'] = third_name if third_name else ''
- else:
- if third:
- old = third
- third = setting.third_fields_sequence + third
- val['third_fields_sequence'] = third
- self.create_m2m(old, setting, 'sequence_third_fields', 'third')
- val['third_name'] = third_name if third_name else ''
- if not setting.fourth_fields_sequence:
- if res_fourth:
- val['sequence_fourth_fields'] = [(6, 0, [int(i) for i in res_fourth])],
- val['fourth_fields_sequence'] = ','.join(res_fourth),
- val['fourth_name'] = fourth_name if fourth_name else '',
- else:
- if fourth:
- old = fourth
- fourth = setting.fourth_fields_sequence + fourth
- val['fourth_fields_sequence'] = fourth,
- self.create_m2m(old, setting, 'sequence_fourth_fields', 'fourth')
- val['fourth_name'] = fourth_name if fourth_name else '',
- # 模块
- if not setting.fifth_fields_sequence:
- if res_fifth:
- val['sequence_fifth_fields'] = [(6, 0, [int(i) for i in res_fifth])],
- val['fifth_fields_sequence'] = ','.join(res_fifth),
- val['fifth_name'] = fifth_name if fifth_name else '',
- else:
- if fifth:
- old = fifth
- fifth = setting.fifth_fields_sequence + fifth
- val['fifth_fields_sequence'] = fifth
- self.create_m2m(old, setting, 'sequence_fifth_fields', 'fifth')
- val['fifth_name'] = fifth_name if fifth_name else '',
- # 模块
- setting.update(val)
- return setting
- def get_name_list(self, table, doc, expr, invisible_flag=None):
- list_name = []
- sequence_ids = []
- res = doc.xpath(expr)
- if res:
- child_node = res[0].getchildren()
- for ch in child_node:
- if invisible_flag:
- if ch.attrib.get('modifiers', False):
- modifiers_dic = json.loads(ch.attrib.get('modifiers'))
- n = ch.attrib.get('name')
- m = modifiers_dic.get('invisible')
- if m == 1:
- list_name.append(ch.attrib.get('name'))
- else:
- list_name.append(ch.attrib.get('name'))
- domain = [('model', '=', table), ('name', 'in', list_name)]
- sequence_ids = self.env['ir.model.fields'].sudo().search(domain)
- sequence_sort = sorted(sequence_ids, key=lambda field: list_name.index(field.name))
- sequence_ids = [str(i.id) for i in sequence_sort]
- return sequence_ids
- def get_head_or_other_sequence(self, table, doc, description=None):
- if description:
- _table = table
- else:
- _table = table.table
- expr = "//group[@name='group_top']"
- expr1 = "//group[@name='group_other']"
- expr2 = "//group[@name='group_second']"
- expr3 = "//group[@name='group_third']"
- expr4 = "//group[@name='group_fourth']"
- expr5 = "//group[@name='group_fourth']"
- second_name, third_name, fourth_name, fifth_name = '', '', '', ''
- head_invisible = self.get_name_list(_table, doc, expr,
- invisible_flag=True) # 获取参与计算的计算的second_name = {_Element: 1} <Element page at 0x7f10a484aa28>字段
- _head = self.get_compute_sequence(description, _table, doc, expr, table, 'head_fields_sequence')
- res_head = self.get_compute_sequence_list(_head, head_invisible)
- other_invisible = self.get_name_list(_table, doc, expr1, invisible_flag=True)
- _other = self.get_compute_sequence(description, _table, doc, expr1, table, 'other_fields_sequence')
- res_other = self.get_compute_sequence_list(_other, other_invisible)
- second_invisible = self.get_name_list(_table, doc, expr2, invisible_flag=True)
- _second = self.get_compute_sequence(description, _table, doc, expr2, table, 'second_fields_sequence')
- res_second = self.get_compute_sequence_list(_second, second_invisible)
- if res_second:
- second_name = doc.xpath(expr2)[0].getparent().attrib.get('string')
- third_invisible = self.get_name_list(_table, doc, expr3, invisible_flag=True)
- _third = self.get_compute_sequence(description, _table, doc, expr3, table, 'third_fields_sequence')
- res_third = self.get_compute_sequence_list(_third, third_invisible)
- if res_third:
- third_name = doc.xpath(expr3)[0].getparent().attrib.get('string')
- fourth_invisible = self.get_name_list(_table, doc, expr4, invisible_flag=True)
- _fourth = self.get_compute_sequence(description, _table, doc, expr4, table, 'fourth_fields_sequence')
- res_fourth = self.get_compute_sequence_list(_fourth, fourth_invisible)
- if res_fourth:
- fourth_name = doc.xpath(expr4)[0].getparent().attrib.get('string')
- fifth_invisible = self.get_name_list(_table, doc, expr5, invisible_flag=True)
- _fifth = self.get_compute_sequence(description, _table, doc, expr5, table, 'fifth_fields_sequence')
- res_fifth = self.get_compute_sequence_list(_fifth, fifth_invisible)
- if res_fifth:
- fifth_name = doc.xpath(expr5)[0].getparent().attrib.get('string')
- return res_head, res_other, res_second, res_third, res_fourth, res_fifth, second_name, third_name, fourth_name, fifth_name
- @staticmethod
- def get_compute_sequence_list(val, invisible_val):
- res = val
- res_ = [i for i in invisible_val if i not in val]
- res_list = filter(lambda a: a != 'None', res + res_)
- return list(res_list)
- def get_compute_sequence(self, description, _table, doc, expr, table, field):
- if description:
- res = self.get_name_list(_table, doc, expr)
- else:
- if getattr(table, field):
- res = [str(i) for i in getattr(table, field).split(',')]
- else:
- res = self.get_name_list(_table, doc, expr)
- return res
- def get_invisible(self, res, sequence):
- seq = ''
- if sequence:
- r_sequence = sequence.split(',')
- invisible = [i for i in res if i not in r_sequence]
- seq = ',' + ','.join(invisible) if invisible else ''
- return seq
- def create_m2m(self, other, setting, sequence, field):
- lis = other.split(',')[1:]
- lis = [int(i) for i in lis]
- setting_id = setting.id
- _lis = [i for i in lis if i not in getattr(setting, sequence).ids]
- if _lis:
- for i in lis:
- sql = """insert into modify_sequence_{}_fields (form_edit_modify_field_name_id,ir_model_fields_id) VALUES({},{})""".format(
- field, setting_id, i)
- self.env.cr.execute(sql)
- def get_company_domain(self):
- domain = []
- if hasattr(self, 'company_id'):
- domain = [('id', 'in', self.env['res.users'].sudo().browse(self._uid).company_ids.ids)]
- return domain
- def form_edit(self):
- if 'form_edit' in self.env['ir.module.module']._installed():
- table = {'table_id': self.id, 'model': self._name}
- return self.env['form_edit.modify_field_name'].get_wizard_page(table)
- else:
- raise ValidationError('请安装字段修改模块')
- def enter_handler(self):
- if 'enter_event' in self.env['ir.module.module']._installed():
- table = {'table_id': self.id, 'model': self._name}
- return self.env['enter_event.config'].get_config(table)
- else:
- raise ValidationError('请安装回车工具模块')
- def get_logic(self):
- table = {'table_id': self.id, 'model': self._name, 'company_id': self.company_id.id}
- return self.env['archives.work_logic_setting'].get_setting(table)
- def batch_finish(self):
- for i in self:
- if int(i.bill_state) == 10:
- i.finish()
- def batch_un_finish(self):
- for i in self:
- if int(i.bill_state) == 20:
- i.un_finish()
- @api.model
- def get_user_group(self):
- flag = False
- if self._uid in self.env.ref('archives.group_user_function_setting').users.ids:
- flag = True
- return flag
- @api.model
- def get_form_weight(self):
- flag = False
- if not self._fields.get('available', False):
- flag = True
- return flag
- class BaseInfoUnique(BaseInfo):
- _name = 'base_info_unique'
- _description = u'档案基类:无重名'
- @api.constrains('name')
- def _check_name(self):
- if self.name:
- result = self.search_count(
- [('name', '=', self.name), ('id', '!=', self.id)])
- if result:
- raise ValidationError('{档案}已存在')
|