Skip to content

Commit

Permalink
Merge pull request #106 from tarunbhardwaj/single_wiz
Browse files Browse the repository at this point in the history
Implemented single wizard to import sale orders #7787
  • Loading branch information
prakashpp committed May 16, 2015
2 parents eeb726b + 299137b commit 5140773
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 105 deletions.
5 changes: 1 addition & 4 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
ExportMagentoShipmentStatus, ImportMagentoOrderStatesStart,
ImportMagentoOrderStates, ImportMagentoCarriersStart,
ImportMagentoCarriers, ConfigureMagento, ImportStoresStart, FailureStart,
SuccessStart, ImportMagentoOrdersStart, ImportMagentoOrders,
ExportMagentoOrderStatusStart, ExportMagentoOrderStatus,
SuccessStart, ExportMagentoOrderStatusStart, ExportMagentoOrderStatus,
UpdateMagentoCatalogStart, UpdateMagentoCatalog,
ImportMagentoCatalogStart, ImportMagentoCatalog,
ExportMagentoCatalogStart, ExportMagentoCatalog,
Expand Down Expand Up @@ -72,7 +71,6 @@ def register():
UpdateMagentoCatalogStart,
Currency,
Sale,
ImportMagentoOrdersStart,
ImportMagentoOrderStatesStart,
ImportMagentoCarriersStart,
ExportMagentoOrderStatusStart,
Expand All @@ -91,7 +89,6 @@ def register():
ImportMagentoCatalog,
UpdateMagentoCatalog,
ExportMagentoCatalog,
ImportMagentoOrders,
ExportMagentoOrderStatus,
ImportMagentoCarriers,
ConfigureMagento,
Expand Down
39 changes: 25 additions & 14 deletions channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,16 @@ def import_magento_products(self):

return map(int, products)

def import_order_from_magento(self):
def import_orders(self):
"""
Imports sale from magento
Downstream implementation of channel.import_orders
:return: List of active record of sale imported
"""
Sale = Pool().get('sale.sale')
MagentoOrderState = Pool().get('magento.order_state')
if self.source != 'magento':
return super(Channel, self).import_orders()

self.validate_magento_channel()
MagentoOrderState = Pool().get('magento.order_state')

new_sales = []
with Transaction().set_context({'current_channel': self.id}):
Expand Down Expand Up @@ -345,16 +345,27 @@ def import_order_from_magento(self):
})
orders_summaries = order_api.list(filter)
for order_summary in orders_summaries:
if Sale.find_using_magento_data(order_summary):
continue
# No sale found, fetch full order_data and create
# sale from the same.
order_data = order_api.info(order_summary['increment_id'])
new_sales.append(
Sale.create_using_magento_data(order_data)
)
new_sales.append(self.import_order(order_summary))
return new_sales

def import_order(self, order_info):
"Downstream implementation to import sale order from magento"
if self.source != 'magento':
return super(Channel, self).import_order(order_info)

Sale = Pool().get('sale.sale')

sale = Sale.find_using_magento_data(order_info)
if sale:
return sale

with Transaction().set_context({'current_channel': self.id}):
with magento.Order(
self.magento_url, self.magento_api_user, self.magento_api_key
) as order_api:
order_data = order_api.info(order_info['increment_id'])
return Sale.create_using_magento_data(order_data)

@classmethod
def export_order_status_to_magento_using_cron(cls):
"""
Expand Down Expand Up @@ -405,7 +416,7 @@ def import_magento_orders(cls):
channels = cls.search([('source', '=', 'magento')])

for channel in channels:
channel.import_order_from_magento()
channel.import_orders()

@classmethod
def export_shipment_status_to_magento_using_cron(cls):
Expand Down
5 changes: 0 additions & 5 deletions view/import_orders_start_form.xml

This file was deleted.

66 changes: 1 addition & 65 deletions wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

__all__ = [
'ExportMagentoInventoryStart', 'ExportMagentoInventory',
'ImportMagentoOrdersStart', 'ExportMagentoTierPricesStart',
'ExportMagentoTierPrices', 'ImportMagentoOrders',
'ExportMagentoTierPricesStart', 'ExportMagentoTierPrices',
'ExportMagentoTierPricesStatus', 'ExportMagentoShipmentStatusStart',
'ExportMagentoShipmentStatus', 'ImportMagentoOrderStatesStart',
'ImportMagentoOrderStates', 'ImportMagentoCarriersStart',
Expand All @@ -35,69 +34,6 @@
__metaclass__ = PoolMeta


class ImportMagentoOrdersStart(ModelView):
"Import Sale Order Start View"
__name__ = 'magento.wizard_import_orders.start'

message = fields.Text("Message", readonly=True)


class ImportMagentoOrders(Wizard):
"""
Import Orders Wizard
Import sale orders from magento for the current channel
"""
__name__ = 'magento.wizard_import_orders'

start = StateView(
'magento.wizard_import_orders.start',
'magento.wizard_import_magento_orders_view_start_form',
[
Button('Cancel', 'end', 'tryton-cancel'),
Button('Continue', 'import_', 'tryton-ok', default=True),
]
)

import_ = StateAction('magento.act_sale_form_all')

def default_start(self, data):
"""
Sets default data for wizard
:param data: Wizard data
"""
Channel = Pool().get('sale.channel')

channel = Channel(Transaction().context.get('active_id'))
channel.validate_magento_channel()
return {
'message':
"This wizard will import all sale orders placed on " +
"this channel on after the Last Order Import " +
"Time. If Last Order Import Time is missing, then it will " +
"import all the orders from beginning of time. [This might " +
"be slow depending on number of orders]."
}

def do_import_(self, action):
"""
Import Orders from mganto
"""
Channel = Pool().get('sale.channel')

channel = Channel(Transaction().context.get('active_id'))
channel.validate_magento_channel()

sales = channel.import_order_from_magento()

data = {'res_id': [sale.id for sale in sales]}
return action, data

def transition_import_(self):
return 'end'


class ExportMagentoOrderStatusStart(ModelView):
"Export Order Status Start View"
__name__ = 'magento.wizard_export_order_status.start'
Expand Down
17 changes: 0 additions & 17 deletions wizard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,6 @@
<field name="name">export_tier_prices_status_form</field>
</record>

<!--Import Orders Wizard-->
<record model="ir.action.wizard" id="wizard_import_magento_orders">
<field name="name">Import Magento Orders</field>
<field name="wiz_name">magento.wizard_import_orders</field>
<field name="model">sale.channel</field>
</record>
<record model="ir.action.keyword" id="wizard_import_magento_orders_keyword">
<field name="keyword">form_action</field>
<field name="model">sale.channel,-1</field>
<field name="action" ref="wizard_import_magento_orders"/>
</record>
<record model="ir.ui.view" id="wizard_import_magento_orders_view_start_form">
<field name="model">magento.wizard_import_orders.start</field>
<field name="type">form</field>
<field name="name">import_orders_start_form</field>
</record>

<!--Export Order Status-->
<record model="ir.action.wizard" id="wizard_export_magento_order_status">
<field name="name">Export Order Status To Magento</field>
Expand Down

0 comments on commit 5140773

Please sign in to comment.