Robin Keunen
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 2254 additions and 32 deletions
-
2.isort.cfg
-
2easy_my_coop_api/__manifest__.py
-
31easy_my_coop_api/controllers/controllers.py
-
13easy_my_coop_api/demo/demo.xml
-
1easy_my_coop_api/models/__init__.py
-
54easy_my_coop_api/models/external_id_mixin.py
-
18easy_my_coop_api/models/subscription_request.py
-
8easy_my_coop_api/services/account_invoice_service.py
-
6easy_my_coop_api/services/account_payment_service.py
-
2easy_my_coop_api/services/schemas.py
-
9easy_my_coop_api/services/subscription_request_service.py
-
34easy_my_coop_api/tests/test_account_invoice.py
-
2easy_my_coop_api/tests/test_account_payment.py
-
17easy_my_coop_api/tests/test_external_id_mixin.py
-
4easy_my_coop_api/tests/test_subscription_requests.py
-
178easy_my_coop_api/views/external_id_mixin_views.xml
-
65easy_my_coop_connector/README.rst
-
3easy_my_coop_connector/__init__.py
-
28easy_my_coop_connector/__manifest__.py
-
3easy_my_coop_connector/components/__init__.py
-
190easy_my_coop_connector/components/emc_adapters.py
-
116easy_my_coop_connector/components/emc_backend.py
-
84easy_my_coop_connector/components/emc_bindings.py
-
19easy_my_coop_connector/data/cron.xml
-
32easy_my_coop_connector/demo/demo.xml
-
5easy_my_coop_connector/models/__init__.py
-
20easy_my_coop_connector/models/account_account.py
-
20easy_my_coop_connector/models/account_invoice.py
-
16easy_my_coop_connector/models/account_journal.py
-
48easy_my_coop_connector/models/account_payment.py
-
121easy_my_coop_connector/models/subscription_request.py
-
2easy_my_coop_connector/readme/CONTRIBUTORS.rst
-
1easy_my_coop_connector/readme/DESCRIPTION.rst
-
0easy_my_coop_connector/readme/ROADMAP.rst
-
22easy_my_coop_connector/readme/USAGE.rst
-
8easy_my_coop_connector/security/ir.model.access.csv
-
423easy_my_coop_connector/static/description/index.html
-
2easy_my_coop_connector/tests/__init__.py
-
92easy_my_coop_connector/tests/test_data.py
-
72easy_my_coop_connector/tests/test_payment.py
-
92easy_my_coop_connector/tests/test_subscription_request.py
-
49easy_my_coop_connector/views/actions.xml
-
48easy_my_coop_connector/views/emc_backend.xml
-
174easy_my_coop_connector/views/emc_bindings.xml
-
70easy_my_coop_connector/views/menus.xml
-
1easy_my_coop_connector/wizards/__init__.py
-
37easy_my_coop_connector/wizards/emc_history_import_sr.py
-
42easy_my_coop_connector/wizards/emc_history_import_sr.xml
@ -1,2 +1,3 @@ |
|||
from . import auth_api_key |
|||
from . import external_id_mixin |
|||
from . import subscription_request |
@ -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()} |
|||
) |
@ -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> |
@ -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. |
@ -0,0 +1,3 @@ |
|||
from . import components |
|||
from . import models |
|||
from . import wizards |
@ -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, |
|||
} |
@ -0,0 +1,3 @@ |
|||
from . import emc_adapters |
|||
from . import emc_backend |
|||
from . import emc_bindings |
@ -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, |
|||
} |
@ -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)) |
|||
) |
@ -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 |
|||
) |
@ -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> |
@ -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> |
@ -0,0 +1,5 @@ |
|||
from . import account_account |
|||
from . import account_invoice |
|||
from . import account_journal |
|||
from . import account_payment |
|||
from . import subscription_request |
@ -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, |
|||
) |
@ -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, |
|||
) |
@ -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, |
|||
) |
@ -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 |
@ -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 |
@ -0,0 +1,2 @@ |
|||
* Coop IT Easy SCRLfs |
|||
* Robin Keunen <robin@coopiteasy.be> |
@ -0,0 +1 @@ |
|||
Connect to Easy My Coop RESTful API. |
@ -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. |
@ -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 |
@ -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 > Technical (debug mode) > 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 <<a class="reference external" href="mailto:robin@coopiteasy.be">robin@coopiteasy.be</a>></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> |
@ -0,0 +1,2 @@ |
|||
from . import test_subscription_request |
|||
from . import test_payment |
@ -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"], |
|||
} |
@ -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) |
@ -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 |
@ -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> |
@ -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> |
@ -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> |
@ -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> |
@ -0,0 +1 @@ |
|||
from . import emc_history_import_sr |
@ -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] |
@ -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> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue