__init__.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from . import controllers
  4. from . import models
  5. from . import report
  6. from odoo import api, fields, SUPERUSER_ID, _
  7. from odoo.addons.project import _check_exists_collaborators_for_project_sharing
  8. def create_internal_project(cr, registry):
  9. env = api.Environment(cr, SUPERUSER_ID, {})
  10. # allow_timesheets is set by default, but erased for existing projects at
  11. # installation, as there is no analytic account for them.
  12. env['project.project'].search([]).write({'allow_timesheets': True})
  13. admin = env.ref('base.user_admin', raise_if_not_found=False)
  14. if not admin:
  15. return
  16. project_ids = env['res.company'].search([])._create_internal_project_task()
  17. env['account.analytic.line'].create([{
  18. 'name': _("Analysis"),
  19. 'user_id': admin.id,
  20. 'date': fields.datetime.today(),
  21. 'unit_amount': 0,
  22. 'project_id': task.project_id.id,
  23. 'task_id': task.id,
  24. } for task in project_ids.task_ids.filtered(lambda t: t.company_id in admin.employee_ids.company_id)])
  25. _check_exists_collaborators_for_project_sharing(env)
  26. def _uninstall_hook(cr, registry):
  27. env = api.Environment(cr, SUPERUSER_ID, {})
  28. act_window = env.ref('project.open_view_project_all', raise_if_not_found=False)
  29. if act_window and act_window.domain and 'is_internal_project' in act_window.domain:
  30. act_window.domain = []
  31. # archive the internal projects
  32. project_ids = env['res.company'].search([('internal_project_id', '!=', False)]).mapped('internal_project_id')
  33. if project_ids:
  34. project_ids.write({'active': False})
  35. env['ir.model.data'].search([('name', 'ilike', 'internal_project_default_stage')]).unlink()