Skip to content

Commit

Permalink
Merge pull request #93 from openlabs/channel
Browse files Browse the repository at this point in the history
Refactored to use magento as a sale channel #7489
  • Loading branch information
tarunbhardwaj committed Apr 29, 2015
2 parents 1ef20ca + fb22819 commit 79aeebf
Show file tree
Hide file tree
Showing 85 changed files with 2,414 additions and 2,999 deletions.
98 changes: 51 additions & 47 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,92 +4,96 @@
Initialize Module
:copyright: (c) 2013 by Openlabs Technologies & Consulting (P) Limited
:copyright: (c) 2013-2015 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
from trytond.pool import Pool
from magento_ import (
Instance, InstanceWebsite, WebsiteStore, WebsiteStoreView,
TestConnectionStart, TestConnection, ImportWebsitesStart, ImportWebsites,
ExportInventoryStart, ExportInventory, StorePriceTier,
ExportTierPricesStart, ExportTierPrices, ExportTierPricesStatus,
ExportShipmentStatusStart, ExportShipmentStatus, ImportOrderStatesStart,
ImportOrderStates, ImportCarriersStart, ImportCarriers, MagentoException
from wizard import (
TestMagentoConnectionStart, ImportWebsitesStart,
ExportMagentoInventoryStart, ExportMagentoInventory,
ExportMagentoTierPricesStart, ExportMagentoTierPrices,
ExportMagentoTierPricesStatus, ExportMagentoShipmentStatusStart,
ExportMagentoShipmentStatus, ImportMagentoOrderStatesStart,
ImportMagentoOrderStates, ImportMagentoCarriersStart,
ImportMagentoCarriers, ConfigureMagento, ImportStoresStart, FailureStart,
SuccessStart, ImportMagentoOrdersStart, ImportMagentoOrders,
ExportMagentoOrderStatusStart, ExportMagentoOrderStatus,
UpdateMagentoCatalogStart, UpdateMagentoCatalog,
ImportMagentoCatalogStart, ImportMagentoCatalog,
ExportMagentoCatalogStart, ExportMagentoCatalog,
)
from channel import Channel, MagentoTier, MagentoException
from party import Party, MagentoWebsiteParty, Address
from product import (
Category, MagentoInstanceCategory, Template, MagentoWebsiteTemplate,
ImportCatalogStart, ImportCatalog, UpdateCatalogStart, UpdateCatalog,
ProductPriceTier, ExportCatalogStart, ExportCatalog
Category, MagentoInstanceCategory, Product,
ProductPriceTier, ProductSaleChannelListing
)
from country import Country, Subdivision
from currency import Currency
from carrier import MagentoInstanceCarrier
from sale import (
MagentoOrderState, Sale, ImportOrdersStart, ImportOrders,
ExportOrderStatusStart, ExportOrderStatus, StockShipmentOut, SaleLine
MagentoOrderState, Sale, StockShipmentOut, SaleLine
)
from bom import BOM
from tax import StoreViewTax, StoreViewTaxRelation
from tax import MagentoTax, MagentoTaxRelation


def register():
"""
Register classes
"""
Pool.register(
Instance,
InstanceWebsite,
WebsiteStore,
StorePriceTier,
WebsiteStoreView,
Channel,
MagentoTier,
MagentoInstanceCarrier,
TestConnectionStart,
TestMagentoConnectionStart,
ImportStoresStart,
FailureStart,
SuccessStart,
ImportWebsitesStart,
ExportInventoryStart,
ExportTierPricesStart,
ExportTierPricesStatus,
ExportShipmentStatusStart,
ExportMagentoInventoryStart,
ExportMagentoTierPricesStart,
ExportMagentoTierPricesStatus,
ExportMagentoShipmentStatusStart,
Country,
Subdivision,
Party,
MagentoWebsiteParty,
Category,
MagentoException,
MagentoInstanceCategory,
Template,
MagentoWebsiteTemplate,
Product,
ProductPriceTier,
ImportCatalogStart,
ExportCatalogStart,
ImportMagentoCatalogStart,
ExportMagentoCatalogStart,
MagentoOrderState,
StockShipmentOut,
Address,
UpdateCatalogStart,
UpdateMagentoCatalogStart,
Currency,
Sale,
ImportOrdersStart,
ImportOrderStatesStart,
ImportCarriersStart,
ExportOrderStatusStart,
ImportMagentoOrdersStart,
ImportMagentoOrderStatesStart,
ImportMagentoCarriersStart,
ExportMagentoOrderStatusStart,
SaleLine,
BOM,
StoreViewTax,
StoreViewTaxRelation,
MagentoTax,
MagentoTaxRelation,
ProductSaleChannelListing,
module='magento', type_='model'
)
Pool.register(
TestConnection,
ImportWebsites,
ImportOrderStates,
ExportInventory,
ExportTierPrices,
ExportShipmentStatus,
ImportCatalog,
UpdateCatalog,
ExportCatalog,
ImportOrders,
ExportOrderStatus,
ImportCarriers,
ImportMagentoOrderStates,
ExportMagentoInventory,
ExportMagentoTierPrices,
ExportMagentoShipmentStatus,
ImportMagentoCatalog,
UpdateMagentoCatalog,
ExportMagentoCatalog,
ImportMagentoOrders,
ExportMagentoOrderStatus,
ImportMagentoCarriers,
ConfigureMagento,
module='magento', type_='wizard'
)
11 changes: 5 additions & 6 deletions bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def find_or_create_bom_for_magento_bundle(cls, order_data):
:return: Found or created BoM's active record
"""
Uom = Pool().get('product.uom')
ProductTemplate = Pool().get('product.template')
Product = Pool().get('product.product')
ProductBom = Pool().get('product.product-production.bom')

identified_boms = cls.identify_boms_from_magento_data(order_data)
Expand All @@ -72,18 +72,17 @@ def find_or_create_bom_for_magento_bundle(cls, order_data):
return

for item_id, data in identified_boms.iteritems():
bundle_product_template = \
ProductTemplate.find_or_create_using_magento_id(
bundle_product = \
Product.find_or_create_using_magento_id(
data['bundle']['product_id']
)
bundle_product = bundle_product_template.products[0]

# It contains a list of tuples, in which the first element is the
# product's active record and second is its quantity in the BoM
child_products = [(
ProductTemplate.find_or_create_using_magento_id(
Product.find_or_create_using_magento_id(
each['product_id']
).products[0], (
), (
float(each['qty_ordered']) /
float(data['bundle']['qty_ordered'])
)
Expand Down
16 changes: 8 additions & 8 deletions carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class MagentoInstanceCarrier(ModelSQL, ModelView):
code = fields.Char("Code", readonly=True)
carrier = fields.Many2One('carrier', 'Carrier')
title = fields.Char('Title', readonly=True)
instance = fields.Many2One(
'magento.instance', 'Magento Instance', readonly=True
channel = fields.Many2One(
'sale.channel', 'Magento Channel', readonly=True
)

@classmethod
Expand All @@ -42,8 +42,8 @@ def __setup__(cls):
super(MagentoInstanceCarrier, cls).__setup__()
cls._sql_constraints += [
(
'code_instance_unique', 'unique(code, instance)',
'Shipping methods must be unique in instance'
'code_channel_unique', 'unique(code, channel)',
'Shipping methods must be unique in channel'
)
]

Expand All @@ -52,7 +52,7 @@ def create_all_using_magento_data(cls, magento_data):
"""
Creates record for list of carriers sent by magento.
It creates a new carrier only if one with the same code does not
exist for this instance.
exist for this channel.
:param magento_data: List of Dictionary of carriers sent by magento
:return: List of active records of carriers Created/Found
Expand All @@ -78,15 +78,15 @@ def create_using_magento_data(cls, carrier_data):
carrier, = cls.create([{
'code': carrier_data['code'],
'title': carrier_data['label'],
'instance': Transaction().context['magento_instance'],
'channel': Transaction().context['current_channel'],
}])

return carrier

@classmethod
def find_using_magento_data(cls, carrier_data):
"""
Search for an existing carrier by matching code and instance.
Search for an existing carrier by matching code and channel.
If found, return its active record else None
:param carrier_data: Dictionary of carrier sent by magento
Expand All @@ -95,7 +95,7 @@ def find_using_magento_data(cls, carrier_data):
try:
carrier, = cls.search([
('code', '=', carrier_data['code']),
('instance', '=', Transaction().context['magento_instance']),
('channel', '=', Transaction().context['current_channel']),
])
except ValueError:
return None
Expand Down

0 comments on commit 79aeebf

Please sign in to comment.