diff --git a/escodoo_setup_base_br/README.rst b/escodoo_setup_base_br/README.rst new file mode 100644 index 0000000..f919ab3 --- /dev/null +++ b/escodoo_setup_base_br/README.rst @@ -0,0 +1,65 @@ +===================== +Escodoo Setup Base BR +===================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:4507a95ed5b59e380ef93bd3d03ee2b751f9447a0f09e0ebf80b2763337ad2b1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-Escodoo%2Fsetup--addons-lightgray.png?logo=github + :target: https://github.com/Escodoo/setup-addons/tree/18.0/escodoo_setup_base_br + :alt: Escodoo/setup-addons + +|badge1| |badge2| |badge3| + + + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Escodoo + +Contributors +------------ + + + +Maintainers +----------- + +This module is part of the `Escodoo/setup-addons `_ project on GitHub. + +You are welcome to contribute. diff --git a/escodoo_setup_base_br/__init__.py b/escodoo_setup_base_br/__init__.py new file mode 100644 index 0000000..e315f7b --- /dev/null +++ b/escodoo_setup_base_br/__init__.py @@ -0,0 +1 @@ +from .hooks import post_init_hook diff --git a/escodoo_setup_base_br/__manifest__.py b/escodoo_setup_base_br/__manifest__.py new file mode 100644 index 0000000..c001b9e --- /dev/null +++ b/escodoo_setup_base_br/__manifest__.py @@ -0,0 +1,52 @@ +# Copyright 2024 - TODAY, Escodoo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Escodoo Setup Base BR", + "summary": """ + Escodoo Setup Base BR""", + "version": "18.0.1.0.0", + "license": "AGPL-3", + "author": "Escodoo", + "website": "https://github.com/Escodoo/setup-addons", + "depends": [ + "escodoo_setup_base", + "l10n_br_base", + "l10n_br_account", + "l10n_br_account_due_list", + # "l10n_br_account_nfe", + "l10n_br_cnpj_search", + "l10n_br_coa", + "l10n_br_coa_generic", + "l10n_br_coa_simple", + # "l10n_br_contract", + "l10n_br_crm", + "l10n_br_crm_cnpj_search", + # "l10n_br_delivery", + # "l10n_br_delivery_nfe", + "l10n_br_fiscal", + "l10n_br_fiscal_certificate", + "l10n_br_fiscal_closing", + "l10n_br_fiscal_dfe", + "l10n_br_fiscal_edi", + "l10n_br_fiscal_notification", + "l10n_br_hr", + "l10n_br_ie_search", + "l10n_br_mis_report", + "l10n_br_nfe", + "l10n_br_nfe_spec", + "l10n_br_nfse", + "l10n_br_nfse_focus", + # "l10n_br_purchase", + # "l10n_br_purchase_stock", + "l10n_br_resource", + # "l10n_br_sale", + # "l10n_br_sale_stock", + "l10n_br_stock", + # "l10n_br_stock_account", + # "l10n_br_stock_account_report", + "l10n_br_zip", + "spec_driven_model", + ], + "post_init_hook": "post_init_hook", +} diff --git a/escodoo_setup_base_br/data/res_partner.xml b/escodoo_setup_base_br/data/res_partner.xml new file mode 100644 index 0000000..c5963ed --- /dev/null +++ b/escodoo_setup_base_br/data/res_partner.xml @@ -0,0 +1,49 @@ + + + + + + + 03.684.524/0001-37 + 1448 + Núcleo de Estudos em Projetos de Ribeirão Preto + Escodoo Sistemas + Jardim Califórnia + + 14026-220 + + 64 + (11) 9999-9999 + Rua Raul Peixoto + https://www.escodoo.com.br + contato@escodoo.com.br + + + + + + Suporte Escodoo + + Suporte Escodoo + suporte@escodoo.com.br + (11) 9999-9999 + + + + + Consultoria Escodoo + + Consultoria Escodoo + consultoria@escodoo.com.br + (11) 9999-9999 + + + + + diff --git a/escodoo_setup_base_br/hooks.py b/escodoo_setup_base_br/hooks.py new file mode 100644 index 0000000..936c197 --- /dev/null +++ b/escodoo_setup_base_br/hooks.py @@ -0,0 +1,260 @@ +# Copyright 2024 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import base64 +import logging + +from odoo import tools + +_logger = logging.getLogger(__name__) + + +def _default_image(env): + """ + Returns the default image encoded in base64 to be used for partners. + + Args: + env: The Odoo environment for accessing resources. + + Returns: + String: Default image encoded in base64. + """ + image = False + try: + image_path = tools.file_path( + "escodoo_setup_base_br/static/img/escodoo_badge.png" + ) + except FileNotFoundError: + image_path = False + if image_path: + image = base64.b64encode(open(image_path, "rb").read()) + return image + + +def is_demo_data_installed(env): + """ + Checks whether demo data is installed in the Odoo environment. + + Args: + env: The Odoo environment for database access. + + Returns: + Bool: True if demo data is installed, False otherwise. + """ + demo_modules = env["ir.module.module"].search([("demo", "=", True)]) + return bool(demo_modules) + + +def _load_partner_escodoo(env): + """ + Loads the Escodoo partner into the database if not already present. + + Args: + env: The Odoo environment for database access. + """ + escodoo_partner = env["res.partner"].search( + [("vat", "=", "03.684.524/0001-37")], limit=1 + ) + if not escodoo_partner: + tools.convert_file( + env, + "escodoo_setup_base_br", + "data/res_partner.xml", + None, + mode="init", + noupdate=True, + kind="init", + ) + else: + env["ir.model.data"]._update_xmlids( + [ + { + "xml_id": "escodoo_setup_base_br.partner_escodoo", + "record": escodoo_partner, + "noupdate": True, + } + ] + ) + + +def _load_default_chart_of_accounts(env): + """ + Loads a default chart of accounts for companies that do not have one. + + Args: + env: The Odoo environment for database access. + """ + # Identifies companies without a chart of accounts + company_ids = env["res.company"].search([("chart_template", "=", False)]).ids + if not company_ids: + return + + # try_loading warns when called before the registry is fully loaded (which is + # the case here, since post_init_hook runs while the module graph is still + # loading). Defer it the same way account/models/ir_module.py does: through + # registry._auto_install_template, consumed by ir.module.module._register_hook + # once every model's _register_hook has run and registry.loaded is True. + def _try_loading(env): + for company in env["res.company"].browse(company_ids): + env["account.chart.template"].try_loading("br_oca_generic", company=company) + + env.registry._auto_install_template = _try_loading + + +def _update_companies(env): + """ + Updates all companies by setting the Escodoo partner as technical support. + + Args: + env: The Odoo environment for database access. + """ + + all_company_records = env["res.company"].search([]) + + escodoo_partner = env.ref( + "escodoo_setup_base_br.partner_escodoo", raise_if_not_found=False + ) + + try: + company_logo_path = tools.file_path( + "escodoo_setup_base_br/static/img/your_company_logo.png" + ) + except FileNotFoundError: + company_logo_path = False + company_logo_image = ( + base64.b64encode(open(company_logo_path, "rb").read()) + if company_logo_path + else False + ) + + values = { + "country_id": env.ref("base.br").id, + } + + if company_logo_image: + values.update({"logo": company_logo_image}) + + if escodoo_partner: + values.update({"technical_support_id": escodoo_partner.id}) + + for company in all_company_records: + company.write(values) + + # falta o regime pis/cofins + # falta o regime do icms + # ativar RIPI + + +def _update_res_config_settings(env): + """ + Updates the 'pwa_icon' field in the res.config.settings of the Odoo environment + by creating or updating an attachment for the icon image. + + Args: + env: The Odoo environment for database access. + """ + + # Obter a imagem padrão codificada em base64 + image_base64 = _default_image(env) + if image_base64: + config_settings = env["res.config.settings"].create({}) + config_settings.write({"pwa_icon": image_base64}) + config_settings.execute() + + +def _add_group_to_admin_user(env): + """ + Adds the 'account.group_account_user' group to the admin user. + + Args: + env: The Odoo environment for database access. + """ + account_user_group = env.ref("account.group_account_user", raise_if_not_found=False) + admin_user_record = env.ref("base.user_admin", raise_if_not_found=False) + if account_user_group and admin_user_record: + admin_user_record.write({"groups_id": [(4, account_user_group.id)]}) + + +def _update_partners(env): + """ + Updates the names and contact information of specific partners. + First updates partners without a parent_id, then updates partners with a + parent_id. + + Args: + env: The Odoo environment for database access. + """ + if is_demo_data_installed(env): + target_partner_names = ["KMEE", "Akretion", "Engenere"] + domain = [("name", "ilike", name) for name in target_partner_names] + filtered_partners = env["res.partner"].search( + ["|"] * (len(domain) - 1) + domain + ) + + # First updates parent partners + parent_index = 1 + for partner in filtered_partners.filtered(lambda p: not p.parent_id): + partner_name = f"Escodoo Company {parent_index}" + partner.write( + { + "name": partner_name, + "legal_name": partner_name, + "website": "https://www.escodoo.com.br", + "email": "test@escodoo.com.br", + "image_1920": _default_image(env), + } + ) + parent_index += 1 + + # Then updates child partners + for partner in filtered_partners.filtered(lambda p: p.parent_id): + parent_name = partner.parent_id.name + partner_name = f"{parent_name} - {partner.state_id.name}" + partner.write( + { + "name": partner_name, + "legal_name": partner_name, + "website": "https://www.escodoo.com.br", + "email": "test@escodoo.com.br", + } + ) + else: + _logger.info("Skipping partner update because demo data is not installed.") + + +def post_init_hook(env): + """ + Post-initialization hook for configuring module setup. + + Args: + env: Odoo environment. + """ + _load_partner_escodoo(env) + _update_companies(env) + # _update_res_config_settings(env) + _load_default_chart_of_accounts(env) + _add_group_to_admin_user(env) + _update_partners(env) + + # Configurar o ambiente Odoo + config = tools.config + + # Obter o nome da base de dados + db_name = config["db_name"] + + db_name_uppercase = db_name.upper() + + env["ir.config_parameter"].set_param("auth_signup.invitation_scope", "b2b") + env["ir.config_parameter"].set_param("pwa.manifest.background_color", "#7C7BAD") + env["ir.config_parameter"].set_param( + "pwa.manifest.name", f"Odoo Online {db_name_uppercase}" + ) + env["ir.config_parameter"].set_param( + "pwa.manifest.short_name", f"Odoo {db_name_uppercase}" + ) + env["ir.config_parameter"].set_param("pwa.manifest.theme_color", "#FFFFFF") + # env["ir.config_parameter"].set_param("support_company", "Escodoo Sistemas") + # env["ir.config_parameter"].set_param("support_company_url", "https://www.escodoo.com.br") + # env["ir.config_parameter"].set_param("support_branding_color", "#fff") + # env["ir.config_parameter"].set_param("support_email", "suporte@escodoo.com.br") + # env["ir.config_parameter"].set_param("support_release", "14.0") diff --git a/escodoo_setup_base_br/i18n/escodoo_setup_base_br.pot b/escodoo_setup_base_br/i18n/escodoo_setup_base_br.pot new file mode 100644 index 0000000..78d58d5 --- /dev/null +++ b/escodoo_setup_base_br/i18n/escodoo_setup_base_br.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" diff --git a/escodoo_setup_base_br/pyproject.toml b/escodoo_setup_base_br/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/escodoo_setup_base_br/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/escodoo_setup_base_br/readme/CONTRIBUTORS.md b/escodoo_setup_base_br/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/escodoo_setup_base_br/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ + diff --git a/escodoo_setup_base_br/readme/DESCRIPTION.md b/escodoo_setup_base_br/readme/DESCRIPTION.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/escodoo_setup_base_br/readme/DESCRIPTION.md @@ -0,0 +1 @@ + diff --git a/escodoo_setup_base_br/readme/USAGE.md b/escodoo_setup_base_br/readme/USAGE.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/escodoo_setup_base_br/readme/USAGE.md @@ -0,0 +1 @@ + diff --git a/escodoo_setup_base_br/static/description/icon.png b/escodoo_setup_base_br/static/description/icon.png new file mode 100644 index 0000000..12ab005 Binary files /dev/null and b/escodoo_setup_base_br/static/description/icon.png differ diff --git a/escodoo_setup_base_br/static/description/index.html b/escodoo_setup_base_br/static/description/index.html new file mode 100644 index 0000000..ee0889b --- /dev/null +++ b/escodoo_setup_base_br/static/description/index.html @@ -0,0 +1,416 @@ + + + + + +Escodoo Setup Base BR + + + +
+

Escodoo Setup Base BR

+ + +

Beta License: AGPL-3 Escodoo/setup-addons

+

Table of contents

+ +
+

Usage

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Escodoo
  • +
+
+ +
+

Maintainers

+

This module is part of the Escodoo/setup-addons project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/escodoo_setup_base_br/static/img/escodoo_badge.png b/escodoo_setup_base_br/static/img/escodoo_badge.png new file mode 100644 index 0000000..8704daf Binary files /dev/null and b/escodoo_setup_base_br/static/img/escodoo_badge.png differ diff --git a/escodoo_setup_base_br/static/img/escodoo_badge.svg b/escodoo_setup_base_br/static/img/escodoo_badge.svg new file mode 100644 index 0000000..dbb6904 --- /dev/null +++ b/escodoo_setup_base_br/static/img/escodoo_badge.svg @@ -0,0 +1,134 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/escodoo_setup_base_br/static/img/your_company_logo.png b/escodoo_setup_base_br/static/img/your_company_logo.png new file mode 100644 index 0000000..77730a3 Binary files /dev/null and b/escodoo_setup_base_br/static/img/your_company_logo.png differ diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..dbd975f --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,5 @@ +odoo-test-helper # Needed by spec_driven_model +pyopenssl==22.1.0 +nfelib>=2.5.2 +xmldiff +odoo-addon-web-escodoo_brand @ git+https://github.com/Escodoo/base-addons@18.0#egg=odoo-addon-web_escodoo_brand&subdirectory=web_escodoo_brand