Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][IMP] mis_builder: add support for branch companies #646

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mis_builder/models/aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from odoo.tools.safe_eval import datetime, dateutil, safe_eval, time

from .accounting_none import AccountingNone
from .simple_array import SimpleArray

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -316,7 +317,7 @@ def do_queries(
aml_model = aml_model.with_context(active_test=False)
company_rates = self._get_company_rates(date_to)
# {(domain, mode): {account_id: (debit, credit)}}
self._data = defaultdict(dict)
self._data = defaultdict(lambda: defaultdict(lambda: SimpleArray((0.0, 0.0))))
domain_by_mode = {}
ends = []
for key in self._map_account_ids:
Expand Down Expand Up @@ -364,7 +365,9 @@ def do_queries(
):
# in initial mode, ignore accounts with 0 balance
continue
self._data[key][acc["account_id"][0]] = (debit * rate, credit * rate)
# due to branches, it's possible to have multiple acc
# with the same account_id
self._data[key][acc["account_id"][0]] += (debit * rate, credit * rate)
# compute ending balances by summing initial and variation
for key in ends:
domain, mode = key
Expand Down
1 change: 1 addition & 0 deletions mis_builder/readme/newsfragments/648.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for branch companies.
25 changes: 25 additions & 0 deletions mis_builder/tests/test_aep.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,28 @@ def test_invalid_field(self):
datetime.date(self.prev_year, 12, 1),
)
assert "Error while querying move line source" in str(cm.exception)

def test_aep_branch(self):
# create branch
self.branch = self.res_company.create(
{
"name": "AEP Branch",
"parent_id": self.company.id,
}
)
# create branch move in March this year
branch_move = self._create_move(
date=datetime.date(self.curr_year, 3, 1),
amount=50,
debit_acc=self.account_ar,
credit_acc=self.account_in,
)
branch_move.company_id = self.branch
self.aep = AEP(self.company | self.branch)
self.aep.parse_expr("balp[]")
self.aep.done_parsing()
self._do_queries(
datetime.date(self.curr_year, 3, 1), datetime.date(self.curr_year, 3, 31)
)
variation = self._eval_by_account_id("balp[]")
self.assertEqual(variation, {self.account_ar.id: 550, self.account_in.id: -550})
Loading