Odoo 14 update/load language during (automatic) module update - localization

I know how to add translations to my custom module (with .po-files in \i18n-folder). I also know how to force Odoo.sh to automatically update my custom module during build, with updating the version-number.
This works fine for data, views, and so on. But is doesn't seem to work for my translations. I always have to go to Developer-mode -> Settings -> Translations -> Activate/update.
How can I also automate the update of my translations?
EDIT:
I've found the post_init_hook, and tried the following:
# coding: utf-8
from odoo import api, fields, models, _, SUPERUSER_ID
def install_languages(cr, registry):
""" Post init function """
env = api.Environment(cr, SUPERUSER_ID, {})
# install DE language
lang_de = env['base.language.install'].create({'lang': 'de_DE', 'overwrite': False})
env['base.language.install'].lang_install(lang_de)
The line env['base.language.install'].create({'lang': 'de_DE', 'overwrite': False}) however, generates a build-warning with Transient module states were reset, and then a build-error occurs Failed to load registry and Failed to load database....
EDIT 2:
the error had another cause and is fixed.
the post_init gives no error, but also does not update the language.

Related

How do I access parsing of .nimble files from the nimble package?

Nim as a language provides .nimble files to describe its packages (example of a .nimble file). I know that the file is parsed by the nimble package and CLI-tool, as they need the information inside the .nimble file for their tasks.
I want basically all the information in there, dependencies, author, license, description, version, all of it. So in order to not do the same work twice and potentially run into issues should the format change, I would like to use the nimble package itself to parse the .nimble file for me.
I know the correct proc for it, which is getPkgInfoFromFile, but I can't seem to access it with import nimble/nimblepkg/packageparser.
Whenever I use that line I receive an error that there is no such file.
What am I doing wrong?
Further: getPkgInfoFromFile requires an Options instance that it generates when parsing a CLI command. I don't have a CLI command, so I'm not generating such an instance, can I use the proc somehow without one?
Thanks to ringabout I came to the correct solution, but first to the question.
Question 1: How do I access the proc in the first place?
You can access nimble like a package, but the import is not import nimble/nimblepkg/packageparser it is directly import nimblepkg/packageparser.
This requires you to have both nimble' installed as a library as well as the compiler` installed as a library.
So you'll have to install those first:
nimble install nimble
nimble install nim # Originally this was called "compiler", but was renamed to "nim"
Ignore any warnings if they pop up.
Now you can compile the following dummy-example:
#dummy.nim
import nimblepkg/packageparser
echo "Pointer to packageparser proc: ", packageparser.getPkgInfoFromFile.repr
with: nimble -d:ssl --mm:refc -r build (-d:ssl is required for nimble's HTTP-client and --mm:refc is required as nimble appears to not work with orc)
Question 2: Can I run the getPkgInfoFromFile without an Options instance?
Yes-ish. You still need one, but it doesn't have to be a "real" one, you can just instantiate one yourself on the fly.
import nimblepkg/[options, packageinfotypes, packageparser]
proc generateDummyOptions(): Options =
result = initOptions()
result.setNimBin()
result.setNimbleDir()
proc parseNimbleFile*(nimblePath: string): PackageInfo =
let options = generateDummyOptions()
result = getPkgInfoFromFile(nimblePath.NimbleFile, options)

Why is this route test failing?

I've been following along with the testdriven.io tutorial for setting up a FastAPI with Docker. The first test I've written using PyTest errored out with the following message:
TypeError: Settings(environment='dev', testing=True, database_url=AnyUrl('postgres://postgres:postgres#web-db:5432/web_test', scheme='postgres', user='*****', password='*****', host='web-db',host_type='int_domain', port='5432', path='/web_test')) is not a callable object.
Looking at the picture, you'll notice that the Settings object has a strange form; in particular, its database_url parameter seems to be wrapping a bunch of other parameters like password, port, and path. However, as shown below my Settings class takes a different form.
From config.py:
# ...imports
class Settings(BaseSettings):
environment: str = os.getenv("ENVIRONMENT", "dev")
testing: bool = os.getenv("TESTING", 0)
database_url: AnyUrl = os.environ.get("DATABASE_URL")
#lru_cache()
def get_settings() -> BaseSettings:
log.info("Loading config settings from the environment...")
return Settings()
Then, in the conftest.py module, I've overridden the settings above with the following:
import os
import pytest
from fastapi.testclient import TestClient
from app.main import create_application
from app.config import get_settings, Settings
def get_settings_override():
return Settings(testing=1, database_url=os.environ.get("DATABASE_TEST_URL"))
#pytest.fixture(scope="module")
def test_app():
app = create_application()
app.dependency_overrides[get_settings] = get_settings_override()
with TestClient(app) as test_client:
yield test_client
As for the offending test itself, that looks like the following:
def test_ping(test_app):
response = test_app.get("/ping")
assert response.status_code == 200
assert response.json() == {"environment": "dev", "ping": "pong", "testing": True}
The container is successfully running on my localhost without issue; this leads me to believe that the issue is wholly related to how I've set up the test and its associated config. However, the structure of the error and how database_url is wrapping up all these key-value pairs from docker-compose.yml gives me the sense that my syntax error could be elsewhere.
At this juncture, I'm not sure if the issue has something to do with how I set up test_ping.py, my construction of the settings_override, with the format of my docker-compose.yml file, or something else altogether.
So far, I've tried to fix this issue by reading up on the use of dependency overrides in FastApi, noodling with my indentation in the docker-compose, changing the TestClient from one provided by starlette to that provided by FastAPI, and manually entering testing mode.
Something I noticed when attempting to manually go into testing mode was that the container doesn't want to follow suit. I've tried setting testing to 1 in docker-compose.yml, and testing: bool = True in config.Settings.
I'm new to all of the relevant tech here and bamboozled. What is causing this discrepancy with my test? Any and all insight would be greatly appreciated. If you need to see any other files, or are interested in the package structure, just let me know. Many thanks.
Any dependency override through app.dependency_overrides should provide the function being overridden as the key and the function that should be used instead. In your case you're assigning the correct override, but you're assigning the result of the function as the override, and not the override itself:
app.dependency_overrides[get_settings] = get_settings_override()
.. this should be:
app.dependency_overrides[get_settings] = get_settings_override
The error message shows that FastAPI tried to call your dictionary as a function, something that hints to it expecting a function instead.

Custom field handlers syntax when using the Jira/Rally Connector

I am working on a Jira/Rally (CA Agile Central) integration and can get a basic sync to work, however some fields require a more complex transformation when syncing them between Jira and Rally.
For this I can see that the CA Agile Connector (https://help.rallydev.com/jira-installation-user-guide) provides some support for "custom field handlers" which are written in Ruby and follow a format like:
# Copyright 2015 CA Technologies. All Rights Reserved.
require 'rallyeif/wrk/field_handlers/field_handler'
module RallyEIF
module WRK
module FieldHandlers
class MyCustomFieldHandler < OtherFieldHandler
def initialize(field_name = nil)
super(field_name)
end
# ... more code here ...
end
end
end
end
However when I create that file and add the following to my connector config:
...
<Connector>
<FieldMapping>
<Field>
<Rally>Description</Rally>
<Other>Description</Other>
<Direction>TO_RALLY</Direction>
</Field>
...
</FieldMapping>
<OtherFieldHandlers>
<MyCustomFieldHandler>
<FieldName>Description</FieldName>
</MyCustomFieldHandler>
</OtherFieldHandlers>
</Connector>
...
When running the connector I get the following error:
[2017-08-22 20:25:39 Z] ERROR : RallyEIF::WRK::Connector.rescue in block in read_field_handlers - For RallyEIF::WRK::JiraConnection: Could not find class for MyCustomFieldHandler
The documentation does not mention how to use the custom handlers at all, so I'm wondering if anyone has used this feature and can share some information on how to declare and use the custom field handlers.
I tested connector version 4.7.2 and it worked. Things to check:
within the folder where the connector is invoked, there must be a folder named "field_handlers"
within this "field_handlers" folder, there must be a file (as you have shown above) with "class MyCustomFieldHandler < ...."
There is an example on the help pages. It's for HP-ALM (QC) not for JIRA, but the concept is the same:
https://help.rallydev.com/QC-custom-fieldhandler.pxml
End of ideas so far.

New relic custom plugin data not showing up - ruby sdk

I am using newrelic's ruby sdk to develop a custom plugin. When I run the sample app, on the terminal it shows that the data is successfully captured. But when i go to the site, it cannot search the metrics and due to that I cannot look at any data reported.
the plugin name and everthing else shows up but don't where the data is going.
This what the agent file looks like:
require "rubygems"
require "bundler/setup"
require "newrelic_plugin"
module ExampleAgent
class Agent < NewRelic::Plugin::Agent::Base
agent_guid "com.phytel.Product1"
agent_version "1.0.1"
agent_config_options :hostname # frequency of the periodic functions
agent_human_labels("Product1") { "Call Statuses" }
def poll_cycle
# x = Time.now.to_f * hertz * Math::PI * 2
report_metric "Component/Status/Progressing", "Value", 10
report_metric "Component/Status/Scheduled", "Value", 20
report_metric "Component/Status/Busy", "Value", 2
end
end
#
# Register this agent with the component.
# The ExampleAgent is the name of the module that defines this
# driver (the module must contain at least three classes - a
# PollCycle, a Metric and an Agent class, as defined above).
#
NewRelic::Plugin::Setup.install_agent :example, ExampleAgent
#
# Launch the agent; this never returns.
#
NewRelic::Plugin::Run.setup_and_run
end
Don't put the Component part in your metric name. The SDK automatically adds that for you.

ipython redirect stdout display corruption

I'm developing a system in python, and one functionality I need is the ability to have console output go to both the console and a user-specified file. This is replicating the Diary function in MATLAB. I have the following that works perfectly well on both IDLE on windows and python cmdline in ubuntu (this all exists inside a module that gets loaded):
class diaryout(object):
def __init__(self):
self.terminal = sys.stdout
self.save = None
def __del__(self):
try:
self.save.flush()
self.save.close()
except:
# do nothing, just catch the error; maybe it self was instantiated, but never opened
1/1
self.save = None
def dclose(self):
self.__del__()
def write(self, message):
self.terminal.write(message)
self.save.write(message)
def dopen(self,outfile):
self.outfile = outfile
try:
self.save = open(self.outfile, "a")
except Exception, e:
# just pass out the error here so the Diary function can handle it
raise e
def Diary(outfile = None):# NEW TO TEST
global this_diary
if outfile == None:
# None passed, so close the diary file if one is open
if isinstance(this_diary, diaryout):
sys.stdout = this_diary.terminal # set the stdout back to stdout
this_diary.dclose() # flush and close the file
this_diary = None # "delete" it
else:
# file passed, so let's open it and set it for the output
this_diary = diaryout() # instantiate
try:
this_diary.dopen(outfile) # open & test that it opened
except IOError:
raise IOError("Can't open %s for append!"%outfile)
this_dairy=none # must uninstantiate it, since already did that
except TypeError:
raise TypeError("Invalid input detected - must be string filename or None: %s"%Diary.__doc__)
this_dairy=none # must uninbstantiate it, since already did that
sys.stdout = this_diary # set stdout to it
Far superior to both IDLE and the plain python cmline, I'm using ipython; herein my problem lies. I can turn on the "diary" perfectly fine with no error but the display on the console gets messed. The attached screenshot shows this . The output file also becomes similarly garbled. Everything goes back to normal when I undo the redirection with Diary(None). I have tried editing the code so that it never even writes to the file, with no effect. It seems almost like something is forcing an unsupported character set or something I don't understand.
Anyone have an idea about this?

Resources