Adds a QWeb PDF "Membership Card" report (85x54mm landscape, custom report.paperformat) showing the company logo, member name/ID, tier, and a QR code generated with the qrcode library (embedded as a base64 PNG via a non-stored res.partner.membership_card_qr compute field). The QR encodes a public verification URL built from ir.config_parameter's web.base.url. Adds the public GET /membership/verify/<member_id> controller: shows valid/expired/not-found with no personal data beyond name (and tier, for valid members) - internal states like 'invoiced'/'none' are deliberately reported as not-found so partial signup state isn't leaked. Adds the member portal: /my/membership (status/tier/expiry), /my/membership/ renew (finds or creates a draft renewal invoice, redirects to the existing portal invoice page), and /my/membership/card (PDF download) - plus a "Membership" entry card on the main /my portal home page. Since community_theme_base doesn't exist yet (that's Phase 6), the card uses res.company.logo rather than a theme setting - still brand-neutral, just resolved from the standard company record for now. Verified against a live Odoo 19 + Postgres 16 container, both via the test suite (12/12 tests: unit tests, HttpCase tests hitting the real verify endpoint for valid/expired/unknown IDs) and by hand end-to-end - created a tier and member over JSON-RPC, activated the membership, fetched the live /membership/verify/ page, and rendered the actual PDF card via /report/pdf/... (11.7KB single-page PDF, confirmed non-blank). Along the way, hit a third real Odoo 19 API change: res.users.groups_id was renamed to group_ids. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
from odoo import http
|
|
from odoo.addons.portal.controllers.portal import CustomerPortal
|
|
from odoo.http import request
|
|
|
|
|
|
class MembershipPortal(CustomerPortal):
|
|
|
|
def _prepare_home_portal_values(self, counters):
|
|
values = super()._prepare_home_portal_values(counters)
|
|
if 'membership_count' in counters:
|
|
partner = request.env.user.partner_id
|
|
values['membership_count'] = 1 if partner.membership_state != 'none' else 0
|
|
return values
|
|
|
|
@http.route(['/my/membership'], type='http', auth='user', website=True)
|
|
def portal_my_membership(self, **kwargs):
|
|
partner = request.env.user.partner_id
|
|
return request.render('community_membership.portal_my_membership', {
|
|
'partner': partner,
|
|
'page_name': 'membership',
|
|
})
|
|
|
|
@http.route(['/my/membership/renew'], type='http', auth='user', website=True)
|
|
def portal_membership_renew(self, **kwargs):
|
|
partner = request.env.user.partner_id
|
|
invoice = request.env['account.move'].sudo().search([
|
|
('partner_id', '=', partner.id),
|
|
('move_type', '=', 'out_invoice'),
|
|
('state', '=', 'draft'),
|
|
], order='create_date desc', limit=1)
|
|
if not invoice:
|
|
invoice = partner.sudo()._create_renewal_invoice()
|
|
if not invoice:
|
|
return request.redirect('/my/membership')
|
|
return request.redirect(f'/my/invoices/{invoice.id}')
|
|
|
|
@http.route(['/my/membership/card'], type='http', auth='user', website=True)
|
|
def portal_membership_card(self, **kwargs):
|
|
partner = request.env.user.partner_id
|
|
pdf_content, _report_type = request.env['ir.actions.report'].sudo()._render_qweb_pdf(
|
|
'community_membership.action_report_membership_card', res_ids=partner.ids,
|
|
)
|
|
return request.make_response(pdf_content, headers=[
|
|
('Content-Type', 'application/pdf'),
|
|
('Content-Length', len(pdf_content)),
|
|
('Content-Disposition', 'attachment; filename=membership-card.pdf'),
|
|
])
|