Skip to content

Commit

Permalink
Merge pull request #61 from aroraumang/feature/task-6786
Browse files Browse the repository at this point in the history
Remove has_magento_exception from sale line #6786
  • Loading branch information
prakashpp committed Jan 24, 2015
2 parents c882a7e + f1596b7 commit 3772e82
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 53 deletions.
68 changes: 30 additions & 38 deletions sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,15 @@ class Sale:
magento_store_view = fields.Many2One(
'magento.store.store_view', 'Store View', readonly=True,
)
has_magento_exception = fields.Boolean('Has Magento import exception')
magento_exceptions = fields.Function(
fields.One2Many('magento.exception', None, 'Magento Exceptions'),
'get_magento_exceptions'
)
has_magento_exception = fields.Function(
fields.Boolean('Has Magento import exception'),
'get_has_magento_exception'
)

@staticmethod
def default_has_magento_exception():
return False

@classmethod
def __setup__(cls):
Expand Down Expand Up @@ -223,17 +224,6 @@ def get_magento_exceptions(self, name):
('origin', '=', '%s,%s' % (self.__name__, self.id)),
]))

def get_has_magento_exception(self, name):
"""
Return True is any sale line has magento exception
"""
SaleLine = Pool().get('sale.line')

return bool(SaleLine.search([
('sale', '=', self),
('has_magento_exception', '=', True),
], limit=1))

@classmethod
def confirm(cls, sales):
"Validate sale before confirming"
Expand Down Expand Up @@ -346,20 +336,9 @@ def create_using_magento_data(cls, order_data):
'magento_store_view': store_view.id,
'invoice_method': tryton_state['invoice_method'],
'shipment_method': shipment_method,
'lines': cls.get_item_line_data_using_magento_data(order_data)
}

if Decimal(order_data.get('shipping_amount')):
sale_data['lines'].append(
cls.get_shipping_line_data_using_magento_data(order_data)
)

if Decimal(order_data.get('discount_amount')):
sale_data['lines'].append(
cls.get_discount_line_data_using_magento_data(order_data)
)

sale, = cls.create([sale_data])
sale.add_lines_using_magento_data(order_data)

# Process sale now
try:
Expand All @@ -377,18 +356,19 @@ def create_using_magento_data(cls, order_data):

return sale

@classmethod
def get_item_line_data_using_magento_data(cls, order_data):
def add_lines_using_magento_data(self, order_data):
"""
Make data for an item line from the magento data.
Create sale lines from the magento data and associate them with
the current sale.
This method decides the actions to be taken on different product types
:param order_data: Order Data from magento
:return: List of data of order lines in required format
"""
Uom = Pool().get('product.uom')
ProductTemplate = Pool().get('product.template')
Bom = Pool().get('production.bom')
MagentoException = Pool().get('magento.exception')
Sale = Pool().get('sale.sale')

unit, = Uom.search([('name', '=', 'Unit')])

Expand All @@ -403,18 +383,23 @@ def get_item_line_data_using_magento_data(cls, order_data):
except xmlrpclib.Fault, exception:
if exception.faultCode == 101:
# Case when product doesnot exist on magento
# create magento exception
MagentoException.create([{
'origin': '%s,%s' % (self.__name__, self.id),
'log': "Product does not exists."
}])
product = None
else:
raise
values = {
'sale': self.id,
'magento_id': int(item['item_id']),
'description': item['name'],
'unit_price': Decimal(item['price']),
'unit': unit.id,
'quantity': Decimal(item['qty_ordered']),
'note': item['product_options'],
'product': product,
'has_magento_exception': (product is None),
}
line_data.append(('create', [values]))

Expand All @@ -429,7 +414,19 @@ def get_item_line_data_using_magento_data(cls, order_data):
# If no bundle products exist in sale, nothing extra will happen
Bom.find_or_create_bom_for_magento_bundle(order_data)

return line_data
if Decimal(order_data.get('shipping_amount')):
line_data.append(
self.get_shipping_line_data_using_magento_data(order_data)
)

if Decimal(order_data.get('discount_amount')):
line_data.append(
self.get_discount_line_data_using_magento_data(order_data)
)

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

@classmethod
def find_or_create_using_magento_increment_id(cls, order_increment_id):
Expand Down Expand Up @@ -710,11 +707,6 @@ class SaleLine:

#: This field stores the magento ID corresponding to this sale line
magento_id = fields.Integer('Magento ID', readonly=True)
has_magento_exception = fields.Boolean('Has Magento import exception')

@staticmethod
def default_has_magento_exception():
return False


class StockShipmentOut:
Expand Down
8 changes: 0 additions & 8 deletions sale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
<field name="act_window" ref="act_sale_form_all"/>
</record>

<!--Sale Line -->
<record model="ir.ui.view" id="sale_line_view_form">
<field name="model">sale.line</field>
<field name="type">form</field>
<field name="inherit" ref="sale.sale_line_view_form"/>
<field name="name">sale_line_form</field>
</record>

<!-- Shipment -->
<record model="ir.ui.view" id="shipment_view_form">
<field name="model">stock.shipment.out</field>
Expand Down
7 changes: 0 additions & 7 deletions view/sale_line_form.xml

This file was deleted.

0 comments on commit 3772e82

Please sign in to comment.