Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docsource/modules180-190.rst
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ Module coverage 18.0 -> 19.0
+---------------------------------------------------+----------------------+-------------------------------------------------+
| |del| l10n_in_edi_ewaybill | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| |new| l10n_in_ewaybill | | |
| |new| l10n_in_ewaybill |Done | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
| |new| l10n_in_ewaybill_irn | | |
+---------------------------------------------------+----------------------+-------------------------------------------------+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from openupgradelib import openupgrade

# Companion to pre-migration.py. The 18.0 ewaybill fields on account.move
# (l10n_in_distance, _mode, _transportation_doc_date, _transportation_doc_no,
# _transporter_id, _type_id, _vehicle_no, _vehicle_type) were preserved as
# openupgrade_legacy_19_0_* columns by the pre-migration. In 19.0 the same
# data lives on l10n.in.ewaybill rows linked via account_move_id.
#
# For each account.move with non-NULL legacy ewaybill data we INSERT one
# l10n.in.ewaybill row capturing the eight transport fields. The new row
# starts in state='pending' (the 19.0 default) since the 18.0 schema did
# not track ewaybill-API status separately from the account.move record
# itself — the operator can re-fetch from the e-Waybill API after
# migration if they need to reconcile with the gov portal.
#
# l10n.in.ewaybill.mode in 19.0 drops the '0' selection key from 18.0;
# we coerce any '0'-valued rows to NULL (operator marks them after the
# fact). Other selection keys ('1'/'2'/'3'/'4' and 'O'/'R') overlap
# cleanly between versions.


@openupgrade.migrate()
def migrate(env, version):
# Discover the legacy column names that pre-migration.py created. If
# the legacy columns are absent (e.g. on a fresh install or a re-run
# where post already executed), exit cleanly.
legacy_distance = openupgrade.get_legacy_name("l10n_in_distance")
env.cr.execute(
"""
SELECT column_name FROM information_schema.columns
WHERE table_name = 'account_move' AND column_name = %s
""",
(legacy_distance,),
)
if not env.cr.fetchone():
return

legacy = {
new_name: openupgrade.get_legacy_name(old_name)
for new_name, old_name in (
("distance", "l10n_in_distance"),
("mode", "l10n_in_mode"),
("transportation_doc_date", "l10n_in_transportation_doc_date"),
("transportation_doc_no", "l10n_in_transportation_doc_no"),
("transporter_id", "l10n_in_transporter_id"),
("type_id", "l10n_in_type_id"),
("vehicle_no", "l10n_in_vehicle_no"),
("vehicle_type", "l10n_in_vehicle_type"),
)
}
any_nonnull = " OR ".join(f"am.{c} IS NOT NULL" for c in legacy.values())

openupgrade.logged_query(
env.cr,
f"""
INSERT INTO l10n_in_ewaybill (
account_move_id, state,
distance, mode,
transportation_doc_date, transportation_doc_no,
transporter_id, type_id,
vehicle_no, vehicle_type,
create_uid, create_date, write_uid, write_date
)
SELECT
am.id,
'pending'::varchar,
am.{legacy["distance"]},
CASE WHEN am.{legacy["mode"]} = '0' THEN NULL ELSE am.{legacy["mode"]} END,
am.{legacy["transportation_doc_date"]},
am.{legacy["transportation_doc_no"]},
am.{legacy["transporter_id"]},
am.{legacy["type_id"]},
am.{legacy["vehicle_no"]},
am.{legacy["vehicle_type"]},
COALESCE(am.write_uid, am.create_uid, 1),
COALESCE(am.write_date, am.create_date, NOW() AT TIME ZONE 'UTC'),
COALESCE(am.write_uid, am.create_uid, 1),
COALESCE(am.write_date, am.create_date, NOW() AT TIME ZONE 'UTC')
FROM account_move am
WHERE {any_nonnull}
""",
)
126 changes: 126 additions & 0 deletions openupgrade_scripts/scripts/l10n_in_ewaybill/19.0.2.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
from openupgradelib import openupgrade

