Trust-Code/odoo-brasil

View on GitHub
br_nfe/models/invoice_eletronic.py

Summary

Maintainability
F
6 days
Test Coverage

File invoice_eletronic.py has 951 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
# © 2016 Danimar Ribeiro <danimaribeiro@gmail.com>, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import re
Severity: Major
Found in br_nfe/models/invoice_eletronic.py - About 2 days to fix

    Function _prepare_eletronic_invoice_values has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
    Open

        def _prepare_eletronic_invoice_values(self):
            res = super(InvoiceEletronic, self)._prepare_eletronic_invoice_values()
            if self.model not in ('55', '65'):
                return res
    
    
    Severity: Minor
    Found in br_nfe/models/invoice_eletronic.py - About 7 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 _hook_validation has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        def _hook_validation(self):
            errors = super(InvoiceEletronic, self)._hook_validation()
            if self.model == '55':
                if not self.company_id.partner_id.inscr_est:
                    errors.append(u'Emitente / Inscrição Estadual')
    Severity: Minor
    Found in br_nfe/models/invoice_eletronic.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 action_send_eletronic_invoice has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def action_send_eletronic_invoice(self):
            super(InvoiceEletronic, self).action_send_eletronic_invoice()
    
            if self.model not in ('55', '65') or self.state in (
               'done', 'denied', 'cancel'):
    Severity: Minor
    Found in br_nfe/models/invoice_eletronic.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 _prepare_eletronic_invoice_item has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def _prepare_eletronic_invoice_item(self, item, invoice):
            res = super(InvoiceEletronic, self)._prepare_eletronic_invoice_item(
                item, invoice)
            if self.model not in ('55', '65'):
                return res
    Severity: Minor
    Found in br_nfe/models/invoice_eletronic.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 action_cancel_document has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def action_cancel_document(self, context=None, justificativa=None):
            if self.model not in ('55', '65'):
                return super(InvoiceEletronic, self).action_cancel_document(
                    justificativa=justificativa)
    
    
    Severity: Minor
    Found in br_nfe/models/invoice_eletronic.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 _prepare_eletronic_invoice_values has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def _prepare_eletronic_invoice_values(self):
            res = super(InvoiceEletronic, self)._prepare_eletronic_invoice_values()
            if self.model not in ('55', '65'):
                return res
    
    
    Severity: Minor
    Found in br_nfe/models/invoice_eletronic.py - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

              if self.commercial_partner_id:
                  partner = self.commercial_partner_id
                  dest = {
                      'tipo': partner.company_type,
                      'cnpj_cpf': re.sub('[^0-9]', '', partner.cnpj_cpf or ''),
      Severity: Major
      Found in br_nfe/models/invoice_eletronic.py - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                if responsavel_tecnico:
                    if len(responsavel_tecnico.child_ids) == 0:
                        raise UserError(
                            "Adicione um contato para o responsável técnico!")
        
        
        Severity: Major
        Found in br_nfe/models/invoice_eletronic.py - About 1 hr to fix

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

              def generate_nfe_proc(self):
                  if self.state in ['cancel', 'done', 'denied']:
                      recibo = self.env['ir.attachment'].search([
                          ('res_model', '=', 'invoice.eletronic'),
                          ('res_id', '=', self.id),
          Severity: Minor
          Found in br_nfe/models/invoice_eletronic.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 _find_attachment_ids_email has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def _find_attachment_ids_email(self):
                  atts = super(InvoiceEletronic, self)._find_attachment_ids_email()
                  if self.model not in ('55'):
                      return atts
          
          
          Severity: Minor
          Found in br_nfe/models/invoice_eletronic.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 action_get_status has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def action_get_status(self):
                  cert = self.company_id.with_context({'bin_size': False}).nfe_a1_file
                  cert_pfx = base64.decodestring(cert)
                  certificado = Certificado(cert_pfx, self.company_id.nfe_a1_password)
                  consulta = {
          Severity: Minor
          Found in br_nfe/models/invoice_eletronic.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 3 locations. Consider refactoring.
          Open

                      if not recibo:
                          recibo = self.env['ir.attachment'].search([
                              ('res_model', '=', 'invoice.eletronic'),
                              ('res_id', '=', self.id),
                              ('datas_fname', 'like', 'nfe-ret')],
          Severity: Major
          Found in br_nfe/models/invoice_eletronic.py and 2 other locations - About 1 hr to fix
          br_nfe/models/invoice_eletronic.py on lines 875..878
          br_nfe/models/invoice_eletronic.py on lines 886..889

          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 44.

          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 3 locations. Consider refactoring.
          Open

                      nfe_envio = self.env['ir.attachment'].search([
                          ('res_model', '=', 'invoice.eletronic'),
                          ('res_id', '=', self.id),
                          ('datas_fname', 'like', 'nfe-envio')],
          Severity: Major
          Found in br_nfe/models/invoice_eletronic.py and 2 other locations - About 1 hr to fix
          br_nfe/models/invoice_eletronic.py on lines 875..878
          br_nfe/models/invoice_eletronic.py on lines 880..884

          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 44.

          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 3 locations. Consider refactoring.
          Open

                      recibo = self.env['ir.attachment'].search([
                          ('res_model', '=', 'invoice.eletronic'),
                          ('res_id', '=', self.id),
                          ('datas_fname', 'like', 'rec-ret')],
          Severity: Major
          Found in br_nfe/models/invoice_eletronic.py and 2 other locations - About 1 hr to fix
          br_nfe/models/invoice_eletronic.py on lines 880..884
          br_nfe/models/invoice_eletronic.py on lines 886..889

          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 44.

          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

                      'COFINS': {
                          'CST': item.cofins_cst,
                          'vBC': "%.02f" % item.cofins_base_calculo,
                          'pCOFINS': "%.02f" % item.cofins_aliquota,
                          'vCOFINS': "%.02f" % item.cofins_valor
          Severity: Minor
          Found in br_nfe/models/invoice_eletronic.py and 1 other location - About 55 mins to fix
          br_nfe/models/invoice_eletronic.py on lines 347..351

          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 37.

          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

                      'PIS': {
                          'CST': item.pis_cst,
                          'vBC': "%.02f" % item.pis_base_calculo,
                          'pPIS': "%.02f" % item.pis_aliquota,
                          'vPIS': "%.02f" % item.pis_valor
          Severity: Minor
          Found in br_nfe/models/invoice_eletronic.py and 1 other location - About 55 mins to fix
          br_nfe/models/invoice_eletronic.py on lines 353..357

          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 37.

          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 2 locations. Consider refactoring.
          Open

                  if logo:
                      tmpLogo = StringIO()
                      tmpLogo.write(logo)
                      tmpLogo.seek(0)
                  else:
          Severity: Minor
          Found in br_nfe/models/invoice_eletronic.py and 1 other location - About 45 mins to fix
          br_nfe/reports/report.py on lines 76..81

          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 35.

          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 justificativa:
                      return {
                          'name': 'Cancelamento NFe',
                          'type': 'ir.actions.act_window',
                          'res_model': 'wizard.cancel.nfe',
          Severity: Minor
          Found in br_nfe/models/invoice_eletronic.py and 1 other location - About 35 mins to fix
          br_nfse/models/nfse_imperial.py on lines 270..279

          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

          There are no issues that match your filters.

          Category
          Status