Skip to content

[16.0][MIG] account_analytic_distribution_model_recalculate#837

Open
andrel-exo wants to merge 1 commit intoOCA:16.0from
andrel-exo:16.0_account_analytic_distribution_model_recalculate
Open

[16.0][MIG] account_analytic_distribution_model_recalculate#837
andrel-exo wants to merge 1 commit intoOCA:16.0from
andrel-exo:16.0_account_analytic_distribution_model_recalculate

Conversation

@andrel-exo
Copy link
Copy Markdown
Contributor

account_analytic_distribution_model_recalculate: Migration to 16.0

  • Adapted manifest to 16.0
  • Updated views to replace direct attributes with attrs
  • No functional changes, only compatibility adjustments

@andrel-exo andrel-exo force-pushed the 16.0_account_analytic_distribution_model_recalculate branch 5 times, most recently from 9c2b430 to 721079e Compare September 30, 2025 12:21
@andrel-exo andrel-exo force-pushed the 16.0_account_analytic_distribution_model_recalculate branch from 721079e to f9a2773 Compare October 27, 2025 18:26
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 1, 2026

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Mar 1, 2026
Copy link
Copy Markdown

@marcos-mendez marcos-mendez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Review -- Tests Failed

1. Root Cause

The test failure occurs because the method _check_duplicate_dates() is called on an account.analytic.distribution.model object, but this method does not exist in the current implementation. It seems like the test expects a constraint to be enforced for overlapping date ranges, but the corresponding validation logic was not implemented or is missing.


2. Suggested Fix

Add the _check_duplicate_dates() method to the AccountAnalyticDistributionModel class in account_analytic_distribution_model.py. This method should validate that no two models exist with overlapping date ranges for the same partner and account prefix.

# In account_analytic_distribution_model.py

    @api.constrains("start_date", "end_date", "partner_id", "account_prefix")
    def _check_duplicate_dates(self):
        for record in self:
            if not record.start_date or not record.end_date:
                continue

            # Find other records with overlapping dates and same partner/account
            domain = [
                ("id", "!=", record.id),
                ("start_date", "!=", False),
                ("end_date", "!=", False),
                ("start_date", "<=", record.end_date),
                ("end_date", ">=", record.start_date),
                ("partner_id", "=", record.partner_id.id),
                ("account_prefix", "=", record.account_prefix),
            ]
            overlapping = self.search(domain)
            if overlapping:
                raise ValidationError(
                    _("Cannot have overlapping dates for the same partner and account prefix.")
                )

This method should be added after the _check_start_date_before_end_date constraint and before the _get_distribution method.


3. Additional Code Issues

  • Missing @api.constrains decorator: The _check_duplicate_dates method is not decorated with @api.constrains, which means it will not be automatically triggered during record creation or update.
  • Incomplete _get_distribution method: The _get_distribution method is defined but only includes a docstring and no actual logic. It should be implemented to support date filtering logic when retrieving distribution models.

4. Test Improvements

Add the following test cases to improve coverage:

a. Test overlapping date constraints

Use TransactionCase or SavepointCase to test that creating two models with overlapping dates raises a ValidationError.

def test_overlapping_dates_constraint(self):
    model1 = self.env['account.analytic.distribution.model'].create({
        'partner_id': self.partner.id,
        'account_prefix': '400',
        'start_date': '2024-01-01',
        'end_date': '2024-12-31',
    })
    with self.assertRaises(ValidationError):
        self.env['account.analytic.distribution.model'].create({
            'partner_id': self.partner.id,
            'account_prefix': '400',
            'start_date': '2024-06-01',
            'end_date': '2025-06-01',
        })

b. Test date filtering in _get_distribution

Ensure that _get_distribution respects start_date and end_date filters by creating journal items with different dates and asserting correct model selection.

def test_distribution_model_date_filtering(self):
    model = self.env['account.analytic.distribution.model'].create({
        'partner_id': self.partner.id,
        'account_prefix': '400',
        'start_date': '2024-01-01',
        'end_date': '2024-12-31',
    })
    # Create move line with date within range
    move_line = self.env['account.move.line'].create({
        'move_id': self.invoice.id,
        'account_id': self.account.id,
        'partner_id': self.partner.id,
        'date': '2024-06-01',
    })
    # Check if model is correctly applied
    distribution = model._get_distribution({'account_id': self.account.id})
    self.assertTrue(distribution)

c. Use @tagged for better test organization

Tag tests with @tagged('post_install', 'manual') or similar to ensure they run in appropriate environments.

from odoo.tests import tagged

@tagged('post_install', 'manual')
def test_constraints(self):
    ...

These improvements will ensure robustness and better test coverage for the new date-based filtering logic.

Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b

@github-actions github-actions bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants