Skip to content

Commit

Permalink
[FIX] account_financial_report : make aged report configuration worki…
Browse files Browse the repository at this point in the history
…ng with multi-company
  • Loading branch information
florian-dacosta committed Oct 30, 2024
1 parent 7a752b3 commit 5853bec
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
2 changes: 1 addition & 1 deletion account_financial_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Account Financial Reports",
"version": "16.0.1.11.0",
"version": "16.0.1.12.0",
"category": "Reporting",
"summary": "OCA Financial Reports",
"author": "Camptocamp,"
Expand Down
27 changes: 27 additions & 0 deletions account_financial_report/migrations/16.0.1.12.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import json

from odoo import SUPERUSER_ID, api


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
field = env["ir.model.fields"]._get(
"aged.partner.balance.report.wizard", "age_partner_config_id"
)
default = env["ir.default"].search(
[
("field_id", "=", field.id),
("user_id", "=", False),
("company_id", "=", False),
("condition", "=", False),
],
limit=1,
)
aged_config_id = json.loads(default.json_value) if default else None
if aged_config_id:
config = env["account.age.report.configuration"].browse(aged_config_id)
if config.exists():
company = config.company_id
if company:
company.write({"age_partner_config_id": config.id})
default.unlink()
1 change: 1 addition & 0 deletions account_financial_report/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import res_company
from . import account_age_report_configuration
from . import account_group
from . import account
Expand Down
12 changes: 12 additions & 0 deletions account_financial_report/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

age_partner_config_id = fields.Many2one(
comodel_name="account.age.report.configuration",
string="Intervals configuration",
)
5 changes: 3 additions & 2 deletions account_financial_report/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

default_age_partner_config_id = fields.Many2one(
age_partner_config_id = fields.Many2one(
"account.age.report.configuration",
related="company_id.age_partner_config_id",
readonly=False,
string="Intervals configuration",
default_model="aged.partner.balance.report.wizard",
)
4 changes: 2 additions & 2 deletions account_financial_report/view/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
<div class="content-group">
<div class="row mt16">
<label
for="default_age_partner_config_id"
for="age_partner_config_id"
class="col-lg-3 o_light_label"
/>
<field
name="default_age_partner_config_id"
name="age_partner_config_id"
options="{'no_create_edit': True, 'no_open': True}"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class AgedPartnerBalanceWizard(models.TransientModel):
help="Ending account in a range",
)
age_partner_config_id = fields.Many2one(
"account.age.report.configuration", string="Intervals configuration"
"account.age.report.configuration",
string="Intervals configuration",
default=lambda self: self.env.company.age_partner_config_id.id,
)

@api.onchange("account_code_from", "account_code_to")
Expand Down

0 comments on commit 5853bec

Please sign in to comment.