From b9b9d16745c1b14f49f65b19d0ce36e919dc991c Mon Sep 17 00:00:00 2001 From: "robin.keunen" Date: Tue, 2 Jun 2020 18:03:56 +0200 Subject: [PATCH] [IMP] emca: generate and export external id [ADD] emca: external_id on invoice --- easy_my_coop_api/__manifest__.py | 4 ++-- easy_my_coop_api/data/sequences.xml | 19 +++++++++++++++ easy_my_coop_api/demo/demo.xml | 10 ++++++++ easy_my_coop_api/models/__init__.py | 2 ++ easy_my_coop_api/models/account_invoice.py | 22 +++++++++++++++++ .../models/subscription_request.py | 24 +++++++++++++++++++ .../services/subscription_request_service.py | 11 ++++++--- 7 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 easy_my_coop_api/data/sequences.xml create mode 100644 easy_my_coop_api/demo/demo.xml create mode 100644 easy_my_coop_api/models/account_invoice.py create mode 100644 easy_my_coop_api/models/subscription_request.py diff --git a/easy_my_coop_api/__manifest__.py b/easy_my_coop_api/__manifest__.py index f42c066..a7f8cd9 100644 --- a/easy_my_coop_api/__manifest__.py +++ b/easy_my_coop_api/__manifest__.py @@ -17,8 +17,8 @@ "summary": """ Open Easy My Coop to the world: RESTful API. """, - "data": [], - "demo": [], + "data": ["data/sequences.xml"], + "demo": ["demo/demo.xml"], "installable": True, "application": False, } diff --git a/easy_my_coop_api/data/sequences.xml b/easy_my_coop_api/data/sequences.xml new file mode 100644 index 0000000..4d03a8a --- /dev/null +++ b/easy_my_coop_api/data/sequences.xml @@ -0,0 +1,19 @@ + + + + + + Subscritpion Request External ID sequence + subscription.request.external.id + 3 + + + Subscritpion Request External ID sequence + account.invoice.external.id + 3 + + + diff --git a/easy_my_coop_api/demo/demo.xml b/easy_my_coop_api/demo/demo.xml new file mode 100644 index 0000000..a88981a --- /dev/null +++ b/easy_my_coop_api/demo/demo.xml @@ -0,0 +1,10 @@ + + + + + 1 + + diff --git a/easy_my_coop_api/models/__init__.py b/easy_my_coop_api/models/__init__.py index 6dfe3f7..b951867 100644 --- a/easy_my_coop_api/models/__init__.py +++ b/easy_my_coop_api/models/__init__.py @@ -1 +1,3 @@ from . import auth_api_key +from . import subscription_request +from . import account_invoice diff --git a/easy_my_coop_api/models/account_invoice.py b/easy_my_coop_api/models/account_invoice.py new file mode 100644 index 0000000..ae3c520 --- /dev/null +++ b/easy_my_coop_api/models/account_invoice.py @@ -0,0 +1,22 @@ +# Copyright 2020 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class AccountInvoice(models.Model): + _inherit = "account.invoice" + + external_id = fields.Integer( + string="External ID", index=True, required=False + ) + + @api.multi + def get_external_id(self): + self.ensure_one() + if not self.external_id: + self.external_id = self.env["ir.sequence"].next_by_code( + "account.invoice.external.id" + ) + return self.external_id diff --git a/easy_my_coop_api/models/subscription_request.py b/easy_my_coop_api/models/subscription_request.py new file mode 100644 index 0000000..717c072 --- /dev/null +++ b/easy_my_coop_api/models/subscription_request.py @@ -0,0 +1,24 @@ +# Copyright 2020 Coop IT Easy SCRL fs +# Robin Keunen +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from os.path import join + +from odoo import api, fields, models + + +class SubscriptionRequest(models.Model): + _inherit = "subscription.request" + + external_id = fields.Integer( + string="External ID", index=True, required=False + ) + + @api.multi + def get_external_id(self): + self.ensure_one() + if not self.external_id: + self.external_id = self.env["ir.sequence"].next_by_code( + "subscription.request.external.id" + ) + return self.external_id diff --git a/easy_my_coop_api/services/subscription_request_service.py b/easy_my_coop_api/services/subscription_request_service.py index 4013739..b120a82 100644 --- a/easy_my_coop_api/services/subscription_request_service.py +++ b/easy_my_coop_api/services/subscription_request_service.py @@ -28,7 +28,9 @@ class SubscriptionRequestService(Component): """ def get(self, _id): - sr = self.env["subscription.request"].browse(_id) + sr = self.env["subscription.request"].search( + [("external_id", "=", _id)] + ) if sr: return self._to_dict(sr) else: @@ -63,7 +65,9 @@ class SubscriptionRequestService(Component): def update(self, _id, **params): params = self._prepare_update(params) - sr = self.env["subscription.request"].browse(_id) + sr = self.env["subscription.request"].search( + [("external_id", "=", _id)] + ) if not sr: raise wrapJsonException( NotFound(_("No subscription request for id %s") % _id) @@ -73,8 +77,9 @@ class SubscriptionRequestService(Component): def _to_dict(self, sr): sr.ensure_one() + return { - "id": sr.id, + "id": sr.get_external_id(), "name": sr.name, "email": sr.email, "state": sr.state,