Skip to content

Commit

Permalink
Merge pull request #165 from Eficent/11.0-fix-account_operating_unit
Browse files Browse the repository at this point in the history
[11.0] [FIX] account_operating_unit: Consistency between operating units
  • Loading branch information
AaronHForgeFlow committed Feb 6, 2019
2 parents 956881f + 40589e2 commit 31b3157
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion account_operating_unit/__manifest__.py
Expand Up @@ -5,7 +5,7 @@
"name": 'Accounting with Operating Units',
"summary": "Introduces Operating Unit fields in invoices and "
"Accounting Entries with clearing account",
"version": "11.0.1.0.0",
"version": "11.0.1.0.1",
"author": "Eficent, "
"Serpent Consulting Services Pvt. Ltd.,"
"WilldooIT Pty Ltd,"
Expand Down
4 changes: 2 additions & 2 deletions account_operating_unit/models/__init__.py
@@ -1,7 +1,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import company
from . import res_company
from . import account_journal
from . import account_move
from . import invoice
from . import account_invoice
from . import account_payment
Expand Up @@ -43,6 +43,19 @@ def _check_company_operating_unit(self):
'Operating Unit must be the same.'))
return True

@api.multi
@api.constrains('operating_unit_id', 'journal_id')
def _check_journal_operating_unit(self):
for ai in self:
if (
ai.journal_id.operating_unit_id and
ai.operating_unit_id and
ai.operating_unit_id != ai.journal_id.operating_unit_id
):
raise ValidationError(_('The OU in the Invoice and in '
'Journal must be the same.'))
return True


class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions account_operating_unit/tests/test_invoice_operating_unit.py
Expand Up @@ -3,6 +3,7 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

from . import test_account_operating_unit as test_ou
from odoo.exceptions import ValidationError


class TestInvoiceOperatingUnit(test_ou.TestAccountOperatingUnit):
Expand All @@ -25,3 +26,18 @@ def test_create_invoice_validate(self):
# have different operating units
self.assertNotEqual(all_op_units, False, 'Journal Entries have\
different Operating Units.')

def test_check_journal_operating_unit(self):
"""
Test that when an invoice is created with different operating unit in
the journal and in the invoice, the ValidationError raises
"""
# Try to create an invoice with a different operating unit in the
# journal and in the invoice
with self.assertRaises(ValidationError):
self.invoice2 = self.invoice_model.sudo(self.user_id.id).create(
self._prepare_invoice(self.ou1.id)
)
self.invoice2.sudo(self.user_id.id).write({
'journal_id': self.cash2_journal_b2b
})

0 comments on commit 31b3157

Please sign in to comment.