summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Raval <var@odoo.com>2019-06-04 09:01:35 +0000
committerqdp-odoo <qdp@odoo.com>2019-06-21 13:33:37 +0000
commita5b6946940eeb1046fee6024aaef180bb1bcee4a (patch)
treea6764f650032da1f89e102a6a1790562e1c91202
parent58c8d1ed37d83bc2b550d7142746f7a861e24dab (diff)
[IMP] account: disallow company discrepancies B/W aml and account.move
Purpose of the commit is when multi-company is active and company A is a parent of company B. When a user creates an account move with a Journal of company A and adds account move lines they are created with company A. But now user changes the journal and select journal of different company and save the record system allows having the different company in account move and account move line. After this commit when account move and account move line have different company and user tries to save, it will show a warning. task-1970459 closes odoo/odoo#34244 Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
-rw-r--r--addons/account/models/account_move.py5
-rw-r--r--addons/account/tests/test_account_move_taxes_edition.py4
2 files changed, 8 insertions, 1 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 6b9469f7a18..07b96fe5e4b 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -308,6 +308,11 @@ class AccountMove(models.Model):
res['fields']['line_ids']['views']['tree']['fields']['tax_line_id']['domain'] = [('tag_ids', 'in', [self.env.ref(self._context.get('vat_domain')).id])]
return res
+ @api.constrains('company_id')
+ def _check_company_id(self):
+ if self.filtered(lambda record: any([x.company_id.id != record.company_id.id for x in record.line_ids])):
+ raise ValidationError(_("Cannot create moves for different companies."))
+
@api.model
def create(self, vals):
move = super(AccountMove, self.with_context(mail_create_nolog=True, check_move_validity=False, partner_id=vals.get('partner_id'))).create(vals)
diff --git a/addons/account/tests/test_account_move_taxes_edition.py b/addons/account/tests/test_account_move_taxes_edition.py
index df17788266c..036ab2abdee 100644
--- a/addons/account/tests/test_account_move_taxes_edition.py
+++ b/addons/account/tests/test_account_move_taxes_edition.py
@@ -14,8 +14,10 @@ class TestAccountMoveTaxesEdition(AccountingTestCase):
'amount_type': 'percent',
'amount': 10,
})
- self.account = self.env['account.account'].search([('deprecated', '=', False)], limit=1)
self.journal = self.env['account.journal'].search([], limit=1)
+ self.account = self.env['account.account'].search([
+ ('deprecated', '=', False), ('company_id', '=', self.journal.company_id.id)
+ ], limit=1)
def test_onchange_taxes_1(self):
'''