Skip to content

Commit

Permalink
Merge pull request #62 from aroraumang/feature/task-6786
Browse files Browse the repository at this point in the history
Mark magento exception True when product does not exist #6786
  • Loading branch information
tarunbhardwaj committed Jan 28, 2015
2 parents f399a60 + 90d44b2 commit 7c86143
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ def add_lines_using_magento_data(self, order_data):
unit, = Uom.search([('name', '=', 'Unit')])

line_data = []
has_magento_exception = False
for item in order_data['items']:
if not item['parent_item_id']:
# If its a top level product, create it
Expand All @@ -386,9 +387,11 @@ def add_lines_using_magento_data(self, order_data):
# create magento exception
MagentoException.create([{
'origin': '%s,%s' % (self.__name__, self.id),
'log': "Product does not exists."
'log': "Product #%s does not exist" %
item['product_id']
}])
product = None
has_magento_exception = True
else:
raise
values = {
Expand Down Expand Up @@ -424,9 +427,14 @@ def add_lines_using_magento_data(self, order_data):
self.get_discount_line_data_using_magento_data(order_data)
)

Sale.write([self], {
'lines': line_data
})
values = {
'lines': line_data,
}

if has_magento_exception:
values['has_magento_exception'] = has_magento_exception

Sale.write([self], values)

@classmethod
def find_or_create_using_magento_increment_id(cls, order_increment_id):
Expand Down
1 change: 1 addition & 0 deletions tests/test_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def test_0030_import_sale_order_with_products_with_new(self):
)

self.assertEqual(order.state, 'confirmed')
self.assertFalse(order.has_magento_exception)

orders = Sale.search([])
self.assertEqual(len(orders), 1)
Expand Down

0 comments on commit 7c86143

Please sign in to comment.