Browse Source

[12.0][ADD] emc_loan: ir_cron

- change state to `closed` when `subscription_end_date` <= today
pull/145/head
Vincent Van Rossem 4 years ago
parent
commit
b764b9cd7f
  1. 1
      easy_my_coop_loan/__manifest__.py
  2. 13
      easy_my_coop_loan/data/ir_cron_data.xml
  3. 16
      easy_my_coop_loan/models/loan.py

1
easy_my_coop_loan/__manifest__.py

@ -17,6 +17,7 @@
"data": [
"security/ir.model.access.csv",
"data/actions.xml",
"data/ir_cron_data.xml",
"data/mail_template_data.xml",
"views/loan_view.xml",
"views/partner_view.xml",

13
easy_my_coop_loan/data/ir_cron_data.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo noupdate="1">
<record id="ir_cron_check_subscription_end_date" model="ir.cron">
<field name="name">Loan Issue: Check Subscription End Date</field>
<field name="model_id" ref="model_loan_issue"/>
<field name="state">code</field>
<field name="code">model._cron_check_subscription_end_date()</field>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="numbercall">-1</field>
<field name="active" eval="False"/>
</record>
</odoo>

16
easy_my_coop_loan/models/loan.py

@ -226,3 +226,19 @@ class LoanIssue(models.Model):
"hasn't been implemented yet"
)
)
def _cron_check_subscription_end_date(self):
today = fields.Date.today()
loans_to_close = self.search(
[("state", "!=", "closed"), ("subscription_end_date", "<=", today)]
)
for loan in loans_to_close:
try:
loan.action_close()
self.env.cr.commit()
_logger.debug("Loan: '%s' - state: '%s'" % (loan, loan.state))
except Exception:
_logger.exception(
"An exception occured while closing loan: '%s'" % (loan)
)
self.env.cr.rollback()
Loading…
Cancel
Save