Friday, February 26, 2016

I started to write documentation for the new module lino_xl.lib.invoicing.

A first problem is that this plugin is not used by lino_cosi.projects.std, so autosummary fails to import it:

WARNING: [autosummary] failed to import u'lino_xl.lib.invoicing.models': no module named lino_xl.lib.invoicing.models

Since autosummary itself does not show me the error. In order to see this message I had to simulate what autosummary does:

>>> from lino import startup
>>> startup('lino_cosi.projects.std.settings.doctests')
>>> import lino_xl.lib.invoicing.models  #doctest: +ELLIPSIS
Traceback (most recent call last):
...
AttributeError: AttrDict instance has no key 'invoicing' (keys are ...)

So the failure was caused by this code:

invoice = models.ForeignKey(
    dd.plugins.invoicing.voucher_model, null=True, blank=True)

Yes, this is a common problem when using Sphinx autodoc to generate API documentation for a Django models.py file. These modules are (often) not importable by a process which has activated Django using a settings module that does not include the module in its INSTALLED_APPS.

A quick workaround is to add lino_xl.lib.invoicing to the get_installed_apps of lino_cosi.projects.std.

This solution has the disadvantage (or advantage?) that every Lino Così site will have these two tables (invoicing.Plan and invoicing.Item) in their database, even if they don’t use the automatic invoicing feature.