12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- from odoo import models, fields, api
- from datetime import timedelta
- from dateutil.relativedelta import relativedelta
- from addons_main.archives.models.base import base_bill
- delta_dict = {
- 'days': relativedelta(days=0),
- 'weeks': relativedelta(weeks=1),
- 'months': relativedelta(months=1),
- 'years': relativedelta(years=1)
- }
- class Plan(base_bill.Bill):
- _name = 'jc_cooperation.plan'
- _description = u'协作:计划'
- _order = 'id desc'
- _inherit = ['mail.thread']
- _module = 'jc_cooperation'
- date_start = fields.Date(string=u'开始日期', default=fields.Date.context_today, required=True)
- date_end = fields.Date(string=u'结束日期', required=True)
- plan_type = fields.Selection([('days', '日计划'), ('weeks', '周计划'), ('months', '月计划'), ('years', '年计划')],
- string=u'计划类型',
- required=True)
- person_id = fields.Many2one('archives.staff', string=u'人员', required=True)
- create_date = fields.Date(string=u'制单日期', default=fields.Date.context_today, required=True, readonly=True)
- plan_content = fields.Html(string=u'计划内容')
- work_summary = fields.Html(string=u'工作总结')
- next_plan_content = fields.Html(string=u'下期计划')
- department_id = fields.Many2one('archives.department', string=u'部门')
- company_id = fields.Many2one('res.company', string=u'公司')
- active = fields.Boolean(default=True)
- color = fields.Integer(string=u'颜色')
- process_id = fields.Many2one('archives.common_archive', domain=[('archive_name', '=', 200)], string=u'阶段',
- group_expand='_read_group_process_ids',
- track_visibility='onchange')
- is_false = fields.Boolean(string='False', helper='仅用于判断值为False的方法中。===请勿赋值===', readonly=True)
- @api.onchange('plan_type')
- def _onchange_for_plan_type(self):
- if self.plan_type:
- self.date_end = fields.Date.from_string(self.date_start) + (delta_dict.get(self.plan_type) or relativedelta(
- days=0))
- @api.onchange('date_start')
- def _onchange_for_date_start(self):
- if self.date_start:
- self.date_end = fields.Date.from_string(self.date_start) + (delta_dict.get(self.plan_type) or relativedelta(
- days=0))
- @api.onchange('date_end')
- def _onchange_for_date_end(self):
- if self.date_end:
- self.date_start = fields.Date.from_string(self.date_end) - (delta_dict.get(self.plan_type) or relativedelta(
- days=0))
- @api.model
- def _read_group_process_ids(self, stages, domain, order):
- """ Read group customization in order to display all the stages in the
- kanban view, even if they are empty
- """
- _domain = [('archive_name', '=', 200)]
- process_ids = stages._search(_domain, order=order)
- return stages.browse(process_ids)
- def do_customer_setting(self):
- return self.env['archives.set_customer_setting'].send_and_open(need_set_fields, self._name,
- self._description)
- @api.model
- def default_get(self, fields_):
- res = super(Plan, self).default_get(fields_)
- self.env['archives.set_customer_setting'].set_default(res, self._name, fields_, need_set_fields)
- return res
- need_set_fields = ['plan_type', 'person_id', 'company_id']
|