Skip to content

Commit 4ed1eca

Browse files
[FIX] Row totals are excl. discount amount. (#13)
Fixes OCA#301
1 parent b0eea50 commit 4ed1eca

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

magentoerpconnect/sale.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ def discount_amount(self, record):
10611061
row_total = float(record.get('row_total') or 0)
10621062
discount = 0
10631063
if discount_value > 0 and row_total > 0:
1064-
discount = 100 * discount_value / row_total
1064+
discount = 100 * discount_value / (discount_value + row_total)
10651065
result = {'discount': discount}
10661066
return result
10671067

@@ -1079,14 +1079,16 @@ def product_id(self, record):
10791079
def price(self, record):
10801080
""" tax key may not be present in magento2 when no taxes apply """
10811081
result = {}
1082+
discount_amount = float(record['base_discount_amount'] or 0)
10821083
base_row_total = float(record['base_row_total'] or 0.)
10831084
base_row_total_incl_tax = float(
10841085
record.get('base_row_total_incl_tax') or base_row_total)
10851086
qty_ordered = float(record['qty_ordered'])
10861087
if self.options.tax_include:
1087-
result['price_unit'] = base_row_total_incl_tax / qty_ordered
1088+
total = base_row_total_incl_tax
10881089
else:
1089-
result['price_unit'] = base_row_total / qty_ordered
1090+
total = base_row_total
1091+
result['price_unit'] = (total + discount_amount) / qty_ordered
10901092
return result
10911093

10921094

magentoerpconnect/tests/data_base.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25907,8 +25907,8 @@
2590725907
'base_price': '28.0300',
2590825908
'base_price_incl_tax': '29.9900',
2590925909
'base_row_invoiced': '28.0300',
25910-
'base_row_total': '28.0300',
25911-
'base_row_total_incl_tax': '29.9900',
25910+
'base_row_total': '24.4600',
25911+
'base_row_total_incl_tax': '26.4200',
2591225912
'base_tax_amount': '1.9600',
2591325913
'base_tax_before_discount': None,
2591425914
'base_tax_invoiced': '1.9600',
@@ -25953,8 +25953,8 @@
2595325953
'qty_shipped': '0.0000',
2595425954
'quote_item_id': 579492,
2595525955
'row_invoiced': '28.0300',
25956-
'row_total': '28.0300',
25957-
'row_total_incl_tax': '29.9900',
25956+
'row_total': '24.4600',
25957+
'row_total_incl_tax': '26.4200',
2595825958
'row_weight': '0.0000',
2595925959
'sku': 'skui1',
2596025960
'store_id': 2,
@@ -25985,8 +25985,8 @@
2598525985
'base_price': '11.1800',
2598625986
'base_price_incl_tax': '11.9600',
2598725987
'base_row_invoiced': '11.1800',
25988-
'base_row_total': '11.1800',
25989-
'base_row_total_incl_tax': '11.9600',
25988+
'base_row_total': '9.7500',
25989+
'base_row_total_incl_tax': '10.5300',
2599025990
'base_tax_amount': '0.7800',
2599125991
'base_tax_before_discount': None,
2599225992
'base_tax_invoiced': '0.7800',
@@ -26031,8 +26031,8 @@
2603126031
'qty_shipped': '0.0000',
2603226032
'quote_item_id': 579493,
2603326033
'row_invoiced': '11.1800',
26034-
'row_total': '11.1800',
26035-
'row_total_incl_tax': '11.9600',
26034+
'row_total': '9.7500',
26035+
'row_total_incl_tax': '10.5300',
2603626036
'row_weight': '0.0000',
2603726037
'sku': 'skui2',
2603826038
'store_id': 2,

0 commit comments

Comments
 (0)