Friday, June 16, 2017

I checked in my yesterday’s work on #1906.

Then continued on #1907 (Lino zeigt keine Konten an in EKR). This is caused by the get_allowed_accounts method. The only problem is that no account had its lino_xl.lib.accounts.Account.purchase_allowed checkbox checked.

The fundamental challenge is here: How to make these fields visible in a flexible way?

Current solution (which is reasonable but not perfect) is that I defined a custom layouts module for Lino Tera (lino_tera.lib.tera.layouts).

This solution is not perfect because this layout is probably used by all applications which have both lino_xl.lib.accounts and lino_xl.lib.ledger. The solution for this would be to define these layouts as part of the Cosi project and to have Tera, Voga, Presto etc inherit the accounts plugin from Cosi. But I am not doing this right now because of a licensing problem: Lino Cosi is GPL licensed (not BSD) because the lino_xl.lib.b2c plugin contains GPL licensed code from Odoo and AFAICS I am not allowed to publish my derivated work under the BSD.

The name field of a partners list

I discovered that there is a problem, probably caused by our move to Django 1.11 : when Lino Tera writes a database snapshot, the generated restore.py fill currently has:

def create_lists_list(partner_ptr_id, ref, list_type_id):
    #return create_mti_child(contacts_Partner, partner_ptr_id, lists_List,ref=ref,list_type_id=list_type_id,name_fr=name_fr)
    return create_mti_child(contacts_Partner, partner_ptr_id, lists_List,ref=ref,list_type_id=list_type_id,name=ref)

which causes a runtime error “UndefinedName name_fr”.

For example in Lino Vilma it doesn’t occur:

def create_lists_list(id, ref, name, list_type_id, remarks):
    kw = dict()
    kw.update(id=id)
    kw.update(ref=ref)
    if name is not None: kw.update(bv2kw('name',name))
    kw.update(list_type_id=list_type_id)
    kw.update(remarks=remarks)
    return lists_List(**kw)

This might be a serious problem which might cause data loss. I created #1908.

I guess that it related to the fact that the lists.List model in Lino Tera also inherits from Partner:

class List(List, Partner):
    ...

An in that case the problem had even been detected by two test cases Diamond inheritance and Diamond inheritance. I deactivated them last week because I didn’t see that they are important. Now I see that they are.

The erroneous code is generated by pm dump2py. I moved the relevant code into a function write_create_function so that I can import it for writing testable docs:

>>> from lino import startup
>>> startup('lino_book.projects.lydia.settings.demo')
>>> from lino.modlib.lino_startup.management.commands.dump2py import write_create_function
>>> import sys
>>> from lino.api import rt
>>> write_create_function(rt.models.lists.List, sys.stdout)
def create_lists_list(partner_ptr_id, ref, list_type_id):
    return create_mti_child(contacts_Partner, partner_ptr_id, lists_List,ref=ref,list_type_id=list_type_id,name_de=name_de,name_fr=name_fr)

See also lino.utils.dpy.create_mti_child()