# l10n_in_ewaybill 19.0 is the result of three converging changes:
#
# 1. l10n_in_edi_ewaybill (the 18.0 EDI module that held the account.move
# ewaybill fields + ewaybill types) is renamed to l10n_in_ewaybill via
# `apriori.renamed_modules`. base/19.0.1.3/pre-migration.py runs
# `update_module_names` over apriori — by the time THIS script runs,
# all ir_module_module / ir_model_data rows with module='l10n_in_edi_ewaybill'
# have been rewritten to 'l10n_in_ewaybill'. No work needed here for that
# renaming.
#
# 2. l10n_in_ewaybill_stock KEEPS its name in 19.0 but the
# l10n.in.ewaybill + l10n.in.ewaybill.cancel models MOVE OUT to
# l10n_in_ewaybill. The table name `l10n_in_ewaybill` is identical
# pre/post; only model ownership and a handful of xmlids change.
# - update_module_moved_models for both models (transfers ir.model
# and ir.model.fields ownership).
# - rename_xmlids for the 6 records that ship under l10n_in_ewaybill
# in 19.0 but were under l10n_in_ewaybill_stock in 18.0.
#
# 3. Three res.company credentials columns rename their prefix from
# `l10n_in_edi_ewaybill_*` to `l10n_in_ewaybill_*` (the apriori
# module rename in step 1 updated ownership in ir_model_fields, but
# the SQL column names on res_company need rename_fields).
#
# 4. Eight DEL fields on account.move move out to the new
# l10n.in.ewaybill rows in 19.0. PRESERVE the columns as legacy
# names here in pre-migration; post-migration.py creates one
# l10n.in.ewaybill row per account.move that had non-NULL ewaybill
# data and copies the values across.

_renamed_xmlids_from_stock = [
(
"l10n_in_ewaybill_stock.l10n_in_ewaybill_form_action",
"l10n_in_ewaybill.l10n_in_ewaybill_form_action",
),
(
"l10n_in_ewaybill_stock.action_report_ewaybill",
"l10n_in_ewaybill.action_report_ewaybill",
),
(
"l10n_in_ewaybill_stock.access_l10n_in_ewaybill",
"l10n_in_ewaybill.access_l10n_in_ewaybill",
),
(
"l10n_in_ewaybill_stock.access_l10n_in_ewaybill_cancel",
"l10n_in_ewaybill.access_l10n_in_ewaybill_cancel",
),
(
"l10n_in_ewaybill_stock.l10n_in_ewaybill_comp_rule",
"l10n_in_ewaybill.l10n_in_ewaybill_comp_rule",
),
(
"l10n_in_ewaybill_stock.paperformat_ewaybill",
"l10n_in_ewaybill.paperformat_ewaybill",
),
]

_preserved_columns_account_move = {
# 18.0 columns owned by l10n_in_edi_ewaybill; DEL in 19.0. We preserve
# them as openupgrade_legacy_19_0_* so post-migration.py can spawn
# l10n.in.ewaybill rows from them.
"account_move": [
("l10n_in_distance", None),
("l10n_in_mode", None),
("l10n_in_transportation_doc_date", None),
("l10n_in_transportation_doc_no", None),
("l10n_in_transporter_id", None),
("l10n_in_type_id", None),
("l10n_in_vehicle_no", None),
("l10n_in_vehicle_type", None),
],
}

_renamed_fields_company_credentials = [
(
"res.company",
"res_company",
"l10n_in_edi_ewaybill_auth_validity",
"l10n_in_ewaybill_auth_validity",
),
(
"res.company",
"res_company",
"l10n_in_edi_ewaybill_password",
"l10n_in_ewaybill_password",
),
(
"res.company",
"res_company",
"l10n_in_edi_ewaybill_username",
"l10n_in_ewaybill_username",
),
]


@openupgrade.migrate()
def migrate(env, version):
# Move the model ownership: ir.model + ir.model.fields rows that point
# at l10n.in.ewaybill / l10n.in.ewaybill.cancel get their `module`
# column rewritten from l10n_in_ewaybill_stock to l10n_in_ewaybill.
# The SQL table itself is not renamed (the table name is identical).
openupgrade.update_module_moved_models(
env.cr, "l10n.in.ewaybill", "l10n_in_ewaybill_stock", "l10n_in_ewaybill"
)
openupgrade.update_module_moved_models(
env.cr, "l10n.in.ewaybill.cancel", "l10n_in_ewaybill_stock", "l10n_in_ewaybill"
)

# Six XML records (action, report, two access rules, rule, paperformat)
# ship under l10n_in_ewaybill in 19.0 but lived under
# l10n_in_ewaybill_stock in 18.0. Rename so customer references to
# them survive the upgrade.
openupgrade.rename_xmlids(env.cr, _renamed_xmlids_from_stock)

# Three res.company credential columns drop the `_edi_` segment.
# apriori's update_module_names already moved the ir_model_fields
# ownership; rename_fields handles the SQL column rename + filter /
# export / translation side effects.
openupgrade.rename_fields(env, _renamed_fields_company_credentials)

