Compare commits

...

21 Commits

Author SHA1 Message Date
robin.keunen ca103c7b21 [FIX] emca: patch for json 4 years ago
robin.keunen 100a6eed91 [IMP] emcc: default date to import wizard 4 years ago
robin.keunen c05a917c22 [FIX] emca: do not copy external_id 4 years ago
robin.keunen b1083b47f7 [IMP] emca: add validate route 4 years ago
robin.keunen a8d13ea9e5 [FIX] emca: return invoice number innstead of name 4 years ago
robin.keunen 4589f75131 fixup! [IMP] emcc: add logs 4 years ago
robin.keunen 3c2413e030 fixup! [ADD] emca: add form pages for API fields 4 years ago
robin.keunen d6c07a2e1c [IMP] emcc: add logs 4 years ago
robin.keunen a8d3276ed3 [ADD] emcc: account account bindings 4 years ago
robin.keunen f4e82d1493 [ADD] emca: add form pages for API fields 4 years ago
robin.keunen eabe83c0fe [IMP] emca: timestamp exported data 4 years ago
robin.keunen 4a2c3f1fb2 [FIX] emcc: name in backend view 4 years ago
robin.keunen 05edbd10f6 [REF] emcc: components to their own directory 4 years ago
robin.keunen 8f210401a6 [ADD] emcc: post payment for emc-api invoice sends the payment to platform 4 years ago
robin.keunen 9c99e34ed1 [REF] emcc: abstract adapter 4 years ago
robin.keunen b2af3a22b0 [ADD] emcc: send validate request to platform 5 years ago
robin.keunen dc8b2276d9 [IMP] emca: sr_service.validate returns the new invoice 4 years ago
robin.keunen 3bf12d7bf4 [ADD] emcc: cron to fetch requests 5 years ago
robin.keunen 09921c0852 [ADD] emcc: manual import wizard 5 years ago
robin.keunen feda238515 [IMP] emcc: catch 403, 404, 500 return code 5 years ago
robin.keunen 7af6ed82bf [ADD] easy_my_coop_connector 5 years ago
  1. 2
      .isort.cfg
  2. 2
      easy_my_coop_api/__manifest__.py
  3. 31
      easy_my_coop_api/controllers/controllers.py
  4. 13
      easy_my_coop_api/demo/demo.xml
  5. 1
      easy_my_coop_api/models/__init__.py
  6. 50
      easy_my_coop_api/models/external_id_mixin.py
  7. 18
      easy_my_coop_api/models/subscription_request.py
  8. 8
      easy_my_coop_api/services/account_invoice_service.py
  9. 6
      easy_my_coop_api/services/account_payment_service.py
  10. 2
      easy_my_coop_api/services/schemas.py
  11. 9
      easy_my_coop_api/services/subscription_request_service.py
  12. 34
      easy_my_coop_api/tests/test_account_invoice.py
  13. 2
      easy_my_coop_api/tests/test_account_payment.py
  14. 17
      easy_my_coop_api/tests/test_external_id_mixin.py
  15. 4
      easy_my_coop_api/tests/test_subscription_requests.py
  16. 178
      easy_my_coop_api/views/external_id_mixin_views.xml
  17. 65
      easy_my_coop_connector/README.rst
  18. 3
      easy_my_coop_connector/__init__.py
  19. 28
      easy_my_coop_connector/__manifest__.py
  20. 3
      easy_my_coop_connector/components/__init__.py
  21. 190
      easy_my_coop_connector/components/emc_adapters.py
  22. 116
      easy_my_coop_connector/components/emc_backend.py
  23. 84
      easy_my_coop_connector/components/emc_bindings.py
  24. 19
      easy_my_coop_connector/data/cron.xml
  25. 32
      easy_my_coop_connector/demo/demo.xml
  26. 5
      easy_my_coop_connector/models/__init__.py
  27. 20
      easy_my_coop_connector/models/account_account.py
  28. 20
      easy_my_coop_connector/models/account_invoice.py
  29. 16
      easy_my_coop_connector/models/account_journal.py
  30. 48
      easy_my_coop_connector/models/account_payment.py
  31. 121
      easy_my_coop_connector/models/subscription_request.py
  32. 2
      easy_my_coop_connector/readme/CONTRIBUTORS.rst
  33. 1
      easy_my_coop_connector/readme/DESCRIPTION.rst
  34. 0
      easy_my_coop_connector/readme/ROADMAP.rst
  35. 22
      easy_my_coop_connector/readme/USAGE.rst
  36. 8
      easy_my_coop_connector/security/ir.model.access.csv
  37. 423
      easy_my_coop_connector/static/description/index.html
  38. 2
      easy_my_coop_connector/tests/__init__.py
  39. 92
      easy_my_coop_connector/tests/test_data.py
  40. 72
      easy_my_coop_connector/tests/test_payment.py
  41. 92
      easy_my_coop_connector/tests/test_subscription_request.py
  42. 49
      easy_my_coop_connector/views/actions.xml
  43. 48
      easy_my_coop_connector/views/emc_backend.xml
  44. 174
      easy_my_coop_connector/views/emc_bindings.xml
  45. 70
      easy_my_coop_connector/views/menus.xml
  46. 1
      easy_my_coop_connector/wizards/__init__.py
  47. 37
      easy_my_coop_connector/wizards/emc_history_import_sr.py
  48. 42
      easy_my_coop_connector/wizards/emc_history_import_sr.xml

2
.isort.cfg

@ -9,4 +9,4 @@ line_length=79
known_odoo=odoo
known_odoo_addons=odoo.addons
sections=FUTURE,STDLIB,THIRDPARTY,ODOO,ODOO_ADDONS,FIRSTPARTY,LOCALFOLDER
known_third_party=addons,cStringIO,lxml,openerp,requests,setuptools,werkzeug,xlsxwriter
known_third_party=addons,cStringIO,dateutil,lxml,openerp,psycopg2,requests,setuptools,werkzeug,xlsxwriter

2
easy_my_coop_api/__manifest__.py

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

31
easy_my_coop_api/controllers/controllers.py

@ -3,11 +3,30 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import re
from odoo import http
from odoo.http import route
from odoo.addons.base_rest.controllers import main
def patch_for_json(path_re):
# this is to avoid Odoo, which assumes json always means json+rpc,
# complaining about "function declared as capable of handling request
# of type 'http' but called with a request of type 'json'"
# cf rest-framework/graphql_base/controllers/main.py
path_re = re.compile(path_re)
orig_get_request = http.Root.get_request
def get_request(self, httprequest):
if path_re.match(httprequest.path):
return http.HttpRequest(httprequest)
return orig_get_request(self, httprequest)
http.Root.get_request = get_request
class UserController(main.RestController):
_root_path = "/api/"
_collection_name = "emc.services"
@ -23,3 +42,15 @@ class UserController(main.RestController):
return self._process_method(
_service_name, "test", _id=None, params=None
)
@route(
_root_path + "<string:_service_name>/<int:_id>/validate",
methods=["POST"],
csrf=False,
)
def validate(self, _service_name, _id, **params):
return self._process_method(
_service_name, "validate", _id=_id, params=params
)
patch_for_json("^/api/subscription-request/[0-9]*/validate$")

13
easy_my_coop_api/demo/demo.xml

@ -11,9 +11,22 @@
<record id="easy_my_coop.subscription_request_1_demo" model="subscription.request">
<field name="_api_external_id">1</field>
<field name="external_id_generated" eval="True"/>
</record>
<record id="easy_my_coop.subscription_request_waiting_demo" model="subscription.request">
<field name="_api_external_id">2</field>
<field name="external_id_generated" eval="True"/>
</record>
<record id="easy_my_coop.product_template_share_type_1_demo" model="product.template">
<field name="_api_external_id">1</field>
<field name="external_id_generated" eval="True"/>
</record>
<record id="easy_my_coop.product_template_share_type_2_demo" model="product.template">
<field name="_api_external_id">2</field>
<field name="external_id_generated" eval="True"/>
</record>
</odoo>

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

50
easy_my_coop_api/models/external_id_mixin.py

@ -2,6 +2,8 @@
# Robin Keunen <robin@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from psycopg2 import IntegrityError
from odoo import api, fields, models
@ -9,14 +11,37 @@ class ExternalIdMixin(models.AbstractModel):
_name = "external.id.mixin"
_description = "External ID Mixin"
_sql_constraints = [
(
"_api_external_id_uniq",
"unique(_api_external_id)",
"API External ID must be unique!",
)
]
# do not access directly, always use get_api_external_id method
_api_external_id = fields.Integer(
string="External ID", index=True, required=False
string="External ID", index=True, required=False, copy=False
)
external_id_sequence_id = fields.Many2one(
comodel_name="ir.sequence",
string="External ID Sequence",
required=False,
copy=False,
)
first_api_export_date = fields.Datetime(
string="First API Export Date", required=False, copy=False
)
last_api_export_date = fields.Datetime(
string="Last API Export Date", required=False, copy=False
)
# only used to display and hide "Generate external ID" button
external_id_generated = fields.Boolean(
string="External ID Generated",
default=False,
required=False,
copy=False,
)
@api.multi
@ -28,7 +53,7 @@ class ExternalIdMixin(models.AbstractModel):
sequence = Sequence.search([("code", "=", code)])
if not sequence:
sequence = Sequence.sudo().create(
{"name": code, "code": code, "number_next": 1}
{"name": code, "code": code, "number_next": 100}
)
self.sudo().write({"external_id_sequence_id": sequence.id})
@ -40,9 +65,23 @@ class ExternalIdMixin(models.AbstractModel):
if not self.external_id_sequence_id:
self.set_external_sequence()
if not self._api_external_id:
# pass already allocated ids
n = 100
while True:
try:
next_id = self.external_id_sequence_id._next()
self.sudo().write(
{"_api_external_id": self.external_id_sequence_id._next()}
{
"_api_external_id": next_id,
"external_id_generated": True,
}
)
break
except IntegrityError as e:
if n > 0:
continue
else:
raise e
return self._api_external_id
@ -51,11 +90,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()}
)

8
easy_my_coop_api/services/account_invoice_service.py

