Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] : code_tracker #274

Open
wants to merge 8 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .copier-answers.yml

This file was deleted.

1 change: 1 addition & 0 deletions code_tracker/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
21 changes: 21 additions & 0 deletions code_tracker/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# @author Syera BONNEAUX <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "code tracker information",
"summary": "code tracker",
"version": "14.0.1.0.0",
"website": "https://github.com/akretion/ak-odoo-incubator",
"author": " Akretion",
"license": "AGPL-3",
"depends": [
"base",
],
"data": [
"security/ir.model.access.csv",
"views/tracker_code_info.xml",
],
"application": False,
"installable": True,
}
39 changes: 39 additions & 0 deletions code_tracker/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging
import traceback
from functools import wraps

from odoo import fields

_logger = logging.getLogger(__name__)

# the decorator to know which function is called or not


def tracker_code(func):
@wraps(func)
def tracker_code_information(cls, *args, **kwargs):
result = func(cls, *args, **kwargs)
running_time = fields.Datetime.now()
model_name = cls._name
user = cls.env.user.name
trace = ""
trace_back = traceback.format_stack()
for line in trace_back:
trace += line
trace_back_info = {}

function_name = func.__name__
trace_back_info = {
"function_name": function_name,
"model_name": model_name,
"running_time": running_time,
"user": user,
"trace": trace,
}
cls.env["tracker.code.info"].create(trace_back_info)
return result

return tracker_code_information
99 changes: 99 additions & 0 deletions code_tracker/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * code_tracker
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-06-02 20:26+0000\n"
"PO-Revision-Date: 2023-06-02 22:28+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 3.0.1\n"

#. module: code_tracker
#: model_terms:ir.ui.view,arch_db:code_tracker.tracker_code_info_tree
msgid "Code tracker info"
msgstr "Information code tracker"

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__create_uid
msgid "Created by"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__create_date
msgid "Created on"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__display_name
msgid "Display Name"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__function_name
msgid "Function name"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__id
msgid "ID"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info____last_update
msgid "Last Modified on"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__write_uid
msgid "Last Updated by"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__write_date
msgid "Last Updated on"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__trace
msgid "Logger"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__model_name
msgid "Model name"
msgstr ""

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__running_time
msgid "Running time"
msgstr "Date et heure"

#. module: code_tracker
#: model:ir.actions.act_window,name:code_tracker.tracker_code_info_action
#: model:ir.ui.menu,name:code_tracker.menu_tracker_code
msgid "Tracker code information"
msgstr "Information code tracker"

#. module: code_tracker
#: model:ir.ui.menu,name:code_tracker.menu_tracker_code_info
msgid "Tracker trace"
msgstr "Trace tracker"

#. module: code_tracker
#: model:ir.model.fields,field_description:code_tracker.field_tracker_code_info__user
msgid "User"
msgstr "Utilisateur"

#. module: code_tracker
#: model:ir.model,name:code_tracker.model_tracker_code_info
msgid "see if a function is used"
msgstr "voir si une fonction est utilisée"
1 change: 1 addition & 0 deletions code_tracker/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import tracker_code_info
15 changes: 15 additions & 0 deletions code_tracker/models/tracker_code_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class TrackerCodeInfo(models.Model):
_name = "tracker.code.info"
_description = "see if a function is used"

function_name = fields.Char(string="Function name")
model_name = fields.Char(string="Model name")
running_time = fields.Datetime(string="Running time")
user = fields.Char(string="User")
trace = fields.Text(string="Logger")
7 changes: 7 additions & 0 deletions code_tracker/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
To be able to see what functions is called or not you should when you install this module :
- Install this module in the manifest
- Add at the beginning of the model from odoo.addons.code_tracker.decorators import tracker_code
- Add the decorator above the called function

To see the list of the called functions :
- Go to settings --> technical --> tracker trace
2 changes: 2 additions & 0 deletions code_tracker/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
"access_tracker_code_info_group_system","tracker code info groupe systeme","model_tracker_code_info","base.group_user",1,1,1,1
2 changes: 2 additions & 0 deletions code_tracker/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_tracker_trace
19 changes: 19 additions & 0 deletions code_tracker/tests/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models

from odoo.addons.code_tracker.decorators import tracker_code


class ResPartner(models.Model):
_inherit = "res.partner"

@api.onchange("state_id")
def _onchange_state(self):
super()._onchange_state()
self.fonction_tracker_test()

@tracker_code
def fonction_tracker_test(self):
return
39 changes: 39 additions & 0 deletions code_tracker/tests/test_tracker_trace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2023 Akretion (https://www.akretion.com).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo_test_helper import FakeModelLoader

from odoo.tests import SavepointCase


class TestTrackerTrace(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()

from .models import ResPartner

cls.loader.update_registry((ResPartner,))

cls.env.ref("base.res_partner_12")._onchange_state()

@classmethod
def tearDownClass(cls):
cls.loader.restore_registry()
super(TestTrackerTrace, cls).tearDownClass()

def test_tracker_trace(self):

# Name of the _onchange_method and on the method called by the _onchange_method
method_tracker = "fonction_tracker_test"
method_onchange = "_onchange_state"

function = self.env["tracker.code.info"].search(
[("function_name", "=", method_tracker)], order="id desc", limit=1
)

self.assertTrue(function)
self.assertTrue(function.user)
self.assertIn(method_onchange, function.trace)
60 changes: 60 additions & 0 deletions code_tracker/views/tracker_code_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" ?>
<!--
Copyright 2023 Akretion
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="tracker_code_info_tree" model="ir.ui.view">
<field name="name">tracker.code.info.tree</field>
<field name="model">tracker.code.info</field>
<field name="arch" type="xml">
<tree string="Code tracker info">
<field name="function_name" />
<field name="model_name" />
<field name="running_time" />
<field name="user" />
</tree>
</field>
</record>

<record id="tracker_code_info_form" model="ir.ui.view">
<field name="name">tracker.code.info.form</field>
<field name="model">tracker.code.info</field>
<field name="arch" type="xml">
<form>
<group>
<field name="function_name" />
<field name="model_name" />
<field name="running_time" />
<field name="user" />
</group>
<group>
<field name="trace" />
</group>
</form>
</field>
</record>

<record id="tracker_code_info_action" model="ir.actions.act_window">
<field name="name">Tracker code information</field>
<field name="res_model">tracker.code.info</field>
<field name="view_id" ref="tracker_code_info_tree" />
<field name="view_mode">tree,form</field>
</record>

<menuitem
id="menu_tracker_code"
name="Tracker code information"
parent="base.menu_custom"
sequence="31"
/>

<menuitem
id="menu_tracker_code_info"
action="tracker_code_info_action"
name="Tracker trace"
parent="code_tracker.menu_tracker_code"
sequence="1"
/>

</odoo>
1 change: 1 addition & 0 deletions setup/code_tracker/odoo/addons/code_tracker
6 changes: 6 additions & 0 deletions setup/code_tracker/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)