# Preserve the 8 account.move ewaybill columns before Odoo's update_db
# drops them. post-migration.py consumes the legacy values to spawn
# l10n.in.ewaybill rows.
openupgrade.rename_columns(env.cr, _preserved_columns_account_move)
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---Models in module 'l10n_in_ewaybill'---
model l10n.in.ewaybill (moved from l10n_in_ewaybill_stock)
model l10n.in.ewaybill.cancel (moved from l10n_in_ewaybill_stock) [transient]

# DONE: model ownership transfer via update_module_moved_models in
# pre-migration. The SQL table name (l10n_in_ewaybill) is unchanged
# pre/post; only the ir.model + ir.model.fields `module` columns get
# rewritten from l10n_in_ewaybill_stock to l10n_in_ewaybill.

---Fields in module 'l10n_in_ewaybill'---
l10n_in_edi_ewaybill / account.move / l10n_in_distance (integer) : DEL
l10n_in_edi_ewaybill / account.move / l10n_in_mode (selection) : DEL selection_keys: ['0', '1', '2', '3', '4']
l10n_in_edi_ewaybill / account.move / l10n_in_transportation_doc_date (date): DEL
l10n_in_edi_ewaybill / account.move / l10n_in_transportation_doc_no (char): DEL
l10n_in_edi_ewaybill / account.move / l10n_in_transporter_id (many2one): DEL relation: res.partner
l10n_in_edi_ewaybill / account.move / l10n_in_type_id (many2one) : DEL relation: l10n.in.ewaybill.type
l10n_in_edi_ewaybill / account.move / l10n_in_vehicle_no (char) : DEL
l10n_in_edi_ewaybill / account.move / l10n_in_vehicle_type (selection): DEL selection_keys: ['O', 'R']

# DONE — these 8 fields used to live on account.move in 18.0 but in
# 19.0 the same data lives on l10n.in.ewaybill rows linked via the NEW
# account.move.l10n_in_ewaybill_ids o2m. Migration is handled in two
# steps:
#
# - pre-migration.py renames the eight columns to openupgrade_legacy_19_0_*
# so Odoo's update_db doesn't drop them on install.
# - post-migration.py inserts one l10n.in.ewaybill row per account.move
# that had non-NULL ewaybill data, copying the eight transport fields
# across. New rows enter state='pending' (the 19.0 default).
#
# Type coercion: the 18.0 selection l10n_in_mode had keys '0'/'1'/'2'/
# '3'/'4'; the 19.0 l10n.in.ewaybill.mode drops '0'. The post-migration
# coerces '0'-valued rows to NULL so the operator can mark them after
# the fact. All other selection keys overlap cleanly between versions.

l10n_in_edi_ewaybill / res.company / l10n_in_edi_ewaybill_auth_validity (datetime): DEL
l10n_in_edi_ewaybill / res.company / l10n_in_edi_ewaybill_password (char): DEL
l10n_in_edi_ewaybill / res.company / l10n_in_edi_ewaybill_username (char): DEL
l10n_in_ewaybill / res.company / l10n_in_ewaybill_auth_validity (datetime): NEW
l10n_in_ewaybill / res.company / l10n_in_ewaybill_password (char): NEW
l10n_in_ewaybill / res.company / l10n_in_ewaybill_username (char): NEW

# DONE: three credentials column renames handled by rename_fields in
# pre-migration. The 18.0 column names (l10n_in_edi_ewaybill_*) match
# the 19.0 names except for the dropped `_edi_` segment. The values
# (auth token / password / username) are operator-configured and worth
# preserving.

l10n_in_ewaybill / res.company / l10n_in_ewaybill_feature (boolean): NEW

# NOTHING TO DO: optional NEW boolean (feature flag) on res.company; Odoo's update_db handles.

l10n_in_ewaybill / account.move / l10n_in_ewaybill_ids (one2many): NEW relation: l10n.in.ewaybill

# NOTHING TO DO: reverse-side of the model move; no scalar column.

l10n_in_ewaybill / l10n.in.ewaybill / account_move_id (many2one) : NEW relation: account.move

# NOTHING TO DO: NEW forward FK on the moved model; Odoo's update_db creates the integer column with NULL.

l10n_in_ewaybill / l10n.in.ewaybill / attachment_file (binary) : NEW attachment: True

# NOTHING TO DO: binary attachment; stored via ir.attachment.

# (60+ "previously in module l10n_in_ewaybill_stock" lines — these are
# the model's existing fields whose ownership transfers via
# update_module_moved_models above. No per-field work needed.)