@ -27,11 +27,11 @@ class AccountInvoiceService(Component):
"""
def get(self, _id):
sr = self.env["account.invoice"].search(
ai = self.env["account.invoice"].search(
[("_api_external_id", "=", _id)]
)
if sr:
return self._to_dict(sr)
if ai:
return self._to_dict(ai)
else:
raise wrapJsonException(
NotFound(_("No invoice found for id %s") % _id)
@ -42,7 +42,7 @@ class AccountInvoiceService(Component):
data = {
"id": invoice.get_api_external_id(),
"name": invoice.name,
"number": invoice.number,
"state": invoice.state,
"type": invoice.type,
"date": Date.to_string(invoice.date),

6
easy_my_coop_api/services/account_payment_service.py

@ -76,10 +76,14 @@ class AccountPaymentService(Component):
}
def _to_dict(self, payment):
invoice = {
"id": payment.invoice_ids.get_api_external_id(),
"name": payment.invoice_ids.number,
}
return {
"id": payment.get_api_external_id(),
"journal": self._one_to_many_to_dict(payment.journal_id),
"invoice": self._one_to_many_to_dict(payment.invoice_ids),
"invoice": invoice,
"payment_date": Date.to_string(payment.payment_date),
"amount": payment.amount,
"communication": payment.communication,

2
easy_my_coop_api/services/schemas.py

@ -124,7 +124,7 @@ S_INVOICE_LINE_RETURN_GET = {
S_INVOICE_RETURN_GET = {
"id": {"type": "integer", "required": True},
"name": {"type": "string", "required": True, "empty": False},
"number": {"type": "string", "required": True, "empty": False},
"state": {"type": "string", "required": True, "empty": False},
"type": {"type": "string", "required": True, "empty": False},
"date": {"type": "string", "required": True, "empty": False},

9
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),
@ -88,8 +90,9 @@ class SubscriptionRequestService(Component):
_("Subscription request %s is not in draft state") % _id
)
)
sr.validate_subscription_request()
return self._to_dict(sr)
invoice = sr.validate_subscription_request()
invoice_service = self.work.component(usage="invoice")
return invoice_service.get(invoice.get_api_external_id())
def _to_dict(self, sr):
sr.ensure_one()
@ -219,4 +222,4 @@ class SubscriptionRequestService(Component):
return schemas.S_SUBSCRIPTION_REQUEST_VALIDATE
def _validator_return_validate(self):
return schemas.S_SUBSCRIPTION_REQUEST_RETURN_GET
return schemas.S_INVOICE_RETURN_GET

34
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,
"name": "Capital Release Example",
"partner": {"id": 1, "name": "Catherine des Champs"},
"account": {"id": 1, "name": "Cooperators"},
"journal": {"id": 1, "name": "Subscription Journal"},
"id": self.capital_release.get_api_external_id(),
"number": "xxx", # can't guess it
"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,
},
}
],
}
@ -79,7 +91,7 @@ class TestAccountInvoiceController(BaseEMCRestCase):
self.capital_release = self.env["account.invoice"].create(
{
"name": "Capital Release Example",
"number": "Capital Release Example",
"partner_id": self.coop_candidate.id,
"type": "out_invoice",
"invoice_line_ids": capital_release_line,
@ -92,10 +104,14 @@ class TestAccountInvoiceController(BaseEMCRestCase):
def test_service_get(self):
external_id = self.capital_release.get_api_external_id()
result = self.ai_service.get(external_id)
self.assertEquals(self.demo_invoice_dict, result)
expected = self.demo_invoice_dict.copy()
expected["number"] = result["number"]
self.assertEquals(expected, result)
def test_route_get(self):
external_id = self.capital_release.get_api_external_id()
route = "/api/invoice/%s" % external_id
content = self.http_get_content(route)
self.assertEquals(self.demo_invoice_dict, content)
expected = self.demo_invoice_dict.copy()
expected["number"] = content["number"]
self.assertEquals(expected, content)

2
easy_my_coop_api/tests/test_account_payment.py

@ -48,7 +48,7 @@ class TestAccountPaymentController(BaseEMCRestCase):
"communication": invoice.reference,
"invoice": {
"id": invoice.get_api_external_id(),
"name": invoice.name,
"name": invoice.number,
},
"amount": self.demo_request_1.subscription_amount,
"payment_date": Date.to_string(Date.today()),

17
easy_my_coop_api/tests/test_external_id_mixin.py

@ -2,6 +2,9 @@
# Robin Keunen <robin@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from psycopg2 import IntegrityError
import odoo
from odoo.fields import Date
from odoo.tests import TransactionCase
@ -81,3 +84,17 @@ class TestExternalIdMixin(TransactionCase):
self.assertTrue(bool(invoice.external_id_sequence_id))
self.assertEquals(external_id, invoice.get_api_external_id())
@odoo.tools.mute_logger("odoo.sql_db")
def test_duplicate_api_external_id_raises(self):
invoice_1 = self.env["account.invoice"].create(
{"name": "create passes"}
)
external_id = invoice_1.get_api_external_id()
self.assertTrue(bool(invoice_1._api_external_id))
invoice_2 = self.env["account.invoice"].create(
{"name": "create passes"}
)
with self.assertRaises(IntegrityError):
invoice_2._api_external_id = external_id

4
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()
@ -193,7 +195,7 @@ class TestSRController(BaseEMCRestCase):
content = json.loads(response.content.decode("utf-8"))
state = content.get("state")
self.assertEquals(state, "done")
self.assertEquals(state, "open")
def test_service_validate_draft_request(self):
self.sr_service.validate(self.demo_request_1.get_api_external_id())

178
easy_my_coop_api/views/external_id_mixin_views.xml

@ -0,0 +1,178 @@
<?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="view_partner_form" model="ir.ui.view">
<field name="name">view_partner_form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='sales_purchases']" position="after">
<page name="api_page" string="API">
<group>
<field name="external_id_generated" invisible="1"/>
<field name="_api_external_id" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="first_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="last_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<button name="get_api_external_id"
string="Generate external ID"
type="object"
class="oe_highlight"
attrs="{'invisible': [('external_id_generated', '=', True)]}"
/>
</group>
</page>
</xpath>
</field>
</record>
<record id="view_account_form" model="ir.ui.view">
<field name="name">view_account_form</field>
<field name="model">account.account</field>
<field name="inherit_id" ref="account.view_account_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='code']/../.." position="after">
<notebook>
<page name="api_page" string="API">
<group>
<field name="external_id_generated" invisible="1"/>
<field name="_api_external_id" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="first_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="last_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<button name="get_api_external_id"
string="Generate external ID"
type="object"
class="oe_highlight"
attrs="{'invisible': [('external_id_generated', '=', True)]}"
/>
</group>
</page>
</notebook>
</xpath>
</field>
</record>
<record id="view_account_journal_form" model="ir.ui.view">
<field name="name">view_account_journal_form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='advanced_settings']" position="after">
<page name="api_page" string="API">
<group>
<field name="external_id_generated" invisible="1"/>
<field name="_api_external_id" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="first_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="last_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<button name="get_api_external_id"
string="Generate external ID"
type="object"
class="oe_highlight"
attrs="{'invisible': [('external_id_generated', '=', True)]}"
/>
</group>
</page>
</xpath>
</field>
</record>
<record id="invoice_form" model="ir.ui.view">
<field name="name">invoice_form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='other_info']" position="after">
<page name="api_page" string="API">
<group>
<field name="external_id_generated" invisible="1"/>
<field name="_api_external_id" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="first_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="last_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<button name="get_api_external_id"
string="Generate external ID"
type="object"
class="oe_highlight"
attrs="{'invisible': [('external_id_generated', '=', True)]}"
/>
</group>
</page>
</xpath>
</field>
</record>
<record id="view_account_payment_form" model="ir.ui.view">
<field name="name">view_account_payment_form</field>
<field name="model">account.payment</field>
<field name="inherit_id" ref="account.view_account_payment_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='communication']/../.." position="after">
<notebook>
<page name="api_page" string="API">
<group>
<field name="external_id_generated" invisible="1"/>
<field name="_api_external_id" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="first_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="last_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<button name="get_api_external_id"
string="Generate external ID"
type="object"
class="oe_highlight"
attrs="{'invisible': [('external_id_generated', '=', True)]}"
/>
</group>
</page>
</notebook>
</xpath>
</field>
</record>
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product_template_form_view</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='inventory']" position="after">
<page name="api_page" string="API">
<group>
<field name="external_id_generated" invisible="1"/>
<field name="_api_external_id" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="first_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="last_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<button name="get_api_external_id"
string="Generate external ID"
type="object"
class="oe_highlight"
attrs="{'invisible': [('external_id_generated', '=', True)]}"
/>
</group>
</page>
</xpath>
</field>
</record>
<record id="subscription_request_form" model="ir.ui.view">
<field name="name">subscription_request_form</field>
<field name="model">subscription.request</field>
<field name="inherit_id" ref="easy_my_coop.subscription_request_form"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='capital_release_request']" position="after">
<page name="api_page" string="API">
<group>
<field name="external_id_generated" invisible="1"/>
<field name="_api_external_id" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="first_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<field name="last_api_export_date" attrs="{'invisible': [('external_id_generated', '=', False)]}"/>
<button name="get_api_external_id"
string="Generate external ID"
type="object"
class="oe_highlight"
attrs="{'invisible': [('external_id_generated', '=', True)]}"
/>
</group>
</page>
</xpath>
</field>
</record>
</odoo>

65
easy_my_coop_connector/README.rst

@ -0,0 +1,65 @@
======================
Easy My Coop Connector
======================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-coopiteasy%2Fvertical--cooperative-lightgray.png?logo=github
:target: https://github.com/coopiteasy/vertical-cooperative/tree/12.0/easy_my_coop_connector
:alt: coopiteasy/vertical-cooperative
|badge1| |badge2| |badge3|
Connect to Easy My Coop RESTful API.
**Table of contents**
.. contents::
:local:
Usage
=====
Get an API token from the Eeasy My Copp API you wish to connect to
and setup a backend at
- Settings > Technical (debug mode) > EMC Backend
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/vertical-cooperative/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/coopiteasy/vertical-cooperative/issues/new?body=module:%20easy_my_coop_connector%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Coop IT Easy SCRLfs
Contributors
~~~~~~~~~~~~
* Coop IT Easy SCRLfs
* Robin Keunen <robin@coopiteasy.be>
Maintainers
~~~~~~~~~~~
This module is part of the `coopiteasy/vertical-cooperative <https://github.com/coopiteasy/vertical-cooperative/tree/12.0/easy_my_coop_connector>`_ project on GitHub.
You are welcome to contribute.

3
easy_my_coop_connector/__init__.py

@ -0,0 +1,3 @@
from . import components
from . import models
from . import wizards

28
easy_my_coop_connector/__manifest__.py

@ -0,0 +1,28 @@
# 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).
{
"name": "Easy My Coop Connector",
"version": "12.0.0.0.1",
"depends": ["easy_my_coop"],
"author": "Coop IT Easy SCRLfs",
"category": "Connector",
"website": "www.coopiteasy.be",
"license": "AGPL-3",
"summary": """
Connect to Easy My Coop RESTful API.
""",
"data": [
"security/ir.model.access.csv",
"views/emc_backend.xml",
"views/emc_bindings.xml",
"wizards/emc_history_import_sr.xml",
"views/actions.xml",
"views/menus.xml",
"data/cron.xml",
],
"demo": ["demo/demo.xml"],
"installable": True,
"application": False,
}

3
easy_my_coop_connector/components/__init__.py

@ -0,0 +1,3 @@
from . import emc_adapters
from . import emc_backend
from . import emc_bindings

190
easy_my_coop_connector/components/emc_adapters.py

@ -0,0 +1,190 @@
# 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 werkzeug.exceptions import BadRequest
from odoo import _
from odoo.exceptions import UserError, ValidationError
from odoo.fields import Date
class AbstractEMCAdapter:
_model = "set in implementation class"
_root = "api"
_service = "set in implementation class"
def __init__(self, backend):
self.backend = backend
def _get_url(self, args=None):
"""args is a list of path elements
:return the complete route to the service
"""
if args is None:
args = []
return join("/", self._root, self._service, *args)
def search(self, **params):
raise NotImplementedError
def read(self, id_):
# pylint: disable=method-required-super
url = self._get_url([str(id_)])
api_dict = self.backend.http_get_content(url)
return self.to_write_values(api_dict)
def create(self, record):
# pylint: disable=method-required-super
url = self._get_url()
api_dict = self.to_api_dict(record)
external_record = self.backend.http_post_content(url, api_dict)
external_id, writeable_dict = self.to_write_values(external_record)
return external_id, writeable_dict
def update(self):
raise NotImplementedError
def delete(self):
raise NotImplementedError
def to_write_values(self, api_dict):
"""
:return a tuple with
- the external id
- a writable dictionary for _model
received from the api
"""
raise NotImplementedError
def to_api_dict(self, record):
raise NotImplementedError
class SubscriptionRequestAdapter(AbstractEMCAdapter):
_model = "subscription.request"
_service = "subscription-request"
def search(self, date_from=None, date_to=None):
url = self._get_url()
params = {}
if date_from:
params.update({"date_from": Date.to_string(date_from)})
if date_to:
params.update({"date_to": Date.to_string(date_to)})
sr_list = self.backend.http_get_content(url, params=params)
return {
"count": sr_list["count"],
"rows": [self.to_write_values(row) for row in sr_list["rows"]],
}
def validate(self, id_):
url = self._get_url([str(id_), "validate"])
data = {}
try:
invoice_dict = self.backend.http_post_content(url, data)
except BadRequest as bad_request:
raise ValidationError(
_(
"The Synergie platform replied with this error message:"
"\n\n %s \n\n"
"Please contact your system administrator."
)
% bad_request.description
)
ai_adapter = AccountInvoiceAdapter(backend=self.backend)
return ai_adapter.to_write_values(invoice_dict)
def to_write_values(self, api_dict):
Country = self.backend.env["res.country"]
ProductTemplateBinding = self.backend.env[
"emc.binding.product.template"
]
address = api_dict["address"]
country = Country.search([("code", "=", address["country"])])
external_product_id = api_dict["share_product"]["id"]
share_product_binding = ProductTemplateBinding.search_binding(
self.backend, external_product_id
)
if not share_product_binding:
raise UserError(
_(
"No binding exists for share product %s. Please contact "
"system administrator "
)
% api_dict["share_product"]["name"]
)
product_product = share_product_binding.internal_id.product_variant_id
external_id = api_dict["id"]
writable_dict = {
"email": api_dict["email"],
"name": api_dict["name"],
"date": api_dict["date"],
"state": api_dict["state"],
"lang": api_dict["lang"],
"ordered_parts": api_dict["ordered_parts"],
"address": address["street"],
"zip_code": address["zip_code"],
"city": address["city"],
"country_id": country.id,
"share_product_id": product_product.id,
"source": "emc_api",
}
return external_id, writable_dict
class AccountInvoiceAdapter(AbstractEMCAdapter):
_model = "account.invoice"
_service = "invoice"
def to_write_values(self, api_dict):
external_id = api_dict.pop("id")
writable_dict = api_dict
return external_id, writable_dict
class AccountPaymentAdapter(AbstractEMCAdapter):
_model = "account.payment"
_service = "payment"
def to_write_values(self, api_dict):
api_dict = api_dict.copy()
external_id = api_dict.pop("id")
writable_dict = api_dict
return external_id, writable_dict
def to_api_dict(self, record):
if not record.journal_id.binding_id:
raise ValidationError(
_(
"Journal %s is not bound to a journal on the platform. "
"Please contact system administrator."
)
% record.journal_id.name
)
if not record.invoice_ids.binding_id:
raise ValidationError(
_(
"Invoice %s is not bound to a journal on the platform. "
"Please contact system administrator."
)
% record.invoice_ids.name
)
return {
"journal": record.journal_id.binding_id.external_id,
"invoice": record.invoice_ids.binding_id.external_id,
"payment_date": Date.to_string(record.payment_date),
"amount": record.amount,
"communication": record.communication,
"payment_type": record.payment_type,
"payment_method": record.payment_method_id.code,
}

116
easy_my_coop_connector/components/emc_backend.py

@ -0,0 +1,116 @@
# 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).
import json
import logging
import requests
from werkzeug.exceptions import BadRequest, InternalServerError, NotFound
from odoo import _, api, fields, models
from odoo.exceptions import AccessDenied, Warning as UserError
_logger = logging.getLogger(__name__)
class EMCBackend(models.Model):
_name = "emc.backend"
_description = "EMC Backend"
name = fields.Char(string="Name", required=True)
location = fields.Char(string="URL")
api_key = fields.Char(string="API Key")
description = fields.Text(string="Description", required=False)
active = fields.Boolean(string="active", default=True)
@api.model
def get_backend(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
return backend
@api.multi
def http_get(self, url, params=None, headers=None):
self.ensure_one()
headers = self._add_api_key(headers)
if url.startswith("/"):
url = self.location + url
_logger.info("GET to {} w/ params {}".format(url, params))
return requests.get(url, params=params, headers=headers)
def _process_response(self, response):
if response.status_code == 200:
content = response.content.decode("utf-8")
return json.loads(content)
elif response.status_code == 400:
content = response.content.decode("utf-8")
raise BadRequest("%s" % content)
elif response.status_code == 403:
raise AccessDenied(
_("You are not allowed to access this resource")
)
elif response.status_code == 404:
raise NotFound(
_("Resource not found %s on server" % response.status_code)
)
else: # 500 et al.
content = response.content.decode("utf-8")
raise InternalServerError(_("%s" % content))
@api.multi
def http_get_content(self, url, params=None, headers=None):
self.ensure_one()
response = self.http_get(url, params=params, headers=headers)
return self._process_response(response)
@api.multi
def http_post(self, url, data, headers=None):
self.ensure_one()
headers = self._add_api_key(headers)
if url.startswith("/"):
url = self.location + url
_logger.info("POST to %s" % url)
return requests.post(url, json=data, headers=headers)
def http_post_content(self, url, data, headers=None):
self.ensure_one()
response = self.http_post(url, data, headers=headers)
return self._process_response(response)
@api.multi
def _add_api_key(self, headers):
self.ensure_one()
key_dict = {"API-KEY": self.api_key}
if headers:
headers.update(key_dict)
else:
headers = key_dict
return headers
@api.multi
def action_ping(self):
self.ensure_one()
url = self.location + "/api/ping/test"
try:
response = requests.get(url)
except Exception as e:
_logger.error(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 UserError(_("Success: %s") % content["message"])
else:
raise UserError(
_("Failed to connect to backend: %s" % str(response.content))
)

84
easy_my_coop_connector/components/emc_bindings.py

@ -0,0 +1,84 @@
# 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 EMCBinding(models.AbstractModel):
_name = "emc.binding"
_description = "EMC Binding (abstract)"
backend_id = fields.Many2one(
comodel_name="emc.backend", string="EMC Backend", ondelete="restrict"
)
external_id = fields.Integer(string="ID in Platform", index=True)
# internal_id = fields.Many2one # implement in concrete class
@api.model
def search_binding(self, backend, external_id):
return self.search(
[
("backend_id", "=", backend.id),
("external_id", "=", external_id),
]
)
class SubscriptionRequestBinding(models.Model):
_name = "emc.binding.subscription.request"
_inherit = "emc.binding"
internal_id = fields.Many2one(
comodel_name="subscription.request",
string="Internal ID",
required=True,
)
class ProductTemplateBinding(models.Model):
_name = "emc.binding.product.template"
_inherit = "emc.binding"
internal_id = fields.Many2one(
comodel_name="product.template",
string="Internal ID",
domain="[('is_share', '=', True)]",
required=True,
)
class AccountInvoiceBinding(models.Model):
_name = "emc.binding.account.invoice"
_inherit = "emc.binding"
internal_id = fields.Many2one(
comodel_name="account.invoice", string="Internal ID", required=True
)
class AccountPaymentBinding(models.Model):
_name = "emc.binding.account.payment"
_inherit = "emc.binding"
internal_id = fields.Many2one(
comodel_name="account.payment", string="Internal ID", required=True
)
class AccountJournalBinding(models.Model):
_name = "emc.binding.account.journal"
_inherit = "emc.binding"
internal_id = fields.Many2one(
comodel_name="account.journal", string="Internal ID", required=True
)
class AccountAccountBinding(models.Model):
_name = "emc.binding.account.account"
_inherit = "emc.binding"
internal_id = fields.Many2one(
comodel_name="account.account", string="Internal ID", required=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>

32
easy_my_coop_connector/demo/demo.xml

@ -0,0 +1,32 @@
<?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="emc_backend_demo" model="emc.backend">
<field name="name">IWP backend</field>
<field name="location">http://localhost:9876</field>
<field name="api_key">cbd07f57-c903-43b4-b668-436b3bec5f15</field>
</record>
</data>
<record id="easy_my_coop.subscription_request_1_demo" model="subscription.request">
<field name="source">emc_api</field>
</record>
<record id="emc_binding_product_template_A_demo" model="emc.binding.product.template">
<field name="backend_id" ref="emc_backend_demo"/>
<field name="internal_id" ref="easy_my_coop.product_template_share_type_1_demo"/>
<field name="external_id">37</field>
</record>
<record id="emc_binding_product_template_B_demo" model="emc.binding.product.template">
<field name="backend_id" ref="emc_backend_demo"/>
<field name="internal_id" ref="easy_my_coop.product_template_share_type_2_demo"/>
<field name="external_id">31</field>
</record>
</odoo>

5
easy_my_coop_connector/models/__init__.py

@ -0,0 +1,5 @@
from . import account_account
from . import account_invoice
from . import account_journal
from . import account_payment
from . import subscription_request

20
easy_my_coop_connector/models/account_account.py

@ -0,0 +1,20 @@
# 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).
import logging
from odoo import fields, models
_logger = logging.getLogger(__name__)
class AccountAccount(models.Model):
_inherit = "account.account"
binding_id = fields.One2many(
comodel_name="emc.binding.account.account",
inverse_name="internal_id",
string="Binding ID",
required=False,
)

20
easy_my_coop_connector/models/account_invoice.py

@ -0,0 +1,20 @@
# 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).
import logging
from odoo import fields, models
_logger = logging.getLogger(__name__)
class AccountInvoice(models.Model):
_inherit = "account.invoice"
binding_id = fields.One2many(
comodel_name="emc.binding.account.invoice",
inverse_name="internal_id",
string="Binding ID",
required=False,
)

16
easy_my_coop_connector/models/account_journal.py

@ -0,0 +1,16 @@
# 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 fields, models
class AccountJournal(models.Model):
_inherit = "account.journal"
binding_id = fields.One2many(
comodel_name="emc.binding.account.journal",
inverse_name="internal_id",
string="Binding ID",
required=False,
)

48
easy_my_coop_connector/models/account_payment.py

@ -0,0 +1,48 @@
# 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
from odoo.exceptions import ValidationError
from ..components.emc_adapters import AccountPaymentAdapter
class AccountPayment(models.Model):
_inherit = "account.payment"
binding_id = fields.One2many(
comodel_name="emc.binding.account.payment",
inverse_name="internal_id",
string="Binding ID",
required=False,
)
@api.multi
def post(self):
res = super(AccountPayment, self).post()
for payment in self:
if any(payment.invoice_ids.mapped("release_capital_request")):
invoice_id = payment.invoice_ids
if len(invoice_id) > 1:
raise ValidationError(
_(
"This version of easy my coop connector "
"can't handle several invoice per"
"payment. Please contact your "
"system administrator"
)
)
backend = self.env["emc.backend"].get_backend()
adapter = AccountPaymentAdapter(backend=backend)
external_id, external_record = adapter.create(payment)
self.env["emc.binding.account.payment"].create(
{
"backend_id": backend.id,
"internal_id": payment.id,
"external_id": external_id,
}
)
return res

121
easy_my_coop_connector/models/subscription_request.py

@ -0,0 +1,121 @@
# 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).
import logging
from datetime import date, timedelta
from odoo import api, fields, models
from ..components.emc_adapters import SubscriptionRequestAdapter
_logger = logging.getLogger(__name__)
class SubscriptionRequest(models.Model):
_inherit = "subscription.request"
source = fields.Selection(selection_add=[("emc_api", "Easy My Coop API")])
binding_id = fields.One2many(
comodel_name="emc.binding.subscription.request",
inverse_name="internal_id",
string="Binding ID",
required=False,
)
@api.model
def fetch_subscription_requests(self, date_from=None, date_to=None):
SRBinding = self.env["emc.binding.subscription.request"]
backend = self.env["emc.backend"].get_backend()
adapter = SubscriptionRequestAdapter(backend=backend)
requests_dict = adapter.search(date_from=date_from, date_to=date_to)
for external_id, request_dict in requests_dict["rows"]:
sr_binding = SRBinding.search_binding(backend, external_id)
if sr_binding: # update request
sr_binding.internal_id.write(request_dict)
else:
srequest = self.env["subscription.request"].create(
request_dict
)
SRBinding.create(
{
"backend_id": backend.id,
"external_id": external_id,
"internal_id": srequest.id,
}
)
external_ids = [
external_id for external_id, _ in requests_dict["rows"]
]
srequests = SRBinding.search(
[
("backend_id", "=", backend.id),
("external_id", "in", external_ids),
]
).mapped("internal_id")
return srequests
@api.model
def backend_read(self, external_id):
SRBinding = self.env["emc.binding.subscription.request"]
backend = self.env["emc.backend"].get_backend()
adapter = SubscriptionRequestAdapter(backend)
_, request_values = adapter.read(external_id)
sr_binding = SRBinding.search_binding(backend, external_id)
if sr_binding: # update request
srequest = sr_binding.internal_id
srequest.write(request_values)
else:
srequest = self.env["subscription.request"].create(request_values)
SRBinding.create(
{
"backend_id": backend.id,
"external_id": external_id,
"internal_id": srequest.id,
}
)
return srequest
@api.model
def fetch_subscription_requests_cron(self):
backend = self.env["emc.backend"].get_backend()
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.")
@api.multi
def validate_subscription_request(self):
self.ensure_one()
invoice = super(
SubscriptionRequest, self
).validate_subscription_request()
if self.source == "emc_api":
backend = self.env["emc.backend"].get_backend()
sr_adapter = SubscriptionRequestAdapter(backend=backend)
external_id, invoice_dict = sr_adapter.validate(
self.binding_id.external_id
)
InvoiceBinding = self.env["emc.binding.account.invoice"]
InvoiceBinding.create(
{
"backend_id": backend.id,
"external_id": external_id,
"internal_id": invoice.id,
}
)
return invoice

2
easy_my_coop_connector/readme/CONTRIBUTORS.rst

@ -0,0 +1,2 @@
* Coop IT Easy SCRLfs
* Robin Keunen <robin@coopiteasy.be>

1
easy_my_coop_connector/readme/DESCRIPTION.rst

@ -0,0 +1 @@
Connect to Easy My Coop RESTful API.

0
easy_my_coop_connector/readme/ROADMAP.rst

22
easy_my_coop_connector/readme/USAGE.rst

@ -0,0 +1,22 @@
## Configuration
Get an API token from the Easy My Coop API you wish to connect to
and setup a backend at
- Settings > Technical (debug mode) > EMC Backend
## Concepts
The models are heavily influenced by the odoo connector:
- emc_backend
- connects to the API, sends HTTP requests, converts json to dictionaries
- <model>_adapter
- uses the backend to send query for model it's responsible for.
- adapts the objects to api format dictionaries
- adapts the result dictionaries to writable dictionaries
- <model>_binding
- links an internal record with an external record for each backend
The <model> is responsible for the orchestration of these components.
In the current implementation, only one backend is allowed.

8
easy_my_coop_connector/security/ir.model.access.csv

@ -0,0 +1,8 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_emc_backend_administrator,access_emc_backend_administrator,model_emc_backend,base.group_system,1,1,1,1
access_emc_binding_subscription_request_administrator,access_emc_binding_subscription_request_administrator,model_emc_binding_subscription_request,base.group_system,1,1,1,1
access_emc_binding_product_template_administrator,access_emc_binding_product_template_administrator,model_emc_binding_product_template,base.group_system,1,1,1,1
access_emc_binding_account_invoice_administrator,access_emc_binding_account_invoice_administrator,model_emc_binding_account_invoice,base.group_system,1,1,1,1
access_emc_binding_account_payment_administrator,access_emc_binding_account_payment_administrator,model_emc_binding_account_payment,base.group_system,1,1,1,1
access_emc_binding_account_journal_administrator,access_emc_binding_account_journal_administrator,model_emc_binding_account_journal,base.group_system,1,1,1,1
access_emc_binding_account_account_administrator,access_emc_binding_account_account_administrator,model_emc_binding_account_account,base.group_system,1,1,1,1

423
easy_my_coop_connector/static/description/index.html

@ -0,0 +1,423 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Easy My Coop Connector</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="easy-my-coop-connector">
<h1 class="title">Easy My Coop Connector</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/coopiteasy/vertical-cooperative/tree/12.0/easy_my_coop_connector"><img alt="coopiteasy/vertical-cooperative" src="https://img.shields.io/badge/github-coopiteasy%2Fvertical--cooperative-lightgray.png?logo=github" /></a></p>
<blockquote>
Connect to Easy My Coop RESTful API.</blockquote>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>Get an API token from the Eeasy My Copp API you wish to connect to
and setup a backend at
- Settings &gt; Technical (debug mode) &gt; EMC Backend</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/coopiteasy/vertical-cooperative/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/coopiteasy/vertical-cooperative/issues/new?body=module:%20easy_my_coop_connector%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
<ul class="simple">
<li>Coop IT Easy SCRLfs</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<ul class="simple">
<li>Coop IT Easy SCRLfs</li>
<li>Robin Keunen &lt;<a class="reference external" href="mailto:robin&#64;coopiteasy.be">robin&#64;coopiteasy.be</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
<p>This module is part of the <a class="reference external" href="https://github.com/coopiteasy/vertical-cooperative/tree/12.0/easy_my_coop_connector">coopiteasy/vertical-cooperative</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
</div>
</div>
</body>
</html>

2
easy_my_coop_connector/tests/__init__.py

@ -0,0 +1,2 @@
from . import test_subscription_request
from . import test_payment

92
easy_my_coop_connector/tests/test_data.py

@ -0,0 +1,92 @@
# 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).
import json
from odoo.fields import Date
def dict_to_dump(content):
return json.dumps(content).encode("utf-8")
NOT_FOUND_ERROR = {"name": "Not Found", "code": 404}
FORBIDDEN_ERROR = {"name": "Forbidden", "code": 403}
SERVER_ERROR = {"name": "Server Error", "code": 500}
NO_RESULT = {"count": 0, "rows": []}
SR_SEARCH_RESULT = {
"count": 1,
"rows": [
{
"id": 1,
"date": "2020-05-14",
"email": "manuel@demo.net",
"address": {
"city": "Brussels",
"street": "schaerbeekstraat",
"zip_code": "1111",
"country": "BE",
},
"lang": "en_US",
"ordered_parts": 3,
"name": "Manuel Dublues",
"share_product": {"name": "Part B - Worker", "id": 31},
"state": "draft",
}
],
}
SR_GET_RESULT = {
"id": 1,
"name": "Robin Des Bois",
"date": "2020-05-14",
"email": "manuel@demo.net",
"address": {
"city": "Brussels",
"street": "schaerbeekstraat",
"zip_code": "1111",
"country": "BE",
},
"lang": "en_US",
"ordered_parts": 3,
"share_product": {"name": "Part B - Worker", "id": 31},
"state": "draft",
}
SR_VALIDATE_RESULT = {
"id": 9999,
"number": "SUBJ/2020/001",
"date_due": "2020-08-12",
"state": "open",
"date_invoice": "2020-08-12",
"date": "2020-08-12",
"type": "out_invoice",
"subscription_request": {"name": "Manuel Dublues", "id": 1},
"partner": {"name": "Manuel Dublues", "id": 1},
"invoice_lines": [
{
"price_unit": 25.0,
"quantity": 3.0,
"account": {"name": "Product Sales", "id": 2},
"name": "Part B - Worker",
"product": {"name": "Part B - Worker", "id": 2},
}
],
"journal": {"name": "Subscription Journal", "id": 1},
"account": {"name": "Cooperators", "id": 1},
}
AP_CREATE_RESULT = {
"id": 9876,
"journal": {"id": 1, "name": "bank"},
"invoice": {
"id": SR_VALIDATE_RESULT["id"],
"name": SR_VALIDATE_RESULT["number"],
},
"payment_date": Date.to_string(Date.today()),
"amount": 75.0,
"communication": SR_VALIDATE_RESULT["number"],
}

72
easy_my_coop_connector/tests/test_payment.py

@ -0,0 +1,72 @@
# 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 unittest.mock import Mock, patch
import requests
from odoo.fields import Date
from odoo.addons.easy_my_coop.tests.test_base import EMCBaseCase
from .test_data import AP_CREATE_RESULT, SR_VALIDATE_RESULT, dict_to_dump
class EMCPaymentConnectorCase(EMCBaseCase):
def setUp(self):
super().setUp()
self.backend = self.browse_ref(
"easy_my_coop_connector.emc_backend_demo"
)
self.env["emc.binding.account.journal"].create(
{
"backend_id": self.backend.id,
"internal_id": self.bank_journal.id,
"external_id": 1,
}
)
def test_post_payment_sends_and_binds_request(self):
srequest = self.browse_ref("easy_my_coop.subscription_request_1_demo")
with patch.object(requests, "post") as mock_get:
mock_get.return_value = mock_response = Mock()
mock_response.status_code = 200
mock_response.content = dict_to_dump(SR_VALIDATE_RESULT)
srequest.validate_subscription_request()
capital_release_request = srequest.capital_release_request
payment_method_manual_in = self.env.ref(
"account.account_payment_method_manual_in"
)
ctx = {
"active_model": "account.invoice",
"active_ids": [capital_release_request.id],
}
register_payments = (
self.env["account.register.payments"]
.with_context(ctx)
.create(
{
"payment_date": Date.today(),
"journal_id": self.bank_journal.id,
"payment_method_id": payment_method_manual_in.id,
}
)
)
with patch.object(requests, "post") as mock_get:
mock_get.return_value = mock_response = Mock()
mock_response.status_code = 200
mock_response.content = dict_to_dump(AP_CREATE_RESULT)
register_payments.create_payments()
self.assertEquals(capital_release_request.state, "paid")
payment = capital_release_request.payment_ids
self.assertEquals(payment.state, "posted")
self.assertEquals(payment.binding_id.external_id, 9876)

92
easy_my_coop_connector/tests/test_subscription_request.py

@ -0,0 +1,92 @@
# 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).
import datetime
from unittest.mock import Mock, patch
import requests
from odoo.addons.easy_my_coop.tests.test_base import EMCBaseCase
from .test_data import (
SR_GET_RESULT,
SR_SEARCH_RESULT,
SR_VALIDATE_RESULT,
dict_to_dump,
)
class EMCSRConnectorCase(EMCBaseCase):
def setUp(self):
super().setUp()
self.backend = self.browse_ref(
"easy_my_coop_connector.emc_backend_demo"
)
self.share_type_B_pt = self.browse_ref(
"easy_my_coop.product_template_share_type_2_demo"
)
self.share_type_B_pp = self.share_type_B_pt.product_variant_id
def test_search_requests(self):
SubscriptionRequest = self.env["subscription.request"]
SRBinding = self.env["emc.binding.subscription.request"]
date_to = datetime.date.today()
date_from = date_to - datetime.timedelta(days=1)
with patch.object(requests, "get") as mock_get:
mock_get.return_value = mock_response = Mock()
mock_response.status_code = 200
mock_response.content = dict_to_dump(SR_SEARCH_RESULT)
SubscriptionRequest.fetch_subscription_requests(
date_from=date_from, date_to=date_to
)
external_id = 1
binding = SRBinding.search_binding(self.backend, external_id)
self.assertTrue(
bool(binding),
"no binding created when searching subscription requests",
)
srequest = binding.internal_id
self.assertEquals(srequest.name, "Manuel Dublues")
self.assertEquals(
srequest.share_product_id.id, self.share_type_B_pp.id
)
self.assertEquals(
srequest.subscription_amount, self.share_type_B_pt.list_price * 3
)
with patch.object(requests, "get") as mock_get:
mock_get.return_value = mock_response = Mock()
mock_response.status_code = 200
mock_response.content = dict_to_dump(SR_GET_RESULT)
SubscriptionRequest.backend_read(external_id)
self.assertEquals(srequest.name, "Robin Des Bois")
def test_validate_request(self):
srequest = self.browse_ref("easy_my_coop.subscription_request_1_demo")
with patch.object(requests, "post") as mock_get:
mock_get.return_value = mock_response = Mock()
mock_response.status_code = 200
mock_response.content = dict_to_dump(SR_VALIDATE_RESULT)
srequest.validate_subscription_request()
self.assertEquals(srequest.state, "done")
# local invoice created
self.assertTrue(len(srequest.capital_release_request) > 0)
# local invoice linked to external invoice
self.assertEquals(
srequest.capital_release_request.binding_id.external_id,
SR_VALIDATE_RESULT["id"],
)
# todo test 400

49
easy_my_coop_connector/views/actions.xml

@ -0,0 +1,49 @@
<?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="emc_backend_action" model="ir.actions.act_window">
<field name="name">EMC Backend</field>
<field name="res_model">emc.backend</field>
<field name="view_mode">tree,form</field>
</record>
<record id="emc_binding_subscription_request_action" model="ir.actions.act_window">
<field name="name">Subscription Request Bindings</field>
<field name="res_model">emc.binding.subscription.request</field>
<field name="view_mode">tree,form</field>
</record>
<record id="emc_binding_product_template_action" model="ir.actions.act_window">
<field name="name">Share Product Bindings</field>
<field name="res_model">emc.binding.product.template</field>
<field name="view_mode">tree,form</field>
</record>
<record id="emc_binding_account_invoice_action" model="ir.actions.act_window">
<field name="name">Invoice Bindings</field>
<field name="res_model">emc.binding.account.invoice</field>
<field name="view_mode">tree,form</field>
</record>
<record id="emc_binding_account_payment_action" model="ir.actions.act_window">
<field name="name">payment Bindings</field>
<field name="res_model">emc.binding.account.payment</field>
<field name="view_mode">tree,form</field>
</record>
<record id="emc_binding_account_journal_action" model="ir.actions.act_window">
<field name="name">Journal Bindings</field>
<field name="res_model">emc.binding.account.journal</field>
<field name="view_mode">tree,form</field>
</record>
<record id="emc_binding_account_account_action" model="ir.actions.act_window">
<field name="name">Account Bindings</field>
<field name="res_model">emc.binding.account.account</field>
<field name="view_mode">tree,form</field>
</record>
</odoo>

48
easy_my_coop_connector/views/emc_backend.xml

@ -0,0 +1,48 @@
<?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="emc_backend_view_form" model="ir.ui.view">
<field name="name">emc_backend_view_form</field>
<field name="model">emc.backend</field>
<field name="arch" type="xml">
<form string="emc_backend_form">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object"
class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"
options="{'terminology': 'active'}"/>
</button>
</div>
<group>
<field name="name"/>
<field name="location"/>
<field name="api_key"/>
<field name="description"/>
</group>
<footer>
<button name="action_ping"
string="Ping the API (no authentication)"
type="object"
class="oe_highlight"/>
</footer>
</sheet>
</form>
</field>
</record>
<record id="emc_backend_view_tree" model="ir.ui.view">
<field name="name">emc_backend_view_tree</field>
<field name="model">emc.backend</field>
<field name="arch" type="xml">
<tree string="emc_backend_tree">
<field name="location"/>
<field name="api_key"/>
</tree>
</field>
</record>
</odoo>

174
easy_my_coop_connector/views/emc_bindings.xml

@ -0,0 +1,174 @@
<?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="emc_binding_subscription_request_view_form" model="ir.ui.view">
<field name="name">emc_binding_subscription_request_view_form</field>
<field name="model">emc.binding.subscription.request</field>
<field name="arch" type="xml">
<form string="emc_binding_subscription_request_form">
<sheet>
<group>
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="emc_binding_subscription_request_view_tree" model="ir.ui.view">
<field name="name">emc_binding_subscription_request_view_tree</field>
<field name="model">emc.binding.subscription.request</field>
<field name="arch" type="xml">
<tree string="emc_binding_subscription_request_tree">
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</tree>
</field>
</record>
<record id="emc_binding_product_template_view_form" model="ir.ui.view">
<field name="name">emc_binding_product_template_view_form</field>
<field name="model">emc.binding.product.template</field>
<field name="arch" type="xml">
<form string="emc_binding_product_template_form">
<sheet>
<group>
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="emc_binding_product_template_view_tree" model="ir.ui.view">
<field name="name">emc_binding_product_template_view_tree</field>
<field name="model">emc.binding.product.template</field>
<field name="arch" type="xml">
<tree string="emc_binding_product_template_tree">
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</tree>
</field>
</record>
<record id="emc_binding_account_invoice_view_form" model="ir.ui.view">
<field name="name">emc_binding_account_invoice_view_form</field>
<field name="model">emc.binding.account.invoice</field>
<field name="arch" type="xml">
<form string="emc_binding_account_invoice_form">
<sheet>
<group>
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="emc_binding_account_invoice_view_tree" model="ir.ui.view">
<field name="name">emc_binding_account_invoice_view_tree</field>
<field name="model">emc.binding.account.invoice</field>
<field name="arch" type="xml">
<tree string="emc_binding_account_invoice_tree">
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</tree>
</field>
</record>
<record id="emc_binding_account_payment_view_form" model="ir.ui.view">
<field name="name">emc_binding_account_payment_view_form</field>
<field name="model">emc.binding.account.payment</field>
<field name="arch" type="xml">
<form string="emc_binding_account_payment_form">
<sheet>
<group>
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="emc_binding_account_payment_view_tree" model="ir.ui.view">
<field name="name">emc_binding_account_payment_view_tree</field>
<field name="model">emc.binding.account.payment</field>
<field name="arch" type="xml">
<tree string="emc_binding_account_payment_tree">
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</tree>
</field>
</record>
<record id="emc_binding_account_journal_view_form" model="ir.ui.view">
<field name="name">emc_binding_account_journal_view_form</field>
<field name="model">emc.binding.account.journal</field>
<field name="arch" type="xml">
<form string="emc_binding_account_journal_form">
<sheet>
<group>
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="emc_binding_account_journal_view_tree" model="ir.ui.view">
<field name="name">emc_binding_account_journal_view_tree</field>
<field name="model">emc.binding.account.journal</field>
<field name="arch" type="xml">
<tree string="emc_binding_account_journal_tree">
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</tree>
</field>
</record>
<record id="emc_binding_account_account_view_form" model="ir.ui.view">
<field name="name">emc_binding_account_account_view_form</field>
<field name="model">emc.binding.account.account</field>
<field name="arch" type="xml">
<form string="emc_binding_account_account_form">
<sheet>
<group>
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="emc_binding_account_account_view_tree" model="ir.ui.view">
<field name="name">emc_binding_account_account_view_tree</field>
<field name="model">emc.binding.account.account</field>
<field name="arch" type="xml">
<tree string="emc_binding_account_account_tree">
<field name="backend_id"/>
<field name="internal_id"/>
<field name="external_id"/>
</tree>
</field>
</record>
</odoo>

70
easy_my_coop_connector/views/menus.xml

@ -0,0 +1,70 @@
<?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>
<menuitem id="emc_connector_menu_menu"
name="EMC Connector Configuration"
parent="easy_my_coop.menu_easy_my_coop_config"
groups="base.group_user"
sequence="1000"/>
<menuitem id="emc_backend_action_menu"
name="EMC Backend"
parent="emc_connector_menu_menu"
action="emc_backend_action"
groups="base.group_user"
sequence="1010"/>
<menuitem id="emc_binding_product_template_action_menu"
name="Share Product Bindings"
parent="emc_connector_menu_menu"
action="emc_binding_product_template_action"
groups="base.group_user"
sequence="1020"/>
<menuitem id="emc_binding_account_journal_action_menu"
name="Journal Bindings"
parent="emc_connector_menu_menu"
action="emc_binding_account_journal_action"
groups="base.group_user"
sequence="1030"/>
<menuitem id="emc_binding_account_account_action_menu"
name="Account Bindings"
parent="emc_connector_menu_menu"
action="emc_binding_account_account_action"
groups="base.group_user"
sequence="1040"/>
<menuitem id="emc_binding_subscription_request_action_menu"
name="Subscription Request Bindings"
parent="emc_connector_menu_menu"
action="emc_binding_subscription_request_action"
groups="base.group_user"
sequence="1050"/>
<menuitem id="emc_binding_account_invoice_action_menu"
name="Invoice Bindings"
parent="emc_connector_menu_menu"
action="emc_binding_account_invoice_action"
groups="base.group_user"
sequence="1060"/>
<menuitem id="emc_binding_account_payment_action_menu"
name="Payment Bindings"
parent="emc_connector_menu_menu"
action="emc_binding_account_payment_action"
groups="base.group_user"
sequence="1070"/>
<menuitem id="emc_history_import_action_menu"
name="Import Subscription Request History"
parent="emc_connector_menu_menu"
action="emc_history_import_action"
groups="base.group_user"
sequence="1100"/>
</odoo>

1
easy_my_coop_connector/wizards/__init__.py

@ -0,0 +1 @@
from . import emc_history_import_sr

37
easy_my_coop_connector/wizards/emc_history_import_sr.py

@ -0,0 +1,37 @@
# 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 datetime import date
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models
class EMCHistoryImportSR(models.TransientModel):
_name = "emc.history.import.sr"
_description = "emc.history.import.sr"
def first_day_of_month(self):
return date.today() - relativedelta(day=1)
def last_day_of_month(self):
return date.today() + relativedelta(day=31)
name = fields.Char("Name", default="Import History")
date_from = fields.Date(
string="Date From", required=True, default=first_day_of_month
)
date_to = fields.Date(
string="Date To", required=True, default=last_day_of_month
)
@api.multi
def import_subscription_button(self):
self.env["subscription.request"].fetch_subscription_requests(
date_from=self.date_from, date_to=self.date_to
)
action = self.env.ref("easy_my_coop.subscription_request_action")
return action.read()[0]

42
easy_my_coop_connector/wizards/emc_history_import_sr.xml

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="emc_history_import_sr_view_form" model="ir.ui.view">
<field name="name">emc_history_import_sr_view_form</field>
<field name="model">emc.history.import.sr</field>
<field name="arch" type="xml">
<form string="emc_history_import_sr_form">
<sheet>
<group>
<field name="date_from"/>
<field name="date_to"/>
</group>
<footer>
<button name="import_subscription_button"
string="Import Subscription History"
type="object"
class="btn-primary"/>
<button string="Cancel" class="btn-default"
special="cancel"/>
</footer>
</sheet>
</form>
</field>
</record>
<record id="emc_history_import_action" model="ir.actions.act_window">
<field name="name">Import Subscription Request History</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">emc.history.import.sr</field>
<field name="view_mode">form</field>
</record>
<!-- <act_window id="action_aged_partner_balance_wizard"-->
<!-- name="Aged Partner Balance"-->
<!-- res_model="aged.partner.balance.wizard"-->
<!-- view_type="form"-->
<!-- view_mode="form"-->
<!-- view_id="aged_partner_balance_wizard"-->
<!-- target="new"/>-->
</data>
</openerp>
Loading…
Cancel
Save