|
@ -7,8 +7,6 @@ from werkzeug import utils |
|
|
import base64 |
|
|
import base64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DonationDonation(models.Model): |
|
|
class DonationDonation(models.Model): |
|
|
_inherit = 'donation.donation' |
|
|
_inherit = 'donation.donation' |
|
|
|
|
|
|
|
@ -29,21 +27,11 @@ class DonationDonation(models.Model): |
|
|
ondelete='restrict' |
|
|
ondelete='restrict' |
|
|
|
|
|
|
|
|
) |
|
|
) |
|
|
# #pour les prélèvements automatiques |
|
|
|
|
|
# rum_direct_debit = fields.Char( |
|
|
|
|
|
# 'RUM' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ) |
|
|
|
|
|
# iban_direct_debit = fields.Char( |
|
|
|
|
|
# 'iban' |
|
|
|
|
|
# ) |
|
|
|
|
|
# bic_direct_debit = fields.Char( |
|
|
|
|
|
# 'bic' |
|
|
|
|
|
# ) |
|
|
|
|
|
|
|
|
|
|
|
start_date = fields.Date( |
|
|
start_date = fields.Date( |
|
|
string='Start Date', |
|
|
string='Start Date', |
|
|
index=True, |
|
|
index=True, |
|
|
|
|
|
required=True, |
|
|
default=datetime.today(), |
|
|
default=datetime.today(), |
|
|
track_visibility='onchange' |
|
|
track_visibility='onchange' |
|
|
) |
|
|
) |
|
@ -70,14 +58,7 @@ class DonationDonation(models.Model): |
|
|
default='monthly' |
|
|
default='monthly' |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# sepa_status_direct_debit=fields.Selection( |
|
|
|
|
|
# [('done','Done'),('rejected','Rejected')] |
|
|
|
|
|
# ) |
|
|
|
|
|
# rejected_date_direct_debit = fields.Date( |
|
|
|
|
|
# string='rejected date', |
|
|
|
|
|
# index=True, |
|
|
|
|
|
# track_visibility='onchange' |
|
|
|
|
|
# ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@api.onchange('operation_id') |
|
|
@api.onchange('operation_id') |
|
|
def _onchange_operation_id(self): |
|
|
def _onchange_operation_id(self): |
|
@ -85,6 +66,12 @@ class DonationDonation(models.Model): |
|
|
res['domain']={'segment_id':[('operation_id', '=', self.operation_id.id)]} |
|
|
res['domain']={'segment_id':[('operation_id', '=', self.operation_id.id)]} |
|
|
return res |
|
|
return res |
|
|
|
|
|
|
|
|
|
|
|
# @api.onchange('start_date') |
|
|
|
|
|
# def _onchange_start_date(self): |
|
|
|
|
|
# if self.start_date: |
|
|
|
|
|
# self.donation_date=fields.Date.context_today(self) |
|
|
|
|
|
# return True |
|
|
|
|
|
|
|
|
# payment_batch_id = fields.Many2one( |
|
|
# payment_batch_id = fields.Many2one( |
|
|
# 'opendons_payment_batch', |
|
|
# 'opendons_payment_batch', |
|
|
# string='Payment Batch', |
|
|
# string='Payment Batch', |
|
@ -97,3 +84,60 @@ class DonationDonation(models.Model): |
|
|
#if rec.recurring_template: rec.rum_direct_debit='GHGHH65767688899976' |
|
|
#if rec.recurring_template: rec.rum_direct_debit='GHGHH65767688899976' |
|
|
#rec.rum_direct_debit='GHGHH65767688899976' |
|
|
#rec.rum_direct_debit='GHGHH65767688899976' |
|
|
|
|
|
|
|
|
|
|
|
class DonationRecurringGenerate(models.TransientModel): |
|
|
|
|
|
_inherit = 'donation.recurring.generate' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate(self): |
|
|
|
|
|
self.ensure_one() |
|
|
|
|
|
doo = self.env["donation.donation"] |
|
|
|
|
|
donations = doo.search( |
|
|
|
|
|
[ |
|
|
|
|
|
("recurring_template", "=", "active"), |
|
|
|
|
|
("company_id", "=", self.company_id.id), |
|
|
|
|
|
] |
|
|
|
|
|
) |
|
|
|
|
|
new_donation_ids = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for donation in donations: |
|
|
|
|
|
generate=True |
|
|
|
|
|
existing_recur_donations = doo.search([("source_recurring_id", "=",int(donation.id))]) |
|
|
|
|
|
|
|
|
|
|
|
delta=0 |
|
|
|
|
|
if donation.frequency=='annually':delta=365 |
|
|
|
|
|
if donation.frequency=='half-yearly':delta=365/2 |
|
|
|
|
|
if donation.frequency=='quarterly':delta=365/4 |
|
|
|
|
|
if donation.frequency=='bimonthly':delta=365/6 |
|
|
|
|
|
if donation.frequency=='monthly':delta=365/12 |
|
|
|
|
|
if existing_recur_donations: |
|
|
|
|
|
for d in existing_recur_donations: |
|
|
|
|
|
days_diff=(d.donation_date-fields.Date.context_today(self)).days |
|
|
|
|
|
if days_diff<=delta: |
|
|
|
|
|
generate=False |
|
|
|
|
|
break |
|
|
|
|
|
#raise UserError("generate="+str(generate)) |
|
|
|
|
|
|
|
|
|
|
|
if generate==True: |
|
|
|
|
|
default = { |
|
|
|
|
|
"recurring_template":'', |
|
|
|
|
|
"donation_date": fields.Date.context_today(self), |
|
|
|
|
|
"source_recurring_id": donation.id, |
|
|
|
|
|
"payment_ref": '', |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
new_donation = donation.copy(default=default) |
|
|
|
|
|
new_donation_ids.append(new_donation.id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
action = self.env.ref("donation.donation_action").sudo().read([])[0] |
|
|
|
|
|
action.update( |
|
|
|
|
|
{ |
|
|
|
|
|
"domain": [("id", "in", new_donation_ids)], |
|
|
|
|
|
"limit": 500, |
|
|
|
|
|
} |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
return action |
|
|
|
|
|
|