Skip to content

Commit

Permalink
wippp
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Aug 8, 2024
1 parent 09d0072 commit 06a65da
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 24 deletions.
9 changes: 6 additions & 3 deletions fiscal_company_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def _where_calc(self, domain, active_test=True):
to filter in an integrated company context, data of other integrated
companies of the same CAE."""
if self.env.context.get("add_company_domain", False):
domain += [
("company_id", "in", self.env.context.get("allowed_company_ids"))
]
if self.env.context.get("allowed_company_ids"):
domain += [
("company_id", "in", self.env.context.get("allowed_company_ids"))
]
else:
domain += [("company_id", "=", self.env.company.id)]
return super()._where_calc(domain, active_test=active_test)
6 changes: 0 additions & 6 deletions fiscal_company_account/readme/CREDITS.rst

This file was deleted.

18 changes: 9 additions & 9 deletions fiscal_company_account/readme/DEVELOP.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
* For the migration to V>12, take care of the tax.filtered occurences in
Odoo and OCA modules.
There are a lot of ``filtered(lambda x: x.company_id == current_company)``
in Odoo. The module ``fiscal_company_account`` alter the behaviour of the function
``filtered`` of the ``account.tax`` module, to filter on the mother fiscal company.
However, the changes is imperfect, and multiple filters (company and not company filters)
will fail.
During migration, please run:
``rgrep "tax.*filtered.*company_id"``
For the migration, take care of the tax.filtered occurences in Odoo and OCA modules.
There are a lot of ``filtered(lambda x: x.company_id == current_company)``
in Odoo. The module ``fiscal_company_account`` alter the behaviour of the function
``filtered`` of the ``account.tax`` module, to filter on the mother fiscal company.
However, the changes is imperfect, and multiple filters (company and not company filters)
will fail.

During migration, please run:
``rgrep "tax.*filtered.*company_id"``
1 change: 1 addition & 0 deletions fiscal_company_account/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import test_account_journal_dashboard
from . import test_mixin_change_filtered
from . import test_mixin_change_search_domain
15 changes: 15 additions & 0 deletions fiscal_company_account/tests/test_abstract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.fiscal_company_base.tests import test_abstract


class TestAbstract(test_abstract.TestAbstract):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.AccountAccount = cls.env["account.account"]
cls.ProductProduct = cls.env["product.product"]
cls.AccountMove = cls.env["account.move"]
cls.AccountJournal = cls.env["account.journal"]
62 changes: 62 additions & 0 deletions fiscal_company_account/tests/test_account_journal_dashboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import json

from odoo import Command

from .test_abstract import TestAbstract


class TestAccountJournalDashboard(TestAbstract):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.user_accountant.company_id = cls.child_company

move_vals = {
"partner_id": cls.ResPartner.with_user(cls.user_accountant)
.search([])[0]
.id,
"move_type": "out_invoice",
"line_ids": [
Command.create(
{
"product_id": cls.ProductProduct.with_user(cls.user_accountant)
.search([])[0]
.id
}
)
],
}
cls.move1 = cls.AccountMove.with_user(cls.user_accountant).create(move_vals)
cls.move2 = cls.AccountMove.with_user(cls.user_accountant).create(move_vals)
cls.move3 = cls.AccountMove.with_user(cls.user_accountant).create(move_vals)
(cls.move1 | cls.move2).action_post()

def test_01_dashboard_in_fiscal_child(self):
self.user_accountant.company_id = self.child_company
sale_journal = self.AccountJournal.with_user(self.user_accountant).search(
[("type", "=", "sale")]
)
res = json.loads(sale_journal.kanban_dashboard)
self.assertEqual(res.get("number_draft"), 1)
self.assertEqual(res.get("number_waiting"), 2)
self.assertEqual(res.get("entries_count"), 3)

res = json.loads(sale_journal.kanban_dashboard_graph)
self.assertEqual(len(res[0].get("values")), 0)

def test_02_dashboard_in_fiscal_mother(self):
self.user_accountant.company_id = self.mother_company
sale_journal = self.AccountJournal.with_user(self.user_accountant).search(
[("type", "=", "sale")]
)
res = json.loads(sale_journal.kanban_dashboard)
self.assertEqual(res.get("number_draft"), 0)
self.assertEqual(res.get("number_waiting"), 0)
self.assertEqual(res.get("entries_count"), 0)

res = json.loads(sale_journal.kanban_dashboard_graph)
self.assertEqual(len(res[0].get("values")), 6)
2 changes: 1 addition & 1 deletion fiscal_company_account/tests/test_mixin_change_filtered.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @author Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.addons.fiscal_company_base.tests.test_abstract import TestAbstract
from .test_abstract import TestAbstract


class TestMixinChangeFiltered(TestAbstract):
Expand Down
12 changes: 7 additions & 5 deletions fiscal_company_account/tests/test_mixin_change_search_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo.addons.fiscal_company_base.tests.test_abstract import TestAbstract
from .test_abstract import TestAbstract


class TestMixinChangeSearchDomain(TestAbstract):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.user_accountant.company_id = cls.child_company.id
cls.AccountAccount = cls.env["account.account"].with_user(cls.user_accountant)
cls.AccountJournal = cls.env["account.journal"].with_user(cls.user_accountant)

# Test Section
def test_01_mixin_change_search_domain_account_account(self):
"""Searching an account in a child company should return
accounts of the mother company"""
res = self.AccountAccount.search([("company_id", "=", self.mother_company.id)])
res = self.AccountAccount.with_user(self.user_accountant).search(
[("company_id", "=", self.mother_company.id)]
)
self.assertNotEqual(
len(res),
0,
Expand All @@ -31,7 +31,9 @@ def test_02_mixin_change_search_domain_account_journal(self):
"""Searching a journal in a child company should return
journals of the mother company"""
self.user_accountant.company_id = self.child_company.id
res = self.AccountJournal.search([("company_id", "=", self.mother_company.id)])
res = self.AccountJournal.with_user(self.user_accountant).search(
[("company_id", "=", self.mother_company.id)]
)
self.assertNotEqual(
len(res),
0,
Expand Down
1 change: 1 addition & 0 deletions fiscal_company_base/tests/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TestAbstract(TransactionCase):
def setUpClass(cls):
super().setUpClass()
cls.ResCompany = cls.env["res.company"]
cls.ResPartner = cls.env["res.partner"]
cls.group_company = cls.env.ref("fiscal_company_base.company_group")
cls.mother_company = cls.env.ref("fiscal_company_base.company_fiscal_mother")
cls.child_company = cls.env.ref("fiscal_company_base.company_fiscal_child_1")
Expand Down

0 comments on commit 06a65da

Please sign in to comment.