"Builder" to populate data

I’m doing a very tiny script to populate some data to Tryton through Proteus.

I’m trying to use something like a “builder” to do that.

Here a representative code:

def payment_term_builder(payment_term_lines=[], **kwargs):
    PaymentTerm = Model.get('account.invoice.payment_term')

    payment_term = PaymentTerm(**kwargs)
    payment_term.lines = payment_term_lines
    return payment_term

def test_payment_term_builder():
    PaymentTermLine = Model.get('account.invoice.payment_term.line')

    line = PaymentTermLine(type='reminder')
    delta, = line.relativedeltas
    delta.day = 10 

    payment_term_builder([line], name='Payment Term Name')

Of course, It doesn’t work 'cause I think is due to One2Many field management.

What is the way to fill the One2Many field for a use case like that?

If it’s possible I prefer not use the former way noted in doc because my intention is encapsulate data (passing a list of PaymentTermLine instead of a list of tuples whit its respective names and values…).


On proteus you should use append and extend to add lines to One2Many.

So this line needs to be chaned to:

Needs to be chaned to:


That should do the trick.

Oh yes!!!

That’s work for me!!! :smiley:

Thank you very much!!!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.