Hi all,

I'm having some issues with on_change and one2many fields.

=== one2many ===

So, I'm working on this timesheet_invoice module [1]. This contains
among other things:

class InvoiceLine(ModelSQL, ModelView):
    """Invoice Line"""
    _name = 'account.invoice.line'
    timesheet_lines = fields.Many2Many(
         'account_invoice_line-timesheet_line',
         'invoice_line', 'timesheet_line', 'Timesheet Lines')


Logically, an invoice-line is connected to a selection of billable
timesheet lines from a single work.

On my first iteration, I used a one2many field because that best models
the relation.

While I can select a subset of work.timesheet_lines and add them to the
one2many field using

...
   for timesheet_line in work.timesheet_lines:
       linedata['timesheet_lines'].append(('add',timesheet_line.id))
...


as far as I can tell the GUI doesn't offer a mechanism for disconnecting
them again, if I decide that certain timesheet lines should not be
billed yet. The one2many widget only allows you to delete lines, not
disconnect them.

Am I wrong here: is there a way to disconnect one2many lines *without*
deleting them from the database?

Using a many2many field I was able to resolve this, but that seems like
a hack, since the relation really is not n-n but 1-n.


=== on_change ===

It seems on_change is not always triggered when the field is changed.

Setting an on_change on timesheet_lines the callback specified is
*never* triggered, even when I delete or modify timesheet_lines
referenced. I would expect the on_change callback to be triggered when I
disconnect a timesheet line, or when I alter the number of billable
hours registered in a specific line, so the invoice line's quantity and
amount can be recalculated.

I was able to resolve this by overloading the quantity and amount fields
in the overloaded InvoiceLine class, and adding 'timesheet_lines' to
their *on_change_with* lists. But again, though it works - kind of, it
seems like a hack that may cause problems if the overloaded class in
'account_invoice' changes these fields in the future.

So: what are the exact conditions that determine when an on_change
handler is or isn't triggered for relationship fields like one2many?


thanks a lot!

[1] http://git.subdir.eu/paul/trytond_timesheet_invoice/

-- 
  ________________________________________________________________
  Paul Stevens                                      paul at nfg.nl
  NET FACILITIES GROUP                     GPG/PGP: 1024D/11F8CD31
  The Netherlands________________________________http://www.nfg.nl

-- 
[email protected] mailing list

Reply via email to