[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>
This commit is contained in:
Varun Raval
2019-06-21 13:33:37 +00:00
committed by qdp-odoo
parent 58c8d1ed37
commit a5b6946940
2 changed files with 8 additions and 1 deletions
+5
View File
@@ -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)
@@ -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):
'''