plan.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. from odoo import models, fields, api
  2. from datetime import timedelta
  3. from dateutil.relativedelta import relativedelta
  4. from addons_main.archives.models.base import base_bill
  5. delta_dict = {
  6. 'days': relativedelta(days=0),
  7. 'weeks': relativedelta(weeks=1),
  8. 'months': relativedelta(months=1),
  9. 'years': relativedelta(years=1)
  10. }
  11. class Plan(base_bill.Bill):
  12. _name = 'jc_cooperation.plan'
  13. _description = u'协作:计划'
  14. _order = 'id desc'
  15. _inherit = ['mail.thread']
  16. _module = 'jc_cooperation'
  17. date_start = fields.Date(string=u'开始日期', default=fields.Date.context_today, required=True)
  18. date_end = fields.Date(string=u'结束日期', required=True)
  19. plan_type = fields.Selection([('days', '日计划'), ('weeks', '周计划'), ('months', '月计划'), ('years', '年计划')],
  20. string=u'计划类型',
  21. required=True)
  22. person_id = fields.Many2one('archives.staff', string=u'人员', required=True)
  23. create_date = fields.Date(string=u'制单日期', default=fields.Date.context_today, required=True, readonly=True)
  24. plan_content = fields.Html(string=u'计划内容')
  25. work_summary = fields.Html(string=u'工作总结')
  26. next_plan_content = fields.Html(string=u'下期计划')
  27. department_id = fields.Many2one('archives.department', string=u'部门')
  28. company_id = fields.Many2one('res.company', string=u'公司')
  29. active = fields.Boolean(default=True)
  30. color = fields.Integer(string=u'颜色')
  31. process_id = fields.Many2one('archives.common_archive', domain=[('archive_name', '=', 200)], string=u'阶段',
  32. group_expand='_read_group_process_ids',
  33. track_visibility='onchange')
  34. is_false = fields.Boolean(string='False', helper='仅用于判断值为False的方法中。===请勿赋值===', readonly=True)
  35. @api.onchange('plan_type')
  36. def _onchange_for_plan_type(self):
  37. if self.plan_type:
  38. self.date_end = fields.Date.from_string(self.date_start) + (delta_dict.get(self.plan_type) or relativedelta(
  39. days=0))
  40. @api.onchange('date_start')
  41. def _onchange_for_date_start(self):
  42. if self.date_start:
  43. self.date_end = fields.Date.from_string(self.date_start) + (delta_dict.get(self.plan_type) or relativedelta(
  44. days=0))
  45. @api.onchange('date_end')
  46. def _onchange_for_date_end(self):
  47. if self.date_end:
  48. self.date_start = fields.Date.from_string(self.date_end) - (delta_dict.get(self.plan_type) or relativedelta(
  49. days=0))
  50. @api.model
  51. def _read_group_process_ids(self, stages, domain, order):
  52. """ Read group customization in order to display all the stages in the
  53. kanban view, even if they are empty
  54. """
  55. _domain = [('archive_name', '=', 200)]
  56. process_ids = stages._search(_domain, order=order)
  57. return stages.browse(process_ids)
  58. def do_customer_setting(self):
  59. return self.env['archives.set_customer_setting'].send_and_open(need_set_fields, self._name,
  60. self._description)
  61. @api.model
  62. def default_get(self, fields_):
  63. res = super(Plan, self).default_get(fields_)
  64. self.env['archives.set_customer_setting'].set_default(res, self._name, fields_, need_set_fields)
  65. return res
  66. need_set_fields = ['plan_type', 'person_id', 'company_id']