l10n_in_ewaybill_stock / l10n.in.ewaybill / company_id (many2one) : is now stored
l10n_in_ewaybill_stock / l10n.in.ewaybill / company_id (many2one) : not related anymore
l10n_in_ewaybill_stock / l10n.in.ewaybill / company_id (many2one) : now a function
l10n_in_ewaybill_stock / l10n.in.ewaybill / document_date (datetime) : not related anymore
l10n_in_ewaybill_stock / l10n.in.ewaybill / document_date (datetime) : now a function
l10n_in_ewaybill_stock / l10n.in.ewaybill / document_number (char) : not related anymore
l10n_in_ewaybill_stock / l10n.in.ewaybill / document_number (char) : now a function

# NOTHING TO DO: company_id was a related field in 18.0 (computed
# from a parent record); in 19.0 it's a stored computed function.
# Odoo's _recompute_field machinery populates it after install.
# document_date / document_number similarly transition from related to
# function — no schema impact, Odoo recomputes.

l10n_in_ewaybill_stock / l10n.in.ewaybill / state (selection) : selection_keys removed: [challan]

# NOTHING TO DO: the 'challan' state was internal-only and would not
# have been used by any production ewaybill records. Standard
# selection-keys narrowing.

---XML records in module 'l10n_in_ewaybill'---

# DONE — 6 xmlid renames from l10n_in_ewaybill_stock to l10n_in_ewaybill
# handled by rename_xmlids in pre-migration (action, report, 2 access
# rules, ir.rule, paperformat). The 8 l10n.in.ewaybill.type renames from
# l10n_in_edi_ewaybill to l10n_in_ewaybill are AUTOMATIC (apriori's
# update_module_names handles the module rename).

NEW ir.actions.act_window: l10n_in_ewaybill.l10n_in_ewaybill_form_action [renamed from l10n_in_ewaybill_stock module]
NEW ir.actions.report: l10n_in_ewaybill.action_report_ewaybill [renamed from l10n_in_ewaybill_stock module]
NEW ir.model.access: l10n_in_ewaybill.access_l10n_in_ewaybill [renamed from l10n_in_ewaybill_stock module]
NEW ir.model.access: l10n_in_ewaybill.access_l10n_in_ewaybill_cancel [renamed from l10n_in_ewaybill_stock module]
NEW ir.rule: l10n_in_ewaybill.l10n_in_ewaybill_comp_rule [renamed from l10n_in_ewaybill_stock module] (noupdate)
NEW report.paperformat: l10n_in_ewaybill.paperformat_ewaybill [renamed from l10n_in_ewaybill_stock module]

# NEW records that have no rename source — install via standard module-data XML:
NEW ir.model.access: l10n_in_ewaybill.view_l10n_in_ewaybill
NEW ir.model.access: l10n_in_ewaybill.access_l10n_in_ewaybill_type [renamed from l10n_in_edi_ewaybill module]
NEW ir.ui.view: l10n_in_ewaybill.invoice_form_inherit_l10n_in_ewaybill
NEW ir.ui.view: l10n_in_ewaybill.l10n_in_ewaybill_form_view
NEW ir.ui.view: l10n_in_ewaybill.l10n_in_ewaybill_report_invoice_document_inherit
NEW ir.ui.view: l10n_in_ewaybill.report_ewaybill
NEW ir.ui.view: l10n_in_ewaybill.res_config_settings_view_form_inherit_l10n_in_edi_ewaybill
NEW ir.ui.view: l10n_in_ewaybill.view_ewaybill_cancel_form
NEW ir.ui.view: l10n_in_ewaybill.view_invoice_list_inherit_l10n_in_ewaybill

# NOTHING TO DO: NEW view records install via standard module-data XML.

DEL account.edi.format: l10n_in_edi_ewaybill.edi_in_ewaybill_json_1_03
DEL ir.ui.view: l10n_in_edi_ewaybill.invoice_form_inherit_l10n_in_edi_ewaybill
DEL ir.ui.view: l10n_in_edi_ewaybill.l10n_in_einvoice_report_invoice_document_inherit
DEL ir.ui.view: l10n_in_edi_ewaybill.res_config_settings_view_form_inherit_l10n_in_edi_ewaybill

# NOTHING TO DO: legacy account.edi.format + three view records removed
# by the standard module-upgrade flow (apriori-rewritten module name +
# Odoo's noupdate flow handle these).

(8 l10n.in.ewaybill.type NEW/DEL pairs from l10n_in_edi_ewaybill — handled by apriori's module rename; no per-record rename_xmlids needed.)
Loading