# Problem creating a default payment term in account invoice

**URL:** https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014
**Category:** Developer
**Created:** [February 24, 2024, 11:46am UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014 "2024-02-24T11:46:34Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![david\_auto](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@david\_auto](https://discuss.tryton.org/u/david_auto)
#### Post date: [February 24, 2024, 11:46am UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/1 "2024-02-24T11:46:34Z")

</div>

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.

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

    @staticmethod
    def default_payment_term():
        print('test')
        return '1'

    @staticmethod
    def default_comment():
        return 'test'

```

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 24, 2024, 11:56am UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/2 "2024-02-24T11:56:50Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![david\_auto](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@david\_auto](https://discuss.tryton.org/u/david_auto)
#### Post date: [February 24, 2024, 12:22pm UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/3 "2024-02-24T12:22:23Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 24, 2024, 12:25pm UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/4 "2024-02-24T12:25:54Z")

</div>

`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`.

---

<div class="post-metadata">

### Author: ![david\_auto](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@david\_auto](https://discuss.tryton.org/u/david_auto)
#### Post date: [February 24, 2024, 1:52pm UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/5 "2024-02-24T13:52:19Z")

</div>

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):  
print(‘2’)

---

<div class="post-metadata">

### Author: ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)
#### Post date: [February 24, 2024, 3:22pm UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/6 "2024-02-24T15:22:15Z")

</div>

> [@david\_auto](#):
>
> removed the on\_change\_party

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.

---

<div class="post-metadata">

### Author: ![david\_auto](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/c77e96/32.png) [@david\_auto](https://discuss.tryton.org/u/david_auto)
#### Post date: [February 24, 2024, 3:27pm UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/7 "2024-02-24T15:27:05Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)
#### Post date: [February 25, 2024, 3:27am UTC](https://discuss.tryton.org/t/problem-creating-a-default-payment-term-in-account-invoice/7014/8 "2024-02-25T03:27:14Z")

</div>

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