2021-09-08 14:21:43 +02:00
|
|
|
# Copyright 2021 Akretion France (http://www.akretion.com/)
|
2022-05-05 17:18:14 +02:00
|
|
|
# Copyright 2022 Vauxoo (https://www.vauxoo.com/)
|
2021-09-08 14:21:43 +02:00
|
|
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
2022-05-05 17:18:14 +02:00
|
|
|
# @author: Moisés López <moylop260@vauxoo.com>
|
2021-09-08 14:21:43 +02:00
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
|
|
|
|
from odoo import SUPERUSER_ID, api
|
|
|
|
|
|
|
|
|
|
|
|
def create_journal_sequences(cr, registry):
|
|
|
|
with api.Environment.manage():
|
|
|
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
2022-05-11 19:18:36 +02:00
|
|
|
journals = (
|
|
|
|
env["account.journal"]
|
|
|
|
.with_context(active_test=False)
|
|
|
|
.search([("sequence_id", "!=", False)])
|
|
|
|
)
|
2021-09-08 14:21:43 +02:00
|
|
|
for journal in journals:
|
|
|
|
journal_vals = {
|
|
|
|
"code": journal.code,
|
|
|
|
"name": journal.name,
|
|
|
|
"company_id": journal.company_id.id,
|
|
|
|
}
|
|
|
|
seq_vals = journal._prepare_sequence(journal_vals)
|
2022-05-05 17:18:14 +02:00
|
|
|
seq_vals.update(journal._prepare_sequence_current_moves())
|
|
|
|
vals = {"sequence_id": env["ir.sequence"].create(seq_vals).id}
|
2021-09-08 14:21:43 +02:00
|
|
|
if journal.type in ("sale", "purchase") and journal.refund_sequence:
|
|
|
|
rseq_vals = journal._prepare_sequence(journal_vals, refund=True)
|
2022-05-05 17:18:14 +02:00
|
|
|
rseq_vals.update(journal._prepare_sequence_current_moves(refund=True))
|
2021-09-08 14:21:43 +02:00
|
|
|
vals["refund_sequence_id"] = env["ir.sequence"].create(rseq_vals).id
|
|
|
|
journal.write(vals)
|
|
|
|
return
|