# -*- coding: utf-8 -*- # Copyright 2021 Joan MarĂ­n # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import models, api, fields, _ class AccountJournal(models.Model): _inherit = "account.journal" debit_note_sequence = fields.Boolean( string="Dedicated Debit Note Sequence", help="Check this box if you don't want to share the same sequence for invoices and debit " "notes made from this journal", default=False) debit_note_sequence_id = fields.Many2one( comodel_name="ir.sequence", string="Debit Note Entry Sequence", help= "This field contains the information related to the numbering of the debit note " "entries of this journal.", copy=False) @api.model def create(self, vals): if (vals.get('type') in ('sale', 'purchase') and vals.get('debit_note_sequence') and not vals.get('debit_note_sequence_id')): values = { 'name': _('Debit Note Sequence - ') + vals.get('name'), 'company_id': vals.get('company_id'), 'prefix': 'DN' + (vals.get('code') or '')} vals['debit_note_sequence_id'] = self.create_sequence(values) return super(AccountJournal, self).create(vals) def write(self, vals): res = super(AccountJournal, self).write(vals) for journal in self.filtered(lambda j: j.type in ('sale', 'purchase')): if journal.debit_note_sequence and not journal.debit_note_sequence_id: values = { 'name': _('Debit Note Sequence - ') + journal.name, 'company_id': journal.company_id, 'prefix': 'DN' + (journal.code or '')} journal.debit_note_sequence_id = self.create_sequence(values) return res