2
0

[MIG] account_move_name_sequence: Migration to 15.0

This commit is contained in:
Francisco Javier Luna Vazquez 2022-05-26 16:20:43 -05:00 committed by Rodrigo
parent 3a1b342a62
commit a800db0440
3 changed files with 41 additions and 37 deletions

View File

@ -7,7 +7,7 @@
{
"name": "Account Move Number Sequence",
"version": "14.0.1.2.2",
"version": "15.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Generate journal entry number from sequence",

View File

@ -2,6 +2,7 @@
# Copyright 2022 Vauxoo (https://www.vauxoo.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# @author: Moisés López <moylop260@vauxoo.com>
# @author: Francisco Luna <fluna@vauxoo.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
@ -45,26 +46,26 @@ class AccountJournal(models.Model):
raise ValidationError(
_(
"On journal '%s', the same sequence is used as "
"Entry Sequence and Credit Note Entry Sequence."
"Entry Sequence and Credit Note Entry Sequence.",
journal.display_name,
)
% journal.display_name
)
if journal.sequence_id and not journal.sequence_id.company_id:
raise ValidationError(
_(
"The company is not set on sequence '%s' configured on "
"journal '%s'."
)
% (journal.sequence_id.display_name, journal.display_name)
msg = _(
"The company is not set on sequence '%(sequence)s' configured on "
"journal '%(journal)s'.",
sequence=journal.sequence_id.display_name,
journal=journal.display_name,
)
raise ValidationError(msg)
if journal.refund_sequence_id and not journal.refund_sequence_id.company_id:
raise ValidationError(
_(
"The company is not set on sequence '%s' configured as "
"credit note sequence of journal '%s'."
)
% (journal.refund_sequence_id.display_name, journal.display_name)
msg = _(
"The company is not set on sequence '%(sequence)s' configured as "
"credit note sequence of journal '%(journal)s'.",
sequence=journal.refund_sequence_id.display_name,
journal=journal.display_name,
)
raise ValidationError(msg)
@api.model
def create(self, vals):
@ -180,7 +181,10 @@ class AccountJournal(models.Model):
)
select_max_number = (
"MAX(split_part(name, '%s', %d)::INTEGER) AS max_number"
% (prefixes[-1], prefixes.count(prefixes[-1]) + 1)
% (
prefixes[-1],
prefixes.count(prefixes[-1]) + 1,
)
)
query = (
"SELECT %s, %s, %s FROM account_move "

View File

@ -2,31 +2,31 @@
# Copyright 2022 Vauxoo (https://www.vauxoo.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# @author: Moisés López <moylop260@vauxoo.com>
# @author: Francisco Luna <fluna@vauxoo.com>
# 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, {})
journals = (
env["account.journal"]
.with_context(active_test=False)
.search([("sequence_id", "=", False)])
)
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)
seq_vals.update(journal._prepare_sequence_current_moves())
vals = {"sequence_id": env["ir.sequence"].create(seq_vals).id}
if journal.type in ("sale", "purchase") and journal.refund_sequence:
rseq_vals = journal._prepare_sequence(journal_vals, refund=True)
rseq_vals.update(journal._prepare_sequence_current_moves(refund=True))
vals["refund_sequence_id"] = env["ir.sequence"].create(rseq_vals).id
journal.write(vals)
env = api.Environment(cr, SUPERUSER_ID, {})
journals = (
env["account.journal"]
.with_context(active_test=False)
.search([("sequence_id", "=", False)])
)
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)
seq_vals.update(journal._prepare_sequence_current_moves())
vals = {"sequence_id": env["ir.sequence"].create(seq_vals).id}
if journal.type in ("sale", "purchase") and journal.refund_sequence:
rseq_vals = journal._prepare_sequence(journal_vals, refund=True)
rseq_vals.update(journal._prepare_sequence_current_moves(refund=True))
vals["refund_sequence_id"] = env["ir.sequence"].create(rseq_vals).id
journal.write(vals)
return