diff --git a/easy_my_coop_connector/__init__.py b/easy_my_coop_connector/__init__.py
index 0650744..aee8895 100644
--- a/easy_my_coop_connector/__init__.py
+++ b/easy_my_coop_connector/__init__.py
@@ -1 +1,2 @@
from . import models
+from . import wizards
diff --git a/easy_my_coop_connector/__manifest__.py b/easy_my_coop_connector/__manifest__.py
index e023e33..1518676 100644
--- a/easy_my_coop_connector/__manifest__.py
+++ b/easy_my_coop_connector/__manifest__.py
@@ -17,6 +17,7 @@
"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",
],
diff --git a/easy_my_coop_connector/models/subscription_request.py b/easy_my_coop_connector/models/subscription_request.py
index c19281f..f82b7dc 100644
--- a/easy_my_coop_connector/models/subscription_request.py
+++ b/easy_my_coop_connector/models/subscription_request.py
@@ -44,6 +44,14 @@ class SubscriptionRequest(models.Model):
"internal_id": srequest.id,
}
)
+ external_ids = [row["id"] for row 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):
diff --git a/easy_my_coop_connector/models/subscription_request_adapter.py b/easy_my_coop_connector/models/subscription_request_adapter.py
index 2987f5a..d28a182 100644
--- a/easy_my_coop_connector/models/subscription_request_adapter.py
+++ b/easy_my_coop_connector/models/subscription_request_adapter.py
@@ -55,14 +55,14 @@ class SubscriptionRequestAdapter:
:return a writable dictionary of values from the dictionary
received from the api
"""
- address = request["address"]
-
Country = self.backend.env["res.country"]
- country = Country.search([("code", "=", address["country"])])
-
ProductTemplateBinding = self.backend.env[
"emc.binding.product.template"
]
+ address = request["address"]
+
+ country = Country.search([("code", "=", address["country"])])
+
external_product_id = request["share_product"]["id"]
share_product_binding = ProductTemplateBinding.search_binding(
self.backend, external_product_id
@@ -75,6 +75,7 @@ class SubscriptionRequestAdapter:
)
% request["share_product"]["name"]
)
+ product_product = share_product_binding.internal_id.product_variant_id
return {
"email": request["email"],
@@ -87,6 +88,6 @@ class SubscriptionRequestAdapter:
"zip_code": address["zip_code"],
"city": address["city"],
"country_id": country.id,
- "share_product_id": share_product_binding.internal_id.id,
+ "share_product_id": product_product.id,
"source": "emc_api",
}
diff --git a/easy_my_coop_connector/tests/test_subscription_request.py b/easy_my_coop_connector/tests/test_subscription_request.py
index a2b25f5..65f4931 100644
--- a/easy_my_coop_connector/tests/test_subscription_request.py
+++ b/easy_my_coop_connector/tests/test_subscription_request.py
@@ -64,6 +64,10 @@ class TestCase(TransactionCase):
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"]
@@ -90,6 +94,12 @@ class TestCase(TransactionCase):
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()
diff --git a/easy_my_coop_connector/views/menus.xml b/easy_my_coop_connector/views/menus.xml
index 2c15069..47c5a00 100644
--- a/easy_my_coop_connector/views/menus.xml
+++ b/easy_my_coop_connector/views/menus.xml
@@ -17,19 +17,26 @@
parent="emc_connector_menu_menu"
action="emc_backend_action"
groups="base.group_user"
- sequence="1000"/>
+ sequence="1010"/>
+ sequence="1020"/>
+ sequence="1030"/>
+
+
diff --git a/easy_my_coop_connector/wizards/__init__.py b/easy_my_coop_connector/wizards/__init__.py
new file mode 100644
index 0000000..f22bdbc
--- /dev/null
+++ b/easy_my_coop_connector/wizards/__init__.py
@@ -0,0 +1 @@
+from . import emc_history_import_sr
diff --git a/easy_my_coop_connector/wizards/emc_history_import_sr.py b/easy_my_coop_connector/wizards/emc_history_import_sr.py
new file mode 100644
index 0000000..70018f7
--- /dev/null
+++ b/easy_my_coop_connector/wizards/emc_history_import_sr.py
@@ -0,0 +1,23 @@
+# Copyright 2020 Coop IT Easy SCRL fs
+# Robin Keunen
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
+
+from odoo import api, fields, models
+
+
+class EMCHistoryImportSR(models.TransientModel):
+ _name = "emc.history.import.sr"
+ _description = "emc.history.import.sr"
+
+ name = fields.Char("Name", default="Import History")
+ date_from = fields.Date(string="Date From", required=True)
+ date_to = fields.Date(string="Date To", required=True)
+
+ @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]
diff --git a/easy_my_coop_connector/wizards/emc_history_import_sr.xml b/easy_my_coop_connector/wizards/emc_history_import_sr.xml
new file mode 100644
index 0000000..8035124
--- /dev/null
+++ b/easy_my_coop_connector/wizards/emc_history_import_sr.xml
@@ -0,0 +1,42 @@
+
+
+
+
+ emc_history_import_sr_view_form
+ emc.history.import.sr
+
+
+
+
+
+
+ Import Subscription Request History
+ ir.actions.act_window
+ emc.history.import.sr
+ form
+
+
+
+
+
+
+
+
+
+
+