2121)
2222FIX_PRODUCT_UOM = str2bool (os .environ .get ("ODOO_MIG_FIX_ALL_UOM_INCONSISTENCIES" ), default = False )
2323
24+ FROM_ENV = object ()
25+
2426
2527def verify_companies (
2628 cr , model , field_name , logger = _logger , model_company_field = "company_id" , comodel_company_field = "company_id"
@@ -107,7 +109,15 @@ def verify_companies(
107109 )
108110
109111
110- def verify_uoms (cr , model , uom_field = "product_uom_id" , product_field = "product_id" , ids = None ):
112+ def verify_uoms (
113+ cr ,
114+ model ,
115+ uom_field = "product_uom_id" ,
116+ product_field = "product_id" ,
117+ include_archived_products = FROM_ENV ,
118+ auto_fix = FROM_ENV ,
119+ ids = None ,
120+ ):
111121 """
112122 Check if the category of uom on `model` is the same as the category of uom on `product.template`.
113123
@@ -120,6 +130,12 @@ def verify_uoms(cr, model, uom_field="product_uom_id", product_field="product_id
120130
121131 q = lambda s : quote_ident (s , cr ._cnx )
122132
133+ if include_archived_products is FROM_ENV :
134+ include_archived_products = INCLUDE_ARCHIVED_PRODUCTS
135+
136+ if auto_fix is FROM_ENV :
137+ auto_fix = FIX_PRODUCT_UOM
138+
123139 query = """
124140 SELECT t.id line_id,
125141 t.{uom_column} line_uom_id,
@@ -148,7 +164,7 @@ def verify_uoms(cr, model, uom_field="product_uom_id", product_field="product_id
148164 category_name = get_value_or_en_translation (cr , "uom_category" , "name" ),
149165 product_template_name = get_value_or_en_translation (cr , "product_template" , "name" ),
150166 ids = " AND t.id IN %s" if ids else "" ,
151- active = " AND pp.active" if not INCLUDE_ARCHIVED_PRODUCTS else "" ,
167+ active = " AND pp.active" if not include_archived_products else "" ,
152168 )
153169
154170 rows = []
@@ -166,7 +182,7 @@ def verify_uoms(cr, model, uom_field="product_uom_id", product_field="product_id
166182
167183 title = model .replace ("." , " " ).title ()
168184
169- if FIX_PRODUCT_UOM :
185+ if auto_fix :
170186 line_new_ids = {line_id : prod_uom_id for line_id , _ , _ , _ , prod_uom_id , _ , _ , _ , _ in rows }
171187 cr .execute (
172188 """
@@ -261,6 +277,7 @@ def verify_products(
261277 foreign_model_reference_field ,
262278 model_product_field = "product_id" ,
263279 foreign_model_product_field = "product_id" ,
280+ include_archived_products = FROM_ENV ,
264281 ids = None ,
265282):
266283 """
@@ -288,6 +305,10 @@ def verify_products(
288305 foreign_table = table_of_model (cr , foreign_model )
289306
290307 q = lambda s : quote_ident (s , cr ._cnx )
308+
309+ if include_archived_products is FROM_ENV :
310+ include_archived_products = INCLUDE_ARCHIVED_PRODUCTS
311+
291312 query = """
292313 SELECT f.id,
293314 f.{foreign_model_product_field},
@@ -312,7 +333,7 @@ def verify_products(
312333 model_product_field = q (model_product_field ),
313334 foreign_model_product_field = q (foreign_model_product_field ),
314335 ids = " AND t.id IN %s" if ids else "" ,
315- active = " AND tpp.active" if not INCLUDE_ARCHIVED_PRODUCTS else "" ,
336+ active = " AND tpp.active" if not include_archived_products else "" ,
316337 )
317338
318339 rows = []
0 commit comments