Browse Source

[IMP] emca: generate and export external id

[ADD] emca: external_id on invoice
pull/116/head
robin.keunen 5 years ago
parent
commit
b9b9d16745
  1. 4
      easy_my_coop_api/__manifest__.py
  2. 19
      easy_my_coop_api/data/sequences.xml
  3. 10
      easy_my_coop_api/demo/demo.xml
  4. 2
      easy_my_coop_api/models/__init__.py
  5. 22
      easy_my_coop_api/models/account_invoice.py
  6. 24
      easy_my_coop_api/models/subscription_request.py
  7. 11
      easy_my_coop_api/services/subscription_request_service.py

4
easy_my_coop_api/__manifest__.py

@ -17,8 +17,8 @@
"summary": """ "summary": """
Open Easy My Coop to the world: RESTful API. Open Easy My Coop to the world: RESTful API.
""", """,
"data": [],
"demo": [],
"data": ["data/sequences.xml"],
"demo": ["demo/demo.xml"],
"installable": True, "installable": True,
"application": False, "application": False,
} }

19
easy_my_coop_api/data/sequences.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>
<data noupdate="1">
<record id="seq_subscription_request_external_id" model="ir.sequence">
<field name="name">Subscritpion Request External ID sequence</field>
<field name="code">subscription.request.external.id</field>
<field name="number_next">3</field>
</record>
<record id="seq_account_invoice_external_id" model="ir.sequence">
<field name="name">Subscritpion Request External ID sequence</field>
<field name="code">account.invoice.external.id</field>
<field name="number_next">3</field>
</record>
</data>
</odoo>

10
easy_my_coop_api/demo/demo.xml

@ -0,0 +1,10 @@
<?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="easy_my_coop.subscription_request_1_demo" model="subscription.request">
<field name="external_id">1</field>
</record>
</odoo>

2
easy_my_coop_api/models/__init__.py

@ -1 +1,3 @@
from . import auth_api_key from . import auth_api_key
from . import subscription_request
from . import account_invoice

22
easy_my_coop_api/models/account_invoice.py

@ -0,0 +1,22 @@
# 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, 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

24
easy_my_coop_api/models/subscription_request.py

@ -0,0 +1,24 @@
# 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 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

11
easy_my_coop_api/services/subscription_request_service.py

@ -28,7 +28,9 @@ class SubscriptionRequestService(Component):
""" """
def get(self, _id): def get(self, _id):
sr = self.env["subscription.request"].browse(_id)
sr = self.env["subscription.request"].search(
[("external_id", "=", _id)]
)
if sr: if sr:
return self._to_dict(sr) return self._to_dict(sr)
else: else:
@ -63,7 +65,9 @@ class SubscriptionRequestService(Component):
def update(self, _id, **params): def update(self, _id, **params):
params = self._prepare_update(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: if not sr:
raise wrapJsonException( raise wrapJsonException(
NotFound(_("No subscription request for id %s") % _id) NotFound(_("No subscription request for id %s") % _id)
@ -73,8 +77,9 @@ class SubscriptionRequestService(Component):
def _to_dict(self, sr): def _to_dict(self, sr):
sr.ensure_one() sr.ensure_one()
return { return {
"id": sr.id,
"id": sr.get_external_id(),
"name": sr.name, "name": sr.name,
"email": sr.email, "email": sr.email,
"state": sr.state, "state": sr.state,

Loading…
Cancel
Save