Skip to content
Snippets Groups Projects

Add period_id in aml tree view (cf account_consult MO16-190)

Merged arthur.mayer requested to merge topic/16.0/MO16-190 into branch/16.0
6 files
+ 51
51
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 16
49
##############################################################################
#
# Accounting periods, for Odoo
# Copyright © 2018, 2022 XCG Consulting <https://xcg-consulting.fr/>
# Copyright © 2018, 2022, 2023 XCG Consulting <https://xcg-consulting.fr/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
@@ -18,9 +18,6 @@
#
##############################################################################
import logging
from math import log10
from dateutil.relativedelta import relativedelta
from odoo import _, exceptions, fields, models, tools
@@ -70,5 +67,6 @@
limit=1,
)
if not period:
# if doing tests, and any matching period not closed
# if doing tests or installing demo data, and any matching period not
# closed
if (
@@ -74,14 +72,15 @@
if (
(tools.config["test_enable"] or tools.config["test_file"])
and (
not self.env.context.get("period_close_enable")
or not self.env["account.period"].search(
[
("company_id", "=", company.id),
("date_start", "<=", acc_date),
("date_effective_cutoff", ">=", acc_date),
("state", "=", "done"),
],
limit=1,
)
tools.config["test_enable"]
or tools.config["test_file"]
or self.env.context.get("install_demo", False)
) and (
not self.env.context.get("period_close_enable")
or not self.env["account.period"].search(
[
("company_id", "=", company.id),
("date_start", "<=", acc_date),
("date_effective_cutoff", ">=", acc_date),
("state", "=", "done"),
],
limit=1,
)
@@ -87,5 +86,4 @@
)
or self.env.context.get("install_demo", False)
):
start_date = acc_date.replace(month=1)
end_date = acc_date.replace(month=12)
@@ -134,34 +132,3 @@
accdoc.write(accdoc_values)
return True
def _populate_factories(self) -> list:
"""Add periods to the generated account.move"""
today = fields.Date.today()
def get_accounting_date(values, counter, random):
"""return an accounting date"""
accounting_date = (
values["date"].date() if values["date"].date() < today else None
)
# make sure target period exists (or action_post will throw an exception)
if accounting_date:
# make it random between the date and today
seconds_after = (today - accounting_date).total_seconds()
accounting_date = accounting_date + relativedelta(
seconds=seconds_after * -log10(0.001 + 0.999 * random.random()) / 3
)
# make sure that period exists
self.env["account.period"].with_context(
company_id=values["company_id"]
).find(accounting_date.date(), True)
return accounting_date
result = super()._populate_factories()
result.append(
# set some accounting_date so that when posting everything does not end up
# on the current period
("accounting_date", tools.populate.compute(get_accounting_date))
)
return result
Loading