Tuesday, June 3, 2014¶
Worked on Lino Così. Steve reported the problem that double-click on the phantom row of the “Unregistered invoices” table opens a dialog window to create a new invoice, but then says “journal may not be null”.
I simply needed to add a journal field to the insert_layout used in that table. But then I stumbled over a strange phenomen. The chooser for that journal field should of couse show only invoice journals. Here is how I did that:
@dd.chooser() def journal_choices(cls): vt = VoucherTypes.get_by_value(dd.full_model_name(cls)) qs = Journal.objects.filter(voucher_type=vt) return qs
But it doesn’t work…
… because the current implementation of choosers is a bit strange. The chooser decorator does not convert the function to a Chooser instance, it just adds the chooser options as attributes to the callable. Chooser instances are instantiated only later, in actions.install_choosers. And they are stored per field. This is the reason for our problem: since Voucher is an MTI child, there is only one field instance for all models. And though each model causes the instantiation of a Chooser, they all are then stored to _lino_chooser attribute of the same field, thus only the last instance survives. It seems that I can optimize that.
fab docs command
contained non-ASCII text.