[FIX] *: sudo() -> with_user()
This commit is contained in:
@@ -470,7 +470,7 @@ class AlarmManager(models.AbstractModel):
|
||||
notifications = []
|
||||
users = self.env['res.users'].search([('partner_id', 'in', tuple(partner_ids))])
|
||||
for user in users:
|
||||
notif = self.sudo(user.id).get_next_notif()
|
||||
notif = self.with_user(user).get_next_notif()
|
||||
notifications.append([(self._cr.dbname, 'calendar.alarm', user.partner_id.id), notif])
|
||||
if len(notifications) > 0:
|
||||
self.env['bus.bus'].sendmany(notifications)
|
||||
|
||||
@@ -228,7 +228,7 @@ class TestCalendar(TransactionCase):
|
||||
test_name, test_description, test_description2 = 'Test-Meeting', '<p>Test-Description</p>', '<p>NotTest</p>'
|
||||
|
||||
# create using default_* keys
|
||||
test_event = self.env['calendar.event'].sudo(test_user).with_context(
|
||||
test_event = self.env['calendar.event'].with_user(test_user).with_context(
|
||||
default_res_model=test_record._name,
|
||||
default_res_id=test_record.id,
|
||||
).create({
|
||||
@@ -263,7 +263,7 @@ class TestCalendar(TransactionCase):
|
||||
self.assertEqual(self.env['calendar.event'], self.env['calendar.event'].search([('name', '=', test_name)]))
|
||||
|
||||
# create using active_model keys
|
||||
test_event = self.env['calendar.event'].sudo(self.env.ref('base.user_demo')).with_context(
|
||||
test_event = self.env['calendar.event'].with_user(self.env.ref('base.user_demo')).with_context(
|
||||
active_model=test_record._name,
|
||||
active_id=test_record.id,
|
||||
).create({
|
||||
|
||||
@@ -34,7 +34,7 @@ class TestCrmMailActivity(TestCrmCases):
|
||||
|
||||
# I create an opportunity, as salesman
|
||||
self.partner_client = self.env.ref("base.res_partner_1")
|
||||
self.lead = self.env['crm.lead'].sudo(self.crm_salesman.id).create({
|
||||
self.lead = self.env['crm.lead'].with_user(self.crm_salesman).create({
|
||||
'name': 'Test Opp',
|
||||
'type': 'opportunity',
|
||||
'partner_id': self.partner_client.id,
|
||||
@@ -61,7 +61,7 @@ class TestCrmMailActivity(TestCrmCases):
|
||||
# Add sale manager as follower of default subtypes
|
||||
self.lead.message_subscribe([self.crm_salemanager.partner_id.id], subtype_ids=[self.env.ref('mail.mt_activities').id, self.env.ref('mail.mt_comment').id])
|
||||
|
||||
activity = self.env['mail.activity'].sudo(self.crm_salesman.id).create({
|
||||
activity = self.env['mail.activity'].with_user(self.crm_salesman).create({
|
||||
'activity_type_id': self.activity1.id,
|
||||
'note': 'Content of the activity to log',
|
||||
'res_id': self.lead.id,
|
||||
@@ -84,7 +84,7 @@ class TestCrmMailActivity(TestCrmCases):
|
||||
""" This test case set the next activity on a lead, log another, and schedule a third. """
|
||||
# Add the next activity (like we set it from a form view)
|
||||
lead_model_id = self.env['ir.model']._get('crm.lead').id
|
||||
activity = self.env['mail.activity'].sudo(self.crm_salesman.id).create({
|
||||
activity = self.env['mail.activity'].with_user(self.crm_salesman).create({
|
||||
'activity_type_id': self.activity1.id,
|
||||
'summary': 'My Own Summary',
|
||||
'res_id': self.lead.id,
|
||||
|
||||
@@ -9,9 +9,9 @@ class TestCRMLead(TestCrmCases):
|
||||
|
||||
def test_crm_lead_cancel(self):
|
||||
# I set a new sales team giving access rights of salesman.
|
||||
team = self.env['crm.team'].sudo(self.crm_salemanager.id).create({'name': "Phone Marketing"})
|
||||
team = self.env['crm.team'].with_user(self.crm_salemanager).create({'name': "Phone Marketing"})
|
||||
lead = self.env.ref('crm.crm_case_1')
|
||||
lead.sudo(self.crm_salemanager.id).write({'team_id': team.id})
|
||||
lead.with_user(self.crm_salemanager).write({'team_id': team.id})
|
||||
# Salesmananger check unqualified lead
|
||||
self.assertEqual(lead.stage_id.sequence, 1, 'Lead is in new stage')
|
||||
|
||||
@@ -21,7 +21,7 @@ class TestCRMLead(TestCrmCases):
|
||||
|
||||
def test_crm_lead_unlink(self):
|
||||
# Only Sales manager Unlink the Lead so test with Manager's access rights
|
||||
self.env.ref('crm.crm_case_4').sudo(self.crm_salemanager.id).unlink()
|
||||
self.env.ref('crm.crm_case_4').with_user(self.crm_salemanager).unlink()
|
||||
|
||||
def test_find_stage(self):
|
||||
# I create a new lead
|
||||
@@ -49,10 +49,10 @@ class TestCRMLead(TestCrmCases):
|
||||
# Mail script will fetch his request from mail server. Then I process that mail after read EML file.
|
||||
request_file = open(get_module_resource('crm', 'tests', 'customer_request.eml'), 'rb')
|
||||
request_message = request_file.read()
|
||||
self.env['mail.thread'].sudo(self.crm_salesman).message_process('crm.lead', request_message)
|
||||
self.env['mail.thread'].with_user(self.crm_salesman).message_process('crm.lead', request_message)
|
||||
|
||||
# After getting the mail, I check details of new lead of that customer
|
||||
lead = self.env['crm.lead'].sudo(self.crm_salesman).search([('email_from', '=', 'Mr. John Right <info@customer.com>')], limit=1)
|
||||
lead = self.env['crm.lead'].with_user(self.crm_salesman).search([('email_from', '=', 'Mr. John Right <info@customer.com>')], limit=1)
|
||||
self.assertTrue(lead.ids, 'Fail to create merge opportunity wizard')
|
||||
self.assertFalse(lead.partner_id, 'Customer should be a new one')
|
||||
self.assertEqual(lead.name, 'Fournir votre devis avec le meilleur prix.', 'Subject does not match')
|
||||
@@ -76,7 +76,7 @@ class TestCRMLead(TestCrmCases):
|
||||
def test_crm_lead_merge(self):
|
||||
# During a mixed merge (involving leads and opps), data should be handled a certain way following their type (m2o, m2m, text, ...) Start by creating two leads and an opp and giving the rights of Sales manager.
|
||||
default_stage_id = self.ref("crm.stage_lead1")
|
||||
LeadSalesmanager = self.env['crm.lead'].sudo(self.crm_salemanager.id)
|
||||
LeadSalesmanager = self.env['crm.lead'].with_user(self.crm_salemanager)
|
||||
|
||||
# TEST CASE 1
|
||||
test_crm_opp_01 = LeadSalesmanager.create({
|
||||
@@ -107,7 +107,7 @@ class TestCRMLead(TestCrmCases):
|
||||
additionnal_context = {'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': lead_ids[0]}
|
||||
|
||||
# I create a merge wizard and merge the leads and opp together in the first item of the list.
|
||||
merge_opp_wizard_01 = self.env['crm.merge.opportunity'].sudo(self.crm_salemanager.id).with_context(**additionnal_context).create({})
|
||||
merge_opp_wizard_01 = self.env['crm.merge.opportunity'].with_user(self.crm_salemanager).with_context(**additionnal_context).create({})
|
||||
merge_opp_wizard_01.action_merge()
|
||||
|
||||
# I check for the resulting merged opp (based on name and partner)
|
||||
@@ -140,7 +140,7 @@ class TestCRMLead(TestCrmCases):
|
||||
additionnal_context = {'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': lead_ids[0]}
|
||||
|
||||
# I create a merge wizard and merge the leads together.
|
||||
merge_opp_wizard_02 = self.env['crm.merge.opportunity'].sudo(self.crm_salemanager.id).with_context(**additionnal_context).create({})
|
||||
merge_opp_wizard_02 = self.env['crm.merge.opportunity'].with_user(self.crm_salemanager).with_context(**additionnal_context).create({})
|
||||
merge_opp_wizard_02.action_merge()
|
||||
|
||||
# I check for the resulting merged lead (based on name and partner)
|
||||
@@ -170,7 +170,7 @@ class TestCRMLead(TestCrmCases):
|
||||
additionnal_context = {'active_model': 'crm.lead', 'active_ids': opportunity_ids, 'active_id': opportunity_ids[0]}
|
||||
|
||||
# I create a merge wizard and merge the opps together.
|
||||
merge_opp_wizard_03 = self.env['crm.merge.opportunity'].sudo(self.crm_salemanager.id).with_context(**additionnal_context).create({})
|
||||
merge_opp_wizard_03 = self.env['crm.merge.opportunity'].with_user(self.crm_salemanager).with_context(**additionnal_context).create({})
|
||||
merge_opp_wizard_03.action_merge()
|
||||
|
||||
merged_opportunity = self.env['crm.lead'].search([('name', '=', 'Test opportunity 2'), ('partner_id', '=', self.env.ref("base.res_partner_3").id)], limit=1)
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
|
||||
# Giving access rights of salesman to convert the lead into opportunity.
|
||||
# I convert lead into opportunity for exiting customer.
|
||||
crm_case_3.sudo(self.crm_salemanager.id).convert_opportunity(self.env.ref("base.res_partner_2").id)
|
||||
crm_case_3.with_user(self.crm_salemanager).convert_opportunity(self.env.ref("base.res_partner_2").id)
|
||||
|
||||
# I check details of converted opportunity.
|
||||
self.assertEqual(crm_case_3.type, 'opportunity', 'Lead is not converted to opportunity!')
|
||||
@@ -38,11 +38,11 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
crm_case_3.message_post(subject='Test note', body='Détails envoyés par le client sur le FAX pour la qualité')
|
||||
|
||||
# I convert mass lead into opportunity customer.
|
||||
mass = CrmLead2OpportunityPartnerMass.sudo(self.crm_salemanager.id).with_context({'active_model': 'crm.lead', 'active_ids': [crm_case_13.id, crm_case_2.id], 'active_id': crm_case_13.id}).create({
|
||||
mass = CrmLead2OpportunityPartnerMass.with_user(self.crm_salemanager).with_context({'active_model': 'crm.lead', 'active_ids': [crm_case_13.id, crm_case_2.id], 'active_id': crm_case_13.id}).create({
|
||||
'user_ids': [(6, 0, self.env.ref('base.user_root').ids)],
|
||||
'team_id': self.env.ref("sales_team.team_sales_department").id
|
||||
})
|
||||
mass.sudo(self.crm_salemanager.id).mass_convert()
|
||||
mass.with_user(self.crm_salemanager).mass_convert()
|
||||
|
||||
# Now I check first lead converted on opportunity.
|
||||
self.assertEqual(crm_case_13.name, "Quote for 600 Chairs", "Opportunity name not correct")
|
||||
@@ -71,7 +71,7 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
def test_lead2opportunity_assign_salesmen(self):
|
||||
""" Tests for Test Lead2opportunity Assign Salesmen """
|
||||
CrmLead2OpportunityPartnerMass = self.env['crm.lead2opportunity.partner.mass']
|
||||
LeadSaleman = self.env['crm.lead'].sudo(self.crm_salesman.id)
|
||||
LeadSaleman = self.env['crm.lead'].with_user(self.crm_salesman)
|
||||
default_stage_id = self.ref("crm.stage_lead1")
|
||||
|
||||
# During a lead to opp conversion, salesmen should be assigned to leads following the round-robin method. Start by creating 4 salesmen (A to D) and 6 leads (1 to 6).
|
||||
@@ -135,16 +135,16 @@ class TestLead2opportunity2win(TestCrmCases):
|
||||
|
||||
# Salesman create a mass convert wizard and convert all the leads.
|
||||
additionnal_context = {'active_model': 'crm.lead', 'active_ids': lead_ids, 'active_id': test_crm_lead_01.id}
|
||||
mass = CrmLead2OpportunityPartnerMass.sudo(self.crm_salesman.id).with_context(**additionnal_context).create({
|
||||
mass = CrmLead2OpportunityPartnerMass.with_user(self.crm_salesman).with_context(**additionnal_context).create({
|
||||
'user_ids': [(6, 0, salesmen_ids)],
|
||||
'team_id': self.env.ref("sales_team.team_sales_department").id,
|
||||
'deduplicate': False,
|
||||
'force_assignation': True
|
||||
})
|
||||
mass.sudo(self.crm_salesman.id).mass_convert()
|
||||
mass.with_user(self.crm_salesman).mass_convert()
|
||||
|
||||
# The leads should now be opps with a salesman and a salesteam. Also, salesmen should have been assigned following a round-robin method.
|
||||
opps = self.env['crm.lead'].sudo(self.crm_salesman.id).browse(lead_ids)
|
||||
opps = self.env['crm.lead'].with_user(self.crm_salesman).browse(lead_ids)
|
||||
i = 0
|
||||
for opp in opps:
|
||||
self.assertEqual(opp.type, 'opportunity', 'Type mismatch: this should be an opp, not a lead')
|
||||
|
||||
@@ -39,7 +39,7 @@ class NewLeadNotification(TestCrmCases):
|
||||
self.assertIn(channel_listen, msg.channel_ids)
|
||||
|
||||
# The user should have a new unread message
|
||||
lead_user = lead.sudo(self.crm_salesman)
|
||||
lead_user = lead.with_user(self.crm_salesman)
|
||||
self.assertTrue(lead_user.message_needaction)
|
||||
|
||||
def test_new_lead_from_email_multicompany(self):
|
||||
|
||||
@@ -109,8 +109,8 @@ class Digest(models.Model):
|
||||
self.ensure_one()
|
||||
res = {}
|
||||
for tf_name, tf in self._compute_timeframes(company).items():
|
||||
digest = self.with_context(start_date=tf[0][0], end_date=tf[0][1], company=company).sudo(user.id)
|
||||
previous_digest = self.with_context(start_date=tf[1][0], end_date=tf[1][1], company=company).sudo(user.id)
|
||||
digest = self.with_context(start_date=tf[0][0], end_date=tf[0][1], company=company).with_user(user)
|
||||
previous_digest = self.with_context(start_date=tf[1][0], end_date=tf[1][1], company=company).with_user(user)
|
||||
kpis = {}
|
||||
for field_name, field in self._fields.items():
|
||||
if field.type == 'boolean' and field_name.startswith(('kpi_', 'x_kpi_', 'x_studio_kpi_')) and self[field_name]:
|
||||
|
||||
@@ -19,7 +19,7 @@ class TestEventFlow(TestEventCommon):
|
||||
def test_00_basic_event_auto_confirm(self):
|
||||
""" Basic event management with auto confirmation """
|
||||
# EventUser creates a new event: ok
|
||||
test_event = self.Event.sudo(self.user_eventmanager).create({
|
||||
test_event = self.Event.with_user(self.user_eventmanager).create({
|
||||
'name': 'TestEvent',
|
||||
'auto_confirm': True,
|
||||
'date_begin': datetime.datetime.now() + relativedelta(days=-1),
|
||||
@@ -30,13 +30,13 @@ class TestEventFlow(TestEventCommon):
|
||||
self.assertEqual(test_event.state, 'confirm', 'Event: auto_confirmation of event failed')
|
||||
|
||||
# EventUser create registrations for this event
|
||||
test_reg1 = self.Registration.sudo(self.user_eventuser).create({
|
||||
test_reg1 = self.Registration.with_user(self.user_eventuser).create({
|
||||
'name': 'TestReg1',
|
||||
'event_id': test_event.id,
|
||||
})
|
||||
self.assertEqual(test_reg1.state, 'open', 'Event: auto_confirmation of registration failed')
|
||||
self.assertEqual(test_event.seats_reserved, 1, 'Event: wrong number of reserved seats after confirmed registration')
|
||||
test_reg2 = self.Registration.sudo(self.user_eventuser).create({
|
||||
test_reg2 = self.Registration.with_user(self.user_eventuser).create({
|
||||
'name': 'TestReg2',
|
||||
'event_id': test_event.id,
|
||||
})
|
||||
@@ -45,7 +45,7 @@ class TestEventFlow(TestEventCommon):
|
||||
|
||||
# EventUser create registrations for this event: too much registrations
|
||||
with self.assertRaises(ValidationError):
|
||||
self.Registration.sudo(self.user_eventuser).create({
|
||||
self.Registration.with_user(self.user_eventuser).create({
|
||||
'name': 'TestReg3',
|
||||
'event_id': test_event.id,
|
||||
})
|
||||
@@ -70,7 +70,7 @@ class TestEventFlow(TestEventCommon):
|
||||
""" Avanced event flow: no auto confirmation, manage minimum / maximum
|
||||
seats, ... """
|
||||
# EventUser creates a new event: ok
|
||||
test_event = self.Event.sudo(self.user_eventmanager).create({
|
||||
test_event = self.Event.with_user(self.user_eventmanager).create({
|
||||
'name': 'TestEvent',
|
||||
'date_begin': datetime.datetime.now() + relativedelta(days=-1),
|
||||
'date_end': datetime.datetime.now() + relativedelta(days=1),
|
||||
@@ -81,7 +81,7 @@ class TestEventFlow(TestEventCommon):
|
||||
'Event: new event should be in draft state, no auto confirmation')
|
||||
|
||||
# EventUser create registrations for this event -> no auto confirmation
|
||||
test_reg1 = self.Registration.sudo(self.user_eventuser).create({
|
||||
test_reg1 = self.Registration.with_user(self.user_eventuser).create({
|
||||
'name': 'TestReg1',
|
||||
'event_id': test_event.id,
|
||||
})
|
||||
@@ -92,14 +92,14 @@ class TestEventFlow(TestEventCommon):
|
||||
def test_event_access_rights(self):
|
||||
# EventManager required to create or update events
|
||||
with self.assertRaises(AccessError):
|
||||
self.Event.sudo(self.user_eventuser).create({
|
||||
self.Event.with_user(self.user_eventuser).create({
|
||||
'name': 'TestEvent',
|
||||
'date_begin': datetime.datetime.now() + relativedelta(days=-1),
|
||||
'date_end': datetime.datetime.now() + relativedelta(days=1),
|
||||
'seats_max': 10,
|
||||
})
|
||||
with self.assertRaises(AccessError):
|
||||
self.event_0.sudo(self.user_eventuser).write({
|
||||
self.event_0.with_user(self.user_eventuser).write({
|
||||
'name': 'TestEvent Modified',
|
||||
})
|
||||
|
||||
@@ -109,7 +109,7 @@ class TestEventFlow(TestEventCommon):
|
||||
(4, self.env.ref('base.group_erp_manager').id)
|
||||
]})
|
||||
with self.assertRaises(AccessError):
|
||||
event_config = self.env['res.config.settings'].sudo(self.user_eventmanager).create({
|
||||
event_config = self.env['res.config.settings'].with_user(self.user_eventmanager).create({
|
||||
})
|
||||
event_config.execute()
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class TestMailSchedule(TestEventCommon):
|
||||
event_date_begin = now + relativedelta(days=1)
|
||||
event_date_end = now + relativedelta(days=3)
|
||||
|
||||
test_event = self.Event.sudo(self.user_eventmanager).create({
|
||||
test_event = self.Event.with_user(self.user_eventmanager).create({
|
||||
'name': 'TestEventMail',
|
||||
'auto_confirm': True,
|
||||
'date_begin': event_date_begin,
|
||||
@@ -37,12 +37,12 @@ class TestMailSchedule(TestEventCommon):
|
||||
})
|
||||
|
||||
# create some registrations
|
||||
self.Registration.sudo(self.user_eventuser).create({
|
||||
self.Registration.with_user(self.user_eventuser).create({
|
||||
'event_id': test_event.id,
|
||||
'name': 'Reg0',
|
||||
'email': 'reg0@example.com',
|
||||
})
|
||||
self.Registration.sudo(self.user_eventuser).create({
|
||||
self.Registration.with_user(self.user_eventuser).create({
|
||||
'event_id': test_event.id,
|
||||
'name': 'Reg1',
|
||||
'email': 'reg1@example.com',
|
||||
|
||||
@@ -581,7 +581,7 @@ class Challenge(models.Model):
|
||||
if not lines:
|
||||
continue
|
||||
|
||||
body_html = MailTemplates.sudo(user).with_context(challenge_lines=lines)._render_template(
|
||||
body_html = MailTemplates.with_user(user).with_context(challenge_lines=lines)._render_template(
|
||||
challenge.report_template_id.body_html,
|
||||
'gamification.challenge',
|
||||
challenge.id)
|
||||
|
||||
@@ -81,7 +81,7 @@ class GoalDefinition(models.Model):
|
||||
Obj = self.env[definition.model_id.model]
|
||||
try:
|
||||
domain = safe_eval(definition.domain, {
|
||||
'user': self.env.user.sudo(self.env.user)
|
||||
'user': self.env.user.with_user(self.env.user)
|
||||
})
|
||||
# dummy search to make sure the domain is valid
|
||||
Obj.search_count(domain)
|
||||
@@ -429,7 +429,7 @@ class Goal(models.Model):
|
||||
action = self.definition_id.action_id.read()[0]
|
||||
|
||||
if self.definition_id.res_id_field:
|
||||
current_user = self.env.user.sudo(self.env.user)
|
||||
current_user = self.env.user.with_user(self.env.user)
|
||||
action['res_id'] = safe_eval(self.definition_id.res_id_field, {
|
||||
'user': current_user
|
||||
})
|
||||
|
||||
@@ -547,7 +547,7 @@ class GoogleCalendar(models.AbstractModel):
|
||||
for user_to_sync in users.ids:
|
||||
_logger.info("Calendar Synchro - Starting synchronization for a new user [%s]", user_to_sync)
|
||||
try:
|
||||
resp = self.sudo(user_to_sync).synchronize_events(lastSync=True)
|
||||
resp = self.with_user(user_to_sync).synchronize_events(lastSync=True)
|
||||
if resp.get("status") == "need_reset":
|
||||
_logger.info("[%s] Calendar Synchro - Failed - NEED RESET !", user_to_sync)
|
||||
else:
|
||||
@@ -561,7 +561,7 @@ class GoogleCalendar(models.AbstractModel):
|
||||
user_to_sync = self.ids and self.ids[0] or self.env.uid
|
||||
current_user = self.env['res.users'].sudo().browse(user_to_sync)
|
||||
|
||||
recs = self.sudo(user_to_sync)
|
||||
recs = self.with_user(user_to_sync)
|
||||
status, current_google, ask_time = recs.get_calendar_primary_id()
|
||||
if current_user.google_calendar_cal_id:
|
||||
if current_google != current_user.google_calendar_cal_id:
|
||||
|
||||
@@ -158,7 +158,7 @@ class HrEmployeePrivate(models.Model):
|
||||
def get_formview_id(self, access_uid=None):
|
||||
""" Override this method in order to redirect many2one towards the right model depending on access_uid """
|
||||
if access_uid:
|
||||
self_sudo = self.sudo(access_uid)
|
||||
self_sudo = self.with_user(access_uid)
|
||||
else:
|
||||
self_sudo = self
|
||||
|
||||
@@ -172,7 +172,7 @@ class HrEmployeePrivate(models.Model):
|
||||
""" Override this method in order to redirect many2one towards the right model depending on access_uid """
|
||||
res = super(HrEmployeePrivate, self).get_formview_action(access_uid=access_uid)
|
||||
if access_uid:
|
||||
self_sudo = self.sudo(access_uid)
|
||||
self_sudo = self.with_user(access_uid)
|
||||
else:
|
||||
self_sudo = self
|
||||
|
||||
@@ -323,7 +323,7 @@ class HrEmployeePrivate(models.Model):
|
||||
"""
|
||||
real_user = self.env.context.get('binary_field_real_user')
|
||||
if self.env.user.id == SUPERUSER_ID and real_user:
|
||||
self = self.sudo(real_user)
|
||||
self = self.with_user(real_user)
|
||||
return self
|
||||
|
||||
def _message_log(self, **kwargs):
|
||||
|
||||
@@ -10,7 +10,7 @@ class TestHrEmployee(TestHrCommon):
|
||||
def test_employee_resource(self):
|
||||
_tz = 'Pacific/Apia'
|
||||
self.res_users_hr_officer.company_id.resource_calendar_id.tz = _tz
|
||||
Employee = self.env['hr.employee'].sudo(self.res_users_hr_officer)
|
||||
Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer)
|
||||
employee_form = Form(Employee)
|
||||
employee_form.name = 'Raoul Grosbedon'
|
||||
employee_form.work_email = 'raoul@example.com'
|
||||
@@ -22,7 +22,7 @@ class TestHrEmployee(TestHrCommon):
|
||||
_tz2 = 'America/Tijuana'
|
||||
self.res_users_hr_officer.company_id.resource_calendar_id.tz = _tz
|
||||
self.res_users_hr_officer.tz = _tz2
|
||||
Employee = self.env['hr.employee'].sudo(self.res_users_hr_officer)
|
||||
Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer)
|
||||
employee_form = Form(Employee)
|
||||
employee_form.name = 'Raoul Grosbedon'
|
||||
employee_form.work_email = 'raoul@example.com'
|
||||
@@ -35,7 +35,7 @@ class TestHrEmployee(TestHrCommon):
|
||||
def test_employee_from_user_tz_no_reset(self):
|
||||
_tz = 'Pacific/Apia'
|
||||
self.res_users_hr_officer.tz = False
|
||||
Employee = self.env['hr.employee'].sudo(self.res_users_hr_officer)
|
||||
Employee = self.env['hr.employee'].with_user(self.res_users_hr_officer)
|
||||
employee_form = Form(Employee)
|
||||
employee_form.name = 'Raoul Grosbedon'
|
||||
employee_form.work_email = 'raoul@example.com'
|
||||
|
||||
@@ -22,7 +22,7 @@ class TestMultiCompany(TestHrCommon):
|
||||
]
|
||||
|
||||
def test_multi_company_report(self):
|
||||
content, content_type = self.env.ref('hr.hr_employee_print_badge').sudo(self.res_users_hr_officer).with_context(
|
||||
content, content_type = self.env.ref('hr.hr_employee_print_badge').with_user(self.res_users_hr_officer).with_context(
|
||||
allowed_company_ids=[self.company_1.id, self.company_2.id]
|
||||
).render_qweb_pdf(res_ids=self.employees.ids)
|
||||
self.assertIn(b'Bidule', content)
|
||||
@@ -30,6 +30,6 @@ class TestMultiCompany(TestHrCommon):
|
||||
|
||||
def test_single_company_report(self):
|
||||
with self.assertRaises(QWebException): # CacheMiss followed by AccessError
|
||||
content, content_type = self.env.ref('hr.hr_employee_print_badge').sudo(self.res_users_hr_officer).with_context(
|
||||
content, content_type = self.env.ref('hr.hr_employee_print_badge').with_user(self.res_users_hr_officer).with_context(
|
||||
allowed_company_ids=[self.company_1.id]
|
||||
).render_qweb_pdf(res_ids=self.employees.ids)
|
||||
|
||||
@@ -37,37 +37,37 @@ class TestSelfAccessRights(TestHrCommon):
|
||||
# Read hr.employee #
|
||||
def testReadSelfEmployee(self):
|
||||
with self.assertRaises(AccessError):
|
||||
self.hubert_emp.sudo(self.richard).read(self.protected_fields_emp.keys())
|
||||
self.hubert_emp.with_user(self.richard).read(self.protected_fields_emp.keys())
|
||||
|
||||
def testReadOtherEmployee(self):
|
||||
with self.assertRaises(AccessError):
|
||||
self.hubert_emp.sudo(self.richard).read(self.protected_fields_emp.keys())
|
||||
self.hubert_emp.with_user(self.richard).read(self.protected_fields_emp.keys())
|
||||
|
||||
# Write hr.employee #
|
||||
def testWriteSelfEmployee(self):
|
||||
for f in self.protected_fields_emp:
|
||||
with self.assertRaises(AccessError):
|
||||
self.richard_emp.sudo(self.richard).write({f: 'dummy'})
|
||||
self.richard_emp.with_user(self.richard).write({f: 'dummy'})
|
||||
|
||||
def testWriteOtherEmployee(self):
|
||||
for f in self.protected_fields_emp:
|
||||
with self.assertRaises(AccessError):
|
||||
self.hubert_emp.sudo(self.richard).write({f: 'dummy'})
|
||||
self.hubert_emp.with_user(self.richard).write({f: 'dummy'})
|
||||
|
||||
# Read res.users #
|
||||
def testReadSelfUserEmployee(self):
|
||||
for f in self.self_protected_fields_user:
|
||||
self.richard.sudo(self.richard).read([f]) # should not raise
|
||||
self.richard.with_user(self.richard).read([f]) # should not raise
|
||||
|
||||
def testReadOtherUserEmployee(self):
|
||||
with self.assertRaises(AccessError):
|
||||
self.hubert.sudo(self.richard).read(self.self_protected_fields_user)
|
||||
self.hubert.with_user(self.richard).read(self.self_protected_fields_user)
|
||||
|
||||
# Write res.users #
|
||||
def testWriteSelfUserEmployeeSettingFalse(self):
|
||||
for f, v in self.self_protected_fields_user.items():
|
||||
with self.assertRaises(AccessError):
|
||||
self.richard.sudo(self.richard).write({f: 'dummy'})
|
||||
self.richard.with_user(self.richard).write({f: 'dummy'})
|
||||
|
||||
def testWriteSelfUserEmployee(self):
|
||||
self.env['ir.config_parameter'].set_param('hr.hr_employee_self_edit', True)
|
||||
@@ -76,7 +76,7 @@ class TestSelfAccessRights(TestHrCommon):
|
||||
if v.type == 'char' or v.type == 'text':
|
||||
val = '0000' if f == 'pin' else 'dummy'
|
||||
if val is not None:
|
||||
self.richard.sudo(self.richard).write({f: val})
|
||||
self.richard.with_user(self.richard).write({f: val})
|
||||
|
||||
def testWriteSelfUserPreferencesEmployee(self):
|
||||
# self should always be able to update non hr.employee fields if
|
||||
@@ -91,7 +91,7 @@ class TestSelfAccessRights(TestHrCommon):
|
||||
]
|
||||
for v in vals:
|
||||
# should not raise
|
||||
self.richard.sudo(self.richard).write(v)
|
||||
self.richard.with_user(self.richard).write(v)
|
||||
|
||||
def testWriteOtherUserPreferencesEmployee(self):
|
||||
# self should always be able to update non hr.employee fields if
|
||||
@@ -105,15 +105,15 @@ class TestSelfAccessRights(TestHrCommon):
|
||||
]
|
||||
for v in vals:
|
||||
with self.assertRaises(AccessError):
|
||||
self.hubert.sudo(self.richard).write(v)
|
||||
self.hubert.with_user(self.richard).write(v)
|
||||
|
||||
def testWriteSelfPhoneEmployee(self):
|
||||
# phone is a related from res.partner (from base) but added in SELF_READABLE_FIELDS
|
||||
self.env['ir.config_parameter'].set_param('hr.hr_employee_self_edit', False)
|
||||
with self.assertRaises(AccessError):
|
||||
self.richard.sudo(self.richard).write({'phone': '2154545'})
|
||||
self.richard.with_user(self.richard).write({'phone': '2154545'})
|
||||
|
||||
def testWriteOtherUserEmployee(self):
|
||||
for f in self.self_protected_fields_user:
|
||||
with self.assertRaises(AccessError):
|
||||
self.hubert.sudo(self.richard).write({f: 'dummy'})
|
||||
self.hubert.with_user(self.richard).write({f: 'dummy'})
|
||||
|
||||
@@ -97,7 +97,7 @@ class HrEmployeeBase(models.AbstractModel):
|
||||
action_message['next_action'] = next_action
|
||||
|
||||
if employee.user_id:
|
||||
modified_attendance = employee.sudo(employee.user_id.id)._attendance_action_change()
|
||||
modified_attendance = employee.with_user(employee.user_id)._attendance_action_change()
|
||||
else:
|
||||
modified_attendance = employee._attendance_action_change()
|
||||
action_message['attendance'] = modified_attendance.read()[0]
|
||||
|
||||
@@ -36,15 +36,15 @@ class TestHrAttendance(TransactionCase):
|
||||
|
||||
def test_checkin_self_without_pin(self):
|
||||
""" Employee can check in/out without pin with his own account """
|
||||
employee = self.test_employee.sudo(self.user)
|
||||
employee.sudo(self.user).attendance_manual({}, entered_pin=None)
|
||||
employee = self.test_employee.with_user(self.user)
|
||||
employee.with_user(self.user).attendance_manual({}, entered_pin=None)
|
||||
self.assertEqual(employee.attendance_state, 'checked_in', "He should be able to check in without pin")
|
||||
employee.attendance_manual({}, entered_pin=None)
|
||||
self.assertEqual(employee.attendance_state, 'checked_out', "He should be able to check out without pin")
|
||||
|
||||
def test_checkin_self_with_pin(self):
|
||||
""" Employee can check in/out with pin with his own account """
|
||||
employee = self.test_employee.sudo(self.user)
|
||||
employee = self.test_employee.with_user(self.user)
|
||||
employee.attendance_manual({}, entered_pin='1234')
|
||||
self.assertEqual(employee.attendance_state, 'checked_in', "He should be able to check in with his pin")
|
||||
employee.attendance_manual({}, entered_pin='1234')
|
||||
@@ -52,14 +52,14 @@ class TestHrAttendance(TransactionCase):
|
||||
|
||||
def test_checkin_self_wrong_pin(self):
|
||||
""" Employee cannot check in/out with wrong pin with his own account """
|
||||
employee = self.test_employee.sudo(self.user)
|
||||
employee = self.test_employee.with_user(self.user)
|
||||
action = employee.attendance_manual({}, entered_pin='9999')
|
||||
self.assertNotEqual(employee.attendance_state, 'checked_in', "He should not be able to check in with a wrong pin")
|
||||
self.assertTrue(action.get('warning'))
|
||||
|
||||
def test_checkin_kiosk_with_pin(self):
|
||||
""" Employee can check in/out with his pin in kiosk """
|
||||
employee = self.employee_kiosk.sudo(self.user)
|
||||
employee = self.employee_kiosk.with_user(self.user)
|
||||
employee.attendance_manual({}, entered_pin='5678')
|
||||
self.assertEqual(employee.attendance_state, 'checked_in', "He should be able to check in with his pin")
|
||||
employee.attendance_manual({}, entered_pin='5678')
|
||||
@@ -67,21 +67,21 @@ class TestHrAttendance(TransactionCase):
|
||||
|
||||
def test_checkin_kiosk_with_wrong_pin(self):
|
||||
""" Employee cannot check in/out with wrong pin in kiosk """
|
||||
employee = self.employee_kiosk.sudo(self.user)
|
||||
employee = self.employee_kiosk.with_user(self.user)
|
||||
action = employee.attendance_manual({}, entered_pin='8888')
|
||||
self.assertNotEqual(employee.attendance_state, 'checked_in', "He should not be able to check in with a wrong pin")
|
||||
self.assertTrue(action.get('warning'))
|
||||
|
||||
def test_checkin_kiosk_without_pin(self):
|
||||
""" Employee cannot check in/out without his pin in kiosk """
|
||||
employee = self.employee_kiosk.sudo(self.user)
|
||||
employee = self.employee_kiosk.with_user(self.user)
|
||||
action = employee.attendance_manual({}, entered_pin=None)
|
||||
self.assertNotEqual(employee.attendance_state, 'checked_in', "He should not be able to check in with no pin")
|
||||
self.assertTrue(action.get('warning'))
|
||||
|
||||
def test_checkin_kiosk_no_pin_mode(self):
|
||||
""" Employee can check in/out without pin in kiosk when user has not group `use_pin` """
|
||||
employee = self.employee_kiosk.sudo(self.user_no_pin)
|
||||
employee = self.employee_kiosk.with_user(self.user_no_pin)
|
||||
employee.attendance_manual({}, entered_pin=None)
|
||||
self.assertEqual(employee.attendance_state, 'checked_in', "He should be able to check in with his pin")
|
||||
employee.attendance_manual({}, entered_pin=None)
|
||||
|
||||
@@ -195,7 +195,7 @@ class TestExpenseRights(TestExpenseCommon):
|
||||
|
||||
def test_expense_create(self):
|
||||
# Employee should be able to create an Expense
|
||||
self.env['hr.expense'].sudo(self.user_employee.id).create({
|
||||
self.env['hr.expense'].with_user(self.user_employee).create({
|
||||
'name': 'Batmobile repair',
|
||||
'employee_id': self.employee.id,
|
||||
'product_id': self.product_1.id,
|
||||
@@ -205,7 +205,7 @@ class TestExpenseRights(TestExpenseCommon):
|
||||
|
||||
# Employee should not be able to create an Expense for someone else
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['hr.expense'].sudo(self.user_employee.id).create({
|
||||
self.env['hr.expense'].with_user(self.user_employee).create({
|
||||
'name': 'Superboy costume washing',
|
||||
'employee_id': self.emp_emp2.id,
|
||||
'product_id': self.product_2.id,
|
||||
@@ -231,19 +231,19 @@ class TestExpenseRights(TestExpenseCommon):
|
||||
|
||||
# Employee should not be able to approve expense sheet
|
||||
with self.assertRaises(UserError):
|
||||
sheet.sudo(self.user_officer).approve_expense_sheets()
|
||||
sheet.with_user(self.user_officer).approve_expense_sheets()
|
||||
# Officer should not be able to approve own expense sheet
|
||||
with self.assertRaises(UserError):
|
||||
sheet.sudo(self.user_officer).approve_expense_sheets()
|
||||
sheet.sudo(self.user_manager).approve_expense_sheets()
|
||||
sheet.with_user(self.user_officer).approve_expense_sheets()
|
||||
sheet.with_user(self.user_manager).approve_expense_sheets()
|
||||
|
||||
# Officer should be able to approve expense from his department
|
||||
sheet_2.sudo(self.user_officer).approve_expense_sheets()
|
||||
sheet_2.with_user(self.user_officer).approve_expense_sheets()
|
||||
|
||||
# Officer should not be able to approve expense sheet from another department
|
||||
with self.assertRaises(AccessError):
|
||||
sheet_3.sudo(self.user_officer).approve_expense_sheets()
|
||||
sheet_3.sudo(self.user_manager).approve_expense_sheets()
|
||||
sheet_3.with_user(self.user_officer).approve_expense_sheets()
|
||||
sheet_3.with_user(self.user_manager).approve_expense_sheets()
|
||||
|
||||
def test_expense_refuse(self):
|
||||
sheet = self.env['hr.expense.sheet'].create({
|
||||
@@ -261,22 +261,22 @@ class TestExpenseRights(TestExpenseCommon):
|
||||
'employee_id': self.emp_emp2.id,
|
||||
})
|
||||
|
||||
sheet.sudo(self.user_manager).approve_expense_sheets()
|
||||
sheet_2.sudo(self.user_manager).approve_expense_sheets()
|
||||
sheet_3.sudo(self.user_manager).approve_expense_sheets()
|
||||
sheet.with_user(self.user_manager).approve_expense_sheets()
|
||||
sheet_2.with_user(self.user_manager).approve_expense_sheets()
|
||||
sheet_3.with_user(self.user_manager).approve_expense_sheets()
|
||||
|
||||
# Employee should not be able to refuse expense sheet
|
||||
with self.assertRaises(UserError):
|
||||
sheet.sudo(self.user_employee).refuse_sheet('')
|
||||
sheet.with_user(self.user_employee).refuse_sheet('')
|
||||
# Officer should not be able to refuse own expense sheet
|
||||
with self.assertRaises(UserError):
|
||||
sheet.sudo(self.user_officer).refuse_sheet('')
|
||||
sheet.sudo(self.user_manager).refuse_sheet('')
|
||||
sheet.with_user(self.user_officer).refuse_sheet('')
|
||||
sheet.with_user(self.user_manager).refuse_sheet('')
|
||||
|
||||
# Officer should be able to refuse expense from his department
|
||||
sheet_2.sudo(self.user_officer).refuse_sheet('')
|
||||
sheet_2.with_user(self.user_officer).refuse_sheet('')
|
||||
|
||||
# Officer should not be able to refuse expense sheet from another department
|
||||
with self.assertRaises(AccessError):
|
||||
sheet_3.sudo(self.user_officer).refuse_sheet('')
|
||||
sheet_3.sudo(self.user_manager).refuse_sheet('')
|
||||
sheet_3.with_user(self.user_officer).refuse_sheet('')
|
||||
sheet_3.with_user(self.user_manager).refuse_sheet('')
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
self.rd_dept.manager_id = False
|
||||
self.hr_dept.manager_id = False
|
||||
self.employee_emp.parent_id = False
|
||||
self.employee_leave = self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
self.employee_leave = self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Test',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'department_id': self.employee_emp.department_id.id,
|
||||
@@ -37,15 +37,15 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_messaging_by_user(self):
|
||||
""" User may communicate on its own leaves, even if validated """
|
||||
self.employee_leave.sudo(self.user_employee_id).message_post(
|
||||
self.employee_leave.with_user(self.user_employee_id).message_post(
|
||||
body='I haz messaging',
|
||||
subtype='mail.mt_comment',
|
||||
message_type='comment'
|
||||
)
|
||||
|
||||
self.employee_leave.sudo(self.user_hrmanager_id).action_approve()
|
||||
self.employee_leave.with_user(self.user_hrmanager_id).action_approve()
|
||||
|
||||
self.employee_leave.sudo(self.user_employee_id).message_post(
|
||||
self.employee_leave.with_user(self.user_employee_id).message_post(
|
||||
body='I still haz messaging',
|
||||
subtype='mail.mt_comment',
|
||||
message_type='comment'
|
||||
@@ -54,7 +54,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_read_by_user_other(self):
|
||||
""" Users should be able to read other people requests except name field """
|
||||
other_leave = self.env['hr.leave'].sudo(self.user_hruser).create({
|
||||
other_leave = self.env['hr.leave'].with_user(self.user_hruser).create({
|
||||
'name': 'Test',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'department_id': self.employee_hruser.department_id.id,
|
||||
@@ -63,7 +63,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'date_to': datetime.now() + relativedelta(days=1),
|
||||
'number_of_days': 1,
|
||||
})
|
||||
res = other_leave.sudo(self.user_employee_id).read(['number_of_days', 'state', 'name'])
|
||||
res = other_leave.with_user(self.user_employee_id).read(['number_of_days', 'state', 'name'])
|
||||
self.assertEqual(
|
||||
res[0]['name'], '*****',
|
||||
'Private information should have been stripped, received %s instead' % res[0]['name']
|
||||
@@ -72,7 +72,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_read_by_user_other_browse(self):
|
||||
""" Users should be able to browse other people requests except name field """
|
||||
other_leave = self.env['hr.leave'].sudo(self.user_hruser).create({
|
||||
other_leave = self.env['hr.leave'].with_user(self.user_hruser).create({
|
||||
'name': 'Test',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'department_id': self.employee_hruser.department_id.id,
|
||||
@@ -82,8 +82,8 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'number_of_days': 1,
|
||||
})
|
||||
self.assertEqual(
|
||||
other_leave.sudo(self.user_employee_id).name, '*****',
|
||||
'Private information should have been stripped, received %s instead' % other_leave.sudo(self.user_employee_id).name
|
||||
other_leave.with_user(self.user_employee_id).name, '*****',
|
||||
'Private information should have been stripped, received %s instead' % other_leave.with_user(self.user_employee_id).name
|
||||
)
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
@@ -101,12 +101,12 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_update_hr_by_user(self):
|
||||
""" User may update its leave """
|
||||
self.employee_leave.sudo(self.user_employee_id).write({'name': 'Crocodile Dundee is my man'})
|
||||
self.employee_leave.with_user(self.user_employee_id).write({'name': 'Crocodile Dundee is my man'})
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_update_hr_by_user_other(self):
|
||||
""" User cannot update other people leaves """
|
||||
other_leave = self.env['hr.leave'].sudo(self.user_hruser).create({
|
||||
other_leave = self.env['hr.leave'].with_user(self.user_hruser).create({
|
||||
'name': 'Test',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'department_id': self.employee_hruser.department_id.id,
|
||||
@@ -116,7 +116,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'number_of_days': 1,
|
||||
})
|
||||
with self.assertRaises(AccessError):
|
||||
other_leave.sudo(self.user_employee_id).write({'name': 'Crocodile Dundee is my man'})
|
||||
other_leave.with_user(self.user_employee_id).write({'name': 'Crocodile Dundee is my man'})
|
||||
|
||||
# ----------------------------------------
|
||||
# Creation
|
||||
@@ -125,7 +125,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_creation_for_other_user(self):
|
||||
""" Employee cannot creates a leave request for another employee """
|
||||
HolidaysEmployeeGroup = self.env['hr.leave'].sudo(self.user_employee_id)
|
||||
HolidaysEmployeeGroup = self.env['hr.leave'].with_user(self.user_employee_id)
|
||||
with self.assertRaises(AccessError):
|
||||
HolidaysEmployeeGroup.create({
|
||||
'name': 'Hol10',
|
||||
@@ -143,7 +143,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_reset_by_manager(self):
|
||||
""" Manager resets its own leaves """
|
||||
manager_leave = self.env['hr.leave'].sudo(self.user_hrmanager).create({
|
||||
manager_leave = self.env['hr.leave'].with_user(self.user_hrmanager).create({
|
||||
'name': 'Test',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'department_id': self.employee_hrmanager.department_id.id,
|
||||
@@ -152,17 +152,17 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'date_to': datetime.now() + relativedelta(days=1),
|
||||
'number_of_days': 1,
|
||||
})
|
||||
manager_leave.sudo(self.user_hrmanager).action_draft()
|
||||
manager_leave.with_user(self.user_hrmanager).action_draft()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_reset_by_manager_other(self):
|
||||
""" Manager may reset other leaves """
|
||||
self.employee_leave.sudo(self.user_hrmanager).action_draft()
|
||||
self.employee_leave.with_user(self.user_hrmanager).action_draft()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_reset_by_officer(self):
|
||||
""" Officer resets its own leaves """
|
||||
officer_leave = self.env['hr.leave'].sudo(self.user_hruser).create({
|
||||
officer_leave = self.env['hr.leave'].with_user(self.user_hruser).create({
|
||||
'name': 'Test',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'department_id': self.employee_hruser.department_id.id,
|
||||
@@ -171,23 +171,23 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'date_to': datetime.now() + relativedelta(days=1),
|
||||
'number_of_days': 1,
|
||||
})
|
||||
officer_leave.sudo(self.user_hruser).action_draft()
|
||||
officer_leave.with_user(self.user_hruser).action_draft()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_reset_by_officer_other(self):
|
||||
""" Officer may not reset other leaves """
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_leave.sudo(self.user_hruser).action_draft()
|
||||
self.employee_leave.with_user(self.user_hruser).action_draft()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_reset_by_user(self):
|
||||
""" User resets its own leaves """
|
||||
self.employee_leave.sudo(self.user_employee_id).action_draft()
|
||||
self.employee_leave.with_user(self.user_employee_id).action_draft()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_reset_by_user_other(self):
|
||||
""" User may not reset other leaves """
|
||||
other_leave = self.env['hr.leave'].sudo(self.user_hruser).create({
|
||||
other_leave = self.env['hr.leave'].with_user(self.user_hruser).create({
|
||||
'name': 'Test',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'department_id': self.employee_hruser.department_id.id,
|
||||
@@ -197,7 +197,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'number_of_days': 1,
|
||||
})
|
||||
with self.assertRaises(UserError):
|
||||
other_leave.sudo(self.user_employee_id).action_draft()
|
||||
other_leave.with_user(self.user_employee_id).action_draft()
|
||||
|
||||
# ----------------------------------------
|
||||
# Validation: one validation, HR
|
||||
@@ -207,14 +207,14 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
def test_leave_validation_hr_by_manager(self):
|
||||
""" Manager validates hr-only leaves """
|
||||
self.assertEqual(self.employee_leave.state, 'confirm')
|
||||
self.employee_leave.sudo(self.user_hrmanager_id).action_approve()
|
||||
self.employee_leave.with_user(self.user_hrmanager_id).action_approve()
|
||||
self.assertEqual(self.employee_leave.state, 'validate')
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_hr_by_officer_department(self):
|
||||
""" Officer validates hr-only leaves for co-workers """
|
||||
self.assertEqual(self.employee_leave.state, 'confirm')
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
self.assertEqual(self.employee_leave.state, 'validate')
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
@@ -222,14 +222,14 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
""" Officer validates hr-only leaves for workers from no department and with no manager """
|
||||
self.employee_hruser.write({'department_id': False})
|
||||
with self.assertRaises(AccessError):
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_hr_by_officer_other_department_with_manager(self):
|
||||
""" Officer may not validate hr-only leaves for workers from another department that has a manager """
|
||||
self.employee_hruser.write({'department_id': self.hr_dept.id})
|
||||
with self.assertRaises(AccessError):
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
self.assertEqual(self.employee_leave.state, 'confirm')
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
@@ -237,7 +237,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
""" Officer may not validate hr-only leaves for workers from another department that has no manager """
|
||||
self.employee_hruser.write({'department_id': self.hr_dept.id})
|
||||
with self.assertRaises(AccessError):
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
self.assertEqual(self.employee_leave.state, 'confirm')
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
@@ -247,22 +247,22 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
self.employee_leave.sudo().department_id.write({'manager_id': self.employee_hruser.id})
|
||||
|
||||
self.assertEqual(self.employee_leave.state, 'confirm')
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
self.assertEqual(self.employee_leave.state, 'validate')
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_hr_by_user(self):
|
||||
""" User may not validate any leaves """
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_leave.sudo(self.user_employee_id).action_approve()
|
||||
self.employee_leave.with_user(self.user_employee_id).action_approve()
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_leave.sudo(self.user_employee_id).write({'state': 'validate'})
|
||||
self.employee_leave.with_user(self.user_employee_id).write({'state': 'validate'})
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validate_by_manager(self):
|
||||
""" Manager (who has no manager) validate its own leaves """
|
||||
manager_leave = self.env['hr.leave'].sudo(self.user_hrmanager_id).create({
|
||||
manager_leave = self.env['hr.leave'].with_user(self.user_hrmanager_id).create({
|
||||
'name': 'Hol manager',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'employee_id': self.employee_hrmanager_id,
|
||||
@@ -277,7 +277,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validate_by_manager_2(self):
|
||||
""" Manager (who has also a manager) validate its own leaves """
|
||||
manager_leave2 = self.env['hr.leave'].sudo(self.user_hrmanager_2_id).create({
|
||||
manager_leave2 = self.env['hr.leave'].with_user(self.user_hrmanager_2_id).create({
|
||||
'name': 'Hol manager2',
|
||||
'holiday_status_id': self.leave_type.id,
|
||||
'employee_id': self.employee_hrmanager_2_id,
|
||||
@@ -297,7 +297,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
def test_leave_validation_manager_by_manager(self):
|
||||
""" Manager validates manager-only leaves """
|
||||
self.leave_type.write({'validation_type': 'manager'})
|
||||
self.employee_leave.sudo(self.user_hrmanager_id).action_approve()
|
||||
self.employee_leave.with_user(self.user_hrmanager_id).action_approve()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_manager_by_officer_department_manager(self):
|
||||
@@ -305,7 +305,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
self.leave_type.write({'validation_type': 'manager'})
|
||||
self.employee_hruser.write({'department_id': self.hr_dept.id})
|
||||
self.employee_leave.sudo().department_id.write({'manager_id': self.employee_hruser.id})
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_manager_by_officer_department_manager_other(self):
|
||||
@@ -314,14 +314,14 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
self.employee_hruser.write({'department_id': self.hr_dept.id})
|
||||
self.employee_leave.sudo().department_id.write({'manager_id': self.employee_hrmanager.id})
|
||||
with self.assertRaises(AccessError):
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_manager_by_officer_manager(self):
|
||||
""" Officer validates manager-only leaves for co-workers that he manages"""
|
||||
self.leave_type.write({'validation_type': 'manager'})
|
||||
self.employee_emp.write({'parent_id': self.employee_hruser.id})
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_manager_by_officer_manager_other(self):
|
||||
@@ -329,10 +329,10 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
self.leave_type.write({'validation_type': 'manager'})
|
||||
self.employee_emp.write({'parent_id': self.employee_hrmanager.id})
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_leave.sudo(self.user_hruser).write({'state': 'validate'})
|
||||
self.employee_leave.with_user(self.user_hruser).write({'state': 'validate'})
|
||||
|
||||
# ----------------------------------------
|
||||
# Validation: double
|
||||
@@ -342,26 +342,26 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
def test_leave_validation_both_by_manager(self):
|
||||
""" Manager validates double validation leaves """
|
||||
self.leave_type.write({'validation_type': 'both'})
|
||||
self.employee_leave.sudo(self.user_hrmanager_id).action_approve()
|
||||
self.employee_leave.sudo(self.user_hrmanager_id).action_validate()
|
||||
self.employee_leave.with_user(self.user_hrmanager_id).action_approve()
|
||||
self.employee_leave.with_user(self.user_hrmanager_id).action_validate()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_both_by_officer(self):
|
||||
""" Officer may not validate double validation leaves """
|
||||
self.leave_type.write({'validation_type': 'both'})
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_leave.sudo(self.user_hruser).action_validate()
|
||||
self.employee_leave.with_user(self.user_hruser).action_validate()
|
||||
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_leave.sudo(self.user_hruser).write({'state': 'validate'})
|
||||
self.employee_leave.with_user(self.user_hruser).write({'state': 'validate'})
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_both_by_officer_and_manager(self):
|
||||
""" Officer + Manager complete double validation leaves """
|
||||
self.leave_type.write({'validation_type': 'both'})
|
||||
self.employee_leave.sudo(self.user_hruser).action_approve()
|
||||
self.employee_leave.sudo(self.user_hrmanager_id).action_validate()
|
||||
self.employee_leave.with_user(self.user_hruser).action_approve()
|
||||
self.employee_leave.with_user(self.user_hrmanager_id).action_validate()
|
||||
|
||||
# ----------------------------------------
|
||||
# Validation: team leader
|
||||
@@ -377,7 +377,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'number_of_days': 10,
|
||||
}).action_approve()
|
||||
with self.assertRaises(AccessError):
|
||||
self.employee_leave.sudo(self.user_team_leader).action_approve()
|
||||
self.employee_leave.with_user(self.user_team_leader).action_approve()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_validation_team_leader(self):
|
||||
@@ -392,7 +392,7 @@ class TestLeavesRights(TestHrHolidaysBase):
|
||||
'employee_id': self.employee_emp.id,
|
||||
'number_of_days': 10,
|
||||
}).action_approve()
|
||||
self.employee_leave.sudo(self.user_team_leader).action_approve()
|
||||
self.employee_leave.with_user(self.user_team_leader).action_approve()
|
||||
|
||||
|
||||
class TestMultiCompany(TestHrHolidaysBase):
|
||||
@@ -423,7 +423,7 @@ class TestMultiCompany(TestHrHolidaysBase):
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_access_other_company_user(self):
|
||||
employee_leave = self.employee_leave.sudo(self.user_employee)
|
||||
employee_leave = self.employee_leave.with_user(self.user_employee)
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
name = employee_leave.name
|
||||
@@ -433,7 +433,7 @@ class TestMultiCompany(TestHrHolidaysBase):
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_access_other_company_officer(self):
|
||||
employee_leave_hruser = self.employee_leave.sudo(self.user_hruser)
|
||||
employee_leave_hruser = self.employee_leave.with_user(self.user_hruser)
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
name = employee_leave_hruser.name
|
||||
@@ -443,7 +443,7 @@ class TestMultiCompany(TestHrHolidaysBase):
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_access_other_company_manager(self):
|
||||
employee_leave_hrmanager = self.employee_leave.sudo(self.user_hrmanager)
|
||||
employee_leave_hrmanager = self.employee_leave.with_user(self.user_hrmanager)
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
name = employee_leave_hrmanager.name
|
||||
@@ -454,7 +454,7 @@ class TestMultiCompany(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_access_no_company_user(self):
|
||||
self.leave_type.write({'company_id': False})
|
||||
employee_leave = self.employee_leave.sudo(self.user_employee)
|
||||
employee_leave = self.employee_leave.with_user(self.user_employee)
|
||||
|
||||
name = employee_leave.name
|
||||
with self.assertRaises(UserError):
|
||||
@@ -464,7 +464,7 @@ class TestMultiCompany(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_access_no_company_officer(self):
|
||||
self.leave_type.write({'company_id': False})
|
||||
employee_leave_hruser = self.employee_leave.sudo(self.user_hruser)
|
||||
employee_leave_hruser = self.employee_leave.with_user(self.user_hruser)
|
||||
|
||||
name = employee_leave_hruser.name
|
||||
employee_leave_hruser.action_approve()
|
||||
@@ -473,7 +473,7 @@ class TestMultiCompany(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_leave_access_no_company_manager(self):
|
||||
self.leave_type.write({'company_id': False})
|
||||
employee_leave_hrmanager = self.employee_leave.sudo(self.user_hrmanager)
|
||||
employee_leave_hrmanager = self.employee_leave.with_user(self.user_hrmanager)
|
||||
|
||||
name = employee_leave_hrmanager.name
|
||||
employee_leave_hrmanager.action_approve()
|
||||
|
||||
@@ -15,7 +15,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
super(TestAccrualAllocations, self).setUp()
|
||||
|
||||
# Make sure we have the rights to create, validate and delete the leaves, leave types and allocations
|
||||
LeaveType = self.env['hr.leave.type'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
LeaveType = self.env['hr.leave.type'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
|
||||
self.accrual_type = LeaveType.create({
|
||||
'name': 'accrual',
|
||||
@@ -47,7 +47,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
|
||||
def test_accrual_base_no_leaves(self):
|
||||
""" Test if we can allocate some leaves accrually to an employee """
|
||||
alloc = self.env['hr.leave.allocation'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
alloc = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
'name': 'Accrual allocation for employee',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.accrual_type.id,
|
||||
@@ -65,7 +65,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
|
||||
def test_accrual_base_leaves(self):
|
||||
""" Test if the accrual allocation take the unpaid leaves into account when allocating leaves """
|
||||
alloc = self.env['hr.leave.allocation'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
alloc = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
'name': 'Accrual allocation for employee with leaves',
|
||||
'employee_id': self.employee_hruser_id,
|
||||
'holiday_status_id': self.accrual_type.id,
|
||||
@@ -83,7 +83,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
# Getting the previous work date
|
||||
df = employee.resource_calendar_id.plan_days(-2, fields.Datetime.now()).date()
|
||||
|
||||
leave = self.env['hr.leave'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
leave = self.env['hr.leave'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
'name': 'Leave for hruser',
|
||||
'employee_id': self.employee_hruser_id,
|
||||
'holiday_status_id': self.unpaid_type.id,
|
||||
@@ -102,7 +102,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
"""
|
||||
Test different configuration of accrual allocations
|
||||
"""
|
||||
Allocation = self.env['hr.leave.allocation'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
Allocation = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
|
||||
alloc_0 = Allocation.create({
|
||||
'name': '1 day per 2 weeks',
|
||||
@@ -166,7 +166,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
Test if accrual allocation takes into account the creation date
|
||||
of an employee
|
||||
"""
|
||||
Allocation = self.env['hr.leave.allocation'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
Allocation = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
|
||||
self.set_employee_create_date(self.employee_emp_id, fields.Datetime.to_string(fields.Datetime.now()))
|
||||
|
||||
@@ -190,7 +190,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
|
||||
def test_accrual_multi(self):
|
||||
""" Test if the cron does not allocate leaves every time it's called but only when necessary """
|
||||
alloc = self.env['hr.leave.allocation'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
alloc = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
'name': '2 days per week',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.accrual_type.id,
|
||||
@@ -211,7 +211,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
"""
|
||||
Test if cron does not allocate past it's validity date
|
||||
"""
|
||||
Allocation = self.env['hr.leave.allocation'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
Allocation = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
|
||||
alloc_0 = Allocation.create({
|
||||
'name': '20 days per year',
|
||||
@@ -233,7 +233,7 @@ class TestAccrualAllocations(TestHrHolidaysBase):
|
||||
|
||||
def test_accrual_balance_limit(self):
|
||||
""" Test if accrual allocation does not allocate more than the balance limit"""
|
||||
allocation = self.env['hr.leave.allocation'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
allocation = self.env['hr.leave.allocation'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True).create({
|
||||
'name': 'accrual 5 max',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.accrual_type.id,
|
||||
|
||||
@@ -11,9 +11,9 @@ from odoo.addons.hr_holidays.tests.common import TestHrHolidaysBase
|
||||
class TestChangeDepartment(TestHrHolidaysBase):
|
||||
|
||||
def test_employee_change_department_request_change_department(self):
|
||||
self.HolidaysEmployeeGroup = self.env['hr.leave'].sudo(self.user_employee_id)
|
||||
self.HolidaysEmployeeGroup = self.env['hr.leave'].with_user(self.user_employee_id)
|
||||
|
||||
HolidayStatusManagerGroup = self.env['hr.leave.type'].sudo(self.user_hrmanager_id)
|
||||
HolidayStatusManagerGroup = self.env['hr.leave.type'].with_user(self.user_hrmanager_id)
|
||||
self.holidays_status_1 = HolidayStatusManagerGroup.create({
|
||||
'name': 'NotLimitedHR',
|
||||
'allocation_type': 'no',
|
||||
@@ -40,7 +40,7 @@ class TestChangeDepartment(TestHrHolidaysBase):
|
||||
# Approved passed leave request change department
|
||||
self.employee_emp.department_id = self.hr_dept
|
||||
hol2_employee_group = create_holiday("hol2", -4, -3)
|
||||
hol2_user_group = hol2_employee_group.sudo(self.user_hruser_id)
|
||||
hol2_user_group = hol2_employee_group.with_user(self.user_hruser_id)
|
||||
hol2_user_group.action_approve()
|
||||
self.employee_emp.department_id = self.rd_dept
|
||||
self.assertEqual(hol2_employee_group.department_id, self.hr_dept, 'hr_holidays: approved passed leave request should stay in previous department if employee change department')
|
||||
@@ -48,7 +48,7 @@ class TestChangeDepartment(TestHrHolidaysBase):
|
||||
# Approved futur leave request change department
|
||||
self.employee_emp.department_id = self.hr_dept
|
||||
hol22_employee_group = create_holiday("hol22", 3, 4)
|
||||
hol22_user_group = hol22_employee_group.sudo(self.user_hruser_id)
|
||||
hol22_user_group = hol22_employee_group.with_user(self.user_hruser_id)
|
||||
hol22_user_group.action_approve()
|
||||
self.employee_emp.department_id = self.rd_dept
|
||||
self.assertEqual(hol22_employee_group.department_id, self.rd_dept, 'hr_holidays: approved futur leave request should change department if employee change department')
|
||||
@@ -56,7 +56,7 @@ class TestChangeDepartment(TestHrHolidaysBase):
|
||||
# Refused passed leave request change department
|
||||
self.employee_emp.department_id = self.rd_dept
|
||||
hol3_employee_group = create_holiday("hol3", -6, -5)
|
||||
hol3_user_group = hol3_employee_group.sudo(self.user_hruser_id)
|
||||
hol3_user_group = hol3_employee_group.with_user(self.user_hruser_id)
|
||||
hol3_user_group.action_refuse()
|
||||
self.employee_emp.department_id = self.hr_dept # Change department
|
||||
self.assertEqual(hol3_employee_group.department_id, self.rd_dept, 'hr_holidays: refused passed leave request should stay in previous department if employee change department')
|
||||
@@ -64,7 +64,7 @@ class TestChangeDepartment(TestHrHolidaysBase):
|
||||
# Refused futur leave request change department
|
||||
self.employee_emp.department_id = self.rd_dept
|
||||
hol32_employee_group = create_holiday("hol32", 5, 6)
|
||||
hol32_user_group = hol32_employee_group.sudo(self.user_hruser_id)
|
||||
hol32_user_group = hol32_employee_group.with_user(self.user_hruser_id)
|
||||
hol32_user_group.action_refuse()
|
||||
self.employee_emp.department_id = self.hr_dept # Change department
|
||||
self.assertEqual(hol32_employee_group.department_id, self.hr_dept, 'hr_holidays: refused futur leave request should change department if employee change department')
|
||||
|
||||
@@ -19,11 +19,11 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
HolidaysStatus = self.env['hr.leave.type']
|
||||
|
||||
# HrManager creates some holiday statuses
|
||||
HolidayStatusManagerGroup = HolidaysStatus.sudo(self.user_hrmanager_id)
|
||||
HolidayStatusManagerGroup = HolidaysStatus.with_user(self.user_hrmanager_id)
|
||||
HolidayStatusManagerGroup.create({
|
||||
'name': 'WithMeetingType',
|
||||
'allocation_type': 'no',
|
||||
'categ_id': self.env['calendar.event.type'].sudo(self.user_hrmanager_id).create({'name': 'NotLimitedMeetingType'}).id
|
||||
'categ_id': self.env['calendar.event.type'].with_user(self.user_hrmanager_id).create({'name': 'NotLimitedMeetingType'}).id
|
||||
})
|
||||
self.holidays_status_hr = HolidayStatusManagerGroup.create({
|
||||
'name': 'NotLimitedHR',
|
||||
@@ -38,7 +38,7 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
HolidaysEmployeeGroup = Requests.sudo(self.user_employee_id)
|
||||
HolidaysEmployeeGroup = Requests.with_user(self.user_employee_id)
|
||||
|
||||
# Employee creates a leave request in a no-limit category hr manager only
|
||||
hol1_employee_group = HolidaysEmployeeGroup.create({
|
||||
@@ -49,8 +49,8 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'date_to': datetime.today(),
|
||||
'number_of_days': 1,
|
||||
})
|
||||
hol1_user_group = hol1_employee_group.sudo(self.user_hruser_id)
|
||||
hol1_manager_group = hol1_employee_group.sudo(self.user_hrmanager_id)
|
||||
hol1_user_group = hol1_employee_group.with_user(self.user_hruser_id)
|
||||
hol1_manager_group = hol1_employee_group.with_user(self.user_hrmanager_id)
|
||||
self.assertEqual(hol1_user_group.state, 'confirm', 'hr_holidays: newly created leave request should be in confirm state')
|
||||
|
||||
# HrUser validates the employee leave request -> should work
|
||||
@@ -66,8 +66,8 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'date_to': (datetime.today() + relativedelta(days=13)),
|
||||
'number_of_days': 1,
|
||||
})
|
||||
hol12_user_group = hol12_employee_group.sudo(self.user_hruser_id)
|
||||
hol12_manager_group = hol12_employee_group.sudo(self.user_hrmanager_id)
|
||||
hol12_user_group = hol12_employee_group.with_user(self.user_hruser_id)
|
||||
hol12_manager_group = hol12_employee_group.with_user(self.user_hrmanager_id)
|
||||
self.assertEqual(hol12_user_group.state, 'confirm', 'hr_holidays: newly created leave request should be in confirm state')
|
||||
|
||||
# HrManager validate the employee leave request
|
||||
@@ -93,11 +93,11 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'hr_holidays: wrong type days computation')
|
||||
|
||||
# HrManager creates some holiday statuses
|
||||
HolidayStatusManagerGroup = HolidaysStatus.sudo(self.user_hrmanager_id)
|
||||
HolidayStatusManagerGroup = HolidaysStatus.with_user(self.user_hrmanager_id)
|
||||
HolidayStatusManagerGroup.create({
|
||||
'name': 'WithMeetingType',
|
||||
'allocation_type': 'no',
|
||||
'categ_id': self.env['calendar.event.type'].sudo(self.user_hrmanager_id).create({'name': 'NotLimitedMeetingType'}).id,
|
||||
'categ_id': self.env['calendar.event.type'].with_user(self.user_hrmanager_id).create({'name': 'NotLimitedMeetingType'}).id,
|
||||
'validity_start': False,
|
||||
})
|
||||
|
||||
@@ -107,10 +107,10 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'validation_type': 'both',
|
||||
'validity_start': False,
|
||||
})
|
||||
HolidaysEmployeeGroup = Requests.sudo(self.user_employee_id)
|
||||
HolidaysEmployeeGroup = Requests.with_user(self.user_employee_id)
|
||||
|
||||
# HrUser allocates some leaves to the employee
|
||||
aloc1_user_group = Allocations.sudo(self.user_hruser_id).create({
|
||||
aloc1_user_group = Allocations.with_user(self.user_hruser_id).create({
|
||||
'name': 'Days for limited category',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_status_limited.id,
|
||||
@@ -120,9 +120,9 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
aloc1_user_group.action_approve()
|
||||
|
||||
# HrManager validates the second step
|
||||
aloc1_user_group.sudo(self.user_hrmanager_id).action_validate()
|
||||
aloc1_user_group.with_user(self.user_hrmanager_id).action_validate()
|
||||
# Checks Employee has effectively some days left
|
||||
hol_status_2_employee_group = self.holidays_status_limited.sudo(self.user_employee_id)
|
||||
hol_status_2_employee_group = self.holidays_status_limited.with_user(self.user_employee_id)
|
||||
_check_holidays_status(hol_status_2_employee_group, 2.0, 0.0, 2.0, 2.0)
|
||||
|
||||
# Employee creates a leave request in the limited category, now that he has some days left
|
||||
@@ -134,25 +134,25 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'date_to': (datetime.today() + relativedelta(days=3)),
|
||||
'number_of_days': 1,
|
||||
})
|
||||
hol2_user_group = hol2.sudo(self.user_hruser_id)
|
||||
hol2_user_group = hol2.with_user(self.user_hruser_id)
|
||||
# Check left days: - 1 virtual remaining day
|
||||
hol_status_2_employee_group.invalidate_cache()
|
||||
_check_holidays_status(hol_status_2_employee_group, 2.0, 0.0, 2.0, 1.0)
|
||||
|
||||
# HrManager validates the first step
|
||||
hol2_user_group.sudo(self.user_hrmanager_id).action_approve()
|
||||
hol2_user_group.with_user(self.user_hrmanager_id).action_approve()
|
||||
self.assertEqual(hol2.state, 'validate1',
|
||||
'hr_holidays: first validation should lead to validate1 state')
|
||||
|
||||
# HrManager validates the second step
|
||||
hol2_user_group.sudo(self.user_hrmanager_id).action_validate()
|
||||
hol2_user_group.with_user(self.user_hrmanager_id).action_validate()
|
||||
self.assertEqual(hol2.state, 'validate',
|
||||
'hr_holidays: second validation should lead to validate state')
|
||||
# Check left days: - 1 day taken
|
||||
_check_holidays_status(hol_status_2_employee_group, 2.0, 1.0, 1.0, 1.0)
|
||||
|
||||
# HrManager finds an error: he refuses the leave request
|
||||
hol2.sudo(self.user_hrmanager_id).action_refuse()
|
||||
hol2.with_user(self.user_hrmanager_id).action_refuse()
|
||||
self.assertEqual(hol2.state, 'refuse',
|
||||
'hr_holidays: refuse should lead to refuse state')
|
||||
# Check left days: 2 days left again
|
||||
@@ -162,7 +162,7 @@ class TestHolidaysFlow(TestHrHolidaysBase):
|
||||
'hr_holidays: hr_user should not be able to reset a refused leave request')
|
||||
|
||||
# HrManager resets the request
|
||||
hol2_manager_group = hol2.sudo(self.user_hrmanager_id)
|
||||
hol2_manager_group = hol2.with_user(self.user_hrmanager_id)
|
||||
hol2_manager_group.action_draft()
|
||||
self.assertEqual(hol2.state, 'draft',
|
||||
'hr_holidays: resetting should lead to draft state')
|
||||
|
||||
@@ -37,7 +37,7 @@ class TestHrLeaveType(TestHrHolidaysBase):
|
||||
def test_type_creation_right(self):
|
||||
# HrUser creates some holiday statuses -> crash because only HrManagers should do this
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['hr.leave.type'].sudo(self.user_hruser_id).create({
|
||||
self.env['hr.leave.type'].with_user(self.user_hruser_id).create({
|
||||
'name': 'UserCheats',
|
||||
'allocation_type': 'no',
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
super(TestLeaveRequests, self).setUp()
|
||||
|
||||
# Make sure we have the rights to create, validate and delete the leaves, leave types and allocations
|
||||
LeaveType = self.env['hr.leave.type'].sudo(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
LeaveType = self.env['hr.leave.type'].with_user(self.user_hrmanager_id).with_context(tracking_disable=True)
|
||||
|
||||
self.holidays_type_1 = LeaveType.create({
|
||||
'name': 'NotLimitedHR',
|
||||
@@ -66,7 +66,7 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_overlapping_requests(self):
|
||||
""" Employee cannot create a new leave request at the same time, avoid interlapping """
|
||||
self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Hol11',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_1.id,
|
||||
@@ -76,7 +76,7 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
})
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Hol21',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_1.id,
|
||||
@@ -90,7 +90,7 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
""" Employee creates a leave request in a limited category but has not enough days left """
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Hol22',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_2.id,
|
||||
@@ -102,7 +102,7 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_limited_type_days_left(self):
|
||||
""" Employee creates a leave request in a limited category and has enough days left """
|
||||
aloc1_user_group = self.env['hr.leave.allocation'].sudo(self.user_hruser_id).create({
|
||||
aloc1_user_group = self.env['hr.leave.allocation'].with_user(self.user_hruser_id).create({
|
||||
'name': 'Days for limited category',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_2.id,
|
||||
@@ -110,10 +110,10 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
})
|
||||
aloc1_user_group.action_approve()
|
||||
|
||||
holiday_status = self.holidays_type_2.sudo(self.user_employee_id)
|
||||
holiday_status = self.holidays_type_2.with_user(self.user_employee_id)
|
||||
self._check_holidays_status(holiday_status, 2.0, 0.0, 2.0, 2.0)
|
||||
|
||||
hol = self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
hol = self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Hol11',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_2.id,
|
||||
@@ -125,14 +125,14 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
holiday_status.invalidate_cache()
|
||||
self._check_holidays_status(holiday_status, 2.0, 0.0, 2.0, 0.0)
|
||||
|
||||
hol.sudo(self.user_hrmanager_id).action_approve()
|
||||
hol.with_user(self.user_hrmanager_id).action_approve()
|
||||
|
||||
self._check_holidays_status(holiday_status, 2.0, 2.0, 0.0, 0.0)
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_accrual_validity_time_valid(self):
|
||||
""" Employee ask leave during a valid validity time """
|
||||
self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Valid time period',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_3.id,
|
||||
@@ -145,7 +145,7 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
def test_accrual_validity_time_not_valid(self):
|
||||
""" Employee ask leav during a not valid validity time """
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Sick Time Off',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_3.id,
|
||||
@@ -159,7 +159,7 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
""" Create a department leave """
|
||||
self.employee_hrmanager.write({'department_id': self.hr_dept.id})
|
||||
self.assertFalse(self.env['hr.leave'].search([('employee_id', 'in', self.hr_dept.member_ids.ids)]))
|
||||
leave_form = Form(self.env['hr.leave'].sudo(self.user_hrmanager), view='hr_holidays.hr_leave_view_form_manager')
|
||||
leave_form = Form(self.env['hr.leave'].with_user(self.user_hrmanager), view='hr_holidays.hr_leave_view_form_manager')
|
||||
leave_form.holiday_type = 'department'
|
||||
leave_form.department_id = self.hr_dept
|
||||
leave_form.holiday_status_id = self.holidays_type_1
|
||||
@@ -172,14 +172,14 @@ class TestLeaveRequests(TestHrHolidaysBase):
|
||||
def test_allocation_request(self):
|
||||
""" Create an allocation request """
|
||||
# employee should be set to current user
|
||||
allocation_form = Form(self.env['hr.leave.allocation'].sudo(self.user_employee))
|
||||
allocation_form = Form(self.env['hr.leave.allocation'].with_user(self.user_employee))
|
||||
allocation_form.holiday_status_id = self.holidays_type_1
|
||||
allocation = allocation_form.save()
|
||||
|
||||
@mute_logger('odoo.models.unlink', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_employee_is_absent(self):
|
||||
""" Only the concerned employee should be considered absent """
|
||||
self.env['hr.leave'].sudo(self.user_employee_id).create({
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Hol11',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_type_1.id,
|
||||
|
||||
@@ -51,7 +51,7 @@ class TestOutOfOffice(TestHrHolidaysBase):
|
||||
'email_send': False,
|
||||
'name': 'test'
|
||||
})
|
||||
infos = channel.sudo(self.user_employee).channel_info()
|
||||
infos = channel.with_user(self.user_employee).channel_info()
|
||||
self.assertEqual(infos[0]['direct_partner'][0]['out_of_office_date_end'], leave_date_end)
|
||||
self.assertEqual(infos[0]['direct_partner'][0]['out_of_office_message'], 'contact tde in case of problems')
|
||||
|
||||
@@ -59,7 +59,7 @@ class TestOutOfOffice(TestHrHolidaysBase):
|
||||
""" Out of office message from Preferences should be used as default value """
|
||||
self.user_hruser.out_of_office_message = 'contact xdo in case of problems'
|
||||
|
||||
leave_form = Form(self.env['hr.leave'].sudo(self.user_hruser), view='hr_holidays.hr_leave_view_form')
|
||||
leave_form = Form(self.env['hr.leave'].with_user(self.user_hruser), view='hr_holidays.hr_leave_view_form')
|
||||
leave_form.date_from = datetime.today() - relativedelta(days=1)
|
||||
leave_form.date_to = datetime.today()
|
||||
leave_form.holiday_status_id = self.leave_type
|
||||
@@ -70,7 +70,7 @@ class TestOutOfOffice(TestHrHolidaysBase):
|
||||
""" Out of office message default value should be overwrittable """
|
||||
self.user_hruser.out_of_office_message = 'contact xdo in case of problems'
|
||||
|
||||
leave_form = Form(self.env['hr.leave'].sudo(self.user_hruser), view='hr_holidays.hr_leave_view_form')
|
||||
leave_form = Form(self.env['hr.leave'].with_user(self.user_hruser), view='hr_holidays.hr_leave_view_form')
|
||||
leave_form.date_from = datetime.today() - relativedelta(days=1)
|
||||
leave_form.date_to = datetime.today()
|
||||
leave_form.holiday_status_id = self.leave_type
|
||||
|
||||
@@ -23,7 +23,7 @@ class TestRecruitmentProcess(common.TransactionCase):
|
||||
# In Order to test process of Recruitment so giving HR officer's rights
|
||||
with open(get_module_resource('hr_recruitment', 'tests', 'resume.eml'), 'rb') as request_file:
|
||||
request_message = request_file.read()
|
||||
self.env['mail.thread'].sudo(self.res_users_hr_recruitment_officer.id).message_process(
|
||||
self.env['mail.thread'].with_user(self.res_users_hr_recruitment_officer).message_process(
|
||||
'hr.applicant', request_message, custom_values={"job_id": self.env.ref('hr.job_developer').id})
|
||||
|
||||
# After getting the mail, I check the details of the new applicant.
|
||||
|
||||
@@ -84,7 +84,7 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
Timesheet = self.env['account.analytic.line']
|
||||
timesheet_uom = self.project_customer.analytic_account_id.company_id.project_time_mode_id
|
||||
# employee 1 log some timesheet on task 1
|
||||
timesheet1 = Timesheet.sudo(self.user_employee.id).create({
|
||||
timesheet1 = Timesheet.with_user(self.user_employee).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'task_id': self.task1.id,
|
||||
'name': 'my first timesheet',
|
||||
@@ -97,7 +97,7 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
|
||||
# employee 1 cannot log timesheet for employee 2
|
||||
with self.assertRaises(AccessError):
|
||||
timesheet2 = Timesheet.sudo(self.user_employee.id).create({
|
||||
timesheet2 = Timesheet.with_user(self.user_employee).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'task_id': self.task1.id,
|
||||
'name': 'a second timesheet but for employee 2',
|
||||
@@ -106,7 +106,7 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
})
|
||||
|
||||
# manager log timesheet for employee 2
|
||||
timesheet3 = Timesheet.sudo(self.user_manager.id).create({
|
||||
timesheet3 = Timesheet.with_user(self.user_manager).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'task_id': self.task1.id,
|
||||
'name': 'a second timesheet but for employee 2',
|
||||
@@ -118,7 +118,7 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
self.assertEquals(timesheet3.product_uom_id, timesheet_uom, "The UoM of the timesheet 3 should be the one set on the company of the analytic account.")
|
||||
|
||||
# employee 1 log some timesheet on project (no task)
|
||||
timesheet4 = Timesheet.sudo(self.user_employee.id).create({
|
||||
timesheet4 = Timesheet.with_user(self.user_employee).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'name': 'my first timesheet',
|
||||
'unit_amount': 4,
|
||||
@@ -129,7 +129,7 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
""" Test access rights : user can update its own timesheets only, and manager can change all """
|
||||
# employee 1 log some timesheet on task 1
|
||||
Timesheet = self.env['account.analytic.line']
|
||||
timesheet1 = Timesheet.sudo(self.user_employee.id).create({
|
||||
timesheet1 = Timesheet.with_user(self.user_employee).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'task_id': self.task1.id,
|
||||
'name': 'my first timesheet',
|
||||
@@ -137,12 +137,12 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
})
|
||||
# then employee 2 try to modify it
|
||||
with self.assertRaises(AccessError):
|
||||
timesheet1.sudo(self.user_employee2.id).write({
|
||||
timesheet1.with_user(self.user_employee2).write({
|
||||
'name': 'i try to update this timesheet',
|
||||
'unit_amount': 2,
|
||||
})
|
||||
# manager can modify all timesheet
|
||||
timesheet1.sudo(self.user_manager.id).write({
|
||||
timesheet1.with_user(self.user_manager).write({
|
||||
'unit_amount': 8,
|
||||
'employee_id': self.empl_employee2.id,
|
||||
})
|
||||
@@ -239,13 +239,13 @@ class TestTimesheet(TestCommonTimesheet):
|
||||
self.empl_employee.timesheet_cost = 5.0
|
||||
self.empl_employee2.timesheet_cost = 6.0
|
||||
# create a timesheet for each employee
|
||||
timesheet_1 = Timesheet.sudo(self.user_employee).create({
|
||||
timesheet_1 = Timesheet.with_user(self.user_employee).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'task_id': self.task1.id,
|
||||
'name': '/',
|
||||
'unit_amount': 1,
|
||||
})
|
||||
timesheet_2 = Timesheet.sudo(self.user_employee2).create({
|
||||
timesheet_2 = Timesheet.with_user(self.user_employee2).create({
|
||||
'project_id': self.project_customer.id,
|
||||
'task_id': self.task1.id,
|
||||
'name': '/',
|
||||
|
||||
@@ -68,7 +68,7 @@ class MailController(http.Controller):
|
||||
|
||||
# the record has a window redirection: check access rights
|
||||
if uid is not None:
|
||||
if not RecordModel.sudo(uid).check_access_rights('read', raise_exception=False):
|
||||
if not RecordModel.with_user(uid).check_access_rights('read', raise_exception=False):
|
||||
return cls._redirect_to_messaging()
|
||||
try:
|
||||
# We need here to extend the "allowed_company_ids" to allow a redirection
|
||||
@@ -77,7 +77,7 @@ class MailController(http.Controller):
|
||||
cids = request.httprequest.cookies.get('cids', str(user.company_id.id))
|
||||
cids = [int(cid) for cid in cids.split(',')]
|
||||
try:
|
||||
record_sudo.sudo(uid).with_context(allowed_company_ids=cids).check_access_rule('read')
|
||||
record_sudo.with_user(uid).with_context(allowed_company_ids=cids).check_access_rule('read')
|
||||
except AccessError:
|
||||
# In case the allowed_company_ids from the cookies (i.e. the last user configuration
|
||||
# on his browser) is not sufficient to avoid an ir.rule access error, try to following
|
||||
@@ -92,7 +92,7 @@ class MailController(http.Controller):
|
||||
if not suggested_company:
|
||||
raise AccessError()
|
||||
cids += [suggested_company.id]
|
||||
record_sudo.sudo(uid).with_context(allowed_company_ids=cids).check_access_rule('read')
|
||||
record_sudo.with_user(uid).with_context(allowed_company_ids=cids).check_access_rule('read')
|
||||
except AccessError:
|
||||
return cls._redirect_to_messaging()
|
||||
else:
|
||||
|
||||
@@ -289,7 +289,7 @@ class MailActivity(models.Model):
|
||||
assigned user should be able to at least read the document. We therefore
|
||||
raise an UserError if the assigned user has no access to the document. """
|
||||
for activity in self:
|
||||
model = self.env[activity.res_model].sudo(activity.user_id.id)
|
||||
model = self.env[activity.res_model].with_user(activity.user_id)
|
||||
try:
|
||||
model.check_access_rights('read')
|
||||
except exceptions.AccessError:
|
||||
|
||||
@@ -500,7 +500,7 @@ class Channel(models.Model):
|
||||
for partner in self.env['res.partner'].browse(partner_ids):
|
||||
user_id = partner.user_ids and partner.user_ids[0] or False
|
||||
if user_id:
|
||||
for channel_info in self.sudo(user_id).channel_info():
|
||||
for channel_info in self.with_user(user_id).channel_info():
|
||||
notifications.append([(self._cr.dbname, 'res.partner', partner.id), channel_info])
|
||||
return notifications
|
||||
|
||||
|
||||
@@ -658,7 +658,7 @@ class Message(models.Model):
|
||||
model_ids = {}
|
||||
|
||||
# check read access rights before checking the actual rules on the given ids
|
||||
super(Message, self.sudo(access_rights_uid or self._uid)).check_access_rights('read')
|
||||
super(Message, self.with_user(access_rights_uid or self._uid)).check_access_rights('read')
|
||||
|
||||
self._cr.execute("""
|
||||
SELECT DISTINCT m.id, m.model, m.res_id, m.author_id, m.message_type,
|
||||
|
||||
@@ -56,7 +56,7 @@ class MailMessageSubtype(models.Model):
|
||||
self.clear_caches()
|
||||
return super(MailMessageSubtype, self).unlink()
|
||||
|
||||
@tools.ormcache('self.env.uid', 'model_name')
|
||||
@tools.ormcache('model_name')
|
||||
def _get_auto_subscription_subtypes(self, model_name):
|
||||
""" Return data related to auto subscription based on subtype matching.
|
||||
Example with tasks and project :
|
||||
@@ -97,7 +97,7 @@ class MailMessageSubtype(models.Model):
|
||||
subtype_ids, internal_ids, external_ids = self._default_subtypes(model_name)
|
||||
return self.browse(subtype_ids), self.browse(internal_ids), self.browse(external_ids)
|
||||
|
||||
@tools.ormcache('self.env.uid', 'model_name')
|
||||
@tools.ormcache('self.env.uid', 'self.env.su', 'model_name')
|
||||
def _default_subtypes(self, model_name):
|
||||
domain = [('default', '=', True),
|
||||
'|', ('res_model', '=', model_name), ('res_model', '=', False)]
|
||||
|
||||
@@ -1044,7 +1044,7 @@ class MailThread(models.AbstractModel):
|
||||
|
||||
# disabled subscriptions during message_new/update to avoid having the system user running the
|
||||
# email gateway become a follower of all inbound messages
|
||||
MessageModel = Model.sudo(user_id).with_context(mail_create_nosubscribe=True, mail_create_nolog=True)
|
||||
MessageModel = Model.with_user(user_id).with_context(mail_create_nosubscribe=True, mail_create_nolog=True)
|
||||
if thread_id and hasattr(MessageModel, 'message_update'):
|
||||
thread = MessageModel.browse(thread_id)
|
||||
thread.message_update(message_dict)
|
||||
|
||||
@@ -39,7 +39,7 @@ class TestEquipment(TransactionCase):
|
||||
def test_10_equipment_request_category(self):
|
||||
|
||||
# Create a new equipment
|
||||
equipment_01 = self.equipment.sudo(self.manager).create({
|
||||
equipment_01 = self.equipment.with_user(self.manager).create({
|
||||
'name': 'Samsung Monitor "15',
|
||||
'category_id': self.ref('maintenance.equipment_monitor'),
|
||||
'technician_user_id': self.ref('base.user_root'),
|
||||
@@ -54,7 +54,7 @@ class TestEquipment(TransactionCase):
|
||||
assert equipment_01, "Equipment not created"
|
||||
|
||||
# Create new maintenance request
|
||||
maintenance_request_01 = self.maintenance_request.sudo(self.user).create({
|
||||
maintenance_request_01 = self.maintenance_request.with_user(self.user).create({
|
||||
'name': 'Resolution is bad',
|
||||
'user_id': self.user.id,
|
||||
'owner_user_id': self.user.id,
|
||||
@@ -71,7 +71,7 @@ class TestEquipment(TransactionCase):
|
||||
self.assertEquals(maintenance_request_01.stage_id.id, self.ref('maintenance.stage_0'))
|
||||
|
||||
# I check that change the maintenance_request stage on click statusbar
|
||||
maintenance_request_01.sudo(self.user).write({'stage_id': self.ref('maintenance.stage_1')})
|
||||
maintenance_request_01.with_user(self.user).write({'stage_id': self.ref('maintenance.stage_1')})
|
||||
|
||||
# I check that maintenance request is in the "In Progress" stage
|
||||
self.assertEquals(maintenance_request_01.stage_id.id, self.ref('maintenance.stage_1'))
|
||||
|
||||
@@ -58,52 +58,52 @@ class TestEquipmentMulticompany(TransactionCase):
|
||||
})
|
||||
|
||||
# create a maintenance team for company A user
|
||||
team = MaintenanceTeam.sudo(equipment_manager).create({
|
||||
team = MaintenanceTeam.with_user(equipment_manager).create({
|
||||
'name': 'Metrology',
|
||||
'company_id': company_a.id,
|
||||
})
|
||||
# create a maintenance team for company B user
|
||||
teamb = MaintenanceTeam.sudo(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
teamb = MaintenanceTeam.with_user(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
'name': 'Subcontractor',
|
||||
'company_id': company_b.id,
|
||||
})
|
||||
|
||||
# User should not able to create equipment category.
|
||||
with self.assertRaises(AccessError):
|
||||
Category.sudo(user).create({
|
||||
Category.with_user(user).create({
|
||||
'name': 'Software',
|
||||
'company_id': company_b.id,
|
||||
'technician_user_id': user.id,
|
||||
})
|
||||
|
||||
# create equipment category for equipment manager
|
||||
category_1 = Category.sudo(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
category_1 = Category.with_user(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
'name': 'Monitors',
|
||||
'company_id': company_b.id,
|
||||
'technician_user_id': equipment_manager.id,
|
||||
})
|
||||
|
||||
# create equipment category for equipment manager
|
||||
Category.sudo(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
Category.with_user(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
'name': 'Computers',
|
||||
'company_id': company_b.id,
|
||||
'technician_user_id': equipment_manager.id,
|
||||
})
|
||||
|
||||
# create equipment category for equipment user
|
||||
Category.sudo(equipment_manager).create({
|
||||
Category.with_user(equipment_manager).create({
|
||||
'name': 'Phones',
|
||||
'company_id': company_a.id,
|
||||
'technician_user_id': equipment_manager.id,
|
||||
})
|
||||
|
||||
# Check category for user equipment_manager and user
|
||||
self.assertEquals(Category.sudo(equipment_manager).with_context(allowed_company_ids=cids).search_count([]), 3)
|
||||
self.assertEquals(Category.sudo(user).search_count([]), 2)
|
||||
self.assertEquals(Category.with_user(equipment_manager).with_context(allowed_company_ids=cids).search_count([]), 3)
|
||||
self.assertEquals(Category.with_user(user).search_count([]), 2)
|
||||
|
||||
# User should not able to create equipment.
|
||||
with self.assertRaises(AccessError):
|
||||
Equipment.sudo(user).create({
|
||||
Equipment.with_user(user).create({
|
||||
'name': 'Samsung Monitor 15',
|
||||
'category_id': category_1.id,
|
||||
'assign_date': time.strftime('%Y-%m-%d'),
|
||||
@@ -111,7 +111,7 @@ class TestEquipmentMulticompany(TransactionCase):
|
||||
'owner_user_id': user.id,
|
||||
})
|
||||
|
||||
Equipment.sudo(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
Equipment.with_user(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
'name': 'Acer Laptop',
|
||||
'category_id': category_1.id,
|
||||
'assign_date': time.strftime('%Y-%m-%d'),
|
||||
@@ -120,7 +120,7 @@ class TestEquipmentMulticompany(TransactionCase):
|
||||
})
|
||||
|
||||
# create an equipment for user
|
||||
Equipment.sudo(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
Equipment.with_user(equipment_manager).with_context(allowed_company_ids=cids).create({
|
||||
'name': 'HP Laptop',
|
||||
'category_id': category_1.id,
|
||||
'assign_date': time.strftime('%Y-%m-%d'),
|
||||
@@ -128,21 +128,21 @@ class TestEquipmentMulticompany(TransactionCase):
|
||||
'owner_user_id': equipment_manager.id,
|
||||
})
|
||||
# Now there are total 2 equipments created and can view by equipment_manager user
|
||||
self.assertEquals(Equipment.sudo(equipment_manager).with_context(allowed_company_ids=cids).search_count([]), 2)
|
||||
self.assertEquals(Equipment.with_user(equipment_manager).with_context(allowed_company_ids=cids).search_count([]), 2)
|
||||
|
||||
# And there is total 1 equipment can be view by Normal User ( Which user is followers)
|
||||
self.assertEquals(Equipment.sudo(user).search_count([]), 1)
|
||||
self.assertEquals(Equipment.with_user(user).search_count([]), 1)
|
||||
|
||||
# create an equipment team BY user
|
||||
with self.assertRaises(AccessError):
|
||||
MaintenanceTeam.sudo(user).create({
|
||||
MaintenanceTeam.with_user(user).create({
|
||||
'name': 'Subcontractor',
|
||||
'company_id': company_b.id,
|
||||
})
|
||||
|
||||
# create an equipment category BY user
|
||||
with self.assertRaises(AccessError):
|
||||
Category.sudo(user).create({
|
||||
Category.with_user(user).create({
|
||||
'name': 'Computers',
|
||||
'company_id': company_b.id,
|
||||
'technician_user_id': user.id,
|
||||
@@ -150,12 +150,12 @@ class TestEquipmentMulticompany(TransactionCase):
|
||||
|
||||
# create an maintenance stage BY user
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['maintenance.stage'].sudo(user).create({
|
||||
self.env['maintenance.stage'].with_user(user).create({
|
||||
'name': 'identify corrective maintenance requirements',
|
||||
})
|
||||
|
||||
# Create an maintenance request for ( User Follower ).
|
||||
MaintenanceRequest.sudo(user).create({
|
||||
MaintenanceRequest.with_user(user).create({
|
||||
'name': 'Some keys are not working',
|
||||
'company_id': company_b.id,
|
||||
'user_id': user.id,
|
||||
@@ -163,7 +163,7 @@ class TestEquipmentMulticompany(TransactionCase):
|
||||
})
|
||||
|
||||
# Create an maintenance request for equipment_manager (Admin Follower)
|
||||
MaintenanceRequest.sudo(equipment_manager).create({
|
||||
MaintenanceRequest.with_user(equipment_manager).create({
|
||||
'name': 'Battery drains fast',
|
||||
'company_id': company_a.id,
|
||||
'user_id': equipment_manager.id,
|
||||
@@ -171,5 +171,5 @@ class TestEquipmentMulticompany(TransactionCase):
|
||||
})
|
||||
|
||||
# Now here is total 1 maintenance request can be view by Normal User
|
||||
self.assertEquals(MaintenanceRequest.sudo(equipment_manager).with_context(allowed_company_ids=cids).search_count([]), 2)
|
||||
self.assertEquals(MaintenanceRequest.sudo(user).search_count([]), 1)
|
||||
self.assertEquals(MaintenanceRequest.with_user(equipment_manager).with_context(allowed_company_ids=cids).search_count([]), 2)
|
||||
self.assertEquals(MaintenanceRequest.with_user(user).search_count([]), 1)
|
||||
|
||||
@@ -1019,7 +1019,7 @@ class MassMailing(models.Model):
|
||||
mass_mailings = self.search([('state', 'in', ('in_queue', 'sending')), '|', ('schedule_date', '<', fields.Datetime.now()), ('schedule_date', '=', False)])
|
||||
for mass_mailing in mass_mailings:
|
||||
user = mass_mailing.write_uid or self.env.user
|
||||
mass_mailing = mass_mailing.with_context(**user.sudo(user=user).context_get())
|
||||
mass_mailing = mass_mailing.with_context(**user.with_user(user).context_get())
|
||||
if len(mass_mailing.get_remaining_recipients()) > 0:
|
||||
mass_mailing.state = 'sending'
|
||||
mass_mailing.send_mail()
|
||||
|
||||
@@ -22,7 +22,7 @@ class TestMrpMulticompany(common.TransactionCase):
|
||||
|
||||
def test_00_multicompany_user(self):
|
||||
"""check no error on getting default mrp.production values in multicompany setting"""
|
||||
StockLocation = self.env['stock.location'].sudo(self.multicompany_user_id)
|
||||
StockLocation = self.env['stock.location'].with_user(self.multicompany_user_id)
|
||||
fields = ['location_src_id', 'location_dest_id']
|
||||
defaults = StockLocation.default_get(['location_id', 'location_dest_id', 'type'])
|
||||
for field in fields:
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestMrpOrder(TestMrpCommon):
|
||||
|
||||
def test_access_rights_manager(self):
|
||||
""" Checks an MRP manager can create, confirm and cancel a manufacturing order. """
|
||||
man_order_form = Form(self.env['mrp.production'].sudo(self.user_mrp_manager))
|
||||
man_order_form = Form(self.env['mrp.production'].with_user(self.user_mrp_manager))
|
||||
man_order_form.product_id = self.product_4
|
||||
man_order_form.product_qty = 5.0
|
||||
man_order_form.bom_id = self.bom_1
|
||||
@@ -27,7 +27,7 @@ class TestMrpOrder(TestMrpCommon):
|
||||
|
||||
def test_access_rights_user(self):
|
||||
""" Checks an MRP user can create, confirm and cancel a manufacturing order. """
|
||||
man_order_form = Form(self.env['mrp.production'].sudo(self.user_mrp_user))
|
||||
man_order_form = Form(self.env['mrp.production'].with_user(self.user_mrp_user))
|
||||
man_order_form.product_id = self.product_4
|
||||
man_order_form.product_qty = 5.0
|
||||
man_order_form.bom_id = self.bom_1
|
||||
@@ -64,7 +64,7 @@ class TestMrpOrder(TestMrpCommon):
|
||||
test_date_planned = Dt.now() - timedelta(days=1)
|
||||
test_quantity = 2.0
|
||||
self.bom_1.routing_id = False
|
||||
man_order_form = Form(self.env['mrp.production'].sudo(self.user_mrp_user))
|
||||
man_order_form = Form(self.env['mrp.production'].with_user(self.user_mrp_user))
|
||||
man_order_form.product_id = self.product_4
|
||||
man_order_form.bom_id = self.bom_1
|
||||
man_order_form.product_uom_id = self.product_4.uom_id
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestWarehouse(common.TestMrpCommon):
|
||||
return p
|
||||
|
||||
def test_manufacturing_route(self):
|
||||
warehouse_1_stock_manager = self.warehouse_1.sudo(self.user_stock_manager)
|
||||
warehouse_1_stock_manager = self.warehouse_1.with_user(self.user_stock_manager)
|
||||
manu_rule = self.env['stock.rule'].search([
|
||||
('action', '=', 'manufacture'),
|
||||
('warehouse_id', '=', self.warehouse_1.id)])
|
||||
|
||||
@@ -228,7 +228,7 @@ class PosSession(models.Model):
|
||||
'balance_start': self.env["account.bank.statement"]._get_opening_balance(journal.id)
|
||||
}
|
||||
|
||||
statements.append(ABS.with_context(ctx).sudo(uid).create(st_values).id)
|
||||
statements.append(ABS.with_context(ctx).with_user(uid).create(st_values).id)
|
||||
|
||||
values.update({
|
||||
'name': pos_name,
|
||||
@@ -236,7 +236,7 @@ class PosSession(models.Model):
|
||||
'config_id': config_id
|
||||
})
|
||||
|
||||
res = super(PosSession, self.with_context(ctx).sudo(uid)).create(values)
|
||||
res = super(PosSession, self.with_context(ctx).with_user(uid)).create(values)
|
||||
if not pos_config.cash_control:
|
||||
res.action_pos_session_open()
|
||||
|
||||
|
||||
@@ -168,8 +168,8 @@ class MailController(MailController):
|
||||
uid = request.session.uid or request.env.ref('base.public_user').id
|
||||
record_sudo = request.env[model].sudo().browse(res_id).exists()
|
||||
try:
|
||||
record_sudo.sudo(uid).check_access_rights('read')
|
||||
record_sudo.sudo(uid).check_access_rule('read')
|
||||
record_sudo.with_user(uid).check_access_rights('read')
|
||||
record_sudo.with_user(uid).check_access_rule('read')
|
||||
except AccessError:
|
||||
if record_sudo.access_token and access_token and consteq(record_sudo.access_token, access_token):
|
||||
record_action = record_sudo.with_context(force_website=True).get_access_action()
|
||||
|
||||
@@ -99,7 +99,7 @@ class PortalMixin(models.AbstractModel):
|
||||
except exceptions.AccessError:
|
||||
return super(PortalMixin, self).get_access_action(access_uid)
|
||||
user = self.env['res.users'].sudo().browse(access_uid)
|
||||
record = self.sudo(user)
|
||||
record = self.with_user(user)
|
||||
if user.share or self.env.context.get('force_website'):
|
||||
try:
|
||||
record.check_access_rights('read')
|
||||
|
||||
@@ -24,7 +24,7 @@ class pos_cache(models.Model):
|
||||
|
||||
@api.one
|
||||
def refresh_cache(self):
|
||||
Product = self.env['product.product'].sudo(self.compute_user_id.id)
|
||||
Product = self.env['product.product'].with_user(self.compute_user_id)
|
||||
products = Product.search(self.get_product_domain())
|
||||
prod_ctx = products.with_context(pricelist=self.config_id.pricelist_id.id, display_default_code=False,
|
||||
lang=self.compute_user_id.lang)
|
||||
|
||||
@@ -847,7 +847,7 @@ class ProductTemplate(models.Model):
|
||||
return self.env['product.product'].browse(self._get_variant_id_for_combination(attribute_values))
|
||||
|
||||
@api.multi
|
||||
@tools.ormcache('self', 'attribute_values')
|
||||
@tools.ormcache('self.id', 'attribute_values')
|
||||
def _get_variant_id_for_combination(self, attribute_values):
|
||||
"""See `_get_variant_for_combination`. This method returns an ID
|
||||
so it can be cached."""
|
||||
@@ -869,7 +869,7 @@ class ProductTemplate(models.Model):
|
||||
)[:1].id
|
||||
|
||||
@api.multi
|
||||
@tools.ormcache('self')
|
||||
@tools.ormcache('self.id')
|
||||
def _get_first_possible_variant_id(self):
|
||||
"""See `_create_first_product_variant`. This method returns an ID
|
||||
so it can be cached."""
|
||||
|
||||
@@ -82,7 +82,7 @@ class RatingProject(http.Controller):
|
||||
project = request.env['project.project'].sudo().browse(project_id)
|
||||
# to avoid giving any access rights on projects to the public user, let's use sudo
|
||||
# and check if the user should be able to view the project (project managers only if it's unpublished or has no rating)
|
||||
if not ((project.rating_status != 'no') and project.portal_show_rating) and not user.sudo(user).has_group('project.group_project_manager'):
|
||||
if not ((project.rating_status != 'no') and project.portal_show_rating) and not user.with_user(user).has_group('project.group_project_manager'):
|
||||
raise NotFound()
|
||||
|
||||
return request.render('project.rating_project_rating_page', {
|
||||
|
||||
@@ -36,25 +36,25 @@ class TestPortalProject(TestPortalProjectBase):
|
||||
|
||||
pigs.write({'privacy_visibility': 'employees'})
|
||||
# Do: Alfred reads project -> ok (employee ok employee)
|
||||
pigs.sudo(self.user_projectuser).read(['user_id'])
|
||||
pigs.with_user(self.user_projectuser).read(['user_id'])
|
||||
# Test: all project tasks visible
|
||||
tasks = self.env['project.task'].sudo(self.user_projectuser).search([('project_id', '=', pigs.id)])
|
||||
tasks = self.env['project.task'].with_user(self.user_projectuser).search([('project_id', '=', pigs.id)])
|
||||
test_task_ids = set([self.task_1.id, self.task_2.id, self.task_3.id, self.task_4.id, self.task_5.id, self.task_6.id])
|
||||
self.assertEqual(set(tasks.ids), test_task_ids,
|
||||
'access rights: project user cannot see all tasks of an employees project')
|
||||
# Do: Bert reads project -> crash, no group
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_noone).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_noone).read, ['user_id'])
|
||||
# Do: Donovan reads project -> ko (public ko employee)
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_public).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_public).read, ['user_id'])
|
||||
# Do: project user is employee and can create a task
|
||||
tmp_task = self.env['project.task'].sudo(self.user_projectuser).with_context({'mail_create_nolog': True}).create({
|
||||
tmp_task = self.env['project.task'].with_user(self.user_projectuser).with_context({'mail_create_nolog': True}).create({
|
||||
'name': 'Pigs task',
|
||||
'project_id': pigs.id})
|
||||
tmp_task.sudo(self.user_projectuser).unlink()
|
||||
tmp_task.with_user(self.user_projectuser).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model')
|
||||
def test_favorite_project_access_rights(self):
|
||||
pigs = self.project_pigs.sudo(self.user_projectuser)
|
||||
pigs = self.project_pigs.with_user(self.user_projectuser)
|
||||
|
||||
# we can't write on project name
|
||||
self.assertRaises(AccessError, pigs.write, {'name': 'False Pigs'})
|
||||
@@ -67,36 +67,36 @@ class TestPortalProject(TestPortalProjectBase):
|
||||
pigs.write({'privacy_visibility': 'followers'})
|
||||
|
||||
# Do: Alfred reads project -> ko (employee ko followers)
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_projectuser).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_projectuser).read, ['user_id'])
|
||||
# Test: no project task visible
|
||||
tasks = self.env['project.task'].sudo(self.user_projectuser).search([('project_id', '=', pigs.id)])
|
||||
tasks = self.env['project.task'].with_user(self.user_projectuser).search([('project_id', '=', pigs.id)])
|
||||
self.assertEqual(tasks, self.task_1,
|
||||
'access rights: employee user should not see tasks of a not-followed followers project, only assigned')
|
||||
|
||||
# Do: Bert reads project -> crash, no group
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_noone).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_noone).read, ['user_id'])
|
||||
|
||||
# Do: Donovan reads project -> ko (public ko employee)
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_public).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_public).read, ['user_id'])
|
||||
|
||||
pigs.message_subscribe(partner_ids=[self.user_projectuser.partner_id.id])
|
||||
|
||||
# Do: Alfred reads project -> ok (follower ok followers)
|
||||
donkey = pigs.sudo(self.user_projectuser)
|
||||
donkey = pigs.with_user(self.user_projectuser)
|
||||
donkey.invalidate_cache()
|
||||
donkey.read(['user_id'])
|
||||
|
||||
# Do: Donovan reads project -> ko (public ko follower even if follower)
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_public).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_public).read, ['user_id'])
|
||||
# Do: project user is follower of the project and can create a task
|
||||
self.env['project.task'].sudo(self.user_projectuser.id).with_context({'mail_create_nolog': True}).create({
|
||||
self.env['project.task'].with_user(self.user_projectuser).with_context({'mail_create_nolog': True}).create({
|
||||
'name': 'Pigs task', 'project_id': pigs.id
|
||||
})
|
||||
# not follower user should not be able to create a task
|
||||
pigs.sudo(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_projectuser.partner_id.id])
|
||||
self.assertRaises(AccessError, self.env['project.task'].sudo(self.user_projectuser).with_context({
|
||||
pigs.with_user(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_projectuser.partner_id.id])
|
||||
self.assertRaises(AccessError, self.env['project.task'].with_user(self.user_projectuser).with_context({
|
||||
'mail_create_nolog': True}).create, {'name': 'Pigs task', 'project_id': pigs.id})
|
||||
|
||||
# Do: project user can create a task without project
|
||||
self.assertRaises(AccessError, self.env['project.task'].sudo(self.user_projectuser).with_context({
|
||||
self.assertRaises(AccessError, self.env['project.task'].with_user(self.user_projectuser).with_context({
|
||||
'mail_create_nolog': True}).create, {'name': 'Pigs task', 'project_id': pigs.id})
|
||||
|
||||
@@ -13,27 +13,27 @@ class TestPortalProject(TestPortalProjectBase):
|
||||
pigs.write({'privacy_visibility': 'portal'})
|
||||
|
||||
# Do: Alfred reads project -> ok (employee ok public)
|
||||
pigs.sudo(self.user_projectuser).read(['user_id'])
|
||||
pigs.with_user(self.user_projectuser).read(['user_id'])
|
||||
# Test: all project tasks visible
|
||||
tasks = self.env['project.task'].sudo(self.user_projectuser).search([('project_id', '=', pigs.id)])
|
||||
tasks = self.env['project.task'].with_user(self.user_projectuser).search([('project_id', '=', pigs.id)])
|
||||
self.assertEqual(tasks, self.task_1 | self.task_2 | self.task_3 | self.task_4 | self.task_5 | self.task_6,
|
||||
'access rights: project user should see all tasks of a portal project')
|
||||
|
||||
# Do: Bert reads project -> crash, no group
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_noone).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_noone).read, ['user_id'])
|
||||
# Test: no project task searchable
|
||||
self.assertRaises(AccessError, self.env['project.task'].sudo(self.user_noone).search, [('project_id', '=', pigs.id)])
|
||||
self.assertRaises(AccessError, self.env['project.task'].with_user(self.user_noone).search, [('project_id', '=', pigs.id)])
|
||||
|
||||
# Data: task follower
|
||||
pigs.sudo(self.user_projectmanager).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.task_1.sudo(self.user_projectuser).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.task_3.sudo(self.user_projectuser).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
pigs.with_user(self.user_projectmanager).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.task_1.with_user(self.user_projectuser).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.task_3.with_user(self.user_projectuser).message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
# Do: Chell reads project -> ok (portal ok public)
|
||||
pigs.sudo(self.user_portal).read(['user_id'])
|
||||
pigs.with_user(self.user_portal).read(['user_id'])
|
||||
# Do: Donovan reads project -> ko (public ko portal)
|
||||
self.assertRaises(AccessError, pigs.sudo(self.user_public).read, ['user_id'])
|
||||
self.assertRaises(AccessError, pigs.with_user(self.user_public).read, ['user_id'])
|
||||
# Test: no access right to project.task
|
||||
self.assertRaises(AccessError, self.env['project.task'].sudo(self.user_public).search, [])
|
||||
self.assertRaises(AccessError, self.env['project.task'].with_user(self.user_public).search, [])
|
||||
# Data: task follower cleaning
|
||||
self.task_1.sudo(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.task_3.sudo(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.task_1.with_user(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.task_3.with_user(self.user_projectuser).message_unsubscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
|
||||
@@ -37,7 +37,7 @@ Integrator at Agrolait"""
|
||||
class TestProjectFlow(TestProjectBase):
|
||||
|
||||
def test_project_process_project_manager_duplicate(self):
|
||||
pigs = self.project_pigs.sudo(self.user_projectmanager)
|
||||
pigs = self.project_pigs.with_user(self.user_projectmanager)
|
||||
dogs = pigs.copy()
|
||||
self.assertEqual(len(dogs.tasks), 2, 'project: duplicating a project must duplicate its tasks')
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class TestTimesheetHolidays(TestCommonTimesheet):
|
||||
def test_validate_with_timesheet(self):
|
||||
# employee creates a leave request
|
||||
number_of_days = (self.leave_end_datetime - self.leave_start_datetime).days
|
||||
holiday = self.Requests.sudo(self.user_employee.id).create({
|
||||
holiday = self.Requests.with_user(self.user_employee).create({
|
||||
'name': 'Leave 1',
|
||||
'employee_id': self.empl_employee.id,
|
||||
'holiday_status_id': self.hr_leave_type_with_ts.id,
|
||||
@@ -96,7 +96,7 @@ class TestTimesheetHolidays(TestCommonTimesheet):
|
||||
def test_validate_without_timesheet(self):
|
||||
# employee creates a leave request
|
||||
number_of_days = (self.leave_end_datetime - self.leave_start_datetime).days
|
||||
holiday = self.Requests.sudo(self.user_employee.id).create({
|
||||
holiday = self.Requests.with_user(self.user_employee).create({
|
||||
'name': 'Leave 1',
|
||||
'employee_id': self.empl_employee.id,
|
||||
'holiday_status_id': self.hr_leave_type_no_ts.id,
|
||||
|
||||
@@ -11,13 +11,13 @@ class TestPurchaseRequisition(TestPurchaseRequisitionCommon):
|
||||
self.assertTrue(self.user_purchase_requisition_user, 'User Should be created')
|
||||
|
||||
def test_01_cancel_purchase_requisition(self):
|
||||
self.requisition1.sudo(self.user_purchase_requisition_user.id).action_cancel()
|
||||
self.requisition1.with_user(self.user_purchase_requisition_user).action_cancel()
|
||||
# Check requisition after cancelled.
|
||||
self.assertEqual(self.requisition1.state, 'cancel', 'Requisition should be in cancelled state.')
|
||||
# I reset requisition as "New".
|
||||
self.requisition1.sudo(self.user_purchase_requisition_user.id).action_draft()
|
||||
self.requisition1.with_user(self.user_purchase_requisition_user).action_draft()
|
||||
# I duplicate requisition.
|
||||
self.requisition1.sudo(self.user_purchase_requisition_user.id).copy()
|
||||
self.requisition1.with_user(self.user_purchase_requisition_user).copy()
|
||||
|
||||
|
||||
def test_02_purchase_requisition(self):
|
||||
|
||||
@@ -34,8 +34,8 @@ class TestPurchaseRequisitionStock(TestPurchaseRequisitionCommon):
|
||||
|
||||
# Give access rights of Purchase Requisition User to open requisition
|
||||
# Set tender state to choose tendering line.
|
||||
self.requisition1.sudo(self.user_purchase_requisition_user.id).action_in_progress()
|
||||
self.requisition1.sudo(self.user_purchase_requisition_user.id).action_open()
|
||||
self.requisition1.with_user(self.user_purchase_requisition_user).action_in_progress()
|
||||
self.requisition1.with_user(self.user_purchase_requisition_user).action_open()
|
||||
|
||||
# Vendor send one RFQ so I create a RfQ of that agreement.
|
||||
PurchaseOrder = self.env['purchase.order']
|
||||
|
||||
@@ -79,7 +79,7 @@ class TestCreatePicking(common.TestProductCommon):
|
||||
self.env.company.write({'po_double_validation': 'two_step','po_double_validation_amount':2000.00})
|
||||
|
||||
# Draft purchase order created
|
||||
self.po = self.env['purchase.order'].sudo(self.user_purchase_user).create(self.po_vals)
|
||||
self.po = self.env['purchase.order'].with_user(self.user_purchase_user).create(self.po_vals)
|
||||
self.assertTrue(self.po, 'Purchase: no purchase order created')
|
||||
|
||||
# Purchase order confirm
|
||||
|
||||
@@ -11,18 +11,18 @@ class TestDeleteOrder(TestPurchase):
|
||||
''' Testcase for deleting purchase order with purchase user group'''
|
||||
|
||||
# In order to test delete process on purchase order,tried to delete a confirmed order and check Error Message.
|
||||
purchase_order_1 = self.env.ref('purchase.purchase_order_1').sudo(self.res_users_purchase_user.id)
|
||||
purchase_order_1 = self.env.ref('purchase.purchase_order_1').with_user(self.res_users_purchase_user)
|
||||
with self.assertRaises(UserError):
|
||||
purchase_order_1.unlink()
|
||||
|
||||
# Delete 'cancelled' purchase order with user group
|
||||
purchase_order_7 = self.env.ref('purchase.purchase_order_7').sudo(self.res_users_purchase_user.id)
|
||||
purchase_order_7 = self.env.ref('purchase.purchase_order_7').with_user(self.res_users_purchase_user)
|
||||
purchase_order_7.button_cancel()
|
||||
self.assertEqual(purchase_order_7.state, 'cancel', 'PO is cancelled!')
|
||||
purchase_order_7.unlink()
|
||||
|
||||
# Delete 'draft' purchase order with user group
|
||||
purchase_order_5 = self.env.ref('purchase.purchase_order_5').sudo(self.res_users_purchase_user.id)
|
||||
purchase_order_5 = self.env.ref('purchase.purchase_order_5').with_user(self.res_users_purchase_user)
|
||||
self.assertEqual(purchase_order_5.state, 'draft', 'PO in draft state!')
|
||||
purchase_order_5.button_cancel()
|
||||
self.assertEqual(purchase_order_5.state, 'cancel', 'PO is cancelled!')
|
||||
|
||||
@@ -7,7 +7,7 @@ class TestPurchaseOrderProcess(TestPurchase):
|
||||
""" Test cancel purchase order with group user."""
|
||||
|
||||
# In order to test the cancel flow,start it from canceling confirmed purchase order.
|
||||
po_edit_with_user = self.env.ref('purchase.purchase_order_5').sudo(self.res_users_purchase_user.id)
|
||||
po_edit_with_user = self.env.ref('purchase.purchase_order_5').with_user(self.res_users_purchase_user)
|
||||
|
||||
# Confirm the purchase order.
|
||||
po_edit_with_user.button_confirm()
|
||||
|
||||
@@ -77,7 +77,7 @@ class TestRepair(AccountingTestCase):
|
||||
repair = self._create_simple_repair_order('after_repair')
|
||||
self._create_simple_operation(repair_id=repair.id, qty=1.0, price_unit=50.0)
|
||||
# I confirm Repair order taking Invoice Method 'After Repair'.
|
||||
repair.sudo(self.res_repair_user.id).action_repair_confirm()
|
||||
repair.with_user(self.res_repair_user).action_repair_confirm()
|
||||
|
||||
# I check the state is in "Confirmed".
|
||||
self.assertEqual(repair.state, "confirmed", 'Repair order should be in "Confirmed" state.')
|
||||
@@ -107,7 +107,7 @@ class TestRepair(AccountingTestCase):
|
||||
def test_01_repair_b4inv(self):
|
||||
repair = self._create_simple_repair_order('b4repair')
|
||||
# I confirm Repair order for Invoice Method 'Before Repair'.
|
||||
repair.sudo(self.res_repair_user.id).action_repair_confirm()
|
||||
repair.with_user(self.res_repair_user).action_repair_confirm()
|
||||
|
||||
# I click on "Create Invoice" button of this wizard to make invoice.
|
||||
repair.action_repair_invoice_create()
|
||||
@@ -128,7 +128,7 @@ class TestRepair(AccountingTestCase):
|
||||
self.assertEqual(repair.amount_total, 26, "Amount_total should be 26")
|
||||
|
||||
# I confirm Repair order for Invoice Method 'No Invoice'.
|
||||
repair.sudo(self.res_repair_user.id).action_repair_confirm()
|
||||
repair.with_user(self.res_repair_user).action_repair_confirm()
|
||||
|
||||
# I start the repairing process by clicking on "Start Repair" button for Invoice Method 'No Invoice'.
|
||||
repair.action_repair_start()
|
||||
|
||||
@@ -62,92 +62,92 @@ class TestAccessRights(TestCommonSaleNoChart):
|
||||
""" Test sales manager's access rights """
|
||||
SaleOrder = self.env['sale.order'].with_context(tracking_disable=True)
|
||||
# Manager can see the SO which is assigned to another salesperson
|
||||
self.order.sudo(self.user_manager).read()
|
||||
self.order.with_user(self.user_manager).read()
|
||||
# Manager can change a salesperson of the SO
|
||||
self.order.sudo(self.user_manager).write({'user_id': self.user_salesperson_1.id})
|
||||
self.order.with_user(self.user_manager).write({'user_id': self.user_salesperson_1.id})
|
||||
# Manager can create the SO for other salesperson
|
||||
sale_order = SaleOrder.sudo(self.user_manager).create({
|
||||
sale_order = SaleOrder.with_user(self.user_manager).create({
|
||||
'partner_id': self.partner_customer_usd.id,
|
||||
'user_id': self.user_salesperson_1.id
|
||||
})
|
||||
self.assertIn(sale_order.id, SaleOrder.search([]).ids, 'Sales manager should be able to create the SO of other salesperson')
|
||||
# Manager can confirm the SO
|
||||
sale_order.sudo(self.user_manager).action_confirm()
|
||||
sale_order.with_user(self.user_manager).action_confirm()
|
||||
# Manager can not delete confirmed SO
|
||||
with self.assertRaises(UserError):
|
||||
sale_order.sudo(self.user_manager).unlink()
|
||||
sale_order.with_user(self.user_manager).unlink()
|
||||
# Manager can delete the SO of other salesperson if SO is in 'draft' or 'cancel' state
|
||||
self.order.sudo(self.user_manager).unlink()
|
||||
self.order.with_user(self.user_manager).unlink()
|
||||
self.assertNotIn(self.order.id, SaleOrder.search([]).ids, 'Sales manager should be able to delete the SO')
|
||||
|
||||
# Manager can create a Sales Team
|
||||
india_channel = self.env['crm.team'].with_context(tracking_disable=True).sudo(self.user_manager).create({
|
||||
india_channel = self.env['crm.team'].with_context(tracking_disable=True).with_user(self.user_manager).create({
|
||||
'name': 'India',
|
||||
})
|
||||
self.assertIn(india_channel.id, self.env['crm.team'].search([]).ids, 'Sales manager should be able to create a Sales Team')
|
||||
# Manager can edit a Sales Team
|
||||
india_channel.sudo(self.user_manager).write({'name': 'new_india'})
|
||||
india_channel.with_user(self.user_manager).write({'name': 'new_india'})
|
||||
self.assertEquals(india_channel.name, 'new_india', 'Sales manager should be able to edit a Sales Team')
|
||||
# Manager can delete a Sales Team
|
||||
india_channel.sudo(self.user_manager).unlink()
|
||||
india_channel.with_user(self.user_manager).unlink()
|
||||
self.assertNotIn(india_channel.id, self.env['crm.team'].search([]).ids, 'Sales manager should be able to delete a Sales Team')
|
||||
|
||||
def test_access_sales_person(self):
|
||||
""" Test Salesperson's access rights """
|
||||
# Salesperson can see only their own sales order
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_salesperson_1).read()
|
||||
self.order.with_user(self.user_salesperson_1).read()
|
||||
# Now assign the SO to themselves
|
||||
self.order.write({'user_id': self.user_salesperson_1.id})
|
||||
self.order.sudo(self.user_salesperson_1).read()
|
||||
self.order.with_user(self.user_salesperson_1).read()
|
||||
# Salesperson can change a Sales Team of SO
|
||||
self.order.sudo(self.user_salesperson_1).write({'team_id': self.sales_channel.id})
|
||||
self.order.with_user(self.user_salesperson_1).write({'team_id': self.sales_channel.id})
|
||||
# Salesperson can't create the SO of other salesperson
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['sale.order'].sudo(self.user_salesperson_1).create({
|
||||
self.env['sale.order'].with_user(self.user_salesperson_1).create({
|
||||
'partner_id': self.partner_customer_usd.id,
|
||||
'user_id': self.user_salesperson.id
|
||||
})
|
||||
# Salesperson can't delete the SO
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_salesperson_1).unlink()
|
||||
self.order.with_user(self.user_salesperson_1).unlink()
|
||||
# Salesperson can confirm the SO
|
||||
self.order.sudo(self.user_salesperson_1).action_confirm()
|
||||
self.order.with_user(self.user_salesperson_1).action_confirm()
|
||||
|
||||
def test_access_portal_user(self):
|
||||
""" Test portal user's access rights """
|
||||
# Portal user can see the confirmed SO for which they are assigned as a customer
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_portal).read()
|
||||
self.order.with_user(self.user_portal).read()
|
||||
|
||||
self.order.write({'partner_id': self.user_portal.partner_id.id})
|
||||
self.order.action_confirm()
|
||||
# Portal user can't edit the SO
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_portal).write({'team_id': self.sales_channel.id})
|
||||
self.order.with_user(self.user_portal).write({'team_id': self.sales_channel.id})
|
||||
# Portal user can't create the SO
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['sale.order'].sudo(self.user_portal).create({
|
||||
self.env['sale.order'].with_user(self.user_portal).create({
|
||||
'partner_id': self.partner_customer_usd.id,
|
||||
})
|
||||
# Portal user can't delete the SO which is in 'draft' or 'cancel' state
|
||||
self.order.action_cancel()
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_portal).unlink()
|
||||
self.order.with_user(self.user_portal).unlink()
|
||||
|
||||
def test_access_employee(self):
|
||||
""" Test classic employee's access rights """
|
||||
# Employee can't see any SO
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_employee).read()
|
||||
self.order.with_user(self.user_employee).read()
|
||||
# Employee can't edit the SO
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_employee).write({'team_id': self.sales_channel.id})
|
||||
self.order.with_user(self.user_employee).write({'team_id': self.sales_channel.id})
|
||||
# Employee can't create the SO
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['sale.order'].sudo(self.user_employee).create({
|
||||
self.env['sale.order'].with_user(self.user_employee).create({
|
||||
'partner_id': self.partner_customer_usd.id,
|
||||
})
|
||||
# Employee can't delete the SO
|
||||
with self.assertRaises(AccessError):
|
||||
self.order.sudo(self.user_employee).unlink()
|
||||
self.order.with_user(self.user_employee).unlink()
|
||||
|
||||
@@ -133,8 +133,8 @@ class TestSaleOrder(TestCommonSaleNoChart):
|
||||
# SO in state 'draft' can be deleted
|
||||
so_copy = self.sale_order.copy()
|
||||
with self.assertRaises(AccessError):
|
||||
so_copy.sudo(self.user_employee).unlink()
|
||||
self.assertTrue(so_copy.sudo(self.user_manager).unlink(), 'Sale: deleting a quotation should be possible')
|
||||
so_copy.with_user(self.user_employee).unlink()
|
||||
self.assertTrue(so_copy.with_user(self.user_manager).unlink(), 'Sale: deleting a quotation should be possible')
|
||||
|
||||
# SO in state 'cancel' can be deleted
|
||||
so_copy = self.sale_order.copy()
|
||||
@@ -143,19 +143,19 @@ class TestSaleOrder(TestCommonSaleNoChart):
|
||||
so_copy.action_cancel()
|
||||
self.assertTrue(so_copy.state == 'cancel', 'Sale: SO should be in state "cancel"')
|
||||
with self.assertRaises(AccessError):
|
||||
so_copy.sudo(self.user_employee).unlink()
|
||||
self.assertTrue(so_copy.sudo(self.user_manager).unlink(), 'Sale: deleting a cancelled SO should be possible')
|
||||
so_copy.with_user(self.user_employee).unlink()
|
||||
self.assertTrue(so_copy.with_user(self.user_manager).unlink(), 'Sale: deleting a cancelled SO should be possible')
|
||||
|
||||
# SO in state 'sale' or 'done' cannot be deleted
|
||||
self.sale_order.action_confirm()
|
||||
self.assertTrue(self.sale_order.state == 'sale', 'Sale: SO should be in state "sale"')
|
||||
with self.assertRaises(UserError):
|
||||
self.sale_order.sudo(self.user_manager).unlink()
|
||||
self.sale_order.with_user(self.user_manager).unlink()
|
||||
|
||||
self.sale_order.action_done()
|
||||
self.assertTrue(self.sale_order.state == 'done', 'Sale: SO should be in state "done"')
|
||||
with self.assertRaises(UserError):
|
||||
self.sale_order.sudo(self.user_manager).unlink()
|
||||
self.sale_order.with_user(self.user_manager).unlink()
|
||||
|
||||
def test_cost_invoicing(self):
|
||||
""" Test confirming a vendor invoice to reinvoice cost on the so """
|
||||
|
||||
@@ -33,12 +33,12 @@ class TestAccessRights(TestCommonSalePurchaseNoChart):
|
||||
""" Check a saleperson (only) can generate a PO and a PO user can not confirm a SO """
|
||||
SaleOrder = self.env['sale.order'].with_context(tracking_disable=True)
|
||||
|
||||
sale_order = SaleOrder.sudo(user=self.user_salesperson).create({
|
||||
sale_order = SaleOrder.with_user(self.user_salesperson).create({
|
||||
'partner_id': self.partner_customer_usd.id,
|
||||
'user_id': self.user_salesperson.id
|
||||
})
|
||||
|
||||
sol_service_purchase = self.env['sale.order.line'].sudo(user=self.user_salesperson).create({
|
||||
sol_service_purchase = self.env['sale.order.line'].with_user(self.user_salesperson).create({
|
||||
'name': self.service_purchase_1.name,
|
||||
'product_id': self.service_purchase_1.id,
|
||||
'product_uom_qty': 4,
|
||||
@@ -58,13 +58,13 @@ class TestAccessRights(TestCommonSalePurchaseNoChart):
|
||||
|
||||
# try to access PO as sale person
|
||||
with self.assertRaises(AccessError):
|
||||
purchase_orders = self.env['purchase.order'].sudo(user=self.user_salesperson).search(action['domain'])
|
||||
purchase_orders = self.env['purchase.order'].with_user(self.user_salesperson).search(action['domain'])
|
||||
purchase_orders.read()
|
||||
|
||||
# try to access PO as purchase person
|
||||
purchase_orders = self.env['purchase.order'].sudo(user=self.user_purchaseperson).search(action['domain'])
|
||||
purchase_orders = self.env['purchase.order'].with_user(self.user_purchaseperson).search(action['domain'])
|
||||
purchase_orders.read()
|
||||
|
||||
# try to access the PO lines from the SO, as sale person
|
||||
with self.assertRaises(AccessError):
|
||||
sol_service_purchase.sudo(user=self.user_salesperson).purchase_line_ids.read()
|
||||
sol_service_purchase.with_user(self.user_salesperson).purchase_line_ids.read()
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestDefaultTeam(common.SavepointCase):
|
||||
|
||||
def test_01_user_team(self):
|
||||
"""Get default team, when user belongs to one."""
|
||||
team = self.CrmTeam.sudo(self.user)._get_default_team_id()
|
||||
team = self.CrmTeam.with_user(self.user)._get_default_team_id()
|
||||
self.assertEqual(team, self.team_1)
|
||||
|
||||
def test_02_fallback_team(self):
|
||||
@@ -40,9 +40,9 @@ class TestDefaultTeam(common.SavepointCase):
|
||||
# Clear users from team.
|
||||
self.team_1.member_ids = [(5,)]
|
||||
# Case 1.
|
||||
team = self.CrmTeam.sudo(self.user)._get_default_team_id()
|
||||
team = self.CrmTeam.with_user(self.user)._get_default_team_id()
|
||||
self.assertEqual(team, self.team_2)
|
||||
# Case 2.
|
||||
self.team_2.active = False
|
||||
team = self.CrmTeam.sudo(self.user)._get_default_team_id()
|
||||
team = self.CrmTeam.with_user(self.user)._get_default_team_id()
|
||||
self.assertEqual(team, self.CrmTeam)
|
||||
|
||||
@@ -22,7 +22,7 @@ class StockReportController(http.Controller):
|
||||
def report(self, output_format, report_name, token, report_id=False, **kw):
|
||||
uid = request.session.uid
|
||||
domain = [('create_uid', '=', uid)]
|
||||
stock_traceability = request.env['stock.traceability.report'].sudo(uid).search(domain, limit=1)
|
||||
stock_traceability = request.env['stock.traceability.report'].with_user(uid).search(domain, limit=1)
|
||||
line_data = json.loads(kw['data'])
|
||||
try:
|
||||
if output_format == 'pdf':
|
||||
|
||||
@@ -224,7 +224,7 @@ class StockQuant(models.Model):
|
||||
domain = expression.AND([[('location_id', '=', location_id.id)], domain])
|
||||
|
||||
# Copy code of _search for special NULLS FIRST/LAST order
|
||||
self.sudo(self._uid).check_access_rights('read')
|
||||
self.with_user(self._uid).check_access_rights('read')
|
||||
query = self._where_calc(domain)
|
||||
self._apply_ir_rules(query, 'read')
|
||||
from_clause, where_clause, where_clause_params = query.get_sql()
|
||||
|
||||
@@ -6,7 +6,7 @@ from odoo.addons.product.tests import common
|
||||
class TestStockCommon(common.TestProductCommon):
|
||||
|
||||
def _create_pack_operation(self, product, product_qty, picking_id, **values):
|
||||
PackOperation = self.env['stock.move.line'].sudo(self.user_stock_manager)
|
||||
PackOperation = self.env['stock.move.line'].with_user(self.user_stock_manager)
|
||||
vals = {
|
||||
'picking_id': picking_id.id,
|
||||
'product_id': product.id,
|
||||
@@ -28,7 +28,7 @@ class TestStockCommon(common.TestProductCommon):
|
||||
|
||||
def _create_move(self, product, src_location, dst_location, **values):
|
||||
# TDE FIXME: user as parameter
|
||||
Move = self.env['stock.move'].sudo(self.user_stock_manager)
|
||||
Move = self.env['stock.move'].with_user(self.user_stock_manager)
|
||||
# simulate create + onchange
|
||||
move = Move.new({'product_id': product.id, 'location_id': src_location.id, 'location_dest_id': dst_location.id})
|
||||
move.onchange_product_id()
|
||||
|
||||
@@ -485,9 +485,9 @@ class StockQuant(SavepointCase):
|
||||
'quantity': 1.0,
|
||||
})
|
||||
with self.assertRaises(AccessError):
|
||||
quant.sudo(self.demo_user).write({'quantity': 2.0})
|
||||
quant.with_user(self.demo_user).write({'quantity': 2.0})
|
||||
with self.assertRaises(AccessError):
|
||||
quant.sudo(self.demo_user).unlink()
|
||||
quant.with_user(self.demo_user).unlink()
|
||||
|
||||
self.env = self.env(user=self.stock_user)
|
||||
with self.assertRaises(AccessError):
|
||||
@@ -497,9 +497,9 @@ class StockQuant(SavepointCase):
|
||||
'quantity': 1.0,
|
||||
})
|
||||
with self.assertRaises(AccessError):
|
||||
quant.sudo(self.demo_user).write({'quantity': 2.0})
|
||||
quant.with_user(self.demo_user).write({'quantity': 2.0})
|
||||
with self.assertRaises(AccessError):
|
||||
quant.sudo(self.demo_user).unlink()
|
||||
quant.with_user(self.demo_user).unlink()
|
||||
|
||||
def test_in_date_1(self):
|
||||
""" Check that no incoming date is set when updating the quantity of an untracked quant.
|
||||
|
||||
@@ -207,9 +207,9 @@ class TestEditableQuant(SavepointCase):
|
||||
self.assertEqual(quant.quantity, 12)
|
||||
# Try to write on quant without permission
|
||||
with self.assertRaises(AccessError):
|
||||
quant.sudo(user_demo).write({'inventory_quantity': 8})
|
||||
quant.with_user(user_demo).write({'inventory_quantity': 8})
|
||||
self.assertEqual(quant.quantity, 12)
|
||||
|
||||
# Try to write on quant with permission
|
||||
quant.sudo(user_admin).write({'inventory_quantity': 8})
|
||||
quant.with_user(user_admin).write({'inventory_quantity': 8})
|
||||
self.assertEqual(quant.quantity, 8)
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestWarehouse(TestStockCommon):
|
||||
'inventory_quantity': 50.0,
|
||||
'location_id': self.warehouse_1.lot_stock_id.id,
|
||||
})
|
||||
inventory = self.env['stock.inventory'].sudo(self.user_stock_manager).create({
|
||||
inventory = self.env['stock.inventory'].with_user(self.user_stock_manager).create({
|
||||
'name': 'Starting for product_1',
|
||||
'location_ids': [(4, self.warehouse_1.lot_stock_id.id)],
|
||||
'product_ids': [(4, self.product_1.id)],
|
||||
@@ -50,7 +50,7 @@ class TestWarehouse(TestStockCommon):
|
||||
""" Using the "Update Quantity" wizard as stock manager.
|
||||
"""
|
||||
self.product_1.type = 'product'
|
||||
InventoryWizard = self.env['stock.change.product.qty'].sudo(self.user_stock_manager.id)
|
||||
InventoryWizard = self.env['stock.change.product.qty'].with_user(self.user_stock_manager)
|
||||
inventory_wizard = InventoryWizard.create({
|
||||
'product_id': self.product_1.id,
|
||||
'product_tmpl_id': self.product_1.product_tmpl_id.id,
|
||||
@@ -69,7 +69,7 @@ class TestWarehouse(TestStockCommon):
|
||||
""" Using the "Update Quantity" wizard as stock user.
|
||||
"""
|
||||
self.product_1.type = 'product'
|
||||
InventoryWizard = self.env['stock.change.product.qty'].sudo(self.user_stock_user.id)
|
||||
InventoryWizard = self.env['stock.change.product.qty'].with_user(self.user_stock_user)
|
||||
inventory_wizard = InventoryWizard.create({
|
||||
'product_id': self.product_1.id,
|
||||
'product_tmpl_id': self.product_1.product_tmpl_id.id,
|
||||
@@ -87,7 +87,7 @@ class TestWarehouse(TestStockCommon):
|
||||
self.assertEqual(len(quant), 0)
|
||||
|
||||
def test_basic_move(self):
|
||||
product = self.product_3.sudo(self.user_stock_manager)
|
||||
product = self.product_3.with_user(self.user_stock_manager)
|
||||
product.type = 'product'
|
||||
picking_out = self.env['stock.picking'].create({
|
||||
'partner_id': self.env.ref('base.res_partner_2').id,
|
||||
|
||||
@@ -96,7 +96,7 @@ class Survey(http.Controller):
|
||||
if validity_code != 'survey_wrong':
|
||||
survey_sudo, answer_sudo = self._fetch_from_access_token(survey_token, answer_token)
|
||||
try:
|
||||
survey_user = survey_sudo.sudo(request.env.user)
|
||||
survey_user = survey_sudo.with_user(request.env.user)
|
||||
survey_user.check_access_rights(self, 'read', raise_exception=True)
|
||||
survey_user.check_access_rule(self, 'read')
|
||||
except:
|
||||
@@ -201,8 +201,8 @@ class Survey(http.Controller):
|
||||
|
||||
if not answer_sudo:
|
||||
try:
|
||||
survey_sudo.sudo(request.env.user).check_access_rights('read')
|
||||
survey_sudo.sudo(request.env.user).check_access_rule('read')
|
||||
survey_sudo.with_user(request.env.user).check_access_rights('read')
|
||||
survey_sudo.with_user(request.env.user).check_access_rule('read')
|
||||
except:
|
||||
return werkzeug.utils.redirect("/")
|
||||
else:
|
||||
|
||||
@@ -63,26 +63,26 @@ class SurveyCase(common.SavepointCase):
|
||||
'customer': True,
|
||||
})
|
||||
|
||||
self.survey = self.env['survey.survey'].sudo(self.survey_manager).create({
|
||||
self.survey = self.env['survey.survey'].with_user(self.survey_manager).create({
|
||||
'title': 'Test Survey',
|
||||
'access_mode': 'public',
|
||||
'users_login_required': True,
|
||||
'users_can_go_back': False,
|
||||
'state': 'open',
|
||||
})
|
||||
self.page_0 = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
self.page_0 = self.env['survey.question'].with_user(self.survey_manager).create({
|
||||
'title': 'First page',
|
||||
'survey_id': self.survey.id,
|
||||
'sequence': 1,
|
||||
'is_page': True,
|
||||
})
|
||||
self.question_ft = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
self.question_ft = self.env['survey.question'].with_user(self.survey_manager).create({
|
||||
'title': 'Test Free Text',
|
||||
'survey_id': self.survey.id,
|
||||
'sequence': 2,
|
||||
'question_type': 'free_text',
|
||||
})
|
||||
self.question_num = self.env['survey.question'].sudo(self.survey_manager).create({
|
||||
self.question_num = self.env['survey.question'].with_user(self.survey_manager).create({
|
||||
'title': 'Test NUmerical Box',
|
||||
'survey_id': self.survey.id,
|
||||
'sequence': 3,
|
||||
@@ -90,8 +90,8 @@ class SurveyCase(common.SavepointCase):
|
||||
})
|
||||
|
||||
@contextmanager
|
||||
def sudo(self, user):
|
||||
""" Quick sudo environment """
|
||||
def with_user(self, user):
|
||||
""" Quick with_user environment """
|
||||
old_uid = self.uid
|
||||
try:
|
||||
self.uid = user.id
|
||||
|
||||
@@ -38,7 +38,7 @@ class TestCertificationFlow(common.SurveyCase, HttpCase):
|
||||
def test_flow_certificate(self):
|
||||
# Step: survey user creates the certification
|
||||
# --------------------------------------------------
|
||||
with self.sudo(self.survey_user):
|
||||
with self.with_user(self.survey_user):
|
||||
certification = self.env['survey.survey'].create({
|
||||
'title': 'User Certification for SO lines',
|
||||
'access_mode': 'public',
|
||||
|
||||
@@ -6,7 +6,7 @@ from odoo.addons.survey.tests import common
|
||||
|
||||
class TestSurveyComputePagesQuestions(common.SurveyCase):
|
||||
def test_compute_pages_questions(self):
|
||||
with self.sudo(self.survey_manager):
|
||||
with self.with_user(self.survey_manager):
|
||||
survey = self.env['survey.survey'].create({
|
||||
'title': 'Test compute survey',
|
||||
'state': 'open',
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestSurveyFlow(common.SurveyCase, HttpCase):
|
||||
def test_flow_public(self):
|
||||
# Step: survey manager creates the survey
|
||||
# --------------------------------------------------
|
||||
with self.sudo(self.survey_manager):
|
||||
with self.with_user(self.survey_manager):
|
||||
survey = self.env['survey.survey'].create({
|
||||
'title': 'Public Survey for Tarte Al Djotte',
|
||||
'access_mode': 'public',
|
||||
|
||||
@@ -32,7 +32,7 @@ class TestSurveyInvite(common.SurveyCase):
|
||||
# no questions
|
||||
self.env['survey.survey'].create({'title': 'Test survey', 'question_and_page_ids': [(0, 0, {'is_page': True, 'title': 'P0', 'sequence': 1})]}),
|
||||
# closed
|
||||
self.env['survey.survey'].sudo(self.survey_manager).create({
|
||||
self.env['survey.survey'].with_user(self.survey_manager).create({
|
||||
'title': 'S0',
|
||||
'state': 'closed',
|
||||
'question_and_page_ids': [
|
||||
|
||||
@@ -33,23 +33,23 @@ class TestAccess(common.SurveyCase):
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['survey.survey'].search([('title', 'ilike', 'Test')])
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).read(['title'])
|
||||
self.survey.with_user(self.env.user).read(['title'])
|
||||
|
||||
# Write: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).write({'title': 'New Title'})
|
||||
self.survey.with_user(self.env.user).write({'title': 'New Title'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.page_0.sudo(self.env.user).write({'title': 'New Title'})
|
||||
self.page_0.with_user(self.env.user).write({'title': 'New Title'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.question_ft.sudo(self.env.user).write({'question': 'New Title'})
|
||||
self.question_ft.with_user(self.env.user).write({'question': 'New Title'})
|
||||
|
||||
# Unlink: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).unlink()
|
||||
self.survey.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.page_0.sudo(self.env.user).unlink()
|
||||
self.page_0.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.question_ft.sudo(self.env.user).unlink()
|
||||
self.question_ft.with_user(self.env.user).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model')
|
||||
@users('user_portal')
|
||||
@@ -66,23 +66,23 @@ class TestAccess(common.SurveyCase):
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['survey.survey'].search([('title', 'ilike', 'Test')])
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).read(['title'])
|
||||
self.survey.with_user(self.env.user).read(['title'])
|
||||
|
||||
# Write: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).write({'title': 'New Title'})
|
||||
self.survey.with_user(self.env.user).write({'title': 'New Title'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.page_0.sudo(self.env.user).write({'title': 'New Title'})
|
||||
self.page_0.with_user(self.env.user).write({'title': 'New Title'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.question_ft.sudo(self.env.user).write({'question': 'New Title'})
|
||||
self.question_ft.with_user(self.env.user).write({'question': 'New Title'})
|
||||
|
||||
# Unlink: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).unlink()
|
||||
self.survey.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.page_0.sudo(self.env.user).unlink()
|
||||
self.page_0.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.question_ft.sudo(self.env.user).unlink()
|
||||
self.question_ft.with_user(self.env.user).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model')
|
||||
@users('user_public')
|
||||
@@ -99,23 +99,23 @@ class TestAccess(common.SurveyCase):
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['survey.survey'].search([('title', 'ilike', 'Test')])
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).read(['title'])
|
||||
self.survey.with_user(self.env.user).read(['title'])
|
||||
|
||||
# Write: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).write({'title': 'New Title'})
|
||||
self.survey.with_user(self.env.user).write({'title': 'New Title'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.page_0.sudo(self.env.user).write({'title': 'New Title'})
|
||||
self.page_0.with_user(self.env.user).write({'title': 'New Title'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.question_ft.sudo(self.env.user).write({'question': 'New Title'})
|
||||
self.question_ft.with_user(self.env.user).write({'question': 'New Title'})
|
||||
|
||||
# Unlink: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).unlink()
|
||||
self.survey.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.page_0.sudo(self.env.user).unlink()
|
||||
self.page_0.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.question_ft.sudo(self.env.user).unlink()
|
||||
self.question_ft.with_user(self.env.user).unlink()
|
||||
|
||||
@users('survey_manager')
|
||||
def test_access_survey_survey_manager(self):
|
||||
@@ -151,12 +151,12 @@ class TestAccess(common.SurveyCase):
|
||||
# Write: own only
|
||||
survey.write({'title': 'New Title'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).write({'title': 'New Title'})
|
||||
self.survey.with_user(self.env.user).write({'title': 'New Title'})
|
||||
|
||||
# Unlink: own only
|
||||
survey.unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.survey.sudo(self.env.user).unlink()
|
||||
self.survey.with_user(self.env.user).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model')
|
||||
@users('user_emp')
|
||||
@@ -179,13 +179,13 @@ class TestAccess(common.SurveyCase):
|
||||
|
||||
# Write: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).write({'state': 'done'})
|
||||
self.answer_0.with_user(self.env.user).write({'state': 'done'})
|
||||
|
||||
# Unlink: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).unlink()
|
||||
self.answer_0.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0_0.sudo(self.env.user).unlink()
|
||||
self.answer_0_0.with_user(self.env.user).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model')
|
||||
@users('user_portal')
|
||||
@@ -208,13 +208,13 @@ class TestAccess(common.SurveyCase):
|
||||
|
||||
# Write: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).write({'state': 'done'})
|
||||
self.answer_0.with_user(self.env.user).write({'state': 'done'})
|
||||
|
||||
# Unlink: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).unlink()
|
||||
self.answer_0.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0_0.sudo(self.env.user).unlink()
|
||||
self.answer_0_0.with_user(self.env.user).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model')
|
||||
@users('user_public')
|
||||
@@ -237,13 +237,13 @@ class TestAccess(common.SurveyCase):
|
||||
|
||||
# Write: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).write({'state': 'done'})
|
||||
self.answer_0.with_user(self.env.user).write({'state': 'done'})
|
||||
|
||||
# Unlink: nope
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).unlink()
|
||||
self.answer_0.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0_0.sudo(self.env.user).unlink()
|
||||
self.answer_0_0.with_user(self.env.user).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model')
|
||||
@users('survey_user')
|
||||
@@ -278,20 +278,20 @@ class TestAccess(common.SurveyCase):
|
||||
# Write: own survey only
|
||||
answer_own.write({'state': 'done'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).write({'state': 'done'})
|
||||
self.answer_0.with_user(self.env.user).write({'state': 'done'})
|
||||
|
||||
# Unlink: own survey only
|
||||
answer_own.unlink()
|
||||
answer_line_own.unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0.sudo(self.env.user).unlink()
|
||||
self.answer_0.with_user(self.env.user).unlink()
|
||||
with self.assertRaises(AccessError):
|
||||
self.answer_0_0.sudo(self.env.user).unlink()
|
||||
self.answer_0_0.with_user(self.env.user).unlink()
|
||||
|
||||
@users('survey_manager')
|
||||
def test_access_answers_survey_manager(self):
|
||||
admin = self.env.ref('base.user_admin')
|
||||
with self.sudo(admin):
|
||||
with self.with_user(admin):
|
||||
survey_other = self.env['survey.survey'].create({'title': 'Other'})
|
||||
self.env['survey.question'].create({'title': 'Other', 'sequence': 0, 'is_page': True, 'survey_id': survey_other.id})
|
||||
question_other = self.env['survey.question'].create({'title': 'Other Question', 'sequence': 1, 'survey_id': survey_other.id})
|
||||
|
||||
@@ -9,36 +9,36 @@ class TestChatterTweaks(BaseFunctionalTest, TestRecipients):
|
||||
|
||||
def test_post_no_subscribe_author(self):
|
||||
original = self.test_record.message_follower_ids
|
||||
self.test_record.sudo(self.user_employee).with_context({'mail_create_nosubscribe': True}).message_post(
|
||||
self.test_record.with_user(self.user_employee).with_context({'mail_create_nosubscribe': True}).message_post(
|
||||
body='Test Body', message_type='comment', subtype='mt_comment')
|
||||
self.assertEqual(self.test_record.message_follower_ids.mapped('partner_id'), original.mapped('partner_id'))
|
||||
self.assertEqual(self.test_record.message_follower_ids.mapped('channel_id'), original.mapped('channel_id'))
|
||||
|
||||
def test_post_no_subscribe_recipients(self):
|
||||
original = self.test_record.message_follower_ids
|
||||
self.test_record.sudo(self.user_employee).with_context({'mail_create_nosubscribe': True}).message_post(
|
||||
self.test_record.with_user(self.user_employee).with_context({'mail_create_nosubscribe': True}).message_post(
|
||||
body='Test Body', message_type='comment', subtype='mt_comment', partner_ids=[self.partner_1.id, self.partner_2.id])
|
||||
self.assertEqual(self.test_record.message_follower_ids.mapped('partner_id'), original.mapped('partner_id'))
|
||||
self.assertEqual(self.test_record.message_follower_ids.mapped('channel_id'), original.mapped('channel_id'))
|
||||
|
||||
def test_post_subscribe_recipients(self):
|
||||
original = self.test_record.message_follower_ids
|
||||
self.test_record.sudo(self.user_employee).with_context({'mail_create_nosubscribe': True, 'mail_post_autofollow': True}).message_post(
|
||||
self.test_record.with_user(self.user_employee).with_context({'mail_create_nosubscribe': True, 'mail_post_autofollow': True}).message_post(
|
||||
body='Test Body', message_type='comment', subtype='mt_comment', partner_ids=[self.partner_1.id, self.partner_2.id])
|
||||
self.assertEqual(self.test_record.message_follower_ids.mapped('partner_id'), original.mapped('partner_id') | self.partner_1 | self.partner_2)
|
||||
self.assertEqual(self.test_record.message_follower_ids.mapped('channel_id'), original.mapped('channel_id'))
|
||||
|
||||
def test_chatter_mail_create_nolog(self):
|
||||
""" Test disable of automatic chatter message at create """
|
||||
rec = self.env['mail.test.simple'].sudo(self.user_employee).with_context({'mail_create_nolog': True}).create({'name': 'Test'})
|
||||
rec = self.env['mail.test.simple'].with_user(self.user_employee).with_context({'mail_create_nolog': True}).create({'name': 'Test'})
|
||||
self.assertEqual(rec.message_ids, self.env['mail.message'])
|
||||
|
||||
rec = self.env['mail.test.simple'].sudo(self.user_employee).with_context({'mail_create_nolog': False}).create({'name': 'Test'})
|
||||
rec = self.env['mail.test.simple'].with_user(self.user_employee).with_context({'mail_create_nolog': False}).create({'name': 'Test'})
|
||||
self.assertEqual(len(rec.message_ids), 1)
|
||||
|
||||
def test_chatter_mail_notrack(self):
|
||||
""" Test disable of automatic value tracking at create and write """
|
||||
rec = self.env['mail.test.track'].sudo(self.user_employee).create({'name': 'Test', 'user_id': self.user_employee.id})
|
||||
rec = self.env['mail.test.track'].with_user(self.user_employee).create({'name': 'Test', 'user_id': self.user_employee.id})
|
||||
self.assertEqual(len(rec.message_ids), 1,
|
||||
"A creation message without tracking values should have been posted")
|
||||
self.assertEqual(len(rec.message_ids.sudo().tracking_value_ids), 0,
|
||||
@@ -56,7 +56,7 @@ class TestChatterTweaks(BaseFunctionalTest, TestRecipients):
|
||||
|
||||
def test_chatter_tracking_disable(self):
|
||||
""" Test disable of all chatter features at create and write """
|
||||
rec = self.env['mail.test.track'].sudo(self.user_employee).with_context({'tracking_disable': True}).create({'name': 'Test', 'user_id': self.user_employee.id})
|
||||
rec = self.env['mail.test.track'].with_user(self.user_employee).with_context({'tracking_disable': True}).create({'name': 'Test', 'user_id': self.user_employee.id})
|
||||
self.assertEqual(rec.sudo().message_ids, self.env['mail.message'])
|
||||
self.assertEqual(rec.sudo().mapped('message_ids.tracking_value_ids'), self.env['mail.tracking.value'])
|
||||
|
||||
@@ -66,7 +66,7 @@ class TestChatterTweaks(BaseFunctionalTest, TestRecipients):
|
||||
rec.with_context({'tracking_disable': False}).write({'user_id': self.user_employee.id})
|
||||
self.assertEqual(len(rec.sudo().mapped('message_ids.tracking_value_ids')), 1)
|
||||
|
||||
rec = self.env['mail.test.track'].sudo(self.user_employee).with_context({'tracking_disable': False}).create({'name': 'Test', 'user_id': self.user_employee.id})
|
||||
rec = self.env['mail.test.track'].with_user(self.user_employee).with_context({'tracking_disable': False}).create({'name': 'Test', 'user_id': self.user_employee.id})
|
||||
self.assertEqual(len(rec.sudo().message_ids), 1,
|
||||
"Creation message without tracking values should have been posted")
|
||||
self.assertEqual(len(rec.sudo().mapped('message_ids.tracking_value_ids')), 0,
|
||||
@@ -114,7 +114,7 @@ class TestNotifications(BaseFunctionalTest, MockEmails):
|
||||
message = self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id])
|
||||
message.sudo(self.user_employee).set_message_done()
|
||||
message.with_user(self.user_employee).set_message_done()
|
||||
|
||||
def test_set_message_done_portal(self):
|
||||
user_portal = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys', notification_type='inbox')
|
||||
@@ -124,11 +124,11 @@ class TestNotifications(BaseFunctionalTest, MockEmails):
|
||||
message = self.test_record.message_post(
|
||||
body='Test', message_type='comment', subtype='mail.mt_comment',
|
||||
partner_ids=[self.user_employee.partner_id.id, user_portal.partner_id.id])
|
||||
message.sudo(user_portal).set_message_done()
|
||||
message.with_user(user_portal).set_message_done()
|
||||
|
||||
def test_set_star(self):
|
||||
msg = self.test_record.sudo(self.user_admin).message_post(body='My Body', subject='1')
|
||||
msg_emp = self.env['mail.message'].sudo(self.user_employee).browse(msg.id)
|
||||
msg = self.test_record.with_user(self.user_admin).message_post(body='My Body', subject='1')
|
||||
msg_emp = self.env['mail.message'].with_user(self.user_employee).browse(msg.id)
|
||||
|
||||
# Admin set as starred
|
||||
msg.toggle_message_starred()
|
||||
|
||||
@@ -16,7 +16,7 @@ class TestInvite(common.BaseFunctionalTest, common.MockEmails):
|
||||
mail_invite = self.env['mail.wizard.invite'].with_context({
|
||||
'default_res_model': 'mail.test.simple',
|
||||
'default_res_id': self.test_record.id
|
||||
}).sudo(self.user_employee.id).create({
|
||||
}).with_user(self.user_employee).create({
|
||||
'partner_ids': [(4, test_partner.id), (4, self.user_admin.partner_id.id)],
|
||||
'send_mail': True})
|
||||
mail_invite.add_followers()
|
||||
|
||||
@@ -32,14 +32,14 @@ class TestActivityCommon(BaseFunctionalTest):
|
||||
class TestActivityRights(TestActivityCommon):
|
||||
|
||||
def test_activity_security_user_access_other(self):
|
||||
activity = self.test_record.sudo(self.user_employee).activity_schedule(
|
||||
activity = self.test_record.with_user(self.user_employee).activity_schedule(
|
||||
'test_mail.mail_act_test_todo',
|
||||
user_id=self.user_admin.id)
|
||||
self.assertTrue(activity.can_write)
|
||||
activity.write({'user_id': self.user_employee.id})
|
||||
|
||||
def test_activity_security_user_access_own(self):
|
||||
activity = self.test_record.sudo(self.user_employee).activity_schedule(
|
||||
activity = self.test_record.with_user(self.user_employee).activity_schedule(
|
||||
'test_mail.mail_act_test_todo')
|
||||
self.assertTrue(activity.can_write)
|
||||
activity.write({'user_id': self.user_admin.id})
|
||||
@@ -81,7 +81,7 @@ class TestActivityRights(TestActivityCommon):
|
||||
# cannot create activities if no access to the document
|
||||
with patch.object(MailTestActivity, 'check_access_rights', autospec=True, side_effect=_employee_crash):
|
||||
with self.assertRaises(exceptions.AccessError):
|
||||
activity = self.test_record.sudo(self.user_employee).activity_schedule(
|
||||
activity = self.test_record.with_user(self.user_employee).activity_schedule(
|
||||
'test_mail.mail_act_test_todo',
|
||||
user_id=self.user_admin.id)
|
||||
|
||||
@@ -133,7 +133,7 @@ class TestActivityFlow(TestActivityCommon):
|
||||
|
||||
def test_activity_notify_other_user(self):
|
||||
self.user_admin.notification_type = 'email'
|
||||
rec = self.test_record.sudo(self.user_employee)
|
||||
rec = self.test_record.with_user(self.user_employee)
|
||||
with self.assertNotifications(partner_admin=(1, 'email', 'read')):
|
||||
activity = rec.activity_schedule(
|
||||
'test_mail.mail_act_test_todo',
|
||||
@@ -143,7 +143,7 @@ class TestActivityFlow(TestActivityCommon):
|
||||
|
||||
def test_activity_notify_same_user(self):
|
||||
self.user_employee.notification_type = 'email'
|
||||
rec = self.test_record.sudo(self.user_employee)
|
||||
rec = self.test_record.with_user(self.user_employee)
|
||||
with self.assertNotifications(partner_employee=(0, 'email', 'read')):
|
||||
activity = rec.activity_schedule(
|
||||
'test_mail.mail_act_test_todo',
|
||||
@@ -155,7 +155,7 @@ class TestActivityFlow(TestActivityCommon):
|
||||
self.user_employee.notification_type = 'email'
|
||||
activity = self.test_record.activity_schedule('test_mail.mail_act_test_todo', user_id=self.user_employee.id)
|
||||
with self.assertNotifications(partner_employee=(0, 'email', 'read')):
|
||||
activity.sudo(self.user_admin).write({'user_id': self.user_employee.id})
|
||||
activity.with_user(self.user_admin).write({'user_id': self.user_employee.id})
|
||||
self.assertEqual(activity.user_id, self.user_employee)
|
||||
|
||||
|
||||
@@ -233,7 +233,7 @@ class TestActivityMixin(TestActivityCommon):
|
||||
self.assertEqual(len(self.test_record.message_ids), 2)
|
||||
|
||||
def test_activity_mixin_archive(self):
|
||||
rec = self.test_record.sudo(self.user_employee)
|
||||
rec = self.test_record.with_user(self.user_employee)
|
||||
new_act = rec.activity_schedule(
|
||||
'test_mail.mail_act_test_todo',
|
||||
user_id=self.user_admin.id)
|
||||
@@ -246,7 +246,7 @@ class TestActivityMixin(TestActivityCommon):
|
||||
self.assertEqual(rec.activity_ids, self.env['mail.activity'])
|
||||
|
||||
def test_activity_mixin_reschedule_user(self):
|
||||
rec = self.test_record.sudo(self.user_employee)
|
||||
rec = self.test_record.with_user(self.user_employee)
|
||||
rec.activity_schedule(
|
||||
'test_mail.mail_act_test_todo',
|
||||
user_id=self.user_admin.id)
|
||||
|
||||
@@ -36,63 +36,63 @@ class TestChannelAccessRights(common.BaseFunctionalTest, common.MockEmails):
|
||||
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.models')
|
||||
def test_access_rights_public(self):
|
||||
# Read public group -> ok
|
||||
self.group_public.sudo(self.user_public).read()
|
||||
self.group_public.with_user(self.user_public).read()
|
||||
|
||||
# Read Pigs -> ko, restricted to employees
|
||||
# TODO: Change the except_orm to Warning ( Because here it's call check_access_rule
|
||||
# which still generate exception in except_orm.So we need to change all
|
||||
# except_orm to warning in mail module.)
|
||||
with self.assertRaises(except_orm):
|
||||
self.group_pigs.sudo(self.user_public).read()
|
||||
self.group_pigs.with_user(self.user_public).read()
|
||||
|
||||
# Read a private group when being a member: ok
|
||||
self.group_private.write({'channel_partner_ids': [(4, self.user_public.partner_id.id)]})
|
||||
self.group_private.sudo(self.user_public).read()
|
||||
self.group_private.with_user(self.user_public).read()
|
||||
|
||||
# Create group: ko, no access rights
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['mail.channel'].sudo(self.user_public).create({'name': 'Test'})
|
||||
self.env['mail.channel'].with_user(self.user_public).create({'name': 'Test'})
|
||||
|
||||
# Update group: ko, no access rights
|
||||
with self.assertRaises(AccessError):
|
||||
self.group_public.sudo(self.user_public).write({'name': 'Broutouschnouk'})
|
||||
self.group_public.with_user(self.user_public).write({'name': 'Broutouschnouk'})
|
||||
|
||||
# Unlink group: ko, no access rights
|
||||
with self.assertRaises(AccessError):
|
||||
self.group_public.sudo(self.user_public).unlink()
|
||||
self.group_public.with_user(self.user_public).unlink()
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.models', 'odoo.models.unlink')
|
||||
def test_access_rights_groups(self):
|
||||
# Employee read employee-based group: ok
|
||||
# TODO Change the except_orm to Warning
|
||||
self.group_pigs.sudo(self.user_employee).read()
|
||||
self.group_pigs.with_user(self.user_employee).read()
|
||||
|
||||
# Employee can create a group
|
||||
self.env['mail.channel'].sudo(self.user_employee).create({'name': 'Test'})
|
||||
self.env['mail.channel'].with_user(self.user_employee).create({'name': 'Test'})
|
||||
|
||||
# Employee update employee-based group: ok
|
||||
self.group_pigs.sudo(self.user_employee).write({'name': 'modified'})
|
||||
self.group_pigs.with_user(self.user_employee).write({'name': 'modified'})
|
||||
|
||||
# Employee unlink employee-based group: ok
|
||||
self.group_pigs.sudo(self.user_employee).unlink()
|
||||
self.group_pigs.with_user(self.user_employee).unlink()
|
||||
|
||||
# Employee cannot read a private group
|
||||
with self.assertRaises(except_orm):
|
||||
self.group_private.sudo(self.user_employee).read()
|
||||
self.group_private.with_user(self.user_employee).read()
|
||||
|
||||
# Employee cannot write on private
|
||||
with self.assertRaises(AccessError):
|
||||
self.group_private.sudo(self.user_employee).write({'name': 're-modified'})
|
||||
self.group_private.with_user(self.user_employee).write({'name': 're-modified'})
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.models')
|
||||
def test_access_rights_followers_ko(self):
|
||||
with self.assertRaises(AccessError):
|
||||
self.group_private.sudo(self.user_portal).name
|
||||
self.group_private.with_user(self.user_portal).name
|
||||
|
||||
def test_access_rights_followers_portal(self):
|
||||
# Do: Chell is added into Pigs members and browse it -> ok for messages, ko for partners (no read permission)
|
||||
self.group_private.write({'channel_partner_ids': [(4, self.user_portal.partner_id.id)]})
|
||||
chell_pigs = self.group_private.sudo(self.user_portal)
|
||||
chell_pigs = self.group_private.with_user(self.user_portal)
|
||||
trigger_read = chell_pigs.name
|
||||
for message in chell_pigs.message_ids:
|
||||
trigger_read = message.subject
|
||||
@@ -206,7 +206,7 @@ class TestChannelFeatures(common.BaseFunctionalTest, common.MockEmails):
|
||||
'email_send': False,
|
||||
'name': 'test'
|
||||
})
|
||||
infos = test_chat.sudo(self.user_admin).channel_info()
|
||||
infos = test_chat.with_user(self.user_admin).channel_info()
|
||||
self.assertEqual(infos[0]['direct_partner'][0]['out_of_office_message'], 'Out')
|
||||
|
||||
|
||||
@@ -246,13 +246,13 @@ class TestChannelModeration(common.Moderation):
|
||||
self.channel_1.write({'channel_partner_ids': [(4, self.partner_employee_2.id), (4, self.partner_admin.id)]})
|
||||
self.channel_1._update_moderation_email([self.partner_admin.email], 'ban')
|
||||
self._init_mock_build_email()
|
||||
self.channel_1.sudo(self.user_employee).send_guidelines()
|
||||
self.channel_1.with_user(self.user_employee).send_guidelines()
|
||||
self.env['mail.mail'].process_email_queue()
|
||||
self.assertEmails(False, self.partner_employee | self.partner_employee_2, email_from=self.env.company.catchall or self.env.company.email)
|
||||
|
||||
def test_send_guidelines_crash(self):
|
||||
with self.assertRaises(UserError):
|
||||
self.channel_1.sudo(self.user_employee_2).send_guidelines()
|
||||
self.channel_1.with_user(self.user_employee_2).send_guidelines()
|
||||
|
||||
def test_update_moderation_email(self):
|
||||
self.channel_1.write({'moderation_ids': [
|
||||
|
||||
@@ -24,7 +24,7 @@ class BaseFollowersTest(common.BaseFunctionalTest):
|
||||
cls.default_group_subtypes_portal = Subtype.search([('internal', '=', False), ('default', '=', True), '|', ('res_model', '=', 'mail.test.simple'), ('res_model', '=', False)])
|
||||
|
||||
def test_field_message_is_follower(self):
|
||||
test_record = self.test_record.sudo(self.user_employee)
|
||||
test_record = self.test_record.with_user(self.user_employee)
|
||||
followed_before = test_record.search([('message_is_follower', '=', True)])
|
||||
self.assertFalse(test_record.message_is_follower)
|
||||
test_record.message_subscribe(partner_ids=[self.user_employee.partner_id.id])
|
||||
@@ -33,7 +33,7 @@ class BaseFollowersTest(common.BaseFunctionalTest):
|
||||
self.assertEqual(followed_before | test_record, followed_after)
|
||||
|
||||
def test_field_followers(self):
|
||||
test_record = self.test_record.sudo(self.user_employee)
|
||||
test_record = self.test_record.with_user(self.user_employee)
|
||||
test_record.message_subscribe(partner_ids=[self.user_employee.partner_id.id, self.user_admin.partner_id.id], channel_ids=[self.channel_listen.id])
|
||||
followers = self.env['mail.followers'].search([
|
||||
('res_model', '=', 'mail.test.simple'),
|
||||
@@ -43,7 +43,7 @@ class BaseFollowersTest(common.BaseFunctionalTest):
|
||||
self.assertEqual(test_record.message_channel_ids, self.channel_listen)
|
||||
|
||||
def test_followers_subtypes_default(self):
|
||||
test_record = self.test_record.sudo(self.user_employee)
|
||||
test_record = self.test_record.with_user(self.user_employee)
|
||||
test_record.message_subscribe(partner_ids=[self.user_employee.partner_id.id])
|
||||
self.assertEqual(test_record.message_partner_ids, self.user_employee.partner_id)
|
||||
follower = self.env['mail.followers'].search([
|
||||
@@ -56,7 +56,7 @@ class BaseFollowersTest(common.BaseFunctionalTest):
|
||||
def test_followers_subtypes_default_internal(self):
|
||||
user_portal = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
test_record = self.test_record.sudo(self.user_employee)
|
||||
test_record = self.test_record.with_user(self.user_employee)
|
||||
test_record.message_subscribe(partner_ids=[user_portal.partner_id.id])
|
||||
self.assertEqual(test_record.message_partner_ids, user_portal.partner_id)
|
||||
follower = self.env['mail.followers'].search([
|
||||
@@ -66,7 +66,7 @@ class BaseFollowersTest(common.BaseFunctionalTest):
|
||||
self.assertEqual(follower.subtype_ids, self.default_group_subtypes_portal)
|
||||
|
||||
def test_followers_subtypes_specified(self):
|
||||
test_record = self.test_record.sudo(self.user_employee)
|
||||
test_record = self.test_record.with_user(self.user_employee)
|
||||
test_record.message_subscribe(partner_ids=[self.user_employee.partner_id.id], subtype_ids=[self.mt_mg_nodef.id])
|
||||
self.assertEqual(test_record.message_partner_ids, self.user_employee.partner_id)
|
||||
follower = self.env['mail.followers'].search([
|
||||
@@ -77,7 +77,7 @@ class BaseFollowersTest(common.BaseFunctionalTest):
|
||||
self.assertEqual(follower.subtype_ids, self.mt_mg_nodef)
|
||||
|
||||
def test_followers_multiple_subscription_force(self):
|
||||
test_record = self.test_record.sudo(self.user_employee)
|
||||
test_record = self.test_record.with_user(self.user_employee)
|
||||
|
||||
test_record.message_subscribe(partner_ids=[self.user_admin.partner_id.id], subtype_ids=[self.mt_mg_nodef.id])
|
||||
self.assertEqual(test_record.message_partner_ids, self.user_admin.partner_id)
|
||||
@@ -90,7 +90,7 @@ class BaseFollowersTest(common.BaseFunctionalTest):
|
||||
self.assertEqual(test_record.message_follower_ids.subtype_ids, self.mt_mg_nodef | self.mt_al_nodef)
|
||||
|
||||
def test_followers_multiple_subscription_noforce(self):
|
||||
test_record = self.test_record.sudo(self.user_employee)
|
||||
test_record = self.test_record.with_user(self.user_employee)
|
||||
|
||||
test_record.message_subscribe(partner_ids=[self.user_admin.partner_id.id], subtype_ids=[self.mt_mg_nodef.id, self.mt_al_nodef.id])
|
||||
self.assertEqual(test_record.message_partner_ids, self.user_admin.partner_id)
|
||||
@@ -123,7 +123,7 @@ class AdvancedFollowersTest(common.BaseFunctionalTest):
|
||||
|
||||
cls.user_portal = mail_new_test_user(cls.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
cls.test_track = cls.env['mail.test.track'].sudo(cls.user_employee).create({
|
||||
cls.test_track = cls.env['mail.test.track'].with_user(cls.user_employee).create({
|
||||
'name': 'Test',
|
||||
})
|
||||
|
||||
@@ -150,22 +150,22 @@ class AdvancedFollowersTest(common.BaseFunctionalTest):
|
||||
|
||||
def test_auto_subscribe_post(self):
|
||||
""" People posting a message are automatically added as followers """
|
||||
self.test_track.sudo(self.user_admin).message_post(body='Coucou hibou', message_type='comment')
|
||||
self.test_track.with_user(self.user_admin).message_post(body='Coucou hibou', message_type='comment')
|
||||
self.assertEqual(self.test_track.message_partner_ids, self.user_employee.partner_id | self.user_admin.partner_id)
|
||||
|
||||
def test_auto_subscribe_post_email(self):
|
||||
""" People posting an email are automatically added as followers """
|
||||
self.test_track.sudo(self.user_admin).message_post(body='Coucou hibou', message_type='email')
|
||||
self.test_track.with_user(self.user_admin).message_post(body='Coucou hibou', message_type='email')
|
||||
self.assertEqual(self.test_track.message_partner_ids, self.user_employee.partner_id | self.user_admin.partner_id)
|
||||
|
||||
def test_auto_subscribe_not_on_notification(self):
|
||||
""" People posting an automatic notification are not subscribed """
|
||||
self.test_track.sudo(self.user_admin).message_post(body='Coucou hibou', message_type='notification')
|
||||
self.test_track.with_user(self.user_admin).message_post(body='Coucou hibou', message_type='notification')
|
||||
self.assertEqual(self.test_track.message_partner_ids, self.user_employee.partner_id)
|
||||
|
||||
def test_auto_subscribe_responsible(self):
|
||||
""" Responsibles are tracked and added as followers """
|
||||
sub = self.env['mail.test.track'].sudo(self.user_employee).create({
|
||||
sub = self.env['mail.test.track'].with_user(self.user_employee).create({
|
||||
'name': 'Test',
|
||||
'user_id': self.user_admin.id,
|
||||
})
|
||||
@@ -190,7 +190,7 @@ class AdvancedFollowersTest(common.BaseFunctionalTest):
|
||||
umbrella.message_subscribe(partner_ids=[self.user_portal.partner_id.id])
|
||||
self.assertEqual(umbrella.message_partner_ids, self.user_portal.partner_id)
|
||||
|
||||
sub1 = self.env['mail.test.track'].sudo(self.user_employee).create({
|
||||
sub1 = self.env['mail.test.track'].with_user(self.user_employee).create({
|
||||
'name': 'Task-Like Test',
|
||||
'umbrella_id': umbrella.id,
|
||||
})
|
||||
|
||||
@@ -482,7 +482,7 @@ class TestMailgateway(BaseFunctionalTest, MockEmails):
|
||||
@mute_logger('odoo.addons.mail.models.mail_thread', 'odoo.models', 'odoo.addons.mail.models.mail_mail')
|
||||
def test_message_process_reply_to_new_thread(self):
|
||||
""" Test replies not being considered as replies but use destination information instead (aka, mass post + specific reply to using aliases) """
|
||||
first_record = self.env['mail.test.simple'].sudo(self.user_employee).create({'name': 'Replies to Record'})
|
||||
first_record = self.env['mail.test.simple'].with_user(self.user_employee).create({'name': 'Replies to Record'})
|
||||
record_msg = first_record.message_post(
|
||||
subject='Discussion',
|
||||
no_auto_thread=False,
|
||||
|
||||
@@ -22,7 +22,7 @@ class TestMessageValues(common.BaseFunctionalTest, common.MockEmails):
|
||||
'alias_contact': 'followers',
|
||||
})
|
||||
|
||||
cls.Message = cls.env['mail.message'].sudo(cls.user_employee)
|
||||
cls.Message = cls.env['mail.message'].with_user(cls.user_employee)
|
||||
|
||||
def test_mail_message_values_basic(self):
|
||||
self.env['ir.config_parameter'].search([('key', '=', 'mail.catchall.domain')]).unlink()
|
||||
@@ -121,7 +121,7 @@ class TestMessageValues(common.BaseFunctionalTest, common.MockEmails):
|
||||
self.assertNotIn('-%d-' % self.alias_record.id, msg.message_id.split('@')[0])
|
||||
|
||||
def test_mail_message_base64_image(self):
|
||||
msg = self.env['mail.message'].sudo(self.user_employee).create({
|
||||
msg = self.env['mail.message'].with_user(self.user_employee).create({
|
||||
'body': 'taratata <img src="data:image/png;base64,iV/+OkI=" width="2"> <img src="data:image/png;base64,iV/+OkI=" width="2">',
|
||||
})
|
||||
self.assertEqual(len(msg.attachment_ids), 1)
|
||||
@@ -182,22 +182,22 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
msg6 = self.env['mail.message'].create({
|
||||
'subject': '_ZTest', 'body': 'A Birds', 'subtype_id': self.ref('mail.mt_comment'),
|
||||
'model': 'mail.channel', 'res_id': self.group_private.id})
|
||||
msg7 = self.env['mail.message'].sudo(self.user_employee).create({
|
||||
msg7 = self.env['mail.message'].with_user(self.user_employee).create({
|
||||
'subject': '_ZTest', 'body': 'B', 'subtype_id': self.ref('mail.mt_comment')})
|
||||
msg8 = self.env['mail.message'].sudo(self.user_employee).create({
|
||||
msg8 = self.env['mail.message'].with_user(self.user_employee).create({
|
||||
'subject': '_ZTest', 'body': 'B+E', 'subtype_id': self.ref('mail.mt_comment'),
|
||||
'partner_ids': [(6, 0, [self.user_employee.partner_id.id])]})
|
||||
|
||||
# Test: Public: 2 messages (recipient)
|
||||
messages = self.env['mail.message'].sudo(self.user_public).search([('subject', 'like', '_ZTest')])
|
||||
messages = self.env['mail.message'].with_user(self.user_public).search([('subject', 'like', '_ZTest')])
|
||||
self.assertEqual(messages, msg2 | msg4)
|
||||
|
||||
# Test: Employee: 3 messages on Pigs Raoul can read (employee can read group with default values)
|
||||
messages = self.env['mail.message'].sudo(self.user_employee).search([('subject', 'like', '_ZTest'), ('body', 'ilike', 'A')])
|
||||
messages = self.env['mail.message'].with_user(self.user_employee).search([('subject', 'like', '_ZTest'), ('body', 'ilike', 'A')])
|
||||
self.assertEqual(messages, msg3 | msg4 | msg5)
|
||||
|
||||
# Test: Raoul: 3 messages on Pigs Raoul can read (employee can read group with default values), 0 on Birds (private group) + 2 messages as author
|
||||
messages = self.env['mail.message'].sudo(self.user_employee).search([('subject', 'like', '_ZTest')])
|
||||
messages = self.env['mail.message'].with_user(self.user_employee).search([('subject', 'like', '_ZTest')])
|
||||
self.assertEqual(messages, msg3 | msg4 | msg5 | msg7 | msg8)
|
||||
|
||||
# Test: Admin: all messages
|
||||
@@ -205,12 +205,12 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
self.assertEqual(messages, msg1 | msg2 | msg3 | msg4 | msg5 | msg6 | msg7 | msg8)
|
||||
|
||||
# Test: Portal: 0 (no access to groups, not recipient)
|
||||
messages = self.env['mail.message'].sudo(self.user_portal).search([('subject', 'like', '_ZTest')])
|
||||
messages = self.env['mail.message'].with_user(self.user_portal).search([('subject', 'like', '_ZTest')])
|
||||
self.assertFalse(messages)
|
||||
|
||||
# Test: Portal: 2 messages (public group with a subtype)
|
||||
self.group_pigs.write({'public': 'public'})
|
||||
messages = self.env['mail.message'].sudo(self.user_portal).search([('subject', 'like', '_ZTest')])
|
||||
messages = self.env['mail.message'].with_user(self.user_portal).search([('subject', 'like', '_ZTest')])
|
||||
self.assertEqual(messages, msg4 | msg5)
|
||||
|
||||
# --------------------------------------------------
|
||||
@@ -223,16 +223,16 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
# which still generate exception in except_orm.So we need to change all
|
||||
# except_orm to warning in mail module.)
|
||||
with self.assertRaises(except_orm):
|
||||
self.message.sudo(self.user_employee).read()
|
||||
self.message.with_user(self.user_employee).read()
|
||||
|
||||
@mute_logger('odoo.models')
|
||||
def test_mail_message_access_read_crash_portal(self):
|
||||
with self.assertRaises(except_orm):
|
||||
self.message.sudo(self.user_portal).read(['body', 'message_type', 'subtype_id'])
|
||||
self.message.with_user(self.user_portal).read(['body', 'message_type', 'subtype_id'])
|
||||
|
||||
def test_mail_message_access_read_ok_portal(self):
|
||||
self.message.write({'subtype_id': self.ref('mail.mt_comment'), 'res_id': self.group_public.id})
|
||||
self.message.sudo(self.user_portal).read(['body', 'message_type', 'subtype_id'])
|
||||
self.message.with_user(self.user_portal).read(['body', 'message_type', 'subtype_id'])
|
||||
|
||||
def test_mail_message_access_read_notification(self):
|
||||
attachment = self.env['ir.attachment'].create({
|
||||
@@ -241,24 +241,24 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
# attach the attachment to the message
|
||||
self.message.write({'attachment_ids': [(4, attachment.id)]})
|
||||
self.message.write({'partner_ids': [(4, self.user_employee.partner_id.id)]})
|
||||
self.message.sudo(self.user_employee).read()
|
||||
self.message.with_user(self.user_employee).read()
|
||||
# Test: Bert has access to attachment, ok because he can read message
|
||||
attachment.sudo(self.user_employee).read(['name', 'datas'])
|
||||
attachment.with_user(self.user_employee).read(['name', 'datas'])
|
||||
|
||||
def test_mail_message_access_read_author(self):
|
||||
self.message.write({'author_id': self.user_employee.partner_id.id})
|
||||
self.message.sudo(self.user_employee).read()
|
||||
self.message.with_user(self.user_employee).read()
|
||||
|
||||
def test_mail_message_access_read_doc(self):
|
||||
self.message.write({'model': 'mail.channel', 'res_id': self.group_public.id})
|
||||
# Test: Bert reads the message, ok because linked to a doc he is allowed to read
|
||||
self.message.sudo(self.user_employee).read()
|
||||
self.message.with_user(self.user_employee).read()
|
||||
|
||||
def test_mail_message_access_read_crash_moderation(self):
|
||||
# with self.assertRaises(AccessError):
|
||||
self.message.write({'model': 'mail.channel', 'res_id': self.group_public.id, 'moderation_status': 'pending_moderation'})
|
||||
# Test: Bert reads the message, ok because linked to a doc he is allowed to read
|
||||
self.message.sudo(self.user_employee).read()
|
||||
self.message.with_user(self.user_employee).read()
|
||||
|
||||
# --------------------------------------------------
|
||||
# CREATE
|
||||
@@ -268,22 +268,22 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
def test_mail_message_access_create_crash_public(self):
|
||||
# Do: Bert creates a message on Pigs -> ko, no creation rights
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['mail.message'].sudo(self.user_public).create({'model': 'mail.channel', 'res_id': self.group_pigs.id, 'body': 'Test'})
|
||||
self.env['mail.message'].with_user(self.user_public).create({'model': 'mail.channel', 'res_id': self.group_pigs.id, 'body': 'Test'})
|
||||
|
||||
# Do: Bert create a message on Jobs -> ko, no creation rights
|
||||
with self.assertRaises(AccessError):
|
||||
self.env['mail.message'].sudo(self.user_public).create({'model': 'mail.channel', 'res_id': self.group_public.id, 'body': 'Test'})
|
||||
self.env['mail.message'].with_user(self.user_public).create({'model': 'mail.channel', 'res_id': self.group_public.id, 'body': 'Test'})
|
||||
|
||||
@mute_logger('odoo.models')
|
||||
def test_mail_message_access_create_crash(self):
|
||||
# Do: Bert create a private message -> ko, no creation rights
|
||||
with self.assertRaises(except_orm):
|
||||
self.env['mail.message'].sudo(self.user_employee).create({'model': 'mail.channel', 'res_id': self.group_private.id, 'body': 'Test'})
|
||||
self.env['mail.message'].with_user(self.user_employee).create({'model': 'mail.channel', 'res_id': self.group_private.id, 'body': 'Test'})
|
||||
|
||||
@mute_logger('odoo.models')
|
||||
def test_mail_message_access_create_doc(self):
|
||||
# TODO Change the except_orm to Warning
|
||||
Message = self.env['mail.message'].sudo(self.user_employee)
|
||||
Message = self.env['mail.message'].with_user(self.user_employee)
|
||||
# Do: Raoul creates a message on Jobs -> ok, write access to the related document
|
||||
Message.create({'model': 'mail.channel', 'res_id': self.group_public.id, 'body': 'Test'})
|
||||
# Do: Raoul creates a message on Priv -> ko, no write access to the related document
|
||||
@@ -291,11 +291,11 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
Message.create({'model': 'mail.channel', 'res_id': self.group_private.id, 'body': 'Test'})
|
||||
|
||||
def test_mail_message_access_create_private(self):
|
||||
self.env['mail.message'].sudo(self.user_employee).create({'body': 'Test'})
|
||||
self.env['mail.message'].with_user(self.user_employee).create({'body': 'Test'})
|
||||
|
||||
def test_mail_message_access_create_reply(self):
|
||||
self.message.write({'partner_ids': [(4, self.user_employee.partner_id.id)]})
|
||||
self.env['mail.message'].sudo(self.user_employee).create({'model': 'mail.channel', 'res_id': self.group_private.id, 'body': 'Test', 'parent_id': self.message.id})
|
||||
self.env['mail.message'].with_user(self.user_employee).create({'model': 'mail.channel', 'res_id': self.group_private.id, 'body': 'Test', 'parent_id': self.message.id})
|
||||
|
||||
# --------------------------------------------------
|
||||
# WRITE
|
||||
@@ -310,17 +310,17 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
'moderator_ids': [(4, self.user_employee.id)],
|
||||
})
|
||||
self.message.write({'model': 'mail.channel', 'res_id': self.group_public.id, 'moderation_status': 'pending_moderation'})
|
||||
self.message.sudo(self.user_employee).write({'moderation_status': 'accepted'})
|
||||
self.message.with_user(self.user_employee).write({'moderation_status': 'accepted'})
|
||||
|
||||
def test_mail_message_access_write_crash_moderation(self):
|
||||
self.message.write({'model': 'mail.channel', 'res_id': self.group_public.id, 'moderation_status': 'pending_moderation'})
|
||||
with self.assertRaises(AccessError):
|
||||
self.message.sudo(self.user_employee).write({'moderation_status': 'accepted'})
|
||||
self.message.with_user(self.user_employee).write({'moderation_status': 'accepted'})
|
||||
|
||||
@mute_logger('openerp.addons.mail.models.mail_mail')
|
||||
def test_mark_all_as_read(self):
|
||||
self.user_employee.notification_type = 'inbox'
|
||||
emp_partner = self.user_employee.partner_id.sudo(self.user_employee.id)
|
||||
emp_partner = self.user_employee.partner_id.with_user(self.user_employee)
|
||||
|
||||
group_private = self.env['mail.channel'].with_context({
|
||||
'mail_create_nolog': True,
|
||||
@@ -360,7 +360,7 @@ class TestMessageAccess(common.BaseFunctionalTest, common.MockEmails):
|
||||
@mute_logger('openerp.addons.mail.models.mail_mail')
|
||||
def test_mark_all_as_read_share(self):
|
||||
self.user_portal.notification_type = 'inbox'
|
||||
portal_partner = self.user_portal.partner_id.sudo(self.user_portal.id)
|
||||
portal_partner = self.user_portal.partner_id.with_user(self.user_portal)
|
||||
|
||||
# mark all as read clear needactions
|
||||
self.group_pigs.message_post(body='Test', message_type='comment', subtype='mail.mt_comment', partner_ids=[portal_partner.id])
|
||||
@@ -402,7 +402,7 @@ class TestMessageModeration(common.Moderation):
|
||||
# A pending moderation message needs to have field channel_ids empty. Moderators
|
||||
# need to be able to notify a pending moderation message (in a channel they moderate).
|
||||
self.assertFalse(self.msg_admin_pending_c1.channel_ids)
|
||||
self.msg_admin_pending_c1.sudo(self.user_employee)._moderate('accept')
|
||||
self.msg_admin_pending_c1.with_user(self.user_employee)._moderate('accept')
|
||||
self.assertEqual(self.msg_admin_pending_c1.channel_ids, self.channel_1)
|
||||
self.assertEqual(self.msg_admin_pending_c1.moderation_status, 'accepted')
|
||||
self.assertEqual(self.msg_admin_pending_c1_2.moderation_status, 'pending_moderation')
|
||||
@@ -415,7 +415,7 @@ class TestMessageModeration(common.Moderation):
|
||||
# need to be able to notify a pending moderation message (in a channel they moderate).
|
||||
self.assertFalse(self.msg_admin_pending_c1.channel_ids)
|
||||
self.assertFalse(self.msg_admin_pending_c1_2.channel_ids)
|
||||
self.msg_admin_pending_c1.sudo(self.user_employee)._moderate('allow')
|
||||
self.msg_admin_pending_c1.with_user(self.user_employee)._moderate('allow')
|
||||
self.assertEqual(self.msg_admin_pending_c1.channel_ids, self.channel_1)
|
||||
self.assertEqual(self.msg_admin_pending_c1_2.channel_ids, self.channel_1)
|
||||
self.assertEqual(self.msg_admin_pending_c1.moderation_status, 'accepted')
|
||||
@@ -427,14 +427,14 @@ class TestMessageModeration(common.Moderation):
|
||||
@mute_logger('odoo.models.unlink')
|
||||
def test_moderate_reject(self):
|
||||
self._init_mock_build_email()
|
||||
(self.msg_admin_pending_c1 | self.msg_emp2_pending_c1).sudo(self.user_employee)._moderate_send_reject_email('Title', 'Message to author')
|
||||
(self.msg_admin_pending_c1 | self.msg_emp2_pending_c1).with_user(self.user_employee)._moderate_send_reject_email('Title', 'Message to author')
|
||||
self.env['mail.mail'].process_email_queue()
|
||||
self.assertEmails(self.partner_employee, self.partner_employee_2 | self.partner_admin, subject='Title', body_content='Message to author')
|
||||
|
||||
def test_moderate_discard(self):
|
||||
self._clear_bus()
|
||||
id1, id2 = self.msg_admin_pending_c1.id, self.msg_emp2_pending_c1.id # save ids because unlink will discard them
|
||||
(self.msg_admin_pending_c1 | self.msg_emp2_pending_c1).sudo(self.user_employee)._moderate_discard()
|
||||
(self.msg_admin_pending_c1 | self.msg_emp2_pending_c1).with_user(self.user_employee)._moderate_discard()
|
||||
|
||||
self.assertBusNotification(
|
||||
[(self.cr.dbname, 'res.partner', self.partner_admin.id),
|
||||
|
||||
@@ -77,7 +77,7 @@ class TestMailResend(common.BaseFunctionalTest, common.MockEmails):
|
||||
def connect_failure(**kwargs):
|
||||
raise Exception
|
||||
with patch.object(IrMailServer, 'connect', side_effect=connect_failure):
|
||||
message = self.test_record.sudo(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
message = self.test_record.with_user(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
self.assertBusMessage([self.partner_admin])
|
||||
self.assertEmails(self.partner_admin, [])
|
||||
self.assertNotifStates(('exception', 'exception', 'exception', 'exception'), message)
|
||||
@@ -102,12 +102,12 @@ class TestMailResend(common.BaseFunctionalTest, common.MockEmails):
|
||||
def test_mail_send_no_failure(self):
|
||||
self.user1.write({"email": 'u1@example.com'})
|
||||
self.partner1.write({"email": 'p1@example.com'})
|
||||
message = self.test_record.sudo(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
message = self.test_record.with_user(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
self.assertBusMessage([]) # one update for cancell
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_remove_mail_become_canceled(self):
|
||||
message = self.test_record.sudo(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
message = self.test_record.with_user(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
self.assertEmails(self.partner_admin, self.partners)
|
||||
self.assertBusMessage([self.partner_admin] * 2) # two failure sent on bus, one for each mail
|
||||
wizard = self.env['mail.resend.message'].with_context({'mail_message_to_resend': message.id}).create({})
|
||||
@@ -121,7 +121,7 @@ class TestMailResend(common.BaseFunctionalTest, common.MockEmails):
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_cancel_all(self):
|
||||
message = self.test_record.sudo(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
message = self.test_record.with_user(self.user_admin).message_post(partner_ids=self.partners.ids, subtype='mail.mt_comment', message_type='notification')
|
||||
self.assertNotifStates(('exception', 'sent', 'exception', 'sent'), message)
|
||||
self.assertBusMessage([self.partner_admin] * 2)
|
||||
wizard = self.env['mail.resend.message'].with_context({'mail_message_to_resend': message.id}).create({})
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_composer_w_template(self):
|
||||
composer = self.env['mail.compose.message'].sudo(self.user_employee).with_context({
|
||||
composer = self.env['mail.compose.message'].with_user(self.user_employee).with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_model': 'mail.test.simple',
|
||||
'default_res_id': self.test_record.id,
|
||||
@@ -110,7 +110,7 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_post_post_w_template(self):
|
||||
self.test_record.sudo(self.user_employee).message_post_with_template(self.email_template.id, composition_mode='comment')
|
||||
self.test_record.with_user(self.user_employee).message_post_with_template(self.email_template.id, composition_mode='comment')
|
||||
|
||||
new_partners = self.env['res.partner'].search([('email', 'in', [self.email_1, self.email_2])])
|
||||
self.assertEmails(
|
||||
@@ -124,7 +124,7 @@ class TestMailTemplate(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
def test_composer_w_template_mass_mailing(self):
|
||||
test_record_2 = self.env['mail.test.simple'].with_context(BaseFunctionalTest._test_context).create({'name': 'Test2', 'email_from': 'laurie.poiret@example.com'})
|
||||
|
||||
composer = self.env['mail.compose.message'].sudo(self.user_employee).with_context({
|
||||
composer = self.env['mail.compose.message'].with_user(self.user_employee).with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
# 'default_notify': True,
|
||||
'default_notify': False,
|
||||
|
||||
@@ -35,7 +35,7 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
# subscribe second employee to the group to test notifications
|
||||
self.test_record.message_subscribe(partner_ids=[self.user_admin.partner_id.id])
|
||||
|
||||
msg = self.test_record.sudo(self.user_employee).message_post(
|
||||
msg = self.test_record.with_user(self.user_employee).message_post(
|
||||
body=_body, subject=_subject,
|
||||
message_type='comment', subtype='mt_comment',
|
||||
partner_ids=[self.partner_1.id, self.partner_2.id]
|
||||
@@ -64,7 +64,7 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
def test_post_notifications_keep_emails(self):
|
||||
self.test_record.message_subscribe(partner_ids=[self.user_admin.partner_id.id])
|
||||
|
||||
msg = self.test_record.sudo(self.user_employee).message_post(
|
||||
msg = self.test_record.with_user(self.user_employee).message_post(
|
||||
body='Test', subject='Test',
|
||||
message_type='comment', subtype='mt_comment',
|
||||
partner_ids=[self.partner_1.id, self.partner_2.id],
|
||||
@@ -85,16 +85,16 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
('List1', b'My first attachment'),
|
||||
('List2', b'My second attachment')
|
||||
]
|
||||
_attach_1 = self.env['ir.attachment'].sudo(self.user_employee).create({
|
||||
_attach_1 = self.env['ir.attachment'].with_user(self.user_employee).create({
|
||||
'name': 'Attach1',
|
||||
'datas': 'bWlncmF0aW9uIHRlc3Q=',
|
||||
'res_model': 'mail.compose.message', 'res_id': 0})
|
||||
_attach_2 = self.env['ir.attachment'].sudo(self.user_employee).create({
|
||||
_attach_2 = self.env['ir.attachment'].with_user(self.user_employee).create({
|
||||
'name': 'Attach2',
|
||||
'datas': 'bWlncmF0aW9uIHRlc3Q=',
|
||||
'res_model': 'mail.compose.message', 'res_id': 0})
|
||||
|
||||
msg = self.test_record.sudo(self.user_employee).message_post(
|
||||
msg = self.test_record.with_user(self.user_employee).message_post(
|
||||
body='Test', subject='Test',
|
||||
message_type='comment', subtype='mt_comment',
|
||||
attachment_ids=[_attach_1.id, _attach_2.id],
|
||||
@@ -122,14 +122,14 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_post_answer(self):
|
||||
parent_msg = self.test_record.sudo(self.user_employee).message_post(
|
||||
parent_msg = self.test_record.with_user(self.user_employee).message_post(
|
||||
body='<p>Test</p>', subject='Test Subject',
|
||||
message_type='comment', subtype='mt_comment')
|
||||
|
||||
self.assertEqual(parent_msg.partner_ids, self.env['res.partner'])
|
||||
self.assertEmails(self.user_employee.partner_id, [])
|
||||
|
||||
msg = self.test_record.sudo(self.user_employee).message_post(
|
||||
msg = self.test_record.with_user(self.user_employee).message_post(
|
||||
body='<p>Test Answer</p>',
|
||||
message_type='comment', subtype='mt_comment',
|
||||
partner_ids=[self.partner_1.id],
|
||||
@@ -143,7 +143,7 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
self.assertEmails(self.user_employee.partner_id, [[self.partner_1]], ref_content='openerp-%d-mail.test.simple' % self.test_record.id)
|
||||
# self.assertTrue(all('openerp-%d-mail.test.simple' % self.test_record.id in m['references'] for m in self._mails))
|
||||
|
||||
new_msg = self.test_record.sudo(self.user_employee).message_post(
|
||||
new_msg = self.test_record.with_user(self.user_employee).message_post(
|
||||
body='<p>Test Answer Bis</p>',
|
||||
message_type='comment', subtype='mt_comment',
|
||||
parent_id=msg.id)
|
||||
@@ -157,7 +157,7 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
|
||||
with patch.object(MailTestSimple, 'check_access_rights', return_value=True):
|
||||
self.test_record.message_subscribe((self.partner_1 | self.user_employee.partner_id).ids)
|
||||
new_msg = self.test_record.sudo(portal_user).message_post(
|
||||
new_msg = self.test_record.with_user(portal_user).message_post(
|
||||
body='<p>Test</p>', subject='Subject',
|
||||
message_type='comment', subtype='mt_comment')
|
||||
|
||||
@@ -168,14 +168,14 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
portal_user = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.test_record.sudo(portal_user).message_post(
|
||||
self.test_record.with_user(portal_user).message_post(
|
||||
body='<p>Test</p>', subject='Subject',
|
||||
message_type='comment', subtype='mt_comment')
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.addons.mail.models.mail_thread')
|
||||
def test_post_internal(self):
|
||||
self.test_record.message_subscribe([self.user_admin.partner_id.id])
|
||||
msg = self.test_record.sudo(self.user_employee).message_post(
|
||||
msg = self.test_record.with_user(self.user_employee).message_post(
|
||||
body='My Body', subject='My Subject',
|
||||
message_type='comment', subtype='mt_note')
|
||||
self.assertEqual(msg.partner_ids, self.env['res.partner'])
|
||||
@@ -193,7 +193,7 @@ class TestMessagePost(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
self.assertEqual(reply.parent_id, msg)
|
||||
|
||||
def test_post_log(self):
|
||||
new_note = self.test_record.sudo(self.user_employee)._message_log(
|
||||
new_note = self.test_record.with_user(self.user_employee)._message_log(
|
||||
body='<p>Labrador</p>',
|
||||
)
|
||||
|
||||
@@ -241,7 +241,7 @@ class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
'default_composition_mode': 'comment',
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': self.test_record.id,
|
||||
}).sudo(self.user_employee).create({
|
||||
}).with_user(self.user_employee).create({
|
||||
'body': '<p>Test Body</p>',
|
||||
'partner_ids': [(4, self.partner_1.id), (4, self.partner_2.id)]
|
||||
})
|
||||
@@ -261,7 +261,7 @@ class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
self.env['mail.compose.message'].with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
'default_parent_id': parent.id
|
||||
}).sudo(self.user_employee).create({
|
||||
}).with_user(self.user_employee).create({
|
||||
'body': '<p>Mega</p>',
|
||||
}).send_mail()
|
||||
|
||||
@@ -278,7 +278,7 @@ class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
'default_model': self.test_record._name,
|
||||
'default_res_id': False,
|
||||
'active_ids': [self.test_record.id, test_record_2.id]
|
||||
}).sudo(self.user_employee).create({
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'Testing ${object.name}',
|
||||
'body': '<p>${object.name}</p>',
|
||||
'partner_ids': [(4, self.partner_1.id), (4, self.partner_2.id)]
|
||||
@@ -314,7 +314,7 @@ class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
'default_use_active_domain': True,
|
||||
'active_ids': [self.test_record.id],
|
||||
'active_domain': [('name', 'in', ['%s' % self.test_record.name, '%s' % test_record_2.name])],
|
||||
}).sudo(self.user_employee).create({
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'From Composer Test',
|
||||
'body': '${object.name}',
|
||||
}).send_mail()
|
||||
@@ -332,7 +332,7 @@ class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
'default_use_active_domain': False,
|
||||
'active_ids': [self.test_record.id],
|
||||
'active_domain': [('name', 'in', ['%s' % self.test_record.name, '%s' % test_record_2.name])],
|
||||
}).sudo(self.user_employee).create({
|
||||
}).with_user(self.user_employee).create({
|
||||
'subject': 'From Composer Test',
|
||||
'body': '${object.name}',
|
||||
}).send_mail()
|
||||
@@ -345,7 +345,7 @@ class TestComposer(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
portal_user = mail_new_test_user(self.env, login='chell', groups='base.group_portal', name='Chell Gladys')
|
||||
|
||||
with patch.object(MailTestSimple, 'check_access_rights', return_value=True):
|
||||
ComposerPortal = self.env['mail.compose.message'].sudo(portal_user)
|
||||
ComposerPortal = self.env['mail.compose.message'].with_user(portal_user)
|
||||
|
||||
ComposerPortal.with_context({
|
||||
'default_composition_mode': 'comment',
|
||||
|
||||
@@ -26,7 +26,7 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
|
||||
def setUp(self):
|
||||
super(TestTracking, self).setUp()
|
||||
|
||||
record = self.env['mail.test.full'].sudo(self.user_employee).with_context(common.BaseFunctionalTest._test_context).create({
|
||||
record = self.env['mail.test.full'].with_user(self.user_employee).with_context(common.BaseFunctionalTest._test_context).create({
|
||||
'name': 'Test',
|
||||
})
|
||||
self.record = record.with_context(mail_notrack=False)
|
||||
@@ -120,7 +120,7 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
|
||||
def test_message_track_template_at_create(self):
|
||||
""" Create a record with tracking template on create, template should be sent."""
|
||||
|
||||
Model = self.env['mail.test.full'].sudo(self.user_employee).with_context(common.BaseFunctionalTest._test_context)
|
||||
Model = self.env['mail.test.full'].with_user(self.user_employee).with_context(common.BaseFunctionalTest._test_context)
|
||||
Model = Model.with_context(mail_notrack=False)
|
||||
record = Model.create({
|
||||
'name': 'Test',
|
||||
@@ -155,7 +155,7 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
|
||||
self.record.sudo().write({'email_from': 'X'})
|
||||
|
||||
msg_emp = self.record.message_ids.message_format()
|
||||
msg_admin = self.record.message_ids.sudo(self.user_admin).message_format()
|
||||
msg_admin = self.record.message_ids.with_user(self.user_admin).message_format()
|
||||
self.assertFalse(msg_emp[0].get('tracking_value_ids'), "should not have protected tracking values")
|
||||
self.assertTrue(msg_admin[0].get('tracking_value_ids'), "should have protected tracking values")
|
||||
|
||||
@@ -163,8 +163,8 @@ class TestTracking(common.BaseFunctionalTest, common.MockEmails):
|
||||
self.record._fields['email_from'].groups = 'base.group_erp_manager' # patch the group attribute
|
||||
self.record.sudo().write({'email_from': 'X'})
|
||||
|
||||
msg_emp = self.record.sudo(self.user_employee)._notify_prepare_template_context(self.record.message_ids, {})
|
||||
msg_admin = self.record.sudo(self.user_admin)._notify_prepare_template_context(self.record.message_ids, {})
|
||||
msg_emp = self.record.with_user(self.user_employee)._notify_prepare_template_context(self.record.message_ids, {})
|
||||
msg_admin = self.record.with_user(self.user_admin)._notify_prepare_template_context(self.record.message_ids, {})
|
||||
self.assertFalse(msg_emp.get('tracking_values'), "should not have protected tracking values")
|
||||
self.assertTrue(msg_admin.get('tracking_values'), "should have protected tracking values")
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ class TestOdoobot(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
'subtype': 'mail.mt_comment'
|
||||
}
|
||||
self.odoobot_ping_body = '<a href="http://odoo.com/web#model=res.partner&id=%s" class="o_mail_redirect" data-oe-id="%s" data-oe-model="res.partner" target="_blank">@OdooBot</a>' % (self.odoobot.id, self.odoobot.id)
|
||||
self.test_record_employe = self.test_record.sudo(self.user_employee)
|
||||
self.test_record_employe = self.test_record.with_user(self.user_employee)
|
||||
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_fetch_listener(self):
|
||||
channel = self.env['mail.channel'].sudo(self.user_employee).init_odoobot()
|
||||
channel = self.env['mail.channel'].with_user(self.user_employee).init_odoobot()
|
||||
partners = self.env['mail.channel'].channel_fetch_listeners(channel.uuid)
|
||||
odoobot = self.env.ref("base.partner_root")
|
||||
odoobot_in_fetch_listeners = [partner for partner in partners if partner['id'] == odoobot.id]
|
||||
@@ -52,7 +52,7 @@ class TestOdoobot(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail')
|
||||
def test_onboarding_flow(self):
|
||||
kwargs = self.message_post_default_kwargs.copy()
|
||||
channel = self.env['mail.channel'].sudo(self.user_employee).init_odoobot()
|
||||
channel = self.env['mail.channel'].with_user(self.user_employee).init_odoobot()
|
||||
|
||||
kwargs['body'] = 'tagada 😊'
|
||||
self.assertNextMessage(
|
||||
@@ -61,7 +61,7 @@ class TestOdoobot(BaseFunctionalTest, MockEmails, TestRecipients):
|
||||
answer=("attachment",)
|
||||
)
|
||||
kwargs['body'] = ''
|
||||
attachment = self.env['ir.attachment'].sudo(self.user_employee).create({
|
||||
attachment = self.env['ir.attachment'].with_user(self.user_employee).create({
|
||||
'datas': 'bWlncmF0aW9uIHRlc3Q=',
|
||||
'name': 'picture_of_your_dog.doc',
|
||||
})
|
||||
|
||||
@@ -371,7 +371,7 @@ class TestHeavyMailPerformance(BaseMailPerformance):
|
||||
@warmup
|
||||
def test_complex_message_post(self):
|
||||
self.umbrella.message_subscribe(self.user_portal.partner_id.ids)
|
||||
record = self.umbrella.sudo(self.env.user)
|
||||
record = self.umbrella.with_user(self.env.user)
|
||||
|
||||
with self.assertQueryCount(__system__=78, emp=82): # com runbot: 78 - 82 // test_mail only: 78 - 82
|
||||
record.message_post(
|
||||
@@ -387,7 +387,7 @@ class TestHeavyMailPerformance(BaseMailPerformance):
|
||||
@warmup
|
||||
def test_complex_message_post_template(self):
|
||||
self.umbrella.message_subscribe(self.user_portal.partner_id.ids)
|
||||
record = self.umbrella.sudo(self.env.user)
|
||||
record = self.umbrella.with_user(self.env.user)
|
||||
template_id = self.env.ref('test_mail.mail_test_tpl').id
|
||||
|
||||
with self.assertQueryCount(__system__=93, emp=99): # com runbot: 93 - 99 // test_mail only: 93 - 99
|
||||
@@ -703,13 +703,13 @@ class TestMailPerformancePost(BaseMailPerformance):
|
||||
# aims to cover as much features of message_post as possible
|
||||
partner_ids = [self.user_inbox.partner_id.id, self.user_email.partner_id.id, self.partner.id]
|
||||
channel_ids = [self.channel_inbox.id, self.channel_email.id]
|
||||
record = self.record.sudo(self.env.user)
|
||||
record = self.record.with_user(self.env.user)
|
||||
attachements = [ # not linear on number of attachements
|
||||
('attach tuple 1', "attachement tupple content 1"),
|
||||
('attach tuple 2', "attachement tupple content 2", {'cid': 'cid1'}),
|
||||
('attach tuple 3', "attachement tupple content 3", {'cid': 'cid2'}),
|
||||
]
|
||||
self.attachements = self.env['ir.attachment'].sudo(self.env.user).create(self.vals) #-> 163-> 165 query
|
||||
self.attachements = self.env['ir.attachment'].with_user(self.env.user).create(self.vals) #-> 163-> 165 query
|
||||
attachement_ids = self.attachements.ids
|
||||
with self.assertQueryCount(emp=175): # com runbot 154 // test_mail only: 133
|
||||
self.cr.sql_log = self.warm and self.cr.sql_log_count
|
||||
|
||||
@@ -25,13 +25,13 @@ class TestBLAccessRights(common.MassMailingCase):
|
||||
self.env['mail.blacklist'].create([{'email': 'Arya.Stark@example.com'}])
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.bl_rec.sudo(self.env.user).read([])
|
||||
self.bl_rec.with_user(self.env.user).read([])
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.bl_rec.sudo(self.env.user).write({'email': 'jaimie.lannister@example.com'})
|
||||
self.bl_rec.with_user(self.env.user).write({'email': 'jaimie.lannister@example.com'})
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.bl_rec.sudo(self.env.user).unlink()
|
||||
self.bl_rec.with_user(self.env.user).unlink()
|
||||
|
||||
@users('port')
|
||||
def test_bl_crud_portal(self):
|
||||
@@ -39,25 +39,25 @@ class TestBLAccessRights(common.MassMailingCase):
|
||||
self.env['mail.blacklist'].create([{'email': 'Arya.Stark@example.com'}])
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.bl_rec.sudo(self.env.user).read([])
|
||||
self.bl_rec.with_user(self.env.user).read([])
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.bl_rec.sudo(self.env.user).write({'email': 'jaimie.lannister@example.com'})
|
||||
self.bl_rec.with_user(self.env.user).write({'email': 'jaimie.lannister@example.com'})
|
||||
|
||||
with self.assertRaises(AccessError):
|
||||
self.bl_rec.sudo(self.env.user).unlink()
|
||||
self.bl_rec.with_user(self.env.user).unlink()
|
||||
|
||||
@users('marketing')
|
||||
def test_bl_crud_marketing(self):
|
||||
self.env['mail.blacklist'].create([{'email': 'Arya.Stark@example.com'}])
|
||||
|
||||
read_res = self.bl_rec.sudo(self.env.user).read([])
|
||||
read_res = self.bl_rec.with_user(self.env.user).read([])
|
||||
self.assertEqual(read_res[0]['id'], self.bl_rec.id)
|
||||
|
||||
self.bl_rec.sudo(self.env.user).write({'email': 'jaimie.lannister@example.com'})
|
||||
self.bl_rec.with_user(self.env.user).write({'email': 'jaimie.lannister@example.com'})
|
||||
self.assertEqual(self.bl_rec.email, 'jaimie.lannister@example.com')
|
||||
|
||||
self.bl_rec.sudo(self.env.user).unlink()
|
||||
self.bl_rec.with_user(self.env.user).unlink()
|
||||
|
||||
|
||||
class TestBLConsistency(common.MassMailingCase):
|
||||
|
||||
@@ -15,14 +15,14 @@ class TestComposer(common.SavepointCase):
|
||||
)
|
||||
|
||||
test_record = self.env['res.partner'].create({'name': 'Mass Mail Partner'})
|
||||
mass_mail_record = self.env['mail.mass_mailing'].sudo(test_user).create({
|
||||
mass_mail_record = self.env['mail.mass_mailing'].with_user(test_user).create({
|
||||
'name': 'Test',
|
||||
'subject': 'Test',
|
||||
'state': 'draft',
|
||||
'mailing_model_id': self.env.ref('base.model_res_partner').id,
|
||||
})
|
||||
|
||||
composer = self.env['mail.compose.message'].sudo(test_user).with_context({
|
||||
composer = self.env['mail.compose.message'].with_user(test_user).with_context({
|
||||
'default_composition_mode': 'mass_mail',
|
||||
'default_model': 'res.partner',
|
||||
'default_res_id': test_record.id,
|
||||
|
||||
@@ -158,7 +158,7 @@ class Website(Home):
|
||||
sitemaps.unlink()
|
||||
|
||||
pages = 0
|
||||
locs = request.website.sudo(user=request.website.user_id.id).enumerate_pages()
|
||||
locs = request.website.with_user(request.website.user_id).enumerate_pages()
|
||||
while True:
|
||||
values = {
|
||||
'locs': islice(locs, 0, LOC_PER_SITEMAP),
|
||||
|
||||
@@ -337,7 +337,7 @@ class Http(models.AbstractModel):
|
||||
class ModelConverter(ModelConverter):
|
||||
|
||||
def generate(self, uid, dom=None, args=None):
|
||||
Model = request.env[self.model].sudo(uid)
|
||||
Model = request.env[self.model].with_user(uid)
|
||||
# Allow to current_website_id directly in route domain
|
||||
args.update(current_website_id=request.env['website'].get_current_website().id)
|
||||
domain = safe_eval(self.domain, (args or {}).copy())
|
||||
|
||||
@@ -272,7 +272,7 @@ class View(models.Model):
|
||||
return [(view.arch, view.id) for view in inheriting_views]
|
||||
|
||||
@api.model
|
||||
@tools.ormcache_context('self._uid', 'xml_id', keys=('website_id',))
|
||||
@tools.ormcache_context('self.env.uid', 'self.env.su', 'xml_id', keys=('website_id',))
|
||||
def get_view_id(self, xml_id):
|
||||
"""If a website_id is in the context and the given xml_id is not an int
|
||||
then try to get the id of the specific view for that website, but
|
||||
|
||||
@@ -18,7 +18,7 @@ class TestWebsiteBlogFlow(TestWebsiteBlogCommon):
|
||||
and receive notification for future comments. """
|
||||
|
||||
# Create a new blog, subscribe the employee to the blog
|
||||
test_blog = self.env['blog.blog'].sudo(self.user_blogmanager).create({
|
||||
test_blog = self.env['blog.blog'].with_user(self.user_blogmanager).create({
|
||||
'name': 'New Blog',
|
||||
})
|
||||
self.assertIn(
|
||||
@@ -27,7 +27,7 @@ class TestWebsiteBlogFlow(TestWebsiteBlogCommon):
|
||||
test_blog.message_subscribe([self.user_employee.partner_id.id, self.user_public.partner_id.id])
|
||||
|
||||
# Create a new post, blog followers should not follow the post
|
||||
test_blog_post = self.env['blog.post'].sudo(self.user_blogmanager).create({
|
||||
test_blog_post = self.env['blog.post'].with_user(self.user_blogmanager).create({
|
||||
'name': 'New Post',
|
||||
'blog_id': test_blog.id,
|
||||
})
|
||||
|
||||
@@ -289,7 +289,7 @@ class CrmLead(models.Model):
|
||||
except AccessError:
|
||||
return super(CrmLead, self).get_access_action(access_uid)
|
||||
user = self.env['res.users'].sudo().browse(access_uid)
|
||||
record = self.sudo(user)
|
||||
record = self.with_user(user)
|
||||
if user.share or self.env.context.get('force_website'):
|
||||
try:
|
||||
record.check_access_rights('read')
|
||||
|
||||
@@ -126,7 +126,7 @@ class TestPartnerLeadPortal(TestCrmCases):
|
||||
team_before = self.lead.team_id
|
||||
user_before = self.lead.user_id
|
||||
|
||||
self.lead.sudo(self.portal_user.id).partner_interested(comment="Oh yeah, I take that lead !")
|
||||
self.lead.with_user(self.portal_user).partner_interested(comment="Oh yeah, I take that lead !")
|
||||
|
||||
self.assertEqual(self.lead.type, 'opportunity', 'Bad Type: accepted lead by portal user should become an opportunity.')
|
||||
self.assertEqual(self.lead.team_id, team_before, 'Accepting lead does not change the sales team.')
|
||||
@@ -134,7 +134,7 @@ class TestPartnerLeadPortal(TestCrmCases):
|
||||
|
||||
def test_partner_lead_decline(self):
|
||||
""" Test an integrating partner decline the lead """
|
||||
self.lead.sudo(self.portal_user.id).partner_desinterested(comment="No thanks, I have enough leads !", contacted=True, spam=False)
|
||||
self.lead.with_user(self.portal_user).partner_desinterested(comment="No thanks, I have enough leads !", contacted=True, spam=False)
|
||||
|
||||
self.assertFalse(self.lead.partner_assigned_id.id, 'The partner_assigned_id of the declined lead should be False.')
|
||||
self.assertTrue(self.portal_user.partner_id in self.lead.sudo().partner_declined_ids, 'Partner who has declined the lead should be in the declined_partner_ids.')
|
||||
@@ -150,11 +150,11 @@ class TestPartnerLeadPortal(TestCrmCases):
|
||||
})
|
||||
# try to accept a lead that is not mine
|
||||
with self.assertRaises(AccessError):
|
||||
self.lead.sudo(poor_portal_user.id).partner_interested(comment="Oh yeah, I take that lead !")
|
||||
self.lead.with_user(poor_portal_user).partner_interested(comment="Oh yeah, I take that lead !")
|
||||
|
||||
def test_lead_creation(self):
|
||||
""" Test the opportinuty creation from portal """
|
||||
data = self.env['crm.lead'].sudo(self.portal_user.id).create_opp_portal({
|
||||
data = self.env['crm.lead'].with_user(self.portal_user).create_opp_portal({
|
||||
'title': "L'ours bleu",
|
||||
'description': 'A good joke',
|
||||
'contact_name': 'Renaud Rutten',
|
||||
|
||||
@@ -749,7 +749,7 @@ class Post(models.Model):
|
||||
'parent_id': question.id,
|
||||
}
|
||||
# done with the author user to have create_uid correctly set
|
||||
new_post = self.sudo(post_create_uid.id).create(post_values)
|
||||
new_post = self.with_user(post_create_uid).create(post_values)
|
||||
|
||||
# delete comment
|
||||
comment.unlink()
|
||||
|
||||
@@ -18,23 +18,23 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# create some posts
|
||||
self.admin_post = self.post
|
||||
self.portal_post = Post.sudo(self.user_portal).create({
|
||||
self.portal_post = Post.with_user(self.user_portal).create({
|
||||
'name': 'Post from Portal User',
|
||||
'content': 'I am not a bird.',
|
||||
'forum_id': self.forum.id,
|
||||
})
|
||||
self.employee_post = Post.sudo(self.user_employee).create({
|
||||
self.employee_post = Post.with_user(self.user_employee).create({
|
||||
'name': 'Post from Employee User',
|
||||
'content': 'I am not a bird.',
|
||||
'forum_id': self.forum.id,
|
||||
})
|
||||
|
||||
# vote on some posts
|
||||
self.employee_vote_on_admin_post = Vote.sudo(self.user_employee).create({
|
||||
self.employee_vote_on_admin_post = Vote.with_user(self.user_employee).create({
|
||||
'post_id': self.admin_post.id,
|
||||
'vote': '1',
|
||||
})
|
||||
self.portal_vote_on_admin_post = Vote.sudo(self.user_portal).create({
|
||||
self.portal_vote_on_admin_post = Vote.with_user(self.user_portal).create({
|
||||
'post_id': self.admin_post.id,
|
||||
'vote': '1',
|
||||
})
|
||||
@@ -49,45 +49,45 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# One should not be able to modify someone else's vote
|
||||
with self.assertRaises(UserError):
|
||||
self.admin_vote_on_portal_post.sudo(self.user_employee).write({
|
||||
self.admin_vote_on_portal_post.with_user(self.user_employee).write({
|
||||
'vote': '-1',
|
||||
})
|
||||
with self.assertRaises(UserError):
|
||||
self.admin_vote_on_employee_post.sudo(self.user_portal).write({
|
||||
self.admin_vote_on_employee_post.with_user(self.user_portal).write({
|
||||
'vote': '-1',
|
||||
})
|
||||
|
||||
# One should not be able to give his vote to someone else
|
||||
self.employee_vote_on_admin_post.sudo(self.user_employee).write({
|
||||
self.employee_vote_on_admin_post.with_user(self.user_employee).write({
|
||||
'user_id': 1,
|
||||
})
|
||||
self.assertEqual(self.employee_vote_on_admin_post.user_id, self.user_employee, 'User employee should not be able to give its vote ownership to someone else')
|
||||
# One should not be able to change his vote's post to a post of his own (would be self voting)
|
||||
with self.assertRaises(UserError):
|
||||
self.employee_vote_on_admin_post.sudo(self.user_employee).write({
|
||||
self.employee_vote_on_admin_post.with_user(self.user_employee).write({
|
||||
'post_id': self.employee_post.id,
|
||||
})
|
||||
|
||||
# One should not be able to give his vote to someone else
|
||||
self.portal_vote_on_admin_post.sudo(self.user_portal).write({
|
||||
self.portal_vote_on_admin_post.with_user(self.user_portal).write({
|
||||
'user_id': 1,
|
||||
})
|
||||
self.assertEqual(self.portal_vote_on_admin_post.user_id, self.user_portal, 'User portal should not be able to give its vote ownership to someone else')
|
||||
# One should not be able to change his vote's post to a post of his own (would be self voting)
|
||||
with self.assertRaises(UserError):
|
||||
self.portal_vote_on_admin_post.sudo(self.user_portal).write({
|
||||
self.portal_vote_on_admin_post.with_user(self.user_portal).write({
|
||||
'post_id': self.portal_post.id,
|
||||
})
|
||||
|
||||
# One should not be able to vote for its own post
|
||||
with self.assertRaises(UserError):
|
||||
Vote.sudo(self.user_employee).create({
|
||||
Vote.with_user(self.user_employee).create({
|
||||
'post_id': self.employee_post.id,
|
||||
'vote': '1',
|
||||
})
|
||||
# One should not be able to vote for its own post
|
||||
with self.assertRaises(UserError):
|
||||
Vote.sudo(self.user_portal).create({
|
||||
Vote.with_user(self.user_portal).create({
|
||||
'post_id': self.portal_post.id,
|
||||
'vote': '1',
|
||||
})
|
||||
@@ -96,27 +96,27 @@ class TestForum(TestForumCommon):
|
||||
with self.assertRaises(IntegrityError):
|
||||
with self.cr.savepoint():
|
||||
# One should not be able to vote more than once on a same post
|
||||
Vote.sudo(self.user_employee).create({
|
||||
Vote.with_user(self.user_employee).create({
|
||||
'post_id': self.admin_post.id,
|
||||
'vote': '1',
|
||||
})
|
||||
with self.assertRaises(IntegrityError):
|
||||
with self.cr.savepoint():
|
||||
# One should not be able to vote more than once on a same post
|
||||
Vote.sudo(self.user_employee).create({
|
||||
Vote.with_user(self.user_employee).create({
|
||||
'post_id': self.admin_post.id,
|
||||
'vote': '1',
|
||||
})
|
||||
|
||||
# One should not be able to create a vote for someone else
|
||||
new_employee_vote = Vote.sudo(self.user_employee).create({
|
||||
new_employee_vote = Vote.with_user(self.user_employee).create({
|
||||
'post_id': self.portal_post.id,
|
||||
'user_id': 1,
|
||||
'vote': '1',
|
||||
})
|
||||
self.assertEqual(new_employee_vote.user_id, self.user_employee, 'Creating a vote for someone else should not be allowed. It should create it for yourself instead')
|
||||
# One should not be able to create a vote for someone else
|
||||
new_portal_vote = Vote.sudo(self.user_portal).create({
|
||||
new_portal_vote = Vote.with_user(self.user_portal).create({
|
||||
'post_id': self.employee_post.id,
|
||||
'user_id': 1,
|
||||
'vote': '1',
|
||||
@@ -129,14 +129,14 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# Public user asks a question: not allowed
|
||||
with self.assertRaises(AccessError):
|
||||
Post.sudo(self.user_public).create({
|
||||
Post.with_user(self.user_public).create({
|
||||
'name': " Question ?",
|
||||
'forum_id': self.forum.id,
|
||||
})
|
||||
|
||||
# Portal user asks a question with tags: not allowed, unsufficient karma
|
||||
with self.assertRaises(KarmaError):
|
||||
Post.sudo(self.user_portal).create({
|
||||
Post.with_user(self.user_portal).create({
|
||||
'name': " Q_0",
|
||||
'forum_id': self.forum.id,
|
||||
'tag_ids': [(0, 0, {'name': 'Tag0', 'forum_id': self.forum.id})]
|
||||
@@ -144,7 +144,7 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# Portal user asks a question with tags: ok if enough karma
|
||||
self.user_portal.karma = KARMA['tag_create']
|
||||
Post.sudo(self.user_portal).create({
|
||||
Post.with_user(self.user_portal).create({
|
||||
'name': " Q0",
|
||||
'forum_id': self.forum.id,
|
||||
'tag_ids': [(0, 0, {'name': 'Tag1', 'forum_id': self.forum.id})]
|
||||
@@ -152,7 +152,7 @@ class TestForum(TestForumCommon):
|
||||
self.assertEqual(self.user_portal.karma, KARMA['tag_create'], 'website_forum: wrong karma generation when asking question')
|
||||
|
||||
self.user_portal.karma = KARMA['post']
|
||||
Post.sudo(self.user_portal).create({
|
||||
Post.with_user(self.user_portal).create({
|
||||
'name': " Q0",
|
||||
'forum_id': self.forum.id,
|
||||
'tag_ids': [(0, 0, {'name': 'Tag42', 'forum_id': self.forum.id})]
|
||||
@@ -165,7 +165,7 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# Answers its own question: not allowed, unsufficient karma
|
||||
with self.assertRaises(KarmaError):
|
||||
Post.sudo(self.user_employee).create({
|
||||
Post.with_user(self.user_employee).create({
|
||||
'name': " A0",
|
||||
'forum_id': self.forum.id,
|
||||
'parent_id': self.post.id,
|
||||
@@ -173,7 +173,7 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# Answers on question: ok if enough karma
|
||||
self.user_employee.karma = KARMA['ans']
|
||||
Post.sudo(self.user_employee).create({
|
||||
Post.with_user(self.user_employee).create({
|
||||
'name': " A0",
|
||||
'forum_id': self.forum.id,
|
||||
'parent_id': self.post.id,
|
||||
@@ -184,7 +184,7 @@ class TestForum(TestForumCommon):
|
||||
def test_vote_crash(self):
|
||||
Post = self.env['forum.post']
|
||||
self.user_employee.karma = KARMA['ans']
|
||||
emp_answer = Post.sudo(self.user_employee).create({
|
||||
emp_answer = Post.with_user(self.user_employee).create({
|
||||
'name': 'TestAnswer',
|
||||
'forum_id': self.forum.id,
|
||||
'parent_id': self.post.id})
|
||||
@@ -195,19 +195,19 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# not enough karma
|
||||
with self.assertRaises(KarmaError):
|
||||
self.post.sudo(self.user_portal).vote(upvote=True)
|
||||
self.post.with_user(self.user_portal).vote(upvote=True)
|
||||
|
||||
def test_vote(self):
|
||||
self.post.create_uid.karma = KARMA['ask']
|
||||
self.user_portal.karma = KARMA['upv']
|
||||
self.post.sudo(self.user_portal).vote(upvote=True)
|
||||
self.post.with_user(self.user_portal).vote(upvote=True)
|
||||
self.assertEqual(self.post.create_uid.karma, KARMA['ask'] + KARMA['gen_que_upv'], 'website_forum: wrong karma generation of upvoted question author')
|
||||
|
||||
@mute_logger('odoo.addons.base.models.ir_model', 'odoo.models')
|
||||
def test_downvote_crash(self):
|
||||
Post = self.env['forum.post']
|
||||
self.user_employee.karma = KARMA['ans']
|
||||
emp_answer = Post.sudo(self.user_employee).create({
|
||||
emp_answer = Post.with_user(self.user_employee).create({
|
||||
'name': 'TestAnswer',
|
||||
'forum_id': self.forum.id,
|
||||
'parent_id': self.post.id})
|
||||
@@ -218,112 +218,112 @@ class TestForum(TestForumCommon):
|
||||
|
||||
# not enough karma
|
||||
with self.assertRaises(KarmaError):
|
||||
self.post.sudo(self.user_portal).vote(upvote=False)
|
||||
self.post.with_user(self.user_portal).vote(upvote=False)
|
||||
|
||||
def test_downvote(self):
|
||||
self.post.create_uid.karma = 50
|
||||
self.user_portal.karma = KARMA['dwv']
|
||||
self.post.sudo(self.user_portal).vote(upvote=False)
|
||||
self.post.with_user(self.user_portal).vote(upvote=False)
|
||||
self.assertEqual(self.post.create_uid.karma, 50 + KARMA['gen_que_dwv'], 'website_forum: wrong karma generation of downvoted question author')
|
||||
|
||||
def test_comment_crash(self):
|
||||
with self.assertRaises(KarmaError):
|
||||
self.post.sudo(self.user_portal).message_post(body='Should crash', message_type='comment')
|
||||
self.post.with_user(self.user_portal).message_post(body='Should crash', message_type='comment')
|
||||
|
||||
def test_comment(self):
|
||||
self.post.sudo(self.user_employee).message_post(body='Test0', message_type='notification')
|
||||
self.post.with_user(self.user_employee).message_post(body='Test0', message_type='notification')
|
||||
self.user_employee.karma = KARMA['com_all']
|
||||
self.post.sudo(self.user_employee).message_post(body='Test1', message_type='comment')
|
||||
self.post.with_user(self.user_employee).message_post(body='Test1', message_type='comment')
|
||||
self.assertEqual(len(self.post.message_ids), 4, 'website_forum: wrong behavior of message_post')
|
||||
|
||||
def test_flag_a_post(self):
|
||||
Post = self.env['forum.post']
|
||||
self.user_portal.karma = KARMA['ask']
|
||||
post = Post.sudo(self.user_portal).create({
|
||||
post = Post.with_user(self.user_portal).create({
|
||||
'name': "Q0",
|
||||
'forum_id': self.forum.id,
|
||||
})
|
||||
|
||||
# portal user flags a post: not allowed, unsufficient karma
|
||||
with self.assertRaises(KarmaError):
|
||||
post.sudo(self.user_portal).flag()
|
||||
post.with_user(self.user_portal).flag()
|
||||
|
||||
# portal user flags a post: ok if enough karma
|
||||
self.user_portal.karma = KARMA['flag']
|
||||
post.state = 'active'
|
||||
post.sudo(self.user_portal).flag()
|
||||
post.with_user(self.user_portal).flag()
|
||||
self.assertEqual(post.state, 'flagged', 'website_forum: wrong state when flagging a post')
|
||||
|
||||
def test_validate_a_post(self):
|
||||
Post = self.env['forum.post']
|
||||
self.user_portal.karma = KARMA['ask']
|
||||
post = Post.sudo(self.user_portal).create({
|
||||
post = Post.with_user(self.user_portal).create({
|
||||
'name': "Q0",
|
||||
'forum_id': self.forum.id,
|
||||
})
|
||||
|
||||
# portal user validate a post: not allowed, unsufficient karma
|
||||
with self.assertRaises(KarmaError):
|
||||
post.sudo(self.user_portal).validate()
|
||||
post.with_user(self.user_portal).validate()
|
||||
|
||||
# portal user validate a pending post
|
||||
self.user_portal.karma = KARMA['moderate']
|
||||
post.state = 'pending'
|
||||
init_karma = post.create_uid.karma
|
||||
post.sudo(self.user_portal).validate()
|
||||
post.with_user(self.user_portal).validate()
|
||||
self.assertEqual(post.state, 'active', 'website_forum: wrong state when validate a post after pending')
|
||||
self.assertEqual(post.create_uid.karma, init_karma + KARMA['gen_que_new'], 'website_forum: wrong karma when validate a post after pending')
|
||||
|
||||
# portal user validate a flagged post: ok if enough karma
|
||||
self.user_portal.karma = KARMA['moderate']
|
||||
post.state = 'flagged'
|
||||
post.sudo(self.user_portal).validate()
|
||||
post.with_user(self.user_portal).validate()
|
||||
self.assertEqual(post.state, 'active', 'website_forum: wrong state when validate a post after flagged')
|
||||
|
||||
# portal user validate an offensive post: ok if enough karma
|
||||
self.user_portal.karma = KARMA['moderate']
|
||||
post.state = 'offensive'
|
||||
init_karma = post.create_uid.karma
|
||||
post.sudo(self.user_portal).validate()
|
||||
post.with_user(self.user_portal).validate()
|
||||
self.assertEqual(post.state, 'active', 'website_forum: wrong state when validate a post after offensive')
|
||||
|
||||
def test_refuse_a_post(self):
|
||||
Post = self.env['forum.post']
|
||||
self.user_portal.karma = KARMA['ask']
|
||||
post = Post.sudo(self.user_portal).create({
|
||||
post = Post.with_user(self.user_portal).create({
|
||||
'name': "Q0",
|
||||
'forum_id': self.forum.id,
|
||||
})
|
||||
|
||||
# portal user validate a post: not allowed, unsufficient karma
|
||||
with self.assertRaises(KarmaError):
|
||||
post.sudo(self.user_portal).refuse()
|
||||
post.with_user(self.user_portal).refuse()
|
||||
|
||||
# portal user validate a pending post
|
||||
self.user_portal.karma = KARMA['moderate']
|
||||
post.state = 'pending'
|
||||
init_karma = post.create_uid.karma
|
||||
post.sudo(self.user_portal).refuse()
|
||||
post.with_user(self.user_portal).refuse()
|
||||
self.assertEqual(post.moderator_id, self.user_portal, 'website_forum: wrong moderator_id when refusing')
|
||||
self.assertEqual(post.create_uid.karma, init_karma, 'website_forum: wrong karma when refusing a post')
|
||||
|
||||
def test_mark_a_post_as_offensive(self):
|
||||
Post = self.env['forum.post']
|
||||
self.user_portal.karma = KARMA['ask']
|
||||
post = Post.sudo(self.user_portal).create({
|
||||
post = Post.with_user(self.user_portal).create({
|
||||
'name': "Q0",
|
||||
'forum_id': self.forum.id,
|
||||
})
|
||||
|
||||
# portal user mark a post as offensive: not allowed, unsufficient karma
|
||||
with self.assertRaises(KarmaError):
|
||||
post.sudo(self.user_portal).mark_as_offensive(12)
|
||||
post.with_user(self.user_portal).mark_as_offensive(12)
|
||||
|
||||
# portal user mark a post as offensive
|
||||
self.user_portal.karma = KARMA['moderate']
|
||||
post.state = 'flagged'
|
||||
init_karma = post.create_uid.karma
|
||||
post.sudo(self.user_portal).mark_as_offensive(12)
|
||||
post.with_user(self.user_portal).mark_as_offensive(12)
|
||||
self.assertEqual(post.state, 'offensive', 'website_forum: wrong state when marking a post as offensive')
|
||||
self.assertEqual(post.create_uid.karma, init_karma + KARMA['gen_ans_flag'], 'website_forum: wrong karma when marking a post as offensive')
|
||||
|
||||
@@ -331,34 +331,34 @@ class TestForum(TestForumCommon):
|
||||
Post = self.env['forum.post']
|
||||
|
||||
# converting a question does nothing
|
||||
new_msg = self.post.sudo(self.user_portal).convert_answer_to_comment()
|
||||
new_msg = self.post.with_user(self.user_portal).convert_answer_to_comment()
|
||||
self.assertEqual(new_msg.id, False, 'website_forum: question to comment conversion failed')
|
||||
self.assertEqual(Post.search([('name', '=', 'TestQuestion')])[0].forum_id.name, 'TestForum', 'website_forum: question to comment conversion failed')
|
||||
|
||||
with self.assertRaises(KarmaError):
|
||||
self.answer.sudo(self.user_portal).convert_answer_to_comment()
|
||||
self.answer.with_user(self.user_portal).convert_answer_to_comment()
|
||||
|
||||
def test_convert_answer_to_comment(self):
|
||||
self.user_portal.karma = KARMA['com_conv_all']
|
||||
post_author = self.answer.create_uid.partner_id
|
||||
new_msg = self.answer.sudo(self.user_portal).convert_answer_to_comment()
|
||||
new_msg = self.answer.with_user(self.user_portal).convert_answer_to_comment()
|
||||
self.assertEqual(len(new_msg), 1, 'website_forum: wrong answer to comment conversion')
|
||||
self.assertEqual(new_msg.author_id, post_author, 'website_forum: wrong answer to comment conversion')
|
||||
self.assertIn('I am an anteater', new_msg.body, 'website_forum: wrong answer to comment conversion')
|
||||
|
||||
def test_edit_post_crash(self):
|
||||
with self.assertRaises(KarmaError):
|
||||
self.post.sudo(self.user_portal).write({'name': 'I am not your father.'})
|
||||
self.post.with_user(self.user_portal).write({'name': 'I am not your father.'})
|
||||
|
||||
def test_edit_post(self):
|
||||
self.post.create_uid.karma = KARMA['edit_own']
|
||||
self.post.write({'name': 'Actually I am your dog.'})
|
||||
self.user_portal.karma = KARMA['edit_all']
|
||||
self.post.sudo(self.user_portal).write({'name': 'Actually I am your cat.'})
|
||||
self.post.with_user(self.user_portal).write({'name': 'Actually I am your cat.'})
|
||||
|
||||
def test_close_post_crash(self):
|
||||
with self.assertRaises(KarmaError):
|
||||
self.post.sudo(self.user_portal).close(None)
|
||||
self.post.with_user(self.user_portal).close(None)
|
||||
|
||||
def test_close_post_own(self):
|
||||
self.post.create_uid.karma = KARMA['close_own']
|
||||
@@ -366,11 +366,11 @@ class TestForum(TestForumCommon):
|
||||
|
||||
def test_close_post_all(self):
|
||||
self.user_portal.karma = KARMA['close_all']
|
||||
self.post.sudo(self.user_portal).close(None)
|
||||
self.post.with_user(self.user_portal).close(None)
|
||||
|
||||
def test_deactivate_post_crash(self):
|
||||
with self.assertRaises(KarmaError):
|
||||
self.post.sudo(self.user_portal).write({'active': False})
|
||||
self.post.with_user(self.user_portal).write({'active': False})
|
||||
|
||||
def test_deactivate_post_own(self):
|
||||
self.post.create_uid.karma = KARMA['unlink_own']
|
||||
@@ -378,11 +378,11 @@ class TestForum(TestForumCommon):
|
||||
|
||||
def test_deactivate_post_all(self):
|
||||
self.user_portal.karma = KARMA['unlink_all']
|
||||
self.post.sudo(self.user_portal).write({'active': False})
|
||||
self.post.with_user(self.user_portal).write({'active': False})
|
||||
|
||||
def test_unlink_post_crash(self):
|
||||
with self.assertRaises(KarmaError):
|
||||
self.post.sudo(self.user_portal).unlink()
|
||||
self.post.with_user(self.user_portal).unlink()
|
||||
|
||||
def test_unlink_post_own(self):
|
||||
self.post.create_uid.karma = KARMA['unlink_own']
|
||||
@@ -390,4 +390,4 @@ class TestForum(TestForumCommon):
|
||||
|
||||
def test_unlink_post_all(self):
|
||||
self.user_portal.karma = KARMA['unlink_all']
|
||||
self.post.sudo(self.user_portal).unlink()
|
||||
self.post.with_user(self.user_portal).unlink()
|
||||
|
||||
@@ -134,7 +134,7 @@ class Website(models.Model):
|
||||
isocountry = req and req.session.geoip and req.session.geoip.get('country_code') or False
|
||||
partner = self.env.user.partner_id
|
||||
last_order_pl = partner.last_website_so_id.pricelist_id
|
||||
partner_pl = partner.sudo(user=self.env.user).property_product_pricelist
|
||||
partner_pl = partner.with_user(self.env.user).property_product_pricelist
|
||||
pricelists = website._get_pl_partner_order(isocountry, show_visible,
|
||||
website.user_id.sudo().partner_id.property_product_pricelist.id,
|
||||
req and req.session.get('website_sale_current_pl') or None,
|
||||
|
||||
@@ -20,7 +20,7 @@ class TestCoursePurchaseFlow(common.SlidesCase):
|
||||
'product_id': course_product.id
|
||||
})
|
||||
|
||||
self.channel_2 = self.env['slide.channel'].sudo(self.user_publisher).create({
|
||||
self.channel_2 = self.env['slide.channel'].with_user(self.user_publisher).create({
|
||||
'name': 'Test Channel',
|
||||
'enroll': 'payment',
|
||||
'product_id': course_product.id
|
||||
|
||||
@@ -40,7 +40,7 @@ class SlidesCase(common.SavepointCase):
|
||||
'customer': True,
|
||||
})
|
||||
|
||||
self.channel = self.env['slide.channel'].sudo(self.user_publisher).create({
|
||||
self.channel = self.env['slide.channel'].with_user(self.user_publisher).create({
|
||||
'name': 'Test Channel',
|
||||
'channel_type': 'documentation',
|
||||
'promote_strategy': 'most_voted',
|
||||
@@ -51,7 +51,7 @@ class SlidesCase(common.SavepointCase):
|
||||
'karma_gen_slide_vote': 5,
|
||||
'karma_gen_channel_rank': 10,
|
||||
})
|
||||
self.slide = self.env['slide.slide'].sudo(self.user_publisher).create({
|
||||
self.slide = self.env['slide.slide'].with_user(self.user_publisher).create({
|
||||
'name': 'How To Cook Humans',
|
||||
'channel_id': self.channel.id,
|
||||
'slide_type': 'presentation',
|
||||
@@ -60,14 +60,12 @@ class SlidesCase(common.SavepointCase):
|
||||
})
|
||||
|
||||
@contextmanager
|
||||
def sudo(self, user):
|
||||
""" Quick sudo environment """
|
||||
def with_user(self, user):
|
||||
""" Quick with_user environment """
|
||||
old_uid = self.uid
|
||||
try:
|
||||
self.uid = user.id
|
||||
self.env = self.env(user=self.uid)
|
||||
yield
|
||||
finally:
|
||||
# back
|
||||
self.uid = old_uid
|
||||
self.env = self.env(user=self.uid)
|
||||
|
||||
@@ -13,7 +13,7 @@ class TestKarmaGain(common.SlidesCase):
|
||||
def setUp(self):
|
||||
super(TestKarmaGain, self).setUp()
|
||||
|
||||
self.channel_2 = self.env['slide.channel'].sudo(self.user_publisher).create({
|
||||
self.channel_2 = self.env['slide.channel'].with_user(self.user_publisher).create({
|
||||
'name': 'Test Channel 2',
|
||||
'channel_type': 'training',
|
||||
'promote_strategy': 'most_voted',
|
||||
@@ -25,14 +25,14 @@ class TestKarmaGain(common.SlidesCase):
|
||||
'karma_gen_channel_rank': 10,
|
||||
})
|
||||
|
||||
self.slide_2_0 = self.env['slide.slide'].sudo(self.user_publisher).create({
|
||||
self.slide_2_0 = self.env['slide.slide'].with_user(self.user_publisher).create({
|
||||
'name': 'How to travel through space and time',
|
||||
'channel_id': self.channel_2.id,
|
||||
'slide_type': 'presentation',
|
||||
'website_published': True,
|
||||
'completion_time': 2.0,
|
||||
})
|
||||
self.slide_2_1 = self.env['slide.slide'].sudo(self.user_publisher).create({
|
||||
self.slide_2_1 = self.env['slide.slide'].with_user(self.user_publisher).create({
|
||||
'name': 'How to duplicate yourself',
|
||||
'channel_id': self.channel_2.id,
|
||||
'slide_type': 'presentation',
|
||||
@@ -52,23 +52,23 @@ class TestKarmaGain(common.SlidesCase):
|
||||
self.assertEqual(user.karma, 0)
|
||||
|
||||
# Finish the Course
|
||||
self.slide.sudo(user).action_set_completed()
|
||||
self.assertTrue(self.channel.sudo(user).completed)
|
||||
self.slide.with_user(user).action_set_completed()
|
||||
self.assertTrue(self.channel.with_user(user).completed)
|
||||
computed_karma += self.channel.karma_gen_channel_finish
|
||||
self.assertEqual(user.karma, computed_karma)
|
||||
|
||||
# Begin then finish the second Course
|
||||
self.slide_2_0.sudo(user).action_set_completed()
|
||||
self.assertFalse(self.channel_2.sudo(user).completed)
|
||||
self.slide_2_0.with_user(user).action_set_completed()
|
||||
self.assertFalse(self.channel_2.with_user(user).completed)
|
||||
self.assertEqual(user.karma, computed_karma)
|
||||
|
||||
self.slide_2_1.sudo(user).action_set_completed()
|
||||
self.assertTrue(self.channel_2.sudo(user).completed)
|
||||
self.slide_2_1.with_user(user).action_set_completed()
|
||||
self.assertTrue(self.channel_2.with_user(user).completed)
|
||||
computed_karma += self.channel_2.karma_gen_channel_finish
|
||||
self.assertEqual(user.karma, computed_karma)
|
||||
|
||||
# Vote for a slide
|
||||
slide_user = self.slide.sudo(user)
|
||||
slide_user = self.slide.with_user(user)
|
||||
slide_user.action_like()
|
||||
computed_karma += self.channel.karma_gen_slide_vote
|
||||
self.assertEqual(user.karma, computed_karma)
|
||||
@@ -93,6 +93,6 @@ class TestKarmaGain(common.SlidesCase):
|
||||
# Finish two course at the same time (should not ever happen but hey, we never know)
|
||||
(self.channel | self.channel_2)._action_add_members(user.partner_id)
|
||||
|
||||
(self.slide | self.slide_2_0 | self.slide_2_1).sudo(user).action_set_completed()
|
||||
(self.slide | self.slide_2_0 | self.slide_2_1).with_user(user).action_set_completed()
|
||||
computed_karma += self.channel.karma_gen_channel_finish + self.channel_2.karma_gen_channel_finish
|
||||
self.assertEqual(user.karma, computed_karma)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user