diff --git a/companyweb_base/README.rst b/companyweb_base/README.rst index 14ee9235..901b7696 100644 --- a/companyweb_base/README.rst +++ b/companyweb_base/README.rst @@ -143,6 +143,7 @@ Contributors - Xavier Bouquiaux - Stéphane Bidoul +- Bert Van Groenendael Other credits ------------- diff --git a/companyweb_base/models/res_partner.py b/companyweb_base/models/res_partner.py index 73d87d7c..1c64562b 100644 --- a/companyweb_base/models/res_partner.py +++ b/companyweb_base/models/res_partner.py @@ -7,7 +7,7 @@ import zeep -from odoo import _, api, fields, models, tools +from odoo import api, fields, models, tools from odoo.exceptions import UserError _logger = logging.getLogger(__name__) @@ -492,7 +492,7 @@ def cweb_button_enhance(self): based on status make decision When status is ok -> populate fields""" if not self.env.user.has_group("companyweb_base.cweb_download"): - raise UserError(_("Companyweb : You don't have access")) + raise UserError(self.env._("Companyweb : You don't have access")) user_login = self.env.user.cweb_login user_password = self.env.user.cweb_password user_lang = self.env.context.get("lang")[:2].upper() @@ -520,7 +520,7 @@ def cweb_button_enhance(self): return self._cweb_call_wizard_credentials("Enter Companyweb credentials") elif r["StatusCode"] != 0: raise UserError( - _("Companyweb status : {status} : {message} ").format( + self.env._("Companyweb status : {status} : {message} ").format( status=r["StatusCode"], message=r["StatusMessage"] ) ) @@ -536,7 +536,7 @@ def cweb_button_enhance(self): def cweb_button_copy_address(self): if not self.env.user.has_group("companyweb_base.cweb_view"): - raise UserError(_("Companyweb : You don't have access")) + raise UserError(self.env._("Companyweb : You don't have access")) self.street = self.cweb_street self.city = self.cweb_city self.zip = self.cweb_zip diff --git a/companyweb_base/readme/CONTRIBUTORS.md b/companyweb_base/readme/CONTRIBUTORS.md index 2a98d847..70da8120 100644 --- a/companyweb_base/readme/CONTRIBUTORS.md +++ b/companyweb_base/readme/CONTRIBUTORS.md @@ -1,2 +1,3 @@ - Xavier Bouquiaux \<\> - Stéphane Bidoul \<\> + - Bert Van Groenendael \<\> diff --git a/companyweb_base/static/description/index.html b/companyweb_base/static/description/index.html index 8d7c0e40..b0b906c6 100644 --- a/companyweb_base/static/description/index.html +++ b/companyweb_base/static/description/index.html @@ -473,6 +473,7 @@

Contributors

diff --git a/companyweb_base/tests/test_api_cweb.py b/companyweb_base/tests/test_api_cweb.py index c96d2835..257eaf59 100644 --- a/companyweb_base/tests/test_api_cweb.py +++ b/companyweb_base/tests/test_api_cweb.py @@ -33,6 +33,9 @@ def _request_handler(cls, s: Session, r: PreparedRequest, /, **kw): def setUp(self, *args, **kwargs): super().setUp(*args, **kwargs) + + self._install_language("fr") + demo_user = self.env.ref("base.user_demo") demo_user.cweb_login = os.environ.get("COMPANYWEB_TEST_LOGIN", "cwebtestlogin") demo_user.cweb_password = os.environ.get( @@ -57,6 +60,23 @@ def _get_vcr_kwargs(self, **kwargs): "decode_compressed_response": True, } + def _install_language(self, lang_code="en_US"): + """Install the language if not already installed.""" + # Check if the language already exists + lang = self.env["res.lang"].search([("code", "=", lang_code)], limit=1) + if not lang: + # If the language doesn't exist, create and load it + lang_id = self.env.ref(f"base.lang_{lang_code}").id + lang_wizard = self.env["base.language.install"].create( + { + "lang_ids": [Command.link(lang_id)], + } + ) + lang_wizard.lang_install() + + # Set the language as active + self.env["res.lang"].search([("code", "=", lang_code)]).write({"active": True}) + @freeze_time("2021-03-23") # because the login hash includes the date def test_cweb_button(self): # companyweb response depends on request language diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000..7b249542 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +vcr_unittest