Problem creating a default payment term in account invoice

Greetings everyone: I have a problem; I want to set a default field in the account invoice module but I can’t manage to do it in any way,
not even with the simple code I used to test it. I get a successful execution response,
but the value doesn’t change, And ID 1 exists in the payment terms.
Could you help me with this issue? Thank you.

class Invoice(metaclass=PoolMeta):
    __name__ = 'account.invoice'

    def default_payment_term():
        return '1'

    def default_comment():
        return 'test'

The default value for a Many2One field must be an integer which is the id of the target.

But also for payment term, the default value will be override by the customer or supplier payment term defined on the party.

Thank you for the responses, but I tried with ‘return 1’, ‘return ‘1’’, and there’s no way. It always happens without selecting the client, but it never takes the payment term. I’m completely stuck.

trytond 7.0.6
trytond-account-invoice 7.0.1

on_change_party is called by on_change_type which is probably called by the client due to the domain inversion applied for the domain on the action.
And on_change_party is clearing the payment term if there is no party selected.
So you should probably also set your default payment term in this case by extending on_change_party.

I removed the on_change_party with the following code, and set the payment field to code 1, and it displays correctly. That was it. Thank you. Now I know where to act.

@fields.depends(‘party’, ‘type’)
def on_change_party(self):

You should not remove existing code, it does important things.
The proper way is to always call the super() method and add your own business logic after.

Sorry for explaining myself poorly. Yes, I simply disabled it to debug and verify if it was causing the issue. I need to provide the necessary logic. Thank you very much.

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