diff --git a/controllers/kalachakra.py b/controllers/kalachakra.py index df490b7..c72b7b7 100755 --- a/controllers/kalachakra.py +++ b/controllers/kalachakra.py @@ -7,7 +7,7 @@ import logging from odoo import models, fields, api import werkzeug from werkzeug.datastructures import OrderedMultiDict -from datetime import datetime,timedelta +from datetime import date,datetime,timedelta from odoo.tools import format_datetime, format_date, is_html_empty from dateutil.relativedelta import relativedelta from odoo.exceptions import UserError @@ -27,6 +27,7 @@ from odoo.addons.auth_signup.models.res_users import SignupError from odoo.addons.auth_signup.controllers.main import AuthSignupHome import json from collections import OrderedDict +from odoo.exceptions import AccessError, MissingError _logger = logging.getLogger(__name__) def create_donation(self): @@ -133,6 +134,24 @@ class Kalachakra_PortalAccount(CustomerPortal): }) return request.render("account.portal_my_invoices", values) + @http.route(['/my/invoices/'], type='http', auth="public", website=True) + def kalachakra_portal_my_invoice_detail(self, invoice_id, access_token=None, report_type=None, download=False, **kw): + try: + invoice_sudo = self._document_check_access('account.move', invoice_id, access_token) + except (AccessError, MissingError): + return request.redirect('/my') + + if report_type in ('html', 'pdf', 'text'): + return self._show_report(model=invoice_sudo, report_type=report_type, report_ref='account.account_invoices', download=download) + + values = self._invoice_get_page_view_values(invoice_sudo, access_token, **kw) + acquirers = values.get('acquirers') + if acquirers: + country_id = values.get('partner_id') and values.get('partner_id')[0].country_id.id + values['acq_extra_fees'] = acquirers.get_acquirer_extra_fees(invoice_sudo.amount_residual, invoice_sudo.currency_id, country_id) + + return request.render("account.portal_invoice_page", values) + def _prepare_home_portal_values(self, counters): values = super()._prepare_home_portal_values(counters) if 'invoice_count' in counters: @@ -889,12 +908,44 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): return http.request.render('kalachakra.onthespotpayment') + def active_membership(self,partner): + actives_membership=request.env['kalachakra.membership'].search([('partner_id','=',int(partner.id)),('state','=','done'),('end_date','>=','%s 00:00:00' % fields.Date.today())],order="end_date desc") + if actives_membership: + for m in actives_membership: + return m + + else: return False + + def has_already_renew_membership(self,partner): + + actives_membership=request.env['kalachakra.membership'].search([('partner_id','=',int(partner.id)),('state','=','done'),('end_date','>=','%s 00:00:00' % fields.Date.today())],order='end_date desc') + if actives_membership: + if len(actives_membership)>1: + + return True + else: + for m in actives_membership: + #on regarde la date de fin la plus récente + #si la date du jour est antérieur à 40 jours avant cette date on + #autorise pas le renouvellement + today=date.today() + today_date = date(today.year,today.month, today.day) + end_date = date(m.end_date.year,m.end_date.month, m.end_date.day) + diff=end_date-today_date + if diff.days>40: + return True + else : return False + else: + return False + @http.route(['/kalachakra/participation'], type='http', auth='public', website=True, sitemap=False,csrf=False) def participation(self,type=None,**post): data={} request.session['kalachakra_transaction']='' - + allow_renew=False + if len(post)>0: + if post.get('renew')=="1": allow_renew=True if type=='participation': res=request.env['event.registration'].sudo().search([('id','=',request.session['res_id'])]) @@ -990,12 +1041,22 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): data['countries']=country data['country_id']=int(partner.country_id) - # if type in ('membership','super_membership'): - - # if partner.member_status in ('member','super member') and request.session['kalachakra_transaction']=='membership': - # data={} - # data['email']=partner.email - # return http.request.render('kalachakra.already_member',data) + #demande d'adhésion : on vérifie qu'il n'est pas déjà adhérent si demande d'adhésion + #si déjà adhérent on affiche la date de sa fin d'adhésion actuelle + #et on lui demande s'il veut renouveler son adhésion avec nouvelle date de fin + if partner.member_status in ('member') and request.session['kalachakra_transaction']=='membership': + data2={} + active_membership=self.active_membership(partner) + end_date=active_membership.end_date + data2['end_date']=str(end_date.day)+'/'+str(end_date.month)+'/'+str(end_date.year) + data2['email']=partner.email + if self.has_already_renew_membership(partner): + return http.request.render('kalachakra.already_renew_membership',data2) + else: + if not allow_renew: + return http.request.render('kalachakra.already_member',data2) + + # si pas connecté else: @@ -1117,15 +1178,7 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): }) user.sudo().action_reset_password() - #demande d'adhésion : on vérifie qu'il n'est pas déjà adhérent si demande d'adhésion - # if partner.member_status in ('member','super member') and request.session['kalachakra_transaction']=='membership': - # data={} - # data['email']=partner.email - # return http.request.render('kalachakra.already_member',data) - - - - + data={} if request.session['kalachakra_transaction']=='donation': data['submit_txt']='Faire un don' @@ -1196,11 +1249,24 @@ class kalachakra_event(WebsiteEventController,PaymentProcessing): if request.session['kalachakra_transaction'] in ['membership']: vals={} - + + if partner.member_status in ('member'): + if not self.has_already_renew_membership(partner): + active_membership=self.active_membership(partner) + + vals['start_date']=active_membership.start_date + vals['end_date']=active_membership.start_date+relativedelta(years=1) + else: + data={} + data['email']=partner.email + return http.request.render('kalachakra.already_renew_membership',data) + + else: + vals['start_date']=datetime.now() + vals['end_date']=datetime.now()+relativedelta(years=1) + vals['partner_id']=partner.id vals['product_id']=int(post.get('product_id')) - vals['start_date']=datetime.now() - vals['end_date']=datetime.now()+relativedelta(years=1) vals['amount']=post.get('amount') membership=request.env['kalachakra.membership'].sudo().create(vals) data['order_id']=membership.id diff --git a/models/account_move.py b/models/account_move.py index 78b140a..08e4daa 100755 --- a/models/account_move.py +++ b/models/account_move.py @@ -21,7 +21,8 @@ class AccountMove(models.Model): date_compta_out_refund=fields.Datetime('date import',default=False) out_invoice_id=fields.Many2one('account.move' ,ondelete="cascade",domain="[('partner_id','=',partner_id),('move_type','=','out_invoice'),('state','!=','paid')]") payment_ids=fields.Many2many('account.payment',compute='_compute_payment_ids') - + down_payment_paid=fields.Boolean(compute='_compute_down_payment_paid') + is_balance_invoice=fields.Boolean(compute='_compute_is_balance_invoice') def write(self, data): @@ -112,6 +113,25 @@ class AccountMove(models.Model): if r_s[0]==" 'vads_order_id'": a.systempay_ref=r_s[1].replace("'","") break + + def _compute_down_payment_paid(self): + reg=self.env['event.registration'].search([('balance_invoice_id','=',self.id)]) + + if reg : + if reg.date_payment_down_payment :self.down_payment_paid=True + else :self.down_payment_paid=False + + else: + self.down_payment_paid=False + + + down_payment_paid=True + + def _compute_is_balance_invoice(self): + reg=self.env['event.registration'].search([('balance_invoice_id','=',self.id)]) + if reg:self.is_balance_invoice=True + else:self.is_balance_invoice=False + def button_event_registration(self): reg=self.env['event.registration'].search(['|','|','|',('invoice_id','=',self.id),\ ('down_payment_invoice_id','=',self.id),\ diff --git a/models/accounting_file.py b/models/accounting_file.py index 18a43bb..7d77580 100755 --- a/models/accounting_file.py +++ b/models/accounting_file.py @@ -11,4 +11,13 @@ class accounting_file(models.Model): exported_date=fields.Date(string='Exported Date',tracking=True, readonly=True) start_date=fields.Date(string='Start Date',tracking=True, readonly=True) end_date=fields.Date(string='End Date',tracking=True, readonly=True) - \ No newline at end of file + +class cdr_accounting_file(models.Model): + _name = 'cdr.accounting.file' + _description = 'Centre de retraite accounting files' + + accounting_file = fields.Binary('accounting file', readonly=True) + document_fname=fields.Char(default='undefined') + exported_date=fields.Date(string='Exported Date',tracking=True, readonly=True) + start_date=fields.Date(string='Start Date',tracking=True, readonly=True) + end_date=fields.Date(string='End Date',tracking=True, readonly=True) \ No newline at end of file diff --git a/models/product.py b/models/product.py index afe6643..ca61fa6 100755 --- a/models/product.py +++ b/models/product.py @@ -14,4 +14,5 @@ class KalachakraProductTemplate(models.Model): booking_option_product = fields.Boolean(string="booking option product", tracking=True) price_per=fields.Selection(string="Price per",selection=[('stay','Stay'),('night', 'Night'), ('day', 'Day')], default='stay', tracking=True) individual_room=fields.Boolean(string="individual room", tracking=True) - on_website=fields.Boolean(string="On website", tracking=True) \ No newline at end of file + on_website=fields.Boolean(string="On website", tracking=True) + cdr_property_account_income_id=fields.Many2one('account.account',string='Compte de revenus Centre de retraite') \ No newline at end of file diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index 193691f..e870d77 100755 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -31,4 +31,7 @@ access_event_teaching_day_public,event_teaching_day_public,model_event_teaching_ access_event_teaching_day_portal,event_teaching_day_portal,model_event_teaching_day,base.group_portal,1,0,0,0 access_accounting_file,access to accounting files,model_accounting_file,account.group_account_manager,1,1,1,1 -access_accounting_file_wizard,access to accounting file wizard,model_accounting_file_wizard,account.group_account_manager,1,1,1,1 \ No newline at end of file +access_accounting_file_wizard,access to accounting file wizard,model_accounting_file_wizard,account.group_account_manager,1,1,1,1 + +access_cdr_accounting_file,access to cdr accounting files,model_cdr_accounting_file,account.group_account_manager,1,1,1,1 +access_cdr_accounting_file_wizard,access to cdr accounting file wizard,model_cdr_accounting_file_wizard,account.group_account_manager,1,1,1,1 diff --git a/static/js/kalachakra.js b/static/js/kalachakra.js index 2a0d5e8..a869e89 100755 --- a/static/js/kalachakra.js +++ b/static/js/kalachakra.js @@ -134,6 +134,14 @@ odoo.define('kalachakra.main', function (require) { $( "#form" ).submit(); }); + $( "#renew_yes" ).click(function() { + + $('#renew').val("1"); + + + $( "#form" ).submit(); + }); + $( "#make_donation_btn" ).click(function() { $('#form').attr('action', '/kalachakra/participation?type=donation'); diff --git a/views/account_portal_templates.xml b/views/account_portal_templates.xml index 220d0cd..601c4bb 100755 --- a/views/account_portal_templates.xml +++ b/views/account_portal_templates.xml @@ -28,4 +28,28 @@ + + + \ No newline at end of file diff --git a/views/accounting_file.xml b/views/accounting_file.xml index fa5b8ba..942d380 100755 --- a/views/accounting_file.xml +++ b/views/accounting_file.xml @@ -15,16 +15,26 @@ + + CDR kalachakra_accounting file list + cdr.accounting.file + + + + + + + + + + + - kalachakra_member form - accounting.file + kalachakra_accounting_file form + cdr.accounting.file -
- - @@ -34,16 +44,30 @@ - - - - -
+ + CDR kalachakra_accounting_file form + cdr.accounting.file + +
+ + + + + + + + + + + +
+
+
Accounting files @@ -51,10 +75,19 @@ tree,form,pivot + + CDR accounting files + cdr.accounting.file + tree,form,pivot + + + + \ No newline at end of file diff --git a/views/contactus.xml b/views/contactus.xml index 5285d93..58f6465 100755 --- a/views/contactus.xml +++ b/views/contactus.xml @@ -2,7 +2,7 @@ diff --git a/views/product.xml b/views/product.xml index dc0d5a7..1ef2ec1 100755 --- a/views/product.xml +++ b/views/product.xml @@ -22,6 +22,9 @@ + + + diff --git a/views/website_event_registration.xml b/views/website_event_registration.xml index 8782302..184d207 100755 --- a/views/website_event_registration.xml +++ b/views/website_event_registration.xml @@ -301,15 +301,34 @@ - +
+
You are already a member with this email adress :
+
and the end date is :
+
Do you want to renew it for one more year ?
+ + no +
+
+
+ + + + +