analytic/populate/analytic_account.py
Данил Воробьев 29d7087a26 initial commit
2024-05-03 12:01:29 +00:00

31 lines
925 B
Python

from odoo import models
from odoo.tools import populate
class AnalyticAccount(models.Model):
_inherit = "account.analytic.account"
_populate_sizes = {
'small': 100,
'medium': 1_000,
'large': 10_000,
}
def _populate_factories(self):
project_plan = self._search_or_create_plan('Projects')
department_plan = self._search_or_create_plan('Departments')
return [
('company_id', populate.constant(False)),
('plan_id', populate.cartesian(
[project_plan.id, department_plan.id],
[0.99, 0.01],
)),
('name', populate.constant("Account {counter}")),
]
def _search_or_create_plan(self, name):
return self.env['account.analytic.plan'].search([
('name', '=', name),
]) or self.env['account.analytic.plan'].create({
'name': name,
})