Skip to content

Commit 925fd6e

Browse files
committed
[IMP] util/inconsistencies.py: Improve message for product mismatch
Improve products inconsistencies warning message. The product name is now displayed to better understand the changes that need to be done. ``` There is a product mismatch in some Account Move Line. The product defined on the Account Move Line is different from that defined on the Purchase Order Line. To allow the upgrade to continue, the product on the Account Move Line and on the Purchase Order Line must be the same. These Account Move Line have inconsistencies: * Account Move Line(id=380573) has Product `Moule (copie)`(id=8773), Purchase Order Line(id=61943) has Product `Vendor Down payment`(id=10924) * Account Move Line(id=372326) has Product `Acompte à livraison des T1`(id=11290), Purchase Order Line(id=61943) has Product `Vendor Down payment`(id=10924) * Account Move Line(id=354616) has Product `Moule (copie)`(id=8773), Purchase Order Line(id=57460) has Product `Milestone for Shipment`(id=10672) * Account Move Line(id=354617) has Product `Prestation Hors U.E.`(id=8598), Purchase Order Line(id=57461) has Product `Milestone for Shipment`(id=10672) * Account Move Line(id=354618) has Product `Moule (copie)`(id=8773), Purchase Order Line(id=57462) has Product `Milestone for Shipment`(id=10672) * Account Move Line(id=354619) has Product `Prestation Hors U.E.`(id=8598), Purchase Order Line(id=57463) has Product `Milestone for Shipment`(id=10672) * Account Move Line(id=380560) has Product `Moule (copie)`(id=8773), Purchase Order Line(id=57471) has Product `Acompte à la commande`(id=11288) * Account Move Line(id=380572) has Product `Moule (copie)`(id=8773), Purchase Order Line(id=57472) has Product `Acompte à la commande`(id=11288) * Account Move Line(id=380566) has Product `Moule (copie)`(id=8773), Purchase Order Line(id=57473) has Product `Acompte à la commande`(id=11288) ``` Part of odoo/upgrade#5212 Signed-off-by: Alvaro Fuentes Suarez (afu) <[email protected]>
1 parent aaba7fd commit 925fd6e

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

src/util/inconsistencies.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# -*- coding: utf-8 -*-
22
import logging
3+
import os
34
from textwrap import dedent
45

56
from psycopg2.extensions import quote_ident
67

8+
from odoo.tools.misc import str2bool
9+
710
from .helpers import _validate_model, table_of_model
811
from .misc import chunks
12+
from .pg import get_value_or_en_translation
913
from .report import add_to_migration_reports
1014

1115
_logger = logging.getLogger(__name__)
1216

17+
INCLUDE_ARCHIVED_PRODUCTS = str2bool(
18+
os.environ.get("ODOO_MIG_DO_NOT_IGNORE_ARCHIVED_PRODUCTS_FOR_UOM_INCONSISTENCIES"),
19+
default=False,
20+
)
21+
1322

1423
def verify_companies(
1524
cr, model, field_name, logger=_logger, model_company_field="company_id", comodel_company_field="company_id"
@@ -202,25 +211,35 @@ def verify_products(
202211
query = """
203212
SELECT f.id,
204213
f.{foreign_model_product_field},
214+
fpt.{name},
205215
t.id,
206-
t.{model_product_field}
216+
t.{model_product_field},
217+
tpt.{name}
207218
FROM {table} t
208219
JOIN {foreign_table} f ON f.{foreign_model_reference_field} = t.id
220+
JOIN product_product tpp ON t.{model_product_field} = tpp.id
221+
JOIN product_template tpt ON tpp.product_tmpl_id = tpt.id
222+
JOIN product_product fpp ON f.{foreign_model_product_field} = fpp.id
223+
JOIN product_template fpt ON fpp.product_tmpl_id = fpt.id
209224
WHERE f.{foreign_model_product_field} != t.{model_product_field}
225+
{ids}
226+
{active}
210227
""".format(
228+
name=get_value_or_en_translation(cr, "product_template", "name"),
211229
table=q(table),
212230
foreign_table=q(foreign_table),
213231
foreign_model_reference_field=q(foreign_model_reference_field),
214232
model_product_field=q(model_product_field),
215233
foreign_model_product_field=q(foreign_model_product_field),
234+
ids=" AND t.id IN %s" if ids else "",
235+
active=" AND tpp.active" if INCLUDE_ARCHIVED_PRODUCTS else "",
216236
)
217237

218238
rows = []
219239
if ids is None:
220240
cr.execute(query)
221241
rows = cr.fetchall()
222242
elif ids:
223-
query += " AND t.id IN %s"
224243
ids_chunks = chunks(ids, size=cr.IN_MAX, fmt=tuple)
225244
for chunk in ids_chunks:
226245
cr.execute(query, [chunk])
@@ -231,21 +250,25 @@ def verify_products(
231250

232251
title = model.replace(".", " ").title()
233252
foreign_title = foreign_model.replace(".", " ").title()
234-
msg = dedent(
235-
"""
236-
There is a product mismatch in some {foreign_title}. The product defined on the {foreign_title}
237-
is different from that defined on the {title}. To allow the upgrade to continue, the product
238-
on the {foreign_title} and on the {title} must be the same.
239-
These {foreign_title} have inconsistencies:
240-
""".format(
241-
**locals()
242-
)
253+
msg = """
254+
There is a product mismatch in some {foreign_title}. The product defined on the {foreign_title}
255+
is different from that defined on the {title}. To allow the upgrade to continue, the product
256+
on the {foreign_title} and on the {title} must be the same.
257+
These {foreign_title} have inconsistencies:
258+
""".format(
259+
**locals()
243260
)
244261
msg += "\n".join(
245-
" * {}(id={}) has Product(id={}), {}(id={}) has Product(id={})".format(
246-
foreign_title, foreign_line_id, foreign_line_product, title, line_id, line_product
262+
" * {}(id={}) has Product `{}`(id={}), {}(id={}) has Product `{}`(id={})".format(
263+
foreign_title, fline_id, fline_product, fline_product_id, title, line_id, line_product, line_product_id
247264
)
248-
for foreign_line_id, foreign_line_product, line_id, line_product in rows
265+
for fline_id, fline_product_id, fline_product, line_id, line_product_id, line_product in rows
266+
)
267+
268+
add_to_migration_reports(
269+
category=title + " - " + foreign_title + " Products Inconsistencies",
270+
message=msg,
271+
format="md",
249272
)
250273
_logger.warning("\n%s\n", msg)
251274
return [r[0] for r in rows]

0 commit comments

Comments
 (0)