Files
odoo_source/addons/project/tests/test_project_profitability.py
T
williamandh4818 dc696c8ed4 [IMP] analytic: allow cross analytics
Purpose
=======

Make it possible to compare analytic values between plans by inputting
up to one account per plan on each line.
For instance, if we have 2 plans: "Country" and "Product Type", with the
following accounts

| Country | Product Type |
| ------- | ------------ |
| BE      | Drinks       |
| LU      | Food         |

And the following invoices:
* 1000€ of drinks in Belgium
* 2000€ of food in Belgium
* 3000€ of food in Luxemburg

We want to be able to display the following pivot tables:

|     | Drinks | Food | Total |
| --- | ------ | ---- | ----- |
| BE  |   1000 | 2000 |  3000 |
| LU  |      0 | 3000 |  3000 |
| Tot |   1000 | 5000 |  6000 |

|        | Total |
| ------ | ----- |
| Food   |  5000 |
| * BE   |  2000 |
| * LU   |  3000 |
| Drinks |  1000 |
| * BE   |  1000 |
| Total  |  6000 |

Implementation
==============

* `ir.fields` are added/removed dynamically on `account.analytic.line`
* Each analytic plan corresponds to one field on `account.analytic.line`
* The fields are added dynamically in the views.
* `account.analytic.plan` doesn't have a `company_id` field anymore,
  meaning that all the companies have access to all the plans. This
  means that the applicability fields and lines are now company
  dependent, and those can be used to know which fields/plans to display
  for which company.
* There can no longer be one "Project" plan per company, even if the
  accounts of that project can still be owned by only one company.
* There is now only one method to get the default (or "Project" plan),
  which is `_get_plan_columns`

task-3497653

closes odoo/odoo#139225

Related: odoo/upgrade#5306
Related: odoo/enterprise#49226
Signed-off-by: William André (wan) <wan@odoo.com>
Co-authored-by: william <wan@odoo.com>
Co-authored-by: h4818 <ayh@odoo.com>
2023-10-25 18:10:57 +00:00

64 lines
2.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests.common import TransactionCase
class TestProjectProfitabilityCommon(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner = cls.env['res.partner'].create({
'name': 'Georges',
'email': 'georges@project-profitability.com'})
cls.analytic_plan = cls.env['account.analytic.plan'].create({
'name': 'Plan A',
})
cls.analytic_account = cls.env['account.analytic.account'].create({
'name': 'Project - AA',
'code': 'AA-1234',
'plan_id': cls.analytic_plan.id,
})
cls.project = cls.env['project.project'].with_context({'mail_create_nolog': True}).create({
'name': 'Project',
'partner_id': cls.partner.id,
'analytic_account_id': cls.analytic_account.id,
})
cls.task = cls.env['project.task'].with_context({'mail_create_nolog': True}).create({
'name': 'Task',
'project_id': cls.project.id,
})
cls.project_profitability_items_empty = {
'revenues': {'data': [], 'total': {'invoiced': 0.0, 'to_invoice': 0.0}},
'costs': {'data': [], 'total': {'billed': 0.0, 'to_bill': 0.0}},
}
cls.foreign_currency = cls.env['res.currency'].create({
'name': 'Chaos orb',
'symbol': '☺',
'rounding': 0.001,
'position': 'after',
'currency_unit_label': 'Chaos',
'currency_subunit_label': 'orb',
})
cls.env['res.currency.rate'].create({
'name': '2016-01-01',
'rate': '5.0',
'currency_id': cls.foreign_currency.id,
})
class TestProfitability(TestProjectProfitabilityCommon):
def test_project_profitability(self):
""" Test the project profitability has no data found
In this module, the project profitability should have no data.
So the no revenue and cost should be found.
"""
self.assertDictEqual(
self.project._get_profitability_items(False),
self.project_profitability_items_empty,
'The profitability data of the project should be return no data and so 0 for each total amount.'
)