Skip to content
Draft
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
33 changes: 6 additions & 27 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
repos:
- repo: local
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
name: Check for added large files
entry: check-added-large-files
language: system
- id: check-toml
name: Check Toml
entry: check-toml
language: system
types: [toml]
- id: check-yaml
name: Check Yaml
entry: check-yaml
language: system
types: [yaml]
- id: end-of-file-fixer
name: Fix End of Files
entry: end-of-file-fixer
language: system
types: [text]
stages: [pre-commit, pre-push, manual]
- id: trailing-whitespace
name: Trim Trailing Whitespace
entry: trailing-whitespace-fixer
language: system
types: [text]
stages: [pre-commit, pre-push, manual]
- repo: local
hooks:
- id: pydoclint
name: pydoclint
entry: pydoclint
language: system
language: python
types: [python]
args: ["--generate-baseline=True"]
additional_dependencies: ["pydoclint"]
- id: ruff
name: ruff
entry: ruff check
Expand All @@ -44,7 +27,3 @@ repos:
entry: ruff format
language: python
types_or: [python, pyi]
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v4.0.0-alpha.8
# hooks:
# - id: prettier
5 changes: 5 additions & 0 deletions modules/odf_data_quality_dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Odoo module for the Data Quality Dashboard."""

from . import models

__all__ = ["models"]
20 changes: 20 additions & 0 deletions modules/odf_data_quality_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Odoo module manifest for the Data Quality Dashboard."""

{
"name": "ODF Data Quality Dashboard",
"summary": """
Provides a dashboard to identify and manage data quality issues
after data import.""",
"author": "OdooDataFlow",
"website": "https://github.com/OdooDataFlow/odoo-data-flow",
"category": "Tools",
"version": "18.0.1.0.0",
"depends": ["base"],
"data": [
"security/ir.model.access.csv",
"views/odf_data_quality_issue_views.xml",
"data/ir_cron_data.xml",
],
"installable": True,
"application": True,
}
17 changes: 17 additions & 0 deletions modules/odf_data_quality_dashboard/data/ir_cron_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- Scheduled action for nightly data quality checks -->
<record id="ir_cron_nightly_data_validation" model="ir.cron">
<field name="name">Data Quality: Nightly Validation</field>
<field name="model_id" ref="model_odf_data_quality_issue"/>
<field name="state">code</field>
<field name="code">model._run_nightly_validation()</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
</record>
</data>
</odoo>
5 changes: 5 additions & 0 deletions modules/odf_data_quality_dashboard/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Models for the Data Quality Dashboard module."""

from . import odf_data_quality_issue

__all__ = ["odf_data_quality_issue"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""Module to manage data quality issues."""

from datetime import datetime, timedelta

from odoo import api, fields, models


class OdfDataQualityIssue(models.Model):
"""Represents a data quality issue found in the system.

This model stores records of data inconsistencies or errors,
allowing users to track and resolve them in a structured manner.
"""

_name = "odf.data.quality.issue"
_description = "Data Quality Issue"
_order = "create_date desc"

name = fields.Char(
string="Title",
required=True,
help="A concise summary of the data quality issue.",
)
issue_type = fields.Char(
string="Issue Type",
required=True,
help="The category of the issue, e.g., 'Invalid VAT'.",
)
related_record = fields.Reference(
string="Related Record",
selection=[("res.partner", "Partner"), ("product.product", "Product")],
help="A reference to the record that has the data quality issue.",
)
status = fields.Selection(
[
("todo", "To Do"),
("in_progress", "In Progress"),
("done", "Done"),
],
string="Status",
default="todo",
required=True,
help="The current stage of the issue resolution process.",
)
notes = fields.Text(
string="Notes",
help="Detailed comments or notes about the issue.",
)

# -------------------------------------------------------------------------
# Business Methods
# -------------------------------------------------------------------------
@api.model
def _run_nightly_validation(self):
"""Run all nightly data validation checks."""
self._check_partners_with_missing_vat()

@api.model
def _check_partners_with_missing_vat(self):
Comment thread
bosd marked this conversation as resolved.
"""Check for partners created in the last 24h with missing VAT."""
yesterday = datetime.now() - timedelta(days=1)
# Search for companies created in the last 24 hours without a VAT
partners = self.env["res.partner"].search(
[
("is_company", "=", True),
("create_date", ">=", yesterday),
("vat", "=", False),
]
)
vals_list = []
for partner in partners:
vals_list.append(
{
"name": f"Missing VAT for Partner: {partner.name}",
"issue_type": "Missing VAT",
"related_record": f"res.partner,{partner.id}",
"status": "todo",
"notes": (
f"The partner '{partner.name}' is a company but does "
"not have a VAT number."
),
}
)
if vals_list:
self.create(vals_list)
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_odf_data_quality_issue_user,odf.data.quality.issue.user,model_odf_data_quality_issue,base.group_user,1,1,1,1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Action -->
<record id="action_odf_data_quality_issue" model="ir.actions.act_window">
<field name="name">Data Quality Issues</field>
<field name="res_model">odf.data.quality.issue</field>
<field name="view_mode">tree,kanban,form</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
No data quality issues found. Everything looks good!
</p>
</field>
</record>

<!-- Kanban View -->
<record id="view_odf_data_quality_issue_kanban" model="ir.ui.view">
<field name="name">odf.data.quality.issue.kanban</field>
<field name="model">odf.data.quality.issue</field>
<field name="arch" type="xml">
<kanban default_group_by="status" class="o_kanban_small_column">
<field name="status"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_global_click">
<div class="oe_kanban_details">
<strong><field name="name"/></strong>
<div>
<span class="text-muted">Type: </span>
<field name="issue_type"/>
</div>
<div>
<span class="text-muted">Record: </span>
<field name="related_record"/>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
</record>

<!-- Form View -->
<record id="view_odf_data_quality_issue_form" model="ir.ui.view">
<field name="name">odf.data.quality.issue.form</field>
<field name="model">odf.data.quality.issue</field>
<field name="arch" type="xml">
<form string="Data Quality Issue">
<sheet>
<group>
<field name="name"/>
<field name="issue_type"/>
<field name="related_record"/>
<field name="status"/>
</group>
<notebook>
<page string="Notes">
<field name="notes"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<!-- Menu -->
<menuitem
id="menu_data_quality_root"
name="Data Quality"
sequence="99"/>

<menuitem
id="menu_data_quality_dashboard"
name="Dashboard"
parent="menu_data_quality_root"
action="action_odf_data_quality_issue"
sequence="10"/>
</odoo>
3 changes: 2 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def precommit(session: nox.Session) -> None:
"lint",
external=True,
)
session.run("pre-commit", *args, external=True)
session.install("pre-commit")
session.run("pre-commit", *args)
if args and args[0] == "install":
activate_virtualenv_in_precommit_hooks(session)

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ exclude = [


[tool.ruff.lint.per-file-ignores]
"**/__manifest__.py" = ["B018"]
"*/test_*.py" = ["S101"]
"noxfile.py" = ["S101"]
"**/conftest.py" = ["S101"]
Expand Down