diff --git a/__manifest__.py b/__manifest__.py index 4cd8f46..d650283 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -53,6 +53,7 @@ 'views/donation_tax_receipt.xml', 'views/laposte_ref.xml', 'views/partner_import.xml', + 'views/portal.xml', 'data/donation_recurring_mail_template.xml' #'views/website_donation.xml' diff --git a/controllers/__init__.py b/controllers/__init__.py index 620ab97..8acfdb9 100644 --- a/controllers/__init__.py +++ b/controllers/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- from . import controllers -from . import donation \ No newline at end of file +from . import donation +from . import portal \ No newline at end of file diff --git a/controllers/portal.py b/controllers/portal.py new file mode 100644 index 0000000..a0d33d4 --- /dev/null +++ b/controllers/portal.py @@ -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/'], 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/'], 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('/') + + + \ No newline at end of file diff --git a/i18n/fr.po b/i18n/fr.po index 03b2f33..e769fef 100644 --- a/i18n/fr.po +++ b/i18n/fr.po @@ -1210,7 +1210,7 @@ msgstr "" #: model:ir.actions.act_window,name:opendons.template_rf_action #: model:ir.ui.menu,name:opendons.opendons_template_rf msgid "Receipts letters Templates " -msgstr "Modèle de lettres de reçu" +msgstr "Modèle de lettres de reçu fiscal" #. module: opendons #: model:ir.actions.act_window,name:opendons.donation_recurring_action diff --git a/models/donation.py b/models/donation.py index 6d49c88..150fe0a 100644 --- a/models/donation.py +++ b/models/donation.py @@ -47,7 +47,6 @@ class DonationDonation(models.Model): start_date= fields.Date( string='Start Date', index=True, - required=True, track_visibility='onchange' ) end_date = fields.Date( @@ -620,4 +619,10 @@ class DonationDonation(models.Model): else: name = super(DonationDonation, donation).name_get()[0][1] res.append((donation.id, name)) - return res \ No newline at end of file + return res + +class DonationLine(models.Model): + _inherit = 'donation.line' + + donation_date=fields.Date(related='donation_id.donation_date') + partner_id=fields.Many2one(related='donation_id.partner_id') \ No newline at end of file diff --git a/models/donation_tax_receipt.py b/models/donation_tax_receipt.py index 095fca5..28383ab 100644 --- a/models/donation_tax_receipt.py +++ b/models/donation_tax_receipt.py @@ -8,6 +8,8 @@ class DonationTaxReceipt(models.Model): html_content=fields.Html('html content',compute='_html_content_rf') html_content_print=fields.Html('html content print') + def get_portal_url(self): + return "my/taxreceipt/print?id="+str(self.id) def action_print_rf(self): self.ensure_one() @@ -23,4 +25,10 @@ class DonationTaxReceipt(models.Model): #return True def _html_content_rf(self): - self.html_content=self.template_rf_id.html_content \ No newline at end of file + self.html_content=self.template_rf_id.html_content + + def update_print_pdf(self): + html_content_print=self.html_content + html_content_print=html_content_print.replace('{{partner_id.name}}',self.partner_id.name) + html_content_print=html_content_print.replace('{{partner_id.firstname}}',self.partner_id.firstname) + self.html_content_print=html_content_print \ No newline at end of file diff --git a/views/portal.xml b/views/portal.xml new file mode 100644 index 0000000..e4bf638 --- /dev/null +++ b/views/portal.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/views/recurring_donation.xml b/views/recurring_donation.xml index 5bab8e5..a444470 100644 --- a/views/recurring_donation.xml +++ b/views/recurring_donation.xml @@ -9,7 +9,7 @@ - + @@ -30,19 +30,21 @@ --> - + + + - + + + + @@ -140,11 +142,11 @@ - + @@ -175,7 +177,7 @@ diff --git a/views/template_rf.xml b/views/template_rf.xml index 22fca83..8ba662f 100644 --- a/views/template_rf.xml +++ b/views/template_rf.xml @@ -25,6 +25,18 @@ + + opendons_template_rf List + opendons.template_rf + + + + + + + + +