# # -*- coding: utf-8 -*- # # from odoo import models, fields, api # from odoo.exceptions import ValidationError # from odoo.utils.constant import APPROVE_MODEL # from odoo.utils import util # # MODEL_ORDER = 'jc_sale.sale_order' # MODEL_CLASS_PRICE = 'jc_sale.class_price' # MODEL_RECEIPT = 'jc_finance.receipt' # MODEL_MEMO_TICKET = 'jc_finance.memo_ticket' # # FIELD_CUSTOMER = u'{客户}' # FIELD_STAFF = u'{业务员}' # FIELD_MONEY = u'{金额}' # FIELD_PERSON = u'{申请人}' # FIELD_UNIT = u'{单位}' # FIELD_EXECUTE_DATE = u'{执行日期}' # DIC = { # MODEL_ORDER: [(FIELD_CUSTOMER, 'customer_id', 'name'), # (FIELD_STAFF, 'staff_id', 'name'), # (FIELD_MONEY, 'total_money'), # (FIELD_PERSON, 'create_uid', 'name')], # MODEL_CLASS_PRICE: [(FIELD_PERSON, 'create_uid', 'name'), # (FIELD_EXECUTE_DATE, 'date')], # MODEL_RECEIPT: [(FIELD_UNIT, 'customer_id', 'name'), # (FIELD_MONEY, 'total_money'), # (FIELD_PERSON, 'create_uid', 'name')], # MODEL_MEMO_TICKET: [(FIELD_UNIT, 'customer_id', 'name'), # (FIELD_MONEY, 'total_money'), # (FIELD_PERSON, 'create_uid', 'name')], # } # # # class MessageSetting(models.Model): # _name = 'we_chart.wx_message_setting' # _description = u'微信小程序:消息设置' # _order = 'id desc' # # model_id = fields.Many2one('ir.model', u'单据', required=True, domain=[('model', 'in', APPROVE_MODEL)]) # template = fields.Char(u'模板') # show = fields.Char(u'可用字段', compute='_compute_show') # # _sql_constraints = [ # ('model_unique', # 'UNIQUE(model_id)', # u"当前单据已设置过"), # ] # # # @api.multi # def name_get(self): # result = super(MessageSetting, self).name_get() # return [(result[0][0], self.model_id.name if self.model_id else u'消息设置')] # # @api.depends('model_id') # def _compute_show(self): # for bill in self: # if bill.model_id.model not in DIC: # continue # template = DIC[self.model_id.model] # _fields = [pair[0] for pair in template] # bill.show = ','.join(_fields) # return # # def query_template(self, model): # domain = [('model_id.model', '=', model)] # res = self.sudo().search(domain) # return res[0] if res else None # # def get_value(self, record): # if self.model_id.model not in DIC: # return self.template # _format = self.template # if not _format: # return '' # template = DIC[self.model_id.model] # for pair in template: # if pair[0] not in _format: # continue # if len(pair) < 2: # continue # if len(pair) == 2: # if hasattr(record, pair[1]): # v = getattr(record, pair[1]) # if not util.is_string(v): # v = str(v) # _format = _format.replace(pair[0], v) # else: # _fields = pair[1:] # data = record # success = True # for _f in _fields: # if hasattr(data, _f): # data = getattr(data, _f) # else: # success = False # break # if not success: # continue # if not util.is_string(data): # data = str(data) # _format = _format.replace(pair[0], data) # return _format