OCA/server-tools

View on GitHub
base_import_odoo/models/import_odoo_database.py

Summary

Maintainability
F
4 days
Test Coverage

File import_odoo_database.py has 602 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
# © 2017 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
try:
Severity: Major
Found in base_import_odoo/models/import_odoo_database.py - About 1 day to fix

    Function _run_import_map_values has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

        def _run_import_map_values(self, context, data):
            model = self.env[context.model_line.model_id.model]
            for field_name in data.keys():
                if not isinstance(
                        model._fields[field_name], fields._Relational
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _run_import_get_record_mapping has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

        def _run_import_get_record_mapping(
            self, context, model, record, create_dummy=True,
        ):
            current_field = self.env['ir.model.fields'].search([
                ('name', '=', context.field_context.field_name),
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _run_import has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def _run_import(self, commit=True, commit_threshold=100):
            """Run the import as cronjob, commit often"""
            self.ensure_one()
            if not self.password:
                return
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _run_import_create_dummy has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def _run_import_create_dummy(
            self, context, model, record, forcecreate=False,
        ):
            """Either misuse some existing record or create an empty one to satisfy
            required links"""
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _run_import_get_record has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def _run_import_get_record(
            self, context, model, record, create_dummy=True,
        ):
            """Find the local id of some remote record. Create a dummy if not
            available"""
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _run_import_model_cleanup_dummies has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def _run_import_model_cleanup_dummies(
                self, context, model, remote_id, local_id
        ):
            if not (model._name, remote_id) in context.dummies:
                return
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _constrain_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def _constrain_url(self):
            for this in self:
                if this == self.env.ref('base_import_odoo.demodb', False):
                    continue
                if tools.config['test_enable']:
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _create_record has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _create_record(self, context, model, record):
            """Create a record, add an xmlid"""
            _id = record.pop('id')
            xmlid = '%d-%s-%d' % (
                self.id, model._name.replace('.', '_'), _id or 0,
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _run_import_model has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def _run_import_model(self, context):
            """Import records of a configured model"""
            model = self.env[context.model_line.model_id.model]
            fields = self._run_import_model_get_fields(context)
            for data in context.remote.execute(
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            if not _id:
                xmlid = self.env['ir.model.data'].search([
                    ('import_database_id', '=', self.id),
                    ('import_database_record_id', '=', record['id']),
                    ('model', '=', model._name),
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py and 1 other location - About 35 mins to fix
    base_import_odoo/models/import_odoo_database.py on lines 287..294

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 33.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

            if not _id:
                _id = self._run_import_get_record_mapping(
                    context, model, record, create_dummy=create_dummy,
                )
            elif not logged:
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py and 1 other location - About 35 mins to fix
    base_import_odoo/models/import_odoo_database.py on lines 296..309

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 33.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

            if commit and not tools.config['test_enable']:
                # pylint: disable=invalid-commit
                self.env.cr.commit()
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py and 2 other locations - About 30 mins to fix
    base_import_odoo/models/import_odoo_database.py on lines 133..135
    base_import_odoo/models/import_odoo_database.py on lines 167..169

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 32.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

                    if commit and not tools.config['test_enable']:
                        # pylint: disable=invalid-commit
                        self.env.cr.commit()
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py and 2 other locations - About 30 mins to fix
    base_import_odoo/models/import_odoo_database.py on lines 114..116
    base_import_odoo/models/import_odoo_database.py on lines 133..135

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 32.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 3 locations. Consider refactoring.
    Open

            if commit and not tools.config['test_enable']:
                # pylint: disable=invalid-commit
                self.env.cr.commit()
    Severity: Minor
    Found in base_import_odoo/models/import_odoo_database.py and 2 other locations - About 30 mins to fix
    base_import_odoo/models/import_odoo_database.py on lines 114..116
    base_import_odoo/models/import_odoo_database.py on lines 167..169

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 32.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status