Browse Source

[IMP] emca: timestamp exported data

pull/115/head
robin.keunen 4 years ago
parent
commit
eabe83c0fe
  1. 1
      easy_my_coop_api/models/__init__.py
  2. 17
      easy_my_coop_api/models/external_id_mixin.py
  3. 18
      easy_my_coop_api/models/subscription_request.py
  4. 2
      easy_my_coop_api/services/subscription_request_service.py
  5. 22
      easy_my_coop_api/tests/test_account_invoice.py
  6. 2
      easy_my_coop_api/tests/test_subscription_requests.py
  7. 8
      easy_my_coop_connector/components/emc_backend.py

1
easy_my_coop_api/models/__init__.py

@ -1,2 +1,3 @@
from . import auth_api_key
from . import external_id_mixin
from . import subscription_request

17
easy_my_coop_api/models/external_id_mixin.py

@ -28,6 +28,12 @@ class ExternalIdMixin(models.AbstractModel):
string="External ID Sequence",
required=False,
)
first_api_export_date = fields.Datetime(
string="First API Export Date", required=False
)
last_api_export_date = fields.Datetime(
string="Last API Export Date", required=False
)
@api.multi
def set_external_sequence(self):
@ -55,11 +61,7 @@ class ExternalIdMixin(models.AbstractModel):
while True:
try:
next_id = self.external_id_sequence_id._next()
self.sudo().write(
{
"_api_external_id": next_id
}
)
self.sudo().write({"_api_external_id": next_id})
break
except IntegrityError as e:
if n > 0:
@ -74,11 +76,6 @@ class ResPartner(models.Model):
_inherit = ["res.partner", "external.id.mixin"]
class SubscriptionRequest(models.Model):
_name = "subscription.request"
_inherit = ["subscription.request", "external.id.mixin"]
class AccountAccount(models.Model):
_name = "account.account"
_inherit = ["account.account", "external.id.mixin"]

18
easy_my_coop_api/models/subscription_request.py

@ -0,0 +1,18 @@
# Copyright 2020 Coop IT Easy SCRL fs
# Robin Keunen <robin@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, models
from odoo.fields import Datetime
class SubscriptionRequest(models.Model):
_name = "subscription.request"
_inherit = ["subscription.request", "external.id.mixin"]
@api.multi
def _timestamp_export(self):
self.write({"last_api_export_date": Datetime.now()})
self.filtered(lambda sr: not sr.first_api_export_date).write(
{"first_api_export_date": Datetime.now()}
)

2
easy_my_coop_api/services/subscription_request_service.py

@ -31,6 +31,7 @@ class SubscriptionRequestService(Component):
[("_api_external_id", "=", _id)]
)
if sr:
sr._timestamp_export()
return self._to_dict(sr)
else:
raise wrapJsonException(
@ -49,6 +50,7 @@ class SubscriptionRequestService(Component):
domain.append(("date", "<=", date_to))
requests = self.env["subscription.request"].search(domain)
requests._timestamp_export()
response = {
"count": len(requests),

22
easy_my_coop_api/tests/test_account_invoice.py

@ -30,11 +30,20 @@ class TestAccountInvoiceController(BaseEMCRestCase):
today = Date.to_string(Date.today())
self.demo_invoice_dict = {
"id": 1,
"id": self.capital_release.get_api_external_id(),
"number": "xxx", # can't guess it
"partner": {"id": 1, "name": "Catherine des Champs"},
"account": {"id": 1, "name": "Cooperators"},
"journal": {"id": 1, "name": "Subscription Journal"},
"partner": {
"id": self.coop_candidate.get_api_external_id(),
"name": self.coop_candidate.name,
},
"account": {
"id": self.cooperator_account.get_api_external_id(),
"name": self.cooperator_account.name,
},
"journal": {
"id": self.subscription_journal.get_api_external_id(),
"name": self.subscription_journal.name,
},
"subscription_request": {},
"state": "open",
"date": today,
@ -47,7 +56,10 @@ class TestAccountInvoiceController(BaseEMCRestCase):
"product": {"id": 1, "name": "Part A - Founder"},
"price_unit": 100.0,
"quantity": 2.0,
"account": {"id": 2, "name": "Equity"},
"account": {
"id": self.equity_account.get_api_external_id(),
"name": self.equity_account.name,
},
}
],
}

2
easy_my_coop_api/tests/test_subscription_requests.py

@ -76,6 +76,8 @@ class TestSRController(BaseEMCRestCase):
date_sr = self.sr_service.search(date_from=date_from, date_to=date_to)
self.assertTrue(date_sr)
self.assertTrue(self.demo_request_1.first_api_export_date)
self.assertTrue(self.demo_request_1.last_api_export_date)
def test_route_get(self):
external_id = self.demo_request_1.get_api_external_id()

8
easy_my_coop_connector/components/emc_backend.py

@ -9,7 +9,7 @@ import requests
from werkzeug.exceptions import BadRequest, InternalServerError, NotFound
from odoo import _, api, fields, models
from odoo.exceptions import AccessDenied
from odoo.exceptions import AccessDenied, Warning as UserError
_logger = logging.getLogger(__name__)
@ -113,12 +113,12 @@ class EMCBackend(models.Model):
response = requests.get(url)
except Exception as e:
_logger.error(e)
raise Warning(_("Failed to connect to backend: %s" % str(e)))
raise UserError(_("Failed to connect to backend: %s" % str(e)))
if response.status_code == 200:
content = json.loads(response.content.decode("utf-8"))
raise Warning(_("Success: %s") % content["message"])
raise UserError(_("Success: %s") % content["message"])
else:
raise Warning(
raise UserError(
_("Failed to connect to backend: %s" % str(response.content))
)
Loading…
Cancel
Save