-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
[14.0][ADD] account_move_default_journal: A module to have more meaningful … #1287
Conversation
e6d1b4e
to
96cd47b
Compare
('type', 'in', journal_types), | ||
] | ||
if self._context.get('default_currency_id'): | ||
domain.push( |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
@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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2021?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
62df896
to
c862895
Compare
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 = [ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
c862895
to
992e5a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
Please add some unit test to get this green. Suggestion:
I think this will get you to 100% overage, |
3b8efce
to
b27c9d4
Compare
b27c9d4
to
eeb1323
Compare
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( |
There was a problem hiding this comment.
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
This PR has the |
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! 😄 |
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. |
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ocabot merge patch
Hey, thanks for contributing! Proceeding to merge this for you. |
@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. |
/ocabot rebase |
…default journals in account move forms.
Congratulations, PR rebased to 14.0. |
eeb1323
to
fd18fc0
Compare
/ocabot merge nobump |
On my way to merge this fine PR! |
Congratulations, your PR was merged at 45cceb7. Thanks a lot for contributing to OCA. ❤️ |
…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.