Browse Source

[ADD] emcc: cron to fetch requests

pull/115/head
robin.keunen 5 years ago
parent
commit
3bf12d7bf4
  1. 1
      easy_my_coop_connector/__manifest__.py
  2. 19
      easy_my_coop_connector/data/cron.xml
  3. 28
      easy_my_coop_connector/models/subscription_request.py

1
easy_my_coop_connector/__manifest__.py

@ -20,6 +20,7 @@
"wizards/emc_history_import_sr.xml",
"views/actions.xml",
"views/menus.xml",
"data/cron.xml",
],
"demo": ["demo/demo.xml"],
"installable": True,

19
easy_my_coop_connector/data/cron.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 Coop IT Easy
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="fetch_subscription_requests_cron" model="ir.cron">
<field name="name">Fetch Subscription Requests</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field name="nextcall" eval="(DateTime.today() + timedelta(days=1)).strftime('%Y-%m-%d 01:00:00')"/>
<field name="doall" eval="True"/>
<field name="model_id" ref="easy_my_coop.model_subscription_request"/>
<field name="state">code</field>
<field name="code">model.fetch_subscription_requests_cron()</field>
<field name="sequence">50</field>
</record>
</odoo>

28
easy_my_coop_connector/models/subscription_request.py

@ -2,10 +2,15 @@
# Robin Keunen <robin@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import logging
from datetime import date, timedelta
from odoo import api, fields, models
from .subscription_request_adapter import SubscriptionRequestAdapter
_logger = logging.getLogger(__name__)
class SubscriptionRequest(models.Model):
_inherit = "subscription.request"
@ -79,3 +84,26 @@ class SubscriptionRequest(models.Model):
}
)
return srequest
@api.model
def fetch_subscription_requests_cron(self):
backend = self.env["emc.backend"].search([("active", "=", True)])
try:
backend.ensure_one()
except ValueError as e:
_logger.error(
"One and only one backend is allowed for the Easy My Coop "
"connector "
)
raise e
date_to = date.today()
date_from = date_to - timedelta(days=1)
_logger.info(
"fetching subscription requests at {backend} from {date_from} to "
"{date_to}.".format(
backend=backend.name, date_from=date_from, date_to=date_to
)
)
self.fetch_subscription_requests(date_from=date_from, date_to=date_to)
_logger.info("fetch done.")
Loading…
Cancel
Save