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

[14.0][IMP] create subscription journal per company #75

Conversation

huguesdk
Copy link
Member

@huguesdk huguesdk commented Jun 9, 2023

this is part of the current effort aiming to make cooperator multi-company compatible.

continue
subscription_request_model.create_journal(company)
# this is called here to support the first 2 cases explained above.
self._init_cooperator_demo_data()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by the demo word here. Why demo? The first 2 cases can happen in production, right?
Did you mean something like default?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand your confusion. indeed, it is about actual demo data, and this will be called in production, but _init_cooperator_demo_data() has an early return in case demo data is disabled, and it has no effect in that case. do you see another way to support the case where a database is initialized with cooperator and demo data but no l10n module? or do you have a suggestion for a comment explaining the situation better maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's sufficient to define the demo data for company 1? Or does the demo data journal get erased that way because of the chart being loaded afterwards?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no demo journal (it is the regular one), but indeed, the demo cooperator account (which must be created manually without demo data) gets erased when loading the account chart template. this is why it is created from here.

_logger.warning(
"Multiple companies found. "
"Please set the subscription journal manually for companies with "
"ids: {company_ids}".format(company_ids=company_ids[1:])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until I noticed the [1:] part, I wasn't understanding the code.
Shouldn't we add some comment saying that we'll migrate only the first company leaving the rest without a journal?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you’re right, a comment is needed here. instead of adding a comment, i’ve changed the migration script to handle multiple companies with a warning in case the subscription journal is not found. what do you think?

Copy link
Member

@carmenbianca carmenbianca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments. I really liked the comment blocks in this PR. Bravo hugues :D

# the subscription journal must be created for each company.
env = api.Environment(cr, SUPERUSER_ID, {})
subscription_request_model = env["subscription.request"]
for company in env.companies:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is env.companies always equal to env["res.company"].search([])?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, indeed, i’ve just checked and it can be different (it depends on the company_ids field of the superuser, which can contain any company, not necessary all of them). i’ve fixed it while converting this post-init hook to a function call from the xml data file.

continue
subscription_request_model.create_journal(company)
# this is called here to support the first 2 cases explained above.
self._init_cooperator_demo_data()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's sufficient to define the demo data for company 1? Or does the demo data journal get erased that way because of the chart being loaded afterwards?

Comment on lines 136 to 101
"account_id": self.company.property_cooperator_account.id,
"account_id": self.env.company.property_cooperator_account.id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit is better than implicit. Let's define a company attribute in the set-up method that is equal to self.env.company so that you can use self.company here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we’re also testing the multi-company behavior here (also possibly when calling test methods), do we really want to reference one particular company from the class? i removed the reference to it because i thought that it wasn’t useful. i’ve re-added it, we’ll see with later cases how it will turn out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's usually useful to have a 'default' record in tests. That doesn't preclude you from using/creating a non-default record in several test methods.

Test that creating a new company creates a new subscription journal
for it.
"""
company_1 = self.env.company
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous comment, for all instances of self.env.company in this file.

Comment on lines +47 to +54
cr.execute(
"""
delete
from ir_model_data
where id = %s
""",
(xml_id,),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: does Odoo not do this itself after updating the module?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tested it and no, it does not. it doesn’t detect data that disappeared. it cleans up all data when uninstalling the module, though.

use xml data instead of post-init hook to initialize company data.
@huguesdk huguesdk force-pushed the 14.0-imp-cooperator_multi_company_subscription_journal branch from 78ea085 to 3aae428 Compare June 12, 2023 13:05
@@ -44,6 +44,11 @@ def _compute_base_logo(self):
" receivable account for the"
" cooperators",
)
subscription_journal_id = fields.Many2one(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i’m not sure about the name of this field. it is used to store the capital release request invoices/moves. any idea?

Copy link
Member

@carmenbianca carmenbianca Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cooperative_share_journal_id? And then rename some stuff accordingly across the module.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after discussion with an accountant, subscription journal is a very appropriate name according to him, because once a capital release request is created, it creates a debt for the person making the subscription request and increments the capital of the cooperative. it does not record shares movements but capital movements (linked to shares).

Copy link
Member

@DaniilDigtyar DaniilDigtyar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@XavierBonetViura XavierBonetViura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@OCA-git-bot OCA-git-bot merged commit ac8e174 into OCA:14.0 Jul 25, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants