GoodERP
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

105 lines
3.0KB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 上海开阖软件有限公司 (http://www.osbzr.com)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import _
  5. from odoo import api, models
  6. from odoo.exceptions import UserError
  7. '''
  8. odoo 按日期分组的显示格式不符合中国用户习惯
  9. 按月分组显示为【十月 2022】 需改成 【2022-10】
  10. 按日期分组显示为 【15 十月 2022】需改成 【2022-10-15】
  11. '''
  12. models.READ_GROUP_DISPLAY_FORMAT = {
  13. 'hour': 'hh:00 dd MM', # 哪里有按小时分组的?
  14. 'day': 'YYYY-MM-dd', # 年月日
  15. 'week': "YYYY-'第'w'周'", # w YYYY = ISO week-year
  16. 'month': 'YYYY-MM',
  17. 'quarter': 'YYYY-QQQ',
  18. 'year': 'YYYY',
  19. }
  20. '''
  21. 单据自动编号,避免在所有单据对象上重载create方法
  22. 只需在ir.sequence里新增一条code与当前model相同的记录即可实现自动编号
  23. '''
  24. create_original = models.BaseModel.create
  25. @api.model_create_multi
  26. @api.returns('self', lambda value: value.id)
  27. def create(self, vals_list):
  28. if not self._name.split('.')[0] in ['mail', 'ir', 'res']:
  29. for vals in vals_list:
  30. if not vals.get('name'):
  31. next_name = self.env['ir.sequence'].next_by_code(self._name)
  32. if next_name:
  33. vals.update({'name': next_name})
  34. record_ids = create_original(self, vals_list)
  35. return record_ids
  36. models.BaseModel.create = create
  37. '''
  38. 不能删除已确认的单据
  39. 避免在所有单据对象上重载unlink
  40. 删除记录要在ir.logging表里记录
  41. '''
  42. # 部分模型也是用了done这个状态,需要放行
  43. BYPASS_MODELS = [
  44. 'survey.user_input',
  45. 'survey.user_input_line'
  46. ]
  47. # 部分模型不需要记录删除时的 log
  48. _NOLOG_MODELS = [
  49. 'ir.logging',
  50. 'website.page',
  51. 'mail.message',
  52. 'ir.model.data',
  53. ]
  54. unlink_original = models.BaseModel.unlink
  55. def unlink(self):
  56. IrLogging = self.env['ir.logging']
  57. field_list = [item[0] for item in self._fields.items()]
  58. for record in self:
  59. if record.is_transient():
  60. continue
  61. if 'state' in field_list and self._name not in BYPASS_MODELS:
  62. if record.state == 'done':
  63. raise UserError(_('不能删除已确认的 %s !') % record._description)
  64. if self._name in _NOLOG_MODELS or not record.display_name:
  65. continue
  66. IrLogging.sudo().create({
  67. 'name': record.display_name,
  68. 'type': 'client',
  69. 'dbname': self.env.cr.dbname,
  70. 'level': 'WARN',
  71. 'message': _('%s被删除') % self._name,
  72. 'path': self.env.user.name,
  73. 'func': 'delete',
  74. 'line': 1})
  75. return unlink_original(self)
  76. models.BaseModel.unlink = unlink
  77. '''
  78. 在所有模型上增加了作废方法
  79. '''
  80. def action_cancel(self):
  81. for record in self:
  82. if 'state' in [item[0] for item in self._fields.items()]:
  83. record.state = 'cancel'
  84. return True
  85. models.BaseModel.action_cancel = action_cancel
上海开阖软件有限公司 沪ICP备12045867号-1