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][ADD] account_move_default_journal: A module to have more meaningful … #1287

Merged

Conversation

ddejong-therp
Copy link

…journals defaults in forms.

This can help you prevent having old Journals being used as the default in forms. For example, when you create a new booking entry, you don't accidentally pick a journal that should not be used anymore.

@ddejong-therp ddejong-therp changed the title [ADD] account_move_default_journal: A module to have more meaningful … [14.0][ADD] account_move_default_journal: A module to have more meaningful … Dec 6, 2021
@ddejong-therp ddejong-therp force-pushed the 14.0-account_move_default_journal branch from e6d1b4e to 96cd47b Compare May 3, 2023 09:18
('type', 'in', journal_types),
]
if self._context.get('default_currency_id'):
domain.push(
Copy link
Contributor

Choose a reason for hiding this comment

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

list does not have a push method, replace by append

Copy link
Contributor

@NL66278 NL66278 left a comment

Choose a reason for hiding this comment

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

There is an obvious programming mistake with trying to use a push method on a domain (that is on a list).

Also the code does not adhere to conventions. Please use pre-commit to fix this.

@NL66278
Copy link
Contributor

NL66278 commented Jul 13, 2023

@ddejong-therp pre-commit created setup files. Those must be git added and included in the PR. See details of pre-commit check. You might want to squash your commits.

@@ -0,0 +1,64 @@
# Copyright 2021 Therp BV <https://therp.nl>
Copy link
Contributor

Choose a reason for hiding this comment

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

2021?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, the PR was put up in dec 2021 :p

class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

account_move_default_general_journal_id = fields.Many2one(
Copy link
Contributor

Choose a reason for hiding this comment

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

This will not really work in a multi-company situation as journals are always linked to a specific company.

Copy link
Contributor

@NL66278 NL66278 Jul 13, 2023

Choose a reason for hiding this comment

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

Have a look at option two here for company specific settings. Note that set_values and get_values are not really needed any more if you use the config_parameter key in the field definition (see option 3 in the link):
https://gist.github.com/ryanc-me/a0e35fb6741d73c39f9e3968eaa485ee

Choose a reason for hiding this comment

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

What I've seen used a lot throughout Odoo 14.0, is the use of properties for this. A property has a default value for each company, and then in addition to that can also be set per each record. Examples of this are found in the stock_account module where a Stock Journal can be configured per product.category, but also in account module where a Receivable Account can be configured on res.partner with a default on the per-company default one.

This concept would be powerful here as well, and would simplify the code, because we could define a property on account.journal.type which could then contain a per-company default.

Anyway, it would just be a refactor to achieve the same, so not blocking IMO

"account_move_default_journal.general_journal_id"
)

# Try to get the journal, or default back to normal behavior
Copy link
Contributor

Choose a reason for hiding this comment

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

If you use option 2 above (related field in res.config.settings to journal fields in company, you will have a journal you could directly return.

However if there is a default currency in the context that differs from the journal currency, you must still default to the standard search method.

# Try to get the journal, or default back to normal behavior
if journal_id:
journal_id = int(journal_id)
journal = self.env["account.journal"].search(
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this might result in an empty record set. If you apply the other changes I suggested you do not need a search at all, therefore you could dispense with creating a domain altogether as well.

@ddejong-therp ddejong-therp force-pushed the 14.0-account_move_default_journal branch 6 times, most recently from 62df896 to c862895 Compare August 15, 2023 13:24
def _search_default_journal(self, journal_types):
company_id = self._context.get("default_company_id", self.env.company.id)
company = self.env["res.company"].browse(company_id)
domain = [
Copy link
Contributor

Choose a reason for hiding this comment

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

You do not need this domain, so delete setting it.

Copy link
Author

Choose a reason for hiding this comment

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

AH I forgot to remove that yes.

@ddejong-therp ddejong-therp force-pushed the 14.0-account_move_default_journal branch from c862895 to 992e5a5 Compare August 18, 2023 09:49
Copy link
Contributor

@NL66278 NL66278 left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@NL66278
Copy link
Contributor

NL66278 commented Aug 23, 2023

Please add some unit test to get this green. Suggestion:

  • Create journals of different types in the test setup, and set three of them up as company defaults;
  • Check whether they are correctly are found using the different types (sales, general...), including a type with no default (should fallback to default search)
  • Check searching for a type with the context set to a different currency (should fallback to default and find journal with correct currency.

I think this will get you to 100% overage,

@ddejong-therp ddejong-therp force-pushed the 14.0-account_move_default_journal branch 5 times, most recently from 3b8efce to b27c9d4 Compare August 31, 2023 15:03
@ddejong-therp ddejong-therp force-pushed the 14.0-account_move_default_journal branch from b27c9d4 to eeb1323 Compare November 20, 2023 19:12
@ddejong-therp
Copy link
Author

I've now added the missing files. Checks are green now.

class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

account_move_default_general_journal_id = fields.Many2one(

Choose a reason for hiding this comment

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

What I've seen used a lot throughout Odoo 14.0, is the use of properties for this. A property has a default value for each company, and then in addition to that can also be set per each record. Examples of this are found in the stock_account module where a Stock Journal can be configured per product.category, but also in account module where a Receivable Account can be configured on res.partner with a default on the per-company default one.

This concept would be powerful here as well, and would simplify the code, because we could define a property on account.journal.type which could then contain a per-company default.

Anyway, it would just be a refactor to achieve the same, so not blocking IMO

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@rafaelbn
Copy link
Member

rafaelbn commented Dec 2, 2023

I'm not blocking, just asking because I don't understand.

Usually when I'm not using a Journal anymore I archive it!

I'm reading the readme and I don't understand it sorry

Best! 😄

@rafaelbn rafaelbn added this to the 14.0 milestone Dec 2, 2023
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Mar 31, 2024
@NL66278
Copy link
Contributor

NL66278 commented Apr 2, 2024

@rafaelbn Preventing the use of old journals was just an example of what the module can achieve. The basics is that the users get to control what journal is picked as default.

Copy link
Member

@rafaelbn rafaelbn left a comment

Choose a reason for hiding this comment

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

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 14.0-ocabot-merge-pr-1287-by-rafaelbn-bump-patch, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Apr 5, 2024
Signed-off-by rafaelbn
@OCA-git-bot
Copy link
Contributor

@rafaelbn your merge command was aborted due to failed check(s), which you can inspect on this commit of 14.0-ocabot-merge-pr-1287-by-rafaelbn-bump-patch.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@rafaelbn
Copy link
Member

rafaelbn commented Apr 6, 2024

/ocabot rebase

@OCA-git-bot
Copy link
Contributor

Congratulations, PR rebased to 14.0.

@OCA-git-bot OCA-git-bot force-pushed the 14.0-account_move_default_journal branch from eeb1323 to fd18fc0 Compare April 6, 2024 15:24
@github-actions github-actions bot removed the stale PR/Issue without recent activity, it'll be soon closed automatically. label Apr 7, 2024
@dreispt
Copy link
Member

dreispt commented May 2, 2024

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 14.0-ocabot-merge-pr-1287-by-dreispt-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 3b50a19 into OCA:14.0 May 2, 2024
11 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 45cceb7. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants