|
|
@ -0,0 +1,135 @@ |
|
|
|
from odoo import http,_ |
|
|
|
from odoo.http import request |
|
|
|
import werkzeug |
|
|
|
from odoo.exceptions import UserError |
|
|
|
from odoo.addons.portal.controllers.portal import CustomerPortal,pager as portal_pager, get_records_pager |
|
|
|
|
|
|
|
class PortalOpendons(CustomerPortal): |
|
|
|
|
|
|
|
def _prepare_home_portal_values(self, counters): |
|
|
|
values = super()._prepare_home_portal_values(counters) |
|
|
|
partner = request.env.user.partner_id |
|
|
|
if 'taxreceipt_count' in counters: |
|
|
|
taxreceipt_count=request.env['donation.tax.receipt'].search_count([('partner_id','=',int(partner.id))]) |
|
|
|
|
|
|
|
values['taxreceipt_count'] = taxreceipt_count |
|
|
|
|
|
|
|
if 'donation_count' in counters: |
|
|
|
donation_count=request.env['donation.donation'].search_count(['&',('partner_id','=',int(partner.id)),('state','=','done')]) |
|
|
|
|
|
|
|
values['donation_count'] = donation_count |
|
|
|
|
|
|
|
return values |
|
|
|
|
|
|
|
@http.route(['/my/taxreceipts', '/my/taxreceipts/page/<int:page>'], type='http', auth="user", website=True) |
|
|
|
def portal_my_taxreceipts(self, page=1, date_begin=None, date_end=None, sortby=None, **kw): |
|
|
|
values = self._prepare_portal_layout_values() |
|
|
|
partner = request.env.user.partner_id |
|
|
|
taxreceipt = request.env['donation.tax.receipt'] |
|
|
|
|
|
|
|
domain = [ |
|
|
|
('partner_id', '=',int(partner.id) ) |
|
|
|
] |
|
|
|
|
|
|
|
searchbar_sortings = { |
|
|
|
'date': {'label': _('Tax receipt Date'), 'taxreceipt': 'date desc'}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
# default sortby order |
|
|
|
if not sortby: |
|
|
|
sortby = 'date' |
|
|
|
sort_taxreceipt = searchbar_sortings[sortby]['taxreceipt'] |
|
|
|
|
|
|
|
if date_begin and date_end: |
|
|
|
domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)] |
|
|
|
|
|
|
|
# count for pager |
|
|
|
taxreceipt_count = taxreceipt.search_count(domain) |
|
|
|
# make pager |
|
|
|
pager = portal_pager( |
|
|
|
url="/my/taxreceipts", |
|
|
|
url_args={'date_begin': date_begin, 'date_end': date_end, 'sortby': sortby}, |
|
|
|
total=taxreceipt_count, |
|
|
|
page=page, |
|
|
|
step=self._items_per_page |
|
|
|
) |
|
|
|
# search the count to display, according to the pager data |
|
|
|
taxreceipts = taxreceipt.search(domain, order=sort_taxreceipt, limit=self._items_per_page, offset=pager['offset']) |
|
|
|
request.session['my_taxreceipt_history'] = taxreceipts.ids[:100] |
|
|
|
|
|
|
|
values.update({ |
|
|
|
'date': date_begin, |
|
|
|
'taxreceipts': taxreceipts.sudo(), |
|
|
|
'page_name': 'tax receipts', |
|
|
|
'pager': pager, |
|
|
|
'default_url': '/my/taxreceipts', |
|
|
|
'searchbar_sortings': searchbar_sortings, |
|
|
|
'sortby': sortby, |
|
|
|
}) |
|
|
|
return request.render("opendons.portal_my_taxreceipts", values) |
|
|
|
|
|
|
|
@http.route(['/my/donations', '/my/donations/page/<int:page>'], type='http', auth="user", website=True) |
|
|
|
def portal_my_donations(self, page=1, date_begin=None, date_end=None, sortby=None, **kw): |
|
|
|
values = self._prepare_portal_layout_values() |
|
|
|
partner = request.env.user.partner_id |
|
|
|
donation = request.env['donation.line'] |
|
|
|
|
|
|
|
domain = [ |
|
|
|
('partner_id', '=',int(partner.id) ) |
|
|
|
] |
|
|
|
|
|
|
|
searchbar_sortings = { |
|
|
|
'date': {'label': _('Donation Date'), 'Donation': 'donation_date desc'}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
# default sortby order |
|
|
|
if not sortby: |
|
|
|
sortby = 'date' |
|
|
|
sort_donation = searchbar_sortings[sortby]['Donation'] |
|
|
|
|
|
|
|
if date_begin and date_end: |
|
|
|
domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)] |
|
|
|
|
|
|
|
# count for pager |
|
|
|
donation_count = donation.search_count(domain) |
|
|
|
# make pager |
|
|
|
pager = portal_pager( |
|
|
|
url="/my/donations", |
|
|
|
url_args={'date_begin': date_begin, 'date_end': date_end, 'sortby': sortby}, |
|
|
|
total=donation_count, |
|
|
|
page=page, |
|
|
|
step=self._items_per_page |
|
|
|
) |
|
|
|
# search the count to display, according to the pager data |
|
|
|
donations = donation.search(domain, order=sort_donation, limit=self._items_per_page, offset=pager['offset']) |
|
|
|
request.session['my_donation_history'] = donations.ids[:100] |
|
|
|
|
|
|
|
values.update({ |
|
|
|
'date': date_begin, |
|
|
|
'donations': donations.sudo(), |
|
|
|
'page_name': 'Donations', |
|
|
|
'pager': pager, |
|
|
|
'default_url': '/my/donations', |
|
|
|
'searchbar_sortings': searchbar_sortings, |
|
|
|
'sortby': sortby, |
|
|
|
}) |
|
|
|
return request.render("opendons.portal_my_donations", values) |
|
|
|
|
|
|
|
@http.route('/my/taxreceipt/print', methods=['POST', 'GET'], csrf=False, type='http', auth="user", website=True) |
|
|
|
def print_id(self, **kw): |
|
|
|
tr=request.env['donation.tax.receipt'].sudo().search([('id','=',int(kw['id']))]) |
|
|
|
if tr: |
|
|
|
|
|
|
|
#mise à jour du champ htl à imprimer |
|
|
|
tr.update_print_pdf() |
|
|
|
|
|
|
|
pdf = request.env.ref('opendons.report_donation_tax_receipt').sudo()._render_qweb_pdf([tr.id])[0] |
|
|
|
pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))] |
|
|
|
return request.make_response(pdf, headers=pdfhttpheaders) |
|
|
|
else: |
|
|
|
return request.redirect('/') |
|
|
|
|
|
|
|
|
|
|
|
|