|
|
@ -47,75 +47,3 @@ class SubscriptionPackage(models.Model): |
|
|
|
email_layout_xmlid= |
|
|
|
"mail.mail_notification_layout_with_responsible_signature", |
|
|
|
email_values=email_vals) |
|
|
|
|
|
|
|
def close_limit_cron(self): |
|
|
|
"""It Checks renew date, close date. It will send mail when renew |
|
|
|
date and also generates invoices based on the plan. |
|
|
|
It wil close the subscription automatically if renewal limit is |
|
|
|
exceeded.""" |
|
|
|
pending_subscriptions = self.env['subscription.package'].search( |
|
|
|
[('stage_category', '=', 'progress')]) |
|
|
|
today_date = fields.Date.today() |
|
|
|
pending_subscription = False |
|
|
|
for pending_subscription in pending_subscriptions: |
|
|
|
get_dates = self.find_renew_date( |
|
|
|
pending_subscription.next_invoice_date, |
|
|
|
pending_subscription.date_started, |
|
|
|
pending_subscription.plan_id.days_to_end) |
|
|
|
renew_date = get_dates['renew_date'] |
|
|
|
end_date = get_dates['end_date'] |
|
|
|
pending_subscription.close_date = get_dates['close_date'] |
|
|
|
if today_date == pending_subscription.next_invoice_date: |
|
|
|
if pending_subscription.plan_id.invoice_mode == 'draft_invoice': |
|
|
|
this_products_line = [] |
|
|
|
for rec in pending_subscription.product_line_ids: |
|
|
|
rec_list = [0, 0, {'product_id': rec.product_id.id, |
|
|
|
'quantity': rec.product_qty, |
|
|
|
'price_unit': rec.unit_price, |
|
|
|
'discount': rec.product_id.subscription_discount, |
|
|
|
'tax_ids': rec.tax_id |
|
|
|
}] |
|
|
|
this_products_line.append(rec_list) |
|
|
|
self.env['account.move'].create( |
|
|
|
{'move_type': 'out_invoice', |
|
|
|
'invoice_date_due': today_date, |
|
|
|
'invoice_payment_term_id': False, |
|
|
|
'invoice_date': today_date, |
|
|
|
'state': 'draft', |
|
|
|
'subscription_id': pending_subscription.id, |
|
|
|
'partner_id': pending_subscription.partner_invoice_id.id, |
|
|
|
'currency_id': pending_subscription.partner_invoice_id.currency_id.id, |
|
|
|
'invoice_line_ids': this_products_line |
|
|
|
}) |
|
|
|
pending_subscription.write({ |
|
|
|
'to_renew': False, |
|
|
|
'start_date': pending_subscription.next_invoice_date}) |
|
|
|
new_date = self.find_renew_date( |
|
|
|
pending_subscription.next_invoice_date, |
|
|
|
pending_subscription.date_started, |
|
|
|
pending_subscription.plan_id.days_to_end) |
|
|
|
pending_subscription.write( |
|
|
|
{'close_date': new_date['close_date']}) |
|
|
|
self.send_renew_alert_mail(today_date, |
|
|
|
new_date['renew_date'], |
|
|
|
pending_subscription.id) |
|
|
|
if (today_date == end_date) and ( |
|
|
|
pending_subscription.plan_id.limit_choice != 'manual'): |
|
|
|
display_msg = ("<h5><i>The renewal limit has been exceeded " |
|
|
|
"today for this subscription based on the " |
|
|
|
"current subscription plan.</i></h5>") |
|
|
|
pending_subscription.message_post(body=display_msg) |
|
|
|
pending_subscription.is_closed = True |
|
|
|
reason = (self.env['subscription.package.stop'].search([ |
|
|
|
('name', '=', 'Renewal Limit Exceeded')]).id) |
|
|
|
pending_subscription.close_reason = reason |
|
|
|
pending_subscription.closed_by = self.user_id |
|
|
|
pending_subscription.close_date = fields.Date.today() |
|
|
|
stage = (self.env['subscription.package.stage'].search([ |
|
|
|
('category', '=', 'closed')]).id) |
|
|
|
values = {'stage_id': stage, 'to_renew': False, |
|
|
|
'next_invoice_date': False} |
|
|
|
pending_subscription.write(values) |
|
|
|
self.send_renew_alert_mail(today_date, renew_date, |
|
|
|
pending_subscription.id) |
|
|
|
return dict(pending=pending_subscription) |
|
|
|