Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions magentoerpconnect/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down
16 changes: 8 additions & 8 deletions magentoerpconnect/tests/data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down