TNCSC_Odoo/addons/community_membership/tests/test_membership_member_details.py
metatroncubeswdev 657792b268
Some checks failed
CI / Brand-leak check (push) Has been cancelled
CI / flake8 / pylint-odoo / manifest completeness (push) Has been cancelled
CI / Install all modules with --test-enable (push) Has been cancelled
Add member application fields and the six real TNCSC membership plans
community_membership:
- Tiers get a fixed-term period (term_years), minimum age, a
  proof-document flag, a family-member flag and a signup description.
- Members get first/last name (composing the contact name), month and
  year of birth with computed age, board approval state with
  approve/reject buttons, terms acceptance, a proof-of-eligibility upload
  and an inline family members list. Birth date and proof document are
  restricted to Membership Managers.
- Constraints: plausible birth year; a tier's minimum age is enforced
  when the birth year is known.
- Fix pre-existing tests that collided with deployment-seeded tier codes
  and member ID format.

tncsc_deployment:
- Five Yes/No eligibility questions from the tncsc.com registration form
  (manager-only), shown in an Eligibility section of the member form.
- Tiers now match tncsc.com/membership-registration: Annual/Family $30,
  Long-Term (10 yr) $250, Life $500, Senior Annual (65+) $15, Senior Life
  (60+) $250, Student Annual $10 (CAD).
- 19.0.1.1.0 post-migrate rewrites existing tiers (noupdate data) and
  archives the unused Individual tier.

scripts/migrate_wp_members.py maps WordPress levels to the new LONG and
SENLIFE tiers. .mcp.json (holds credentials) is now gitignored.

Verified on the local Docker stack: -u on tncsc_site ran the migration
cleanly, and a fresh install with --test-enable passed 32/32 tests for
community_membership and tncsc_deployment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 10:46:31 -04:00

59 lines
2.7 KiB
Python

from datetime import date
from dateutil.relativedelta import relativedelta
from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase, tagged
@tagged('post_install', '-at_install')
class TestMembershipMemberDetails(TransactionCase):
def _tier(self, code, **values):
return self.env['community.membership.tier'].create({
'name': code, 'code': code, 'price': 10.0, 'period': 'annual', **values,
})
def test_fixed_term_tier_expires_after_term_years(self):
tier = self._tier('DET-10Y', period='fixed_term', term_years=10)
partner = self.env['res.partner'].create({'name': 'Ten Year Member', 'membership_tier_id': tier.id})
partner.action_activate_membership()
self.assertEqual(partner.membership_expiry, partner.membership_start + relativedelta(years=10))
def test_name_built_from_first_and_last_name(self):
partner = self.env['res.partner'].create({'first_name': 'Arun', 'last_name': 'Kumar'})
self.assertEqual(partner.name, 'Arun Kumar')
def test_age_counts_birth_month(self):
partner = self.env['res.partner'].create({'name': 'Aged Member', 'birth_month': '6', 'birth_year': 1960})
self.assertEqual(partner._age_on(date(2026, 5, 31)), 65)
self.assertEqual(partner._age_on(date(2026, 6, 1)), 66)
def test_tier_minimum_age_enforced(self):
tier = self._tier('DET-SEN', min_age=65)
this_year = date.today().year
with self.assertRaises(ValidationError):
self.env['res.partner'].create({
'name': 'Too Young', 'membership_tier_id': tier.id,
'birth_month': '1', 'birth_year': this_year - 30,
})
# Unknown birth year is allowed; the board can check documents instead.
self.env['res.partner'].create({'name': 'Unknown Age', 'membership_tier_id': tier.id})
def test_birth_year_must_be_plausible(self):
with self.assertRaises(ValidationError):
self.env['res.partner'].create({'name': 'Bad Year', 'birth_year': 1850})
def test_family_members_listed_on_head(self):
tier = self._tier('DET-FAM', allows_family_members=True)
head = self.env['res.partner'].create({'name': 'Family Head', 'membership_tier_id': tier.id})
spouse = self.env['res.partner'].create({'name': 'Spouse', 'family_head_id': head.id})
self.assertEqual(head.family_member_ids, spouse)
def test_board_approval(self):
partner = self.env['res.partner'].create({
'name': 'Applicant', 'membership_approval_state': 'pending',
})
partner.action_approve_membership()
self.assertEqual(partner.membership_approval_state, 'approved')