Skip to Content
Menú
This question has been flagged
1 Respondre
1777 Vistes

To refund an invoice a credit note is created. However even after refund, there is an option of creating a credit note against that invoice. How to restrict creating a credit note against already refunded invoice?

Avatar
Descartar
Best Answer

Hi,

Try this code:

from odoo import models,api
from odoo.exceptions import ValidationError


class AccountMove(models.Model):
    _inherit = 'account.move'

    @api.model
    def create(self, vals):
        credit = self.env['account.move'].search(
            [('reversed_entry_id', '=', self.id)])
        if credit and self.id:
            raise ValidationError(
                "Cannot create a credit note for an already refunded invoice.")
        return super(AccountMove, self).create(vals)


Hope it helps

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
d’abr. 23
4712
0
de març 15
4004
1
de març 22
3249
2
de juny 25
849
0
de febr. 24
1290