← Back to Pull requests

[19.0] account_cutoff_start_end_dates: Move the constraint on uniqueness for cutoff date at line level #384

Open
petrus-v opened this pull request with 5533 lines diff across 50 files
View on GitHub
petrus-v petrus-v commented on Jul 16, 2026 12:17 UTC
Author

port #343 account_cutoff_start_end_dates part.

based on #382 depends on #382

Diff: 5533 lines (+5533 / -0) across 50 files Reviewer: AnizR Review duration: 202720m
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.79) × (1 − Review Confidence (0.70)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.79 · 5533 lines diff across 50 files
0.79
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.45 · 3 substantive comment(s)
0.45
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
70%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
7 items
AnizR AnizR commented on code on Jul 17, 2026 13:50 UTC
Code Review
account_cutoff_start_end_dates/models/account_cutoff.py:1
@@ -0,0 +1,254 @@
+# Copyright 2016-2022 Akretion France
+# @author: Alexis de Lattre <alexis.delattre@akretion.com>
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import api, fields, models
+from odoo.exceptions import UserError, ValidationError
+from odoo.fields import Domain
+from odoo.tools import str2bool
+
+
+class AccountCutoff(models.Model):
+    _inherit = "account.cutoff"
+
+    source_journal_ids = fields.Many2many(
+        "account.journal",
+        column1="cutoff_id",
+        column2="journal_id",
+        string="Source Journals",
+        compute="_compute_source_journal_ids",
+        store=True,
+        readonly=False,
+        precompute=True,
+        check_company=True,
+        domain="[('company_id', '=', company_id)]",
+    )
+    state = fields.Selection(selection_add=[("forecast", "Forecast")])
+    start_date = fields.Date(help="This field is only for the forecast mode")
+    end_date = fields.Date(help="This field is only for the forecast mode")
+
+    @api.depends("company_id", "cutoff_type")
+    def _compute_source_journal_ids(self):
+        mapping = {
+            "accrued_revenue": "sale",
+            "accrued_expense": "purchase",
+            "prepaid_revenue": "sale",
+            "prepaid_expense": "purchase",
+        }
+        for rec in self:
+            source_journal_ids = self.env["account.journal"]
+            if rec.cutoff_type in mapping:
+                source_journal_ids = self.env["account.journal"].search(
+                    [
+                        ("type", "=", mapping[rec.cutoff_type]),
+                        ("company_id", "=", rec.company_id.id),
+                    ]
+                )

I think that we could improve this from a performance point of view.
What about doing 1 search (or maybe a readgroup if we have multiple company) before the loop then assigning your source journals?

(code should be modified and not taken as it is)

self.env["account.journal"].search(
                    [
                        ("type", "in", ["sale","purchase"]),
                        ("company_id", "in", self.company_id.ids),
                    ]
                )

petrus-v petrus-v commented on code on Jul 17, 2026 16:19 UTC
Code Review
account_cutoff_start_end_dates/models/account_cutoff.py:1
@@ -0,0 +1,254 @@
+# Copyright 2016-2022 Akretion France
+# @author: Alexis de Lattre <alexis.delattre@akretion.com>
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+from odoo import api, fields, models
+from odoo.exceptions import UserError, ValidationError
+from odoo.fields import Domain
+from odoo.tools import str2bool
+
+
+class AccountCutoff(models.Model):
+    _inherit = "account.cutoff"
+
+    source_journal_ids = fields.Many2many(
+        "account.journal",
+        column1="cutoff_id",
+        column2="journal_id",
+        string="Source Journals",
+        compute="_compute_source_journal_ids",
+        store=True,
+        readonly=False,
+        precompute=True,
+        check_company=True,
+        domain="[('company_id', '=', company_id)]",
+    )
+    state = fields.Selection(selection_add=[("forecast", "Forecast")])
+    start_date = fields.Date(help="This field is only for the forecast mode")
+    end_date = fields.Date(help="This field is only for the forecast mode")
+
+    @api.depends("company_id", "cutoff_type")
+    def _compute_source_journal_ids(self):
+        mapping = {
+            "accrued_revenue": "sale",
+            "accrued_expense": "purchase",
+            "prepaid_revenue": "sale",
+            "prepaid_expense": "purchase",
+        }
+        for rec in self:
+            source_journal_ids = self.env["account.journal"]
+            if rec.cutoff_type in mapping:
+                source_journal_ids = self.env["account.journal"].search(
+                    [
+                        ("type", "=", mapping[rec.cutoff_type]),
+                        ("company_id", "=", rec.company_id.id),
+                    ]
+                )

Thanks for suggestion :)

done using read group !

AnizR AnizR approved these changes on Jul 20, 2026 05:59 UTC
Approved Reviewer

Code LGTM 👍

santostelmo santostelmo approved these changes on Oct 23, 2026 05:44 UTC
Approved Reviewer

LG

jbaudoux jbaudoux requested changes on Oct 23, 2026 11:34 UTC
Changes Requested Reviewer

Please drop the port of https://github.com/OCA/account-closing/pull/343 from the migration PR. I don't approve that commit.

Edit: This is not the module migration PR. This one is based on:

  • https://github.com/OCA/account-closing/pull/384
  • There is a typo in this PR description

    santostelmo santostelmo commented on Nov 20, 2026 08:26 UTC
    Contributor

    @petrus-v do you have a moment to address the review of @jbaudoux ?

    Reviewers
    Assignees
    petrus-v petrus-v
    Labels
    risk: low confidence: 70% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 78.5% (HIGH) · Higher = larger blast radius
    78.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 70% · Lower = rushed or shallow review
    70%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.5% · Safe to merge
    23.5%