company.py 1.1 KB

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. from odoo import fields, models
  3. class ResCompany(models.Model):
  4. _name = "res.company"
  5. _inherit = "res.company"
  6. analytic_plan_id = fields.Many2one(
  7. 'account.analytic.plan',
  8. string="Default Plan",
  9. check_company=True,
  10. readonly=False,
  11. compute="_compute_analytic_plan_id",
  12. help="Default Plan for a new analytic account for projects")
  13. def _compute_analytic_plan_id(self):
  14. for company in self:
  15. default_plan = self.env['ir.config_parameter'].with_company(company).sudo().get_param("default_analytic_plan_id_%s" % company.id)
  16. company.analytic_plan_id = int(default_plan) if default_plan else False
  17. if not company.analytic_plan_id:
  18. company.analytic_plan_id = self.env['account.analytic.plan'].with_company(company)._get_default()
  19. def write(self, values):
  20. for company in self:
  21. if 'analytic_plan_id' in values:
  22. self.env['ir.config_parameter'].sudo().set_param("default_analytic_plan_id_%s" % company.id, values['analytic_plan_id'])
  23. return super().write(values)