-
-
Notifications
You must be signed in to change notification settings - Fork 271
[18.0][FIX] account_operating_unit: filter payment register journals by OU (#843) #844
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
Open
IJOL
wants to merge
2
commits into
OCA:18.0
Choose a base branch
from
BITVAX:18.0-fix-payment-register-ou
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
|
|
||
| from . import models | ||
| from . import report | ||
| from . import wizard | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
account_operating_unit/tests/test_payment_register_journal_ou.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| # © 2026 BITVAX | ||
| # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
| """Bug: account.payment.register wizard's available_journal_ids | ||
| includes journals from operating units the invoice does not belong to. | ||
|
|
||
| A B2B invoice should only offer journals whose operating_unit_id | ||
| matches B2B (or no OU). On upstream/18.0 the wizard pulls journals via | ||
| ``account.journal.search()`` without OU context, so it returns every | ||
| sale/cash journal of the company regardless of OU. | ||
|
|
||
| The fix is to override | ||
| ``account.payment.register._get_batch_available_journals`` and filter | ||
| the returned set by the operating_unit_id of the invoices in the | ||
| batch. | ||
| """ | ||
|
|
||
| from odoo.models import Command | ||
| from odoo.tests import tagged | ||
|
|
||
| from odoo.addons.account.tests.common import AccountTestInvoicingCommon | ||
| from odoo.addons.operating_unit.tests.common import OperatingUnitCommon | ||
|
|
||
|
|
||
| @tagged("post_install", "-at_install") | ||
| class TestPaymentRegisterJournalOu(AccountTestInvoicingCommon, OperatingUnitCommon): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| super().setUpClass() | ||
|
|
||
| (cls.ou1 | cls.b2b | cls.b2c).sudo().write({"company_id": cls.company.id}) | ||
|
|
||
| cls.env.user.sudo().write( | ||
| { | ||
| "groups_id": [ | ||
| Command.link( | ||
| cls.env.ref("operating_unit.group_manager_operating_unit").id | ||
| ), | ||
| ], | ||
| "operating_unit_ids": [ | ||
| Command.link(cls.ou1.id), | ||
| Command.link(cls.b2b.id), | ||
| ], | ||
| "default_operating_unit_id": cls.ou1.id, | ||
| "company_ids": [Command.link(cls.company.id)], | ||
| "company_id": cls.company.id, | ||
| } | ||
| ) | ||
|
|
||
| cls.user1.write( | ||
| { | ||
| "groups_id": [ | ||
| ( | ||
| 3, | ||
| cls.env.ref("operating_unit.group_manager_operating_unit").id, | ||
| ), | ||
| Command.link( | ||
| cls.env.ref("operating_unit.group_multi_operating_unit").id | ||
| ), | ||
| Command.link(cls.env.ref("account.group_account_invoice").id), | ||
| ], | ||
| "assigned_operating_unit_ids": [(6, 0, [cls.b2b.id])], | ||
| "default_operating_unit_id": cls.b2b.id, | ||
| "company_id": cls.company.id, | ||
| "company_ids": [Command.link(cls.company.id)], | ||
| } | ||
| ) | ||
|
|
||
| Journal = cls.env["account.journal"].sudo() | ||
| cls.purchase_journal_b2b = Journal.create( | ||
| { | ||
| "name": "Vendor Bills B2B (test_pay_reg)", | ||
| "code": "TPRPB", | ||
| "type": "purchase", | ||
| "company_id": cls.company.id, | ||
| "operating_unit_id": cls.b2b.id, | ||
| } | ||
| ) | ||
| cls.cash_journal_ou1 = Journal.create( | ||
| { | ||
| "name": "Cash OU1 (test_pay_reg)", | ||
| "code": "TPRC1", | ||
| "type": "cash", | ||
| "company_id": cls.company.id, | ||
| "operating_unit_id": cls.ou1.id, | ||
| } | ||
| ) | ||
| cls.cash_journal_b2b = Journal.create( | ||
| { | ||
| "name": "Cash B2B (test_pay_reg)", | ||
| "code": "TPRCB", | ||
| "type": "cash", | ||
| "company_id": cls.company.id, | ||
| "operating_unit_id": cls.b2b.id, | ||
| } | ||
| ) | ||
| cls.expense_account = cls.env["account.account"].search( | ||
| [ | ||
| ("account_type", "=", "expense"), | ||
| ("company_ids", "in", cls.company.ids), | ||
| ], | ||
| limit=1, | ||
| ) | ||
|
|
||
| def test_payment_register_filters_journals_by_invoice_ou(self): | ||
| invoice = ( | ||
| self.env["account.move"] | ||
| .with_context(default_move_type="in_invoice") | ||
| .create( | ||
| { | ||
| "partner_id": self.partner1.id, | ||
| "operating_unit_id": self.b2b.id, | ||
| "invoice_date": "2026-01-01", | ||
| "journal_id": self.purchase_journal_b2b.id, | ||
| "invoice_line_ids": [ | ||
| ( | ||
| 0, | ||
| 0, | ||
| { | ||
| "name": "Line", | ||
| "quantity": 1, | ||
| "price_unit": 100.0, | ||
| "account_id": self.expense_account.id, | ||
| "tax_ids": [], | ||
| }, | ||
| ) | ||
| ], | ||
| } | ||
| ) | ||
| ) | ||
| invoice.action_post() | ||
|
|
||
| wizard = ( | ||
| self.env["account.payment.register"] | ||
| .with_user(self.user1) | ||
| .with_context( | ||
| active_model="account.move", | ||
| active_ids=invoice.ids, | ||
| ) | ||
| .create({"journal_id": self.cash_journal_b2b.id}) | ||
| ) | ||
| available = wizard.available_journal_ids | ||
| self.assertIn( | ||
| self.cash_journal_b2b, | ||
| available, | ||
| "B2B cash journal must be available to pay a B2B invoice.", | ||
| ) | ||
| self.assertNotIn( | ||
| self.cash_journal_ou1, | ||
| available, | ||
| "OU1 cash journal must NOT be available when paying a " "B2B invoice.", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import account_payment_register |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
|
|
||
| from odoo import api, models | ||
|
|
||
|
|
||
| class AccountPaymentRegister(models.TransientModel): | ||
| _inherit = "account.payment.register" | ||
|
|
||
| @api.model | ||
| def _get_batch_available_journals(self, batch_result): | ||
| """Filter available journals by the operating unit of the invoices.""" | ||
| journals = super()._get_batch_available_journals(batch_result) | ||
| lines = batch_result.get("lines") | ||
| if lines: | ||
| invoice_ous = lines.move_id.operating_unit_id | ||
| if invoice_ous and len(invoice_ous) == 1: | ||
| journals = journals.filtered( | ||
| lambda j: not j.operating_unit_id | ||
| or j.operating_unit_id == invoice_ous | ||
| ) | ||
| return journals |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
sorry for the nitpicking, can you remove all the empty lines inside the method?