Skip to content

Commit

Permalink
[IMP] l10n_it_dichiarazione_intento: Add multi-company test
Browse files Browse the repository at this point in the history
  • Loading branch information
monen17 committed Jan 24, 2022
1 parent 803afa5 commit 0c41ac3
Showing 1 changed file with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class TestDichiarazioneIntento(TransactionCase):

def _create_dichiarazione(self, partner, type_d):
return self.env['dichiarazione.intento'].sudo().create({
return self.env['dichiarazione.intento'].create({
'partner_id': partner.id,
'date': self.today_date.strftime('%Y-%m-%d'),
'date_start': self.today_date.strftime('%Y-%m-%d'),
Expand Down Expand Up @@ -160,6 +160,17 @@ def setUp(self):
self.invoice4 = self._create_invoice(self.partner3, tax=self.tax22)
self.invoice4.fiscal_position_id = self.fiscal_position2.id
self.invoice5 = self._create_invoice(self.partner4, tax=self.tax1, in_type=True)
self.other_company = self.env['res.company'].create({
'name': 'other',
})
self.other_user = self.env['res.users'].create({
'name': "User of other company",
'login': "other",
'company_ids': [
(4, self.other_company.id),
],
'company_id': self.other_company.id,
})

def test_dichiarazione_data(self):
self.assertTrue(self.dichiarazione1.number)
Expand Down Expand Up @@ -263,3 +274,16 @@ def test_invoice_vendor_with_no_effect_on_dichiarazione(self):
def test_copy_dichiarazione_in(self):
dichiarazione_copy = self.dichiarazione4.copy()
self.assertTrue(dichiarazione_copy)

def test_multi_company(self):
"""Check that a user can only see and create declarations in his company."""
self.env = self.env(user=self.other_user)
declaration_model = self.env['dichiarazione.intento']

# See only declarations in current company
self.assertFalse(declaration_model.search_count([]))

# Created declaration is in current company
declaration = self._create_dichiarazione(self.partner1, 'out')
self.assertEqual(declaration_model.search([]), declaration)
self.assertEqual(self.env.user.company_id, declaration.company_id)

0 comments on commit 0c41ac3

Please sign in to comment.