[REF] l10n_ru_base: отрефакторена логика установки модуля, код стайл
This commit is contained in:
parent
57ffd768c9
commit
ade3cfe5a9
l10n_ru_base/models
@ -1,4 +1 @@
|
||||
from . import res_config_settings
|
||||
|
||||
|
||||
|
||||
|
@ -1,41 +1,54 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo import fields, models, modules
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_FIELDS_MODUL = [
|
||||
'module_l10n_ru_act_rev',
|
||||
'module_l10n_ru_contract',
|
||||
'module_l10n_ru_upd_xml',
|
||||
'module_l10n_ru_doc',
|
||||
'module_l10n_ru_attorney'
|
||||
MODULE_FIELDS = [
|
||||
"module_l10n_ru_act_rev",
|
||||
"module_l10n_ru_contract",
|
||||
"module_l10n_ru_upd_xml",
|
||||
"module_l10n_ru_doc",
|
||||
"module_l10n_ru_attorney",
|
||||
]
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = 'res.config.settings'
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
module_l10n_ru_act_rev = fields.Boolean(_("Act revise"))
|
||||
module_l10n_ru_contract = fields.Boolean(_("Contract"))
|
||||
module_l10n_ru_upd_xml = fields.Boolean(_("Report_xml"))
|
||||
module_l10n_ru_doc = fields.Boolean(_("Print forms"))
|
||||
module_l10n_ru_attorney = fields.Boolean(_("Consent"))
|
||||
module_l10n_ru_act_rev = fields.Boolean(
|
||||
string="Акты сверки", help="Создание актов сверки"
|
||||
)
|
||||
module_l10n_ru_contract = fields.Boolean(
|
||||
string="Договоры", help="Управление договорами"
|
||||
)
|
||||
module_l10n_ru_upd_xml = fields.Boolean(
|
||||
string="Экспорт УПД", help="Экспорт УПД в формате XML"
|
||||
)
|
||||
module_l10n_ru_doc = fields.Boolean(
|
||||
string="Печатные формы", help="Формирование документов"
|
||||
)
|
||||
module_l10n_ru_attorney = fields.Boolean(
|
||||
string="Доверенности", help="Оформление доверенностей"
|
||||
)
|
||||
|
||||
@api.model
|
||||
def write(self, values):
|
||||
company = self.env.company
|
||||
if company.country_id.code != 'RU':
|
||||
raise UserError("Признак Российской компании не обнаружен!")
|
||||
if _FIELDS_MODUL:
|
||||
missing_modules = set()
|
||||
for field in _FIELDS_MODUL:
|
||||
if self.mapped(field)[0]:
|
||||
module_name = field[7:]
|
||||
module_installed = self.env['ir.module.module'].search([('name', '=', module_name)], limit=1)
|
||||
if not module_installed:
|
||||
missing_modules.add(module_name)
|
||||
if missing_modules:
|
||||
message = "Обратитесь в тех.поддержку для получения лицензии для следующих модулей:\n" + \
|
||||
"\n".join(missing_modules)
|
||||
raise UserError(message)
|
||||
return super(ResConfigSettings, self).write(values)
|
||||
if self.env.company.country_id.code != "RU":
|
||||
raise UserError("Признак Российской компании не обнаружен.")
|
||||
|
||||
# Проверяем наличие модуля в addons path,
|
||||
# чтобы избежать ситуации, когда модуль присутствует в базе, но фактически удалён
|
||||
missing_modules = {
|
||||
field[7:]
|
||||
for field in MODULE_FIELDS
|
||||
if self.mapped(field)[0] and not modules.get_module_path(field[7:])
|
||||
}
|
||||
|
||||
if missing_modules:
|
||||
raise UserError(
|
||||
"Обратитесь в тех.поддержку для получения лицензии для следующих модулей:\n{}".format(
|
||||
"\n".join(missing_modules)
|
||||
)
|
||||
)
|
||||
|
||||
return super().write(values)
|
||||
|
Loading…
x
Reference in New Issue
Block a user