Skip to content

Commit 90edeeb

Browse files
committed
Merge PR #70 into master
Signed-off-by legalsylvain
2 parents 553b3d8 + 53f3787 commit 90edeeb

15 files changed

Lines changed: 278 additions & 9 deletions

File tree

DEVELOP.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ The list of the operations are written in the subfolder
162162
.. code-block:: yaml
163163
- ['account.account', 'user_type_id', 'account_type', 'Commit https://github.com/odoo/odoo/commit/26b2472f4977ccedbb0b5ed5f']
164164
165+
* ``removed_models/migrate_FROM_TO/NAME.yaml`` — removed models rule. Display errors / warnings if files contains a given partern:
166+
* errors: "old_model_name", 'old_model_name', old_table_name["',]
167+
* warnings: old.model.name, old_model_name
168+
169+
For example, for migration from version 15.0 to 16.0:
170+
.. code-block:: yaml
171+
- ["account.account.type", "Commit https://github.com/odoo/odoo/commit/26b2472f4977ccedbb0b5ed5f"]
172+
173+
* ``renamed_models/migrate_FROM_TO/NAME.yaml`` — renamed models rule. Display errors / warnings if files contains a given partern:
174+
* errors: "old_model_name", 'old_model_name', old_table_name["',]
175+
* warnings: old.model.name, old_model_name
176+
177+
For example, for migration from version 15.0 to 16.0:
178+
.. code-block:: yaml
179+
- ["stock.production.lot", "stock.lot", None]
180+
165181
How to improve the library
166182
==========================
167183

odoo_module_migrate/base_migration_script.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class BaseMigrationScript(object):
2020
_FILE_RENAMES = {}
2121
_REMOVED_FIELDS = []
2222
_RENAMED_FIELDS = []
23+
_RENAMED_MODELS = []
24+
_REMOVED_MODELS = []
2325
_GLOBAL_FUNCTIONS = [] # [function_object]
2426
_module_path = ""
2527

@@ -67,6 +69,16 @@ def parse_rules(self):
6769
"type": TYPE_ARRAY,
6870
"doc": [],
6971
},
72+
# [(old.model.name, new.model.name, more_info)]
73+
"_RENAMED_MODELS": {
74+
"type": TYPE_ARRAY,
75+
"doc": [],
76+
},
77+
# [(old.model.name, more_info)]
78+
"_REMOVED_MODELS": {
79+
"type": TYPE_ARRAY,
80+
"doc": [],
81+
},
7082
}
7183
# read
7284
for rule in rules.keys():
@@ -188,10 +200,14 @@ def process_file(
188200

189201
removed_fields = self.handle_removed_fields(self._REMOVED_FIELDS)
190202
renamed_fields = self.handle_renamed_fields(self._RENAMED_FIELDS)
203+
renamed_models = self.handle_renamed_models(self._RENAMED_MODELS)
204+
removed_models = self.handle_removed_models(self._REMOVED_MODELS)
191205

192206
# Operate changes in the file (replacements, removals)
193207
replaces = self._TEXT_REPLACES.get("*", {})
194208
replaces.update(self._TEXT_REPLACES.get(extension, {}))
209+
replaces.update(renamed_models.get("replaces"))
210+
replaces.update(removed_models.get("replaces"))
195211

196212
new_text = tools._replace_in_file(
197213
absolute_file_path, replaces, "Change file content of %s" % filename
@@ -201,6 +217,8 @@ def process_file(
201217
# pattern
202218
errors = self._TEXT_ERRORS.get("*", {})
203219
errors.update(self._TEXT_ERRORS.get(extension, {}))
220+
errors.update(renamed_models.get("errors"))
221+
errors.update(removed_models.get("errors"))
204222
for pattern, error_message in errors.items():
205223
if re.findall(pattern, new_text):
206224
logger.error(error_message)
@@ -209,6 +227,8 @@ def process_file(
209227
warnings.update(self._TEXT_WARNINGS.get(extension, {}))
210228
warnings.update(removed_fields.get("warnings"))
211229
warnings.update(renamed_fields.get("warnings"))
230+
warnings.update(renamed_models.get("warnings"))
231+
warnings.update(removed_models.get("warnings"))
212232
for pattern, warning_message in warnings.items():
213233
if re.findall(pattern, new_text):
214234
logger.warning(warning_message + ". File " + root + os.sep + filename)
@@ -311,6 +331,95 @@ def handle_deprecated_modules(self, manifest_path, deprecated_modules):
311331
if current_manifest_text != new_manifest_text:
312332
tools._write_content(manifest_path, new_manifest_text)
313333

334+
def handle_renamed_models(self, renamed_models):
335+
"""renamed_models = [(old.model, new.model, msg)]
336+
returns dictionary of all replaces / warnings / errors produced
337+
by a model renamed
338+
{
339+
'replaces':
340+
{
341+
"old_model_name", 'old_model_name': new_model_name
342+
old_table_name["',]: new_table_name["',]
343+
},
344+
'warnings':
345+
{
346+
old.model.name: warning msg
347+
old_model_name: warning msg
348+
}
349+
}
350+
"""
351+
res = {"replaces": {}, "warnings": {}, "errors": {}}
352+
for old_model_name, new_model_name, more_info in renamed_models:
353+
old_table_name = old_model_name.replace(".", "_")
354+
new_table_name = new_model_name.replace(".", "_")
355+
old_name_esc = re.escape(old_model_name)
356+
res["replaces"].update(
357+
{
358+
r"\"%s\"" % old_name_esc: '"%s"' % new_model_name,
359+
r"\'%s\'" % old_name_esc: "'%s'" % new_model_name,
360+
r"\"%s\"" % old_table_name: '"%s"' % new_table_name,
361+
r"\'%s\'" % old_table_name: "'%s'" % new_table_name,
362+
r"model_%s\"" % old_table_name: 'model_%s"' % new_table_name,
363+
r"model_%s\'" % old_table_name: "model_%s'" % new_table_name,
364+
r"model_%s," % old_table_name: "model_%s," % new_table_name,
365+
}
366+
)
367+
msg = "The model %s has been renamed to %s.%s" % (
368+
old_model_name,
369+
new_model_name,
370+
(" %s" % more_info) or "",
371+
)
372+
res["warnings"].update(
373+
{
374+
old_name_esc: msg,
375+
old_table_name: msg,
376+
}
377+
)
378+
return res
379+
380+
def handle_removed_models(self, removed_models):
381+
"""removed_models = [(old.model, msg)]
382+
returns dictionary of all replaces / warnings / errors produced
383+
by a model renamed
384+
{
385+
'error':
386+
{
387+
"old_model_name", 'old_model_name': new_model_name
388+
old_table_name["',]: new_table_name["',]
389+
},
390+
'warnings':
391+
{
392+
old.model.name: warning msg
393+
old_model_name: warning msg
394+
}
395+
}
396+
"""
397+
res = {"replaces": {}, "warnings": {}, "errors": {}}
398+
for model_name, more_info in removed_models:
399+
table_name = model_name.replace(".", "_")
400+
model_name_esc = re.escape(model_name)
401+
402+
msg = "The model %s has been .%s" % (model_name, (" %s" % more_info) or "")
403+
404+
res["errors"].update(
405+
{
406+
r"\"%s\"" % model_name_esc: msg,
407+
r"\'%s\'" % model_name_esc: msg,
408+
r"\"%s\"" % table_name: msg,
409+
r"\'%s\'" % table_name: msg,
410+
r"model_%s\"" % table_name: msg,
411+
r"model_%s\'" % table_name: msg,
412+
r"model_%s," % table_name: msg,
413+
}
414+
)
415+
res["warnings"].update(
416+
{
417+
model_name_esc: msg,
418+
table_name: msg,
419+
}
420+
)
421+
return res
422+
314423
def _get_correct_manifest_path(self, manifest_path, file_renames):
315424
current_manifest_file_name = manifest_path.as_posix().split("/")[-1]
316425
if current_manifest_file_name in file_renames:

odoo_module_migrate/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@
5959
},
6060
]
6161

62-
_ALLOWED_EXTENSIONS = [".py", ".xml", ".js"]
62+
_ALLOWED_EXTENSIONS = [".py", ".xml", ".js", ".csv"]
6363

6464
_MANIFEST_NAMES = ["__openerp__.py", "__manifest__.py"]

odoo_module_migrate/migration_scripts/migrate_150_160.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
from odoo_module_migrate.base_migration_script import BaseMigrationScript
44

5-
_TEXT_REPLACES = {
6-
".py": {
7-
r"\.get_xml_id\(": ".get_external_id(",
8-
r"\.fields_get_keys\(\)": "._fields",
9-
},
10-
}
11-
125

136
class MigrationScript(BaseMigrationScript):
14-
_TEXT_REPLACES = _TEXT_REPLACES
7+
pass
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- ["account.account.type", "Commit https://github.com/odoo/odoo/commit/26b2472f4977ccedbb0b5ed5f"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- ["stock.production.lot", "stock.lot", None]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.py:
2+
\.get_xml_id\(: ".get_external_id("
3+
\.fields_get_keys\(\): "._fields"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from odoo import fields, models
2+
3+
4+
class AccountAccountType(models.Model):
5+
_inherit = "account.account.type"
6+
7+
analytic_account_required = fields.Boolean(
8+
string='Analytic Account Required?',
9+
help="If True, then an analytic account will be required when posting "
10+
"journal entries with this type of account.",
11+
)
12+
analytic_tag_required = fields.Boolean(
13+
string='Analytic Tag Required?',
14+
help="If True, then analytic tags will be required when posting "
15+
"journal entries with this type of account.",
16+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from odoo import models, _
2+
from odoo.exceptions import UserError
3+
4+
5+
class StockProductionLot(models.Model):
6+
_inherit = 'stock.lot'
7+
_barcode_field = 'name'
8+
9+
def _get_stock_barcode_specific_data(self):
10+
products = self.product_id
11+
return {
12+
'product.product': products.read(self.env['product.product']._get_fields_stock_barcode(), load=False),
13+
'uom.uom': products.uom_id.read(self.env['uom.uom']._get_fields_stock_barcode(), load=False)
14+
}
15+
16+
def _check_create(self):
17+
active_mo_id = self.env.context.get('active_mo_id')
18+
if active_mo_id:
19+
active_mo = self.env['mrp.production'].browse(active_mo_id)
20+
if not active_mo.picking_type_id.use_create_components_lots:
21+
raise UserError(_('You are not allowed to create or edit a lot or serial number for the components with the operation type "Manufacturing". To change this, go on the operation type and tick the box "Create New Lots/Serial Numbers for Components".'))
22+
return super()._check_create()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_stock_production_user,stock.production.lot,stock.model_stock_lot,quality.group_quality_user,1,0,0,0

0 commit comments

Comments
 (0)