Skip to content
Snippets Groups Projects
Commit d52326576a47 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:ambulance: fix populate

There is no more need to set an accounting date as the usual date is now used.
parent f699a0cff30a
No related branches found
No related tags found
2 merge requests!30Add period_id in aml tree view (cf account_consult MO16-190),!29🚑 fix populate
Pipeline #59225 failed
This commit is part of merge request !30. Comments created here will be created in the context of that merge request.
...@@ -2,6 +2,11 @@ ...@@ -2,6 +2,11 @@
Changelog Changelog
========= =========
16.0.1.0.3
----------
Fix populate.
16.0.1.0.2 16.0.1.0.2
---------- ----------
......
from . import demo, models, wizards from . import demo, models, populate, wizards
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
"name": "Accounting Periods", "name": "Accounting Periods",
"license": "AGPL-3", "license": "AGPL-3",
"summary": "Add period accounting concept", "summary": "Add period accounting concept",
"version": "16.0.1.0.2", "version": "16.0.1.0.3",
"category": "Accounting/Accounting", "category": "Accounting/Accounting",
"author": "XCG Consulting", "author": "XCG Consulting",
"website": "https://orbeet.io/", "website": "https://orbeet.io/",
......
############################################################################## ##############################################################################
# #
# Accounting periods, for Odoo # 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 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -18,9 +18,6 @@ ...@@ -18,9 +18,6 @@
# #
############################################################################## ##############################################################################
import logging import logging
from math import log10
from dateutil.relativedelta import relativedelta
from odoo import _, exceptions, fields, models, tools from odoo import _, exceptions, fields, models, tools
...@@ -70,5 +67,6 @@ ...@@ -70,5 +67,6 @@
limit=1, limit=1,
) )
if not period: 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 ( if (
...@@ -74,14 +72,15 @@ ...@@ -74,14 +72,15 @@
if ( if (
(tools.config["test_enable"] or tools.config["test_file"]) tools.config["test_enable"]
and ( or tools.config["test_file"]
not self.env.context.get("period_close_enable") or self.env.context.get("install_demo", False)
or not self.env["account.period"].search( ) and (
[ not self.env.context.get("period_close_enable")
("company_id", "=", company.id), or not self.env["account.period"].search(
("date_start", "<=", acc_date), [
("date_effective_cutoff", ">=", acc_date), ("company_id", "=", company.id),
("state", "=", "done"), ("date_start", "<=", acc_date),
], ("date_effective_cutoff", ">=", acc_date),
limit=1, ("state", "=", "done"),
) ],
limit=1,
) )
...@@ -87,5 +86,4 @@ ...@@ -87,5 +86,4 @@
) )
or self.env.context.get("install_demo", False)
): ):
start_date = acc_date.replace(month=1) start_date = acc_date.replace(month=1)
end_date = acc_date.replace(month=12) end_date = acc_date.replace(month=12)
...@@ -134,34 +132,3 @@ ...@@ -134,34 +132,3 @@
accdoc.write(accdoc_values) accdoc.write(accdoc_values)
return True 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
from . import account_move
##############################################################################
#
# Part of Accounting periods, for Odoo
# Copyright © 2023 XCG Consulting <https://xcg-consulting.fr/>
#
# Accounting periods is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# Accounting periods is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Accounting periods. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def _populate(self, size):
return super(AccountMove, self.with_context(install_demo=True))._populate(size)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment