Friday, March 16, 2018

GCP CloudEndure: Failed to create a Replication Server

If you ever encounter this and have no clue what the problem is even after visiting the help page, then it might be the Default subnet in the settings page in CloudEndure. Use default (default) instead:

Wednesday, December 13, 2017

Odoo XMLRPC: create ir.attachment with non-ascii datas

Consider the following Python 3 code:

import xmlrpc.client
import functools
import base64

url = 'http://myodoo:8069'
db = 'a_database'
username = 'admin'
password = 'admin'

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
call = functools.partial(models.execute_kw, db, uid, password)

vals = {'res_model': 'crm.lead', 'company_id': 1, 'res_name': 'A Name', 
        'res_id': 1, 'datas_fname': 'TEST.txt', 'name': 'TEST.txt'}
  'datas': 'Hi!'
call('ir.attachment', 'create', [vals])

This should work fine. However, if the data contains non-ASCII characters, the server side complains:

ValueError: string argument should contain only ASCII characters

So we must encode the data, but it must stay ASCII. To do that, use this:

'datas': base64.b64encode("allĂ´!".encode()).decode('ascii')

Thursday, June 1, 2017

Odoo restore DB: No space left on device

If you encounter this error while restoring a database using Odoo's web database manager, it might be because the device where your temporary folder is, is out of free space. In my case, it was /tmp. So I couldn't just free up space, so I wanted to change the temporary folder Odoo uses. Turns out Odoo uses the Python module tempfiles and it can use environment variables.

So, to set a different temporary folder, set the TMPDIR environment variable, run Odoo, and then proceed to the database restore.

$ export TMPDIR=/home/jerther
$ ./odoo-bin

Wednesday, March 22, 2017

Odoo 8 Many2many or One2many users field domain based on group

Here's an example of a collection of users that I wanted to be filtered by some group:

def _get_users_domain(self):
    return [('groups_id', 'in', self.env.ref('topo.users').id)]

user_ids = fields.Many2many('res.users', domain=_get_users_domain, string="Users", help="Who is allowed to access this board")

When you expose the field in a view, the selection widget should only show users that are members of the given group.

This should also work for a One2many field.

Thursday, January 26, 2017

UnitTest odoo 8 modules with coverage

At the time of this writing, help is a bit sparse on testing with odoo, let alone testing inside eclipse. Although I've been able to achieve it, it's quite the journey so I've decided to write this article.

Before we start, if you've not done so already, take a look at Python UnitTest Framework doc and then Testing Odoo Modules . I now assume you know how to write and organize unit tests for odoo. Also, in the latter link, you'll read that testing outside odoo is not supported. Which might be true for the odoo team, but lately I came accross a really neat plugin. But enough of this, let's dig in!

We're gonna be using pytest and the plugin won't work with older versions so make sure it is up to date:
sudo pip install -U pytest
Then install pytest-odoo plugin:
sudo pip install pytest-odoo
Then you need to export a variable that points to an odoo config file with some database information:
export OPENERP_SERVER=/etc/odoo/openerp-server.conf
If you're already running odoo, this file should already be configured but could miss this important parameter so make sure it is there:
db_name = testjerther
And last, go to the root of your module and run:
pytest -v

I'd like to run this inside Eclipse with its pytest runner, but I gave up after (too) many hours.

Now for coverage, install pytest-cov
sudo pip install pytest-cov
You can then add coverage to your tests with:
pytest -v --cov
But that gives a LOT, and I found that using --cov=moduleName does not work, but we can apply a filter in a config file. So go ahead and create one in the root folder of your project and put these lines in:
include = */moduleName/*
There are many other parameters that can go in there. Now you can run:
pytest -v --cov --cov-config=coverage.config

You can also export the coverage in html by adding --cov-report html:cov_html where cov_html is a folder. check out the doc for more options!

Tuesday, April 19, 2016

TFS 2015: Build failed but no issues and WI images not showing

Some people had this problem and it was due to some permissions but it got fixed with Update 1. I still had it with the recently released Update 2. The build would fail with no issue, no log, no nothing.

Also, attached images in work items would not show!

The problem was that we upgraded from TFS 2010, and the upgrade did not update all the Application Tier URLs: the Notification URL was still set to an old URL. Correcting this fixed the problem!

Wednesday, September 23, 2015

Visual Paradigm: Draw a table

Just a quick tip. Here's how to create a table in Visual Paradigm.

First, create a Text box, then use this associated tool:

This may seem quite obvious but at first I had to look around for quite a bit. Hope this help save some time.