account_journal.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. """Classes defining the populate factory for Accounting Journals and related models."""
  3. import logging
  4. from odoo import models
  5. from odoo.tools import populate
  6. _logger = logging.getLogger(__name__)
  7. class AccountJournal(models.Model):
  8. """Populate factory part for account.journal."""
  9. _inherit = "account.journal"
  10. _populate_sizes = {
  11. 'small': 10,
  12. 'medium': 30,
  13. 'large': 100,
  14. }
  15. _populate_dependencies = ['res.company']
  16. def _populate_factories(self):
  17. company_ids = self.env['res.company'].search([
  18. ('chart_template_id', '!=', False),
  19. ('id', 'in', self.env.registry.populated_models['res.company']),
  20. ])
  21. return [
  22. ('company_id', populate.cartesian(company_ids.ids)),
  23. ('type', populate.cartesian(['sale', 'purchase', 'cash', 'bank', 'general'])),
  24. ('currency_id', populate.randomize(self.env['res.currency'].search([
  25. ('active', '=', True),
  26. ]).ids + [False])),
  27. ('name', populate.constant("Journal {values[type]} {counter}")),
  28. ('code', populate.constant("{values[type]:.2}{counter}")),
  29. ]