Skip to content

Commit b45d713

Browse files
author
bosd
committed
Fix add tests
1 parent 7a9b37f commit b45d713

1 file changed

Lines changed: 178 additions & 0 deletions

File tree

partner_identification_automation_activity/tests/test_identification_activity.py

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,3 +3460,181 @@ def test_write_method_status_change_triggers_activity_creation(self):
34603460
)
34613461

34623462
self.assertTrue(activity.exists())
3463+
3464+
def test_create_method_fallback_no_responsible_user(self):
3465+
"""Test create method fallback when no responsible user is set"""
3466+
# Create category with initial activity but no responsible user
3467+
category_no_user = self.env["res.partner.id_category"].create(
3468+
{
3469+
"code": "no_user",
3470+
"name": "No User Category",
3471+
"create_activity_on_new": True,
3472+
"initial_activity_type_id": self.env.ref(
3473+
"mail.mail_activity_data_todo"
3474+
).id,
3475+
# No responsible_user_id set
3476+
}
3477+
)
3478+
3479+
# Create identification with no responsible user in category
3480+
identification = self.env["res.partner.id_number"].create(
3481+
{
3482+
"partner_id": self.test_partner.id,
3483+
"category_id": category_no_user.id,
3484+
"name": "TEST_NO_USER",
3485+
"status": "draft",
3486+
}
3487+
)
3488+
3489+
# Activity should be assigned to current user as fallback
3490+
activity = self.env["mail.activity"].search(
3491+
[
3492+
("res_model", "=", "res.partner.id_number"),
3493+
("res_id", "=", identification.id),
3494+
],
3495+
limit=1,
3496+
)
3497+
3498+
self.assertTrue(activity.exists())
3499+
# Should fall back to current user when no responsible user is set
3500+
self.assertEqual(activity.user_id, self.env.user)
3501+
3502+
def test_renewal_activities_fallback_no_responsible_user(self):
3503+
"""Test _create_renewal_activities fallback when no responsible user is set"""
3504+
# Create category with renewal settings but no responsible user
3505+
category_no_user = self.env["res.partner.id_category"].create(
3506+
{
3507+
"code": "no_user_renew",
3508+
"name": "No User Renew Category",
3509+
"renewal_lead_number": 5,
3510+
"renewal_lead_unit": "days",
3511+
# No responsible_user_id set
3512+
}
3513+
)
3514+
3515+
# Create identification
3516+
identification = self.env["res.partner.id_number"].create(
3517+
{
3518+
"partner_id": self.test_partner.id,
3519+
"category_id": category_no_user.id,
3520+
"name": "TEST_NO_USER_RENEW",
3521+
"status": "draft",
3522+
"valid_until": "2023-12-31",
3523+
}
3524+
)
3525+
3526+
# Change status to pending to trigger renewal activity
3527+
identification.write({"status": "pending"})
3528+
3529+
# Check that activity was created and assigned to current user
3530+
activity = self.env["mail.activity"].search(
3531+
[
3532+
("res_model", "=", "res.partner.id_number"),
3533+
("res_id", "=", identification.id),
3534+
],
3535+
limit=1,
3536+
)
3537+
3538+
self.assertTrue(activity.exists())
3539+
# Should fall back to current user when no responsible user is set
3540+
self.assertEqual(activity.user_id, self.env.user)
3541+
3542+
def test_renewal_activities_no_valid_until_date(self):
3543+
"""Test _create_renewal_activities with no valid_until date (edge case)"""
3544+
# Create identification without valid_until date
3545+
identification = self.env["res.partner.id_number"].create(
3546+
{
3547+
"partner_id": self.test_partner.id,
3548+
"category_id": self.category.id,
3549+
"name": "TEST_NO_EXPIRY_DATE",
3550+
"status": "draft",
3551+
# No valid_until date
3552+
}
3553+
)
3554+
3555+
# Call _create_renewal_activities directly - should handle missing expiry
3556+
# This should not raise an error
3557+
try:
3558+
identification._create_renewal_activities()
3559+
success = True
3560+
except Exception:
3561+
success = False
3562+
3563+
self.assertTrue(success)
3564+
3565+
def test_write_method_with_status_not_in_vals(self):
3566+
"""Test write method when status is not in the vals dictionary"""
3567+
# Create identification
3568+
identification = self.env["res.partner.id_number"].create(
3569+
{
3570+
"partner_id": self.test_partner.id,
3571+
"category_id": self.category.id,
3572+
"name": "TEST_NO_STATUS_WRITE",
3573+
"status": "draft",
3574+
}
3575+
)
3576+
3577+
# Update a field other than status - should not trigger activity creation
3578+
identification.write({"name": "UPDATED_NAME_NO_ACTIVITY"})
3579+
3580+
# No activity should be created since status didn't change to 'pending'
3581+
activities = self.env["mail.activity"].search(
3582+
[
3583+
("res_model", "=", "res.partner.id_number"),
3584+
("res_id", "=", identification.id),
3585+
]
3586+
)
3587+
self.assertEqual(len(activities), 0)
3588+
3589+
def test_create_method_with_summary_containing_record_name(self):
3590+
"""Test create method handles summary that already contains record name"""
3591+
# Create custom activity type with summary that includes placeholder
3592+
custom_activity_type = self.env["mail.activity.type"].create(
3593+
{
3594+
"name": "Custom Summary",
3595+
"summary": "Initial check: TEST_NO_EXPIRY_DATE", # Same name as record
3596+
}
3597+
)
3598+
3599+
self.category.write(
3600+
{
3601+
"create_activity_on_new": True,
3602+
"initial_activity_type_id": custom_activity_type.id,
3603+
}
3604+
)
3605+
3606+
# Create identification - the summary should not be duplicated
3607+
identification = self.env["res.partner.id_number"].create(
3608+
{
3609+
"partner_id": self.test_partner.id,
3610+
"category_id": self.category.id,
3611+
"name": "TEST_NO_EXPIRY_DATE", # Same name as in activity summary
3612+
"status": "draft",
3613+
}
3614+
)
3615+
3616+
# Check that the activity summary doesn't have duplicate name
3617+
activity = self.env["mail.activity"].search(
3618+
[
3619+
("res_model", "=", "res.partner.id_number"),
3620+
("res_id", "=", identification.id),
3621+
],
3622+
limit=1,
3623+
)
3624+
3625+
self.assertTrue(activity.exists())
3626+
# Summary should contain the name, but not duplicate it
3627+
self.assertIn("TEST_NO_EXPIRY_DATE", activity.summary)
3628+
3629+
def test_renewal_activities_with_nonexistent_activity_type(self):
3630+
"""Test _create_renewal_activities handles nonexistent activity type"""
3631+
# Create custom activity type and then delete it (to make it nonexistent)
3632+
temp_activity_type = self.env["mail.activity.type"].create(
3633+
{
3634+
"name": "Temp Activity Type",
3635+
}
3636+
)
3637+
temp_activity_type_id = temp_activity_type.id
3638+
temp_activity_type.unlink() # Now it doesn't exist
3639+
3640+
# Create category with the now-deleted activity type

0 commit comments

Comments
 (0)