wx_message_setting.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # # -*- coding: utf-8 -*-
  2. #
  3. # from odoo import models, fields, api
  4. # from odoo.exceptions import ValidationError
  5. # from odoo.utils.constant import APPROVE_MODEL
  6. # from odoo.utils import util
  7. #
  8. # MODEL_ORDER = 'jc_sale.sale_order'
  9. # MODEL_CLASS_PRICE = 'jc_sale.class_price'
  10. # MODEL_RECEIPT = 'jc_finance.receipt'
  11. # MODEL_MEMO_TICKET = 'jc_finance.memo_ticket'
  12. #
  13. # FIELD_CUSTOMER = u'{客户}'
  14. # FIELD_STAFF = u'{业务员}'
  15. # FIELD_MONEY = u'{金额}'
  16. # FIELD_PERSON = u'{申请人}'
  17. # FIELD_UNIT = u'{单位}'
  18. # FIELD_EXECUTE_DATE = u'{执行日期}'
  19. # DIC = {
  20. # MODEL_ORDER: [(FIELD_CUSTOMER, 'customer_id', 'name'),
  21. # (FIELD_STAFF, 'staff_id', 'name'),
  22. # (FIELD_MONEY, 'total_money'),
  23. # (FIELD_PERSON, 'create_uid', 'name')],
  24. # MODEL_CLASS_PRICE: [(FIELD_PERSON, 'create_uid', 'name'),
  25. # (FIELD_EXECUTE_DATE, 'date')],
  26. # MODEL_RECEIPT: [(FIELD_UNIT, 'customer_id', 'name'),
  27. # (FIELD_MONEY, 'total_money'),
  28. # (FIELD_PERSON, 'create_uid', 'name')],
  29. # MODEL_MEMO_TICKET: [(FIELD_UNIT, 'customer_id', 'name'),
  30. # (FIELD_MONEY, 'total_money'),
  31. # (FIELD_PERSON, 'create_uid', 'name')],
  32. # }
  33. #
  34. #
  35. # class MessageSetting(models.Model):
  36. # _name = 'we_chart.wx_message_setting'
  37. # _description = u'微信小程序:消息设置'
  38. # _order = 'id desc'
  39. #
  40. # model_id = fields.Many2one('ir.model', u'单据', required=True, domain=[('model', 'in', APPROVE_MODEL)])
  41. # template = fields.Char(u'模板')
  42. # show = fields.Char(u'可用字段', compute='_compute_show')
  43. #
  44. # _sql_constraints = [
  45. # ('model_unique',
  46. # 'UNIQUE(model_id)',
  47. # u"当前单据已设置过"),
  48. # ]
  49. #
  50. # # @api.multi
  51. # def name_get(self):
  52. # result = super(MessageSetting, self).name_get()
  53. # return [(result[0][0], self.model_id.name if self.model_id else u'消息设置')]
  54. #
  55. # @api.depends('model_id')
  56. # def _compute_show(self):
  57. # for bill in self:
  58. # if bill.model_id.model not in DIC:
  59. # continue
  60. # template = DIC[self.model_id.model]
  61. # _fields = [pair[0] for pair in template]
  62. # bill.show = ','.join(_fields)
  63. # return
  64. #
  65. # def query_template(self, model):
  66. # domain = [('model_id.model', '=', model)]
  67. # res = self.sudo().search(domain)
  68. # return res[0] if res else None
  69. #
  70. # def get_value(self, record):
  71. # if self.model_id.model not in DIC:
  72. # return self.template
  73. # _format = self.template
  74. # if not _format:
  75. # return ''
  76. # template = DIC[self.model_id.model]
  77. # for pair in template:
  78. # if pair[0] not in _format:
  79. # continue
  80. # if len(pair) < 2:
  81. # continue
  82. # if len(pair) == 2:
  83. # if hasattr(record, pair[1]):
  84. # v = getattr(record, pair[1])
  85. # if not util.is_string(v):
  86. # v = str(v)
  87. # _format = _format.replace(pair[0], v)
  88. # else:
  89. # _fields = pair[1:]
  90. # data = record
  91. # success = True
  92. # for _f in _fields:
  93. # if hasattr(data, _f):
  94. # data = getattr(data, _f)
  95. # else:
  96. # success = False
  97. # break
  98. # if not success:
  99. # continue
  100. # if not util.is_string(data):
  101. # data = str(data)
  102. # _format = _format.replace(pair[0], data)
  103. # return _format