Sélectionner une révision Git
res_config_settings.py 2,73 Kio
# © 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class CotisationsConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
is_contribution = fields.Boolean(
string='Cotisations',
related="company_id.is_contribution",
readonly=False)
contribution_journal_id = fields.Many2one(
comodel_name='account.journal',
related="company_id.contribution_journal_id",
readonly=False,
string='Journal des cotisations',
domain="[('type', '=', 'sale')]")
contribution_default_payment_term_id = fields.Many2one(
comodel_name='account.payment.term',
related="company_id.contribution_default_payment_term_id",
readonly=False,
string="Conditions de paiement par défaut pour les cotisations",
domain=[('is_contribution', '=', True)],
)
tag_cotiz_id = fields.Many2one(
comodel_name='res.partner.category',
related="company_id.tag_cotiz_id",
readonly=False,
string='Etiquette de cotisation')
# ------------------------------------------------------
# Actions
# ------------------------------------------------------
def add_company_to_menu(self, menu, bool_condition):
"""
Add current company to the list of companies allowed to see menu
:param menu: target menu
:param bool_condition: condition to check to allow company or not
:return: add company to menu
"""
current_company_id = self.env.user.company_id
if bool_condition:
if current_company_id not in menu.company_ids:
menu.write({
"company_ids": [(4, current_company_id.id)]
})
else:
if current_company_id in menu.company_ids:
menu.write({
"company_ids": [(3, current_company_id.id)]
})
# ------------------------------------------------------
# Override Parent
# ------------------------------------------------------
def execute(self):
"""
Rewrite execute() function to add current company to the list
of available company in ir_ui_menu
"""
res = super(CotisationsConfigSettings, self).execute()
menu_cotiz = self.env.ref(
'cgscop_cotisation.menu_scop_cotisation')
menu_cotiz_task_create = self.env.ref(
'cgscop_cotisation.menu_scop_cotisation_list_task')
bool_condition = self.is_contribution
self.add_company_to_menu(menu_cotiz, bool_condition)
self.add_company_to_menu(menu_cotiz_task_create, bool_condition)
return res