Skip to content

Commit

Permalink
Merge pull request #64 from tarunbhardwaj/develop
Browse files Browse the repository at this point in the history
Refactored sale.create_using_magento_data method to active record pattern #6946
  • Loading branch information
Sharoon Thomas committed Feb 7, 2015
2 parents 2455384 + 7c79cc1 commit 11d2b26
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,16 @@ def find_using_magento_data(cls, order_data):
return sales and sales[0] or None

@classmethod
def create_using_magento_data(cls, order_data):
def get_sale_using_magento_data(cls, order_data):
"""
Create a sale from magento data
:param order_data: Order data from magento
:return: Active record of record created
Return an active record of the sale from magento data
"""
Party = Pool().get('party.party')
Address = Pool().get('party.address')
StoreView = Pool().get('magento.store.store_view')
MagentoException = Pool().get('magento.exception')
Currency = Pool().get('currency.currency')
Uom = Pool().get('product.uom')
MagentoOrderState = Pool().get('magento.order_state')

store_view = StoreView(Transaction().context.get('magento_store_view'))
instance = store_view.instance
Expand Down Expand Up @@ -337,10 +334,31 @@ def create_using_magento_data(cls, order_data):
'invoice_method': tryton_state['invoice_method'],
'shipment_method': shipment_method,
}
sale, = cls.create([sale_data])
Sale = Pool().get('sale.sale')
return Sale(**sale_data)

@classmethod
def create_using_magento_data(cls, order_data):
"""
Create a sale from magento data. If you wish to override the creation
process, it is recommended to subclass and manipulate the returned
unsaved active record from the `get_sale_using_magento_data` method.
:param order_data: Order data from magento
:return: Active record of record created
"""
MagentoException = Pool().get('magento.exception')
MagentoOrderState = Pool().get('magento.order_state')

sale = cls.get_sale_using_magento_data(order_data)
sale.save()

# TODO: make the add_lines_using_magento_data method also work
# with unsaved active records
sale.add_lines_using_magento_data(order_data)

# Process sale now
tryton_state = MagentoOrderState.get_tryton_state(order_data['state'])
try:
sale.process_sale_using_magento_state(order_data['state'])
except UserError, e:
Expand Down

0 comments on commit 11d2b26

Please sign in to comment.