52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Copyright 2021 Joan Marín <Github@JoanMarin>
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
|
|
|
from odoo import fields, models, _
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class AccountMove(models.Model):
|
|
_inherit = "account.move"
|
|
|
|
refund_type = fields.Selection(
|
|
selection=[('debit', 'Debit Note'), ('credit', 'Credit Note')],
|
|
index=True,
|
|
string='Refund Type',
|
|
tracking=True)
|
|
discrepancy_response_code_id = fields.Many2one(
|
|
comodel_name='account.move.discrepancy.response.code',
|
|
string='Correction concept for Refund Invoice')
|
|
|
|
def action_post(self):
|
|
msg1 = _('Please define a sequence for the refunds')
|
|
msg2 = _('Please define a sequence for the debit notes')
|
|
msg3 = _('Please define a sequence on the journal.')
|
|
|
|
for move in self:
|
|
if move.move_name == '/':
|
|
new_name = '/'
|
|
|
|
if move.journal_id.sequence_id:
|
|
sequence = move.journal_id.sequence_id
|
|
|
|
if move.journal_id.refund_sequence and move.refund_type == 'credit':
|
|
if not move.journal_id.refund_sequence_id:
|
|
raise UserError(msg1)
|
|
|
|
sequence = move.journal_id.refund_sequence_id
|
|
|
|
if move.journal_id.debit_note_sequence and move.refund_type == 'debit':
|
|
if not move.journal_id.debit_note_sequence_id:
|
|
raise UserError(msg2)
|
|
|
|
sequence = move.journal_id.debit_note_sequence_id
|
|
|
|
new_name = sequence.next_by_id()
|
|
else:
|
|
raise UserError(msg3)
|
|
|
|
move.move_name = new_name
|
|
|
|
return super(AccountMove, self).action_post()
|