diff --git a/magentoerpconnect/sale.py b/magentoerpconnect/sale.py index 20f88a5c7..fcd57c70f 100644 --- a/magentoerpconnect/sale.py +++ b/magentoerpconnect/sale.py @@ -1061,7 +1061,7 @@ def discount_amount(self, record): row_total = float(record.get('row_total') or 0) discount = 0 if discount_value > 0 and row_total > 0: - discount = 100 * discount_value / row_total + discount = 100 * discount_value / (discount_value + row_total) result = {'discount': discount} return result @@ -1079,14 +1079,16 @@ def product_id(self, record): def price(self, record): """ tax key may not be present in magento2 when no taxes apply """ result = {} + discount_amount = float(record['base_discount_amount'] or 0) base_row_total = float(record['base_row_total'] or 0.) base_row_total_incl_tax = float( record.get('base_row_total_incl_tax') or base_row_total) qty_ordered = float(record['qty_ordered']) if self.options.tax_include: - result['price_unit'] = base_row_total_incl_tax / qty_ordered + total = base_row_total_incl_tax else: - result['price_unit'] = base_row_total / qty_ordered + total = base_row_total + result['price_unit'] = (total + discount_amount) / qty_ordered return result diff --git a/magentoerpconnect/tests/data_base.py b/magentoerpconnect/tests/data_base.py index c88c8e3a0..ab7178549 100644 --- a/magentoerpconnect/tests/data_base.py +++ b/magentoerpconnect/tests/data_base.py @@ -25907,8 +25907,8 @@ 'base_price': '28.0300', 'base_price_incl_tax': '29.9900', 'base_row_invoiced': '28.0300', - 'base_row_total': '28.0300', - 'base_row_total_incl_tax': '29.9900', + 'base_row_total': '24.4600', + 'base_row_total_incl_tax': '26.4200', 'base_tax_amount': '1.9600', 'base_tax_before_discount': None, 'base_tax_invoiced': '1.9600', @@ -25953,8 +25953,8 @@ 'qty_shipped': '0.0000', 'quote_item_id': 579492, 'row_invoiced': '28.0300', - 'row_total': '28.0300', - 'row_total_incl_tax': '29.9900', + 'row_total': '24.4600', + 'row_total_incl_tax': '26.4200', 'row_weight': '0.0000', 'sku': 'skui1', 'store_id': 2, @@ -25985,8 +25985,8 @@ 'base_price': '11.1800', 'base_price_incl_tax': '11.9600', 'base_row_invoiced': '11.1800', - 'base_row_total': '11.1800', - 'base_row_total_incl_tax': '11.9600', + 'base_row_total': '9.7500', + 'base_row_total_incl_tax': '10.5300', 'base_tax_amount': '0.7800', 'base_tax_before_discount': None, 'base_tax_invoiced': '0.7800', @@ -26031,8 +26031,8 @@ 'qty_shipped': '0.0000', 'quote_item_id': 579493, 'row_invoiced': '11.1800', - 'row_total': '11.1800', - 'row_total_incl_tax': '11.9600', + 'row_total': '9.7500', + 'row_total_incl_tax': '10.5300', 'row_weight': '0.0000', 'sku': 'skui2', 'store_id': 2,