Browse Source

[ADD] emcc: manual import wizard

pull/115/head
robin.keunen 5 years ago
parent
commit
09921c0852
  1. 1
      easy_my_coop_connector/__init__.py
  2. 1
      easy_my_coop_connector/__manifest__.py
  3. 8
      easy_my_coop_connector/models/subscription_request.py
  4. 11
      easy_my_coop_connector/models/subscription_request_adapter.py
  5. 10
      easy_my_coop_connector/tests/test_subscription_request.py
  6. 13
      easy_my_coop_connector/views/menus.xml
  7. 1
      easy_my_coop_connector/wizards/__init__.py
  8. 23
      easy_my_coop_connector/wizards/emc_history_import_sr.py
  9. 42
      easy_my_coop_connector/wizards/emc_history_import_sr.xml

1
easy_my_coop_connector/__init__.py

@ -1 +1,2 @@
from . import models
from . import wizards

1
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",
],

8
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):

11
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",
}

10
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()

13
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"/>
<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="1000"/>
sequence="1020"/>
<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="1000"/>
sequence="1030"/>
<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="1050"/>
</odoo>

1
easy_my_coop_connector/wizards/__init__.py

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

23
easy_my_coop_connector/wizards/emc_history_import_sr.py

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

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