21
21
)
22
22
FIX_PRODUCT_UOM = str2bool (os .environ .get ("ODOO_MIG_FIX_ALL_UOM_INCONSISTENCIES" ), default = False )
23
23
24
+ FROM_ENV = object ()
25
+
24
26
25
27
def verify_companies (
26
28
cr , model , field_name , logger = _logger , model_company_field = "company_id" , comodel_company_field = "company_id"
@@ -107,7 +109,15 @@ def verify_companies(
107
109
)
108
110
109
111
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
+ ):
111
121
"""
112
122
Check if the category of uom on `model` is the same as the category of uom on `product.template`.
113
123
@@ -120,6 +130,12 @@ def verify_uoms(cr, model, uom_field="product_uom_id", product_field="product_id
120
130
121
131
q = lambda s : quote_ident (s , cr ._cnx )
122
132
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
+
123
139
query = """
124
140
SELECT t.id line_id,
125
141
t.{uom_column} line_uom_id,
@@ -148,7 +164,7 @@ def verify_uoms(cr, model, uom_field="product_uom_id", product_field="product_id
148
164
category_name = get_value_or_en_translation (cr , "uom_category" , "name" ),
149
165
product_template_name = get_value_or_en_translation (cr , "product_template" , "name" ),
150
166
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 "" ,
152
168
)
153
169
154
170
rows = []
@@ -166,7 +182,7 @@ def verify_uoms(cr, model, uom_field="product_uom_id", product_field="product_id
166
182
167
183
title = model .replace ("." , " " ).title ()
168
184
169
- if FIX_PRODUCT_UOM :
185
+ if auto_fix :
170
186
line_new_ids = {line_id : prod_uom_id for line_id , _ , _ , _ , prod_uom_id , _ , _ , _ , _ in rows }
171
187
cr .execute (
172
188
"""
@@ -261,6 +277,7 @@ def verify_products(
261
277
foreign_model_reference_field ,
262
278
model_product_field = "product_id" ,
263
279
foreign_model_product_field = "product_id" ,
280
+ include_archived_products = FROM_ENV ,
264
281
ids = None ,
265
282
):
266
283
"""
@@ -288,6 +305,10 @@ def verify_products(
288
305
foreign_table = table_of_model (cr , foreign_model )
289
306
290
307
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
+
291
312
query = """
292
313
SELECT f.id,
293
314
f.{foreign_model_product_field},
@@ -312,7 +333,7 @@ def verify_products(
312
333
model_product_field = q (model_product_field ),
313
334
foreign_model_product_field = q (foreign_model_product_field ),
314
335
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 "" ,
316
337
)
317
338
318
339
rows = []
0 commit comments