Skip to content

Commit

Permalink
sale_import_base: be v16 ready
Browse files Browse the repository at this point in the history
code is renamed ref in v16
but there is also a code in the same table in v16
this code prevent an openupgrade failing because of already
existing column (code)
  • Loading branch information
hparfr authored and Clément Mombereau committed Jan 22, 2025
1 parent 5e9cadc commit 4b4b186
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sale_import_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Sale Import Base",
"summary": "Base for importing Sale Orders through a JSON file format",
"version": "14.0.1.2.0",
"version": "14.0.2.0.0",
"category": "Generic Modules/Sale",
"author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/akretion/sale-import",
Expand Down
27 changes: 27 additions & 0 deletions sale_import_base/migrations/14.0.2.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 Akretion France (http://www.akretion.com/)
# @author: Raphaël Reverdy <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
if not openupgrade.column_exists(env.cr, "payment_acquirer", "ref"):
# in v16
# payment_acquirer is renamed payment_provider
# and there is another different "code" field on payment_provider
# in sale_import_base (v16) the code field is now ref
# but without migration script
# therefore, we change it here to be future proof.
openupgrade.rename_fields(
env,
[
(
"payment.aquirer",
"payment_acquirer",
"code",
"ref",
),
],
)
5 changes: 4 additions & 1 deletion sale_import_base/models/payment_acquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
class PaymentAcquirer(models.Model):
_inherit = "payment.acquirer"

# code is renamed in ref in v16
# we keep it as is, to keep compatibility only in v14
code = fields.Char(string="code", related="ref")
ref = fields.Char()

_sql_constraints = [("uniq_ref", "uniq(ref)", "The Provider ref must be uniq")]
_sql_constraints = [("uniq_ref", "uniq(ref)", "The Acquirer ref must be uniq")]

0 comments on commit 4b4b186

Please sign in to comment.