You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.7 KiB
Python
55 lines
2.7 KiB
Python
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class AccountAnalyticTag(models.Model):
|
|
_name = 'account.analytic.tag'
|
|
_description = 'Analytic Tags'
|
|
|
|
name = fields.Char(string='Analytic Tag', index=True, required=True)
|
|
color = fields.Integer('Color Index')
|
|
active = fields.Boolean(default=True, help="Set active to false to hide the Analytic Tag without removing it.")
|
|
active_analytic_distribution = fields.Boolean('Analytic Distribution')
|
|
analytic_distribution_ids = fields.One2many('account.analytic.distribution', 'tag_id', string="Analytic Accounts")
|
|
company_id = fields.Many2one('res.company', string='Company')
|
|
|
|
|
|
class AccountAnalyticDistribution(models.Model):
|
|
_name = 'account.analytic.distribution'
|
|
_description = 'Analytic Account Distribution'
|
|
_rec_name = 'account_id'
|
|
|
|
account_id = fields.Many2one('account.analytic.account', string='Analytic Account', required=True)
|
|
percentage = fields.Float(string='Percentage', required=True, default=100.0)
|
|
name = fields.Char(string='Name', related='account_id.name', readonly=False)
|
|
tag_id = fields.Many2one('account.analytic.tag', string="Parent tag", required=True)
|
|
|
|
_sql_constraints = [
|
|
('check_percentage', 'CHECK(percentage >= 0 AND percentage <= 100)',
|
|
'The percentage of an analytic distribution should be between 0 and 100.')
|
|
]
|
|
|
|
|
|
class AccountAnalyticGroup(models.Model):
|
|
_name = 'account.analytic.group'
|
|
_description = 'Analytic Categories'
|
|
_parent_store = True
|
|
_rec_name = 'complete_name'
|
|
|
|
name = fields.Char(required=True)
|
|
description = fields.Text(string='Description')
|
|
# parent_id = fields.Many2one('account.analytic.group', string="Parent", ondelete='cascade', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]")
|
|
parent_id = fields.Many2one('account.analytic.group', string="Parent", ondelete='cascade', domain="['|', ('company_id', '=', False)]")
|
|
parent_path = fields.Char(index=True)
|
|
children_ids = fields.One2many('account.analytic.group', 'parent_id', string="Childrens")
|
|
# complete_name = fields.Char('Complete Name', compute='_compute_complete_name', store=True)
|
|
complete_name = fields.Char('Complete Name', compute='_compute_complete_name', store=True, recursive=True)
|
|
company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company)
|
|
|
|
@api.depends('name', 'parent_id.complete_name')
|
|
def _compute_complete_name(self):
|
|
for group in self:
|
|
if group.parent_id:
|
|
group.complete_name = '%s / %s' % (group.parent_id.complete_name, group.name)
|
|
else:
|
|
group.complete_name = group.name |