-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by legalsylvain
- Loading branch information
Showing
11 changed files
with
234 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
fiscal_company_account/migrations/16.0.3.0.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
import logging | ||
|
||
from openupgradelib import openupgrade | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
IrProperty = env["ir.property"] | ||
mother_companies = env["res.company"].search( | ||
[("fiscal_type", "=", "fiscal_mother")] | ||
) | ||
|
||
todo_list = [ | ||
("property_account_receivable_id", "res.partner"), | ||
("property_account_payable_id", "res.partner"), | ||
] | ||
|
||
for field, model in todo_list: | ||
for mother_company in mother_companies: | ||
value = IrProperty.with_company(mother_company)._get(field, model) | ||
if value: | ||
for company in mother_company.child_ids: | ||
_logger.info( | ||
f"Company {company.code}-{company.name}. Model {model}." | ||
" Field: {field}. New default value: {value}" | ||
) | ||
IrProperty._set_default(field, model, value, company=company) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
fiscal_company_base/models/fiscal_company_propagate_child_company_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (C) 2025 - 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 import api, models | ||
|
||
|
||
class FiscalCompanyPropagateChildCompanyMixin(models.AbstractModel): | ||
"""This abstract allow to propagate properties of mother companies | ||
in child companies context. | ||
- When creating a new child company, all the properties defined | ||
at mother company will be set in the new child company. | ||
""" | ||
|
||
_name = "fiscal.company.propagate.child.company.mixin" | ||
_description = "Fiscal Company : Propagate in Child Company Mixin" | ||
|
||
@api.model | ||
def _fiscal_property_creation_list(self): | ||
"""Overload me to define property fields to create to a new | ||
fiscal company | ||
""" | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright (C) 2018 - 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 import models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_name = "res.partner" | ||
_inherit = ["res.partner", "fiscal.company.propagate.child.company.mixin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
fiscal_company_base/tests/test_fiscal_company_propagate_child_company_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 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_test_helper import FakeModelLoader | ||
|
||
from .test_abstract import TestAbstract | ||
|
||
|
||
class TestFiscalCompanyPropagateChildCompanyMixin(TestAbstract): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
# Load a test model using odoo_test_helper | ||
cls.loader = FakeModelLoader(cls.env, cls.__module__) | ||
cls.loader.backup_registry() | ||
from .models import ( | ||
ModelFiscalCompanyPropagateChildCompanyMixin, | ||
ModelFiscalCompanyPropagateChildCompanyMixinResCompany, | ||
) | ||
|
||
cls.loader.update_registry( | ||
( | ||
ModelFiscalCompanyPropagateChildCompanyMixin, | ||
ModelFiscalCompanyPropagateChildCompanyMixinResCompany, | ||
) | ||
) | ||
|
||
cls.model_propagate_child_company = cls.env[ | ||
"model.fiscal.company.propagate.child.company.mixin" | ||
] | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.loader.restore_registry() | ||
return super().tearDownClass() | ||
|
||
def test_check_propagation_ok(self): | ||
item = self.model_propagate_child_company.with_company( | ||
self.mother_company | ||
).create({"company_dependent_field": "BOB"}) | ||
new_child_company = self.env["res.company"].create( | ||
{ | ||
"name": "NEW FISCAL CHILD", | ||
"parent_id": self.mother_company.id, | ||
"fiscal_type": "fiscal_child", | ||
} | ||
) | ||
self.assertEqual( | ||
item.with_company(new_child_company).company_dependent_field, "BOB" | ||
) | ||
self.assertEqual( | ||
item.with_company(self.normal_company).company_dependent_field, False | ||
) |