Skip to content

Commit a5f9d70

Browse files
committed
[UPD] enhance importer.py to return empty dict for missing team, analytic account, fiscal position, and warehouse; fix discount calculation edge case
1 parent 58768c6 commit a5f9d70

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

connector_magento/models/sale_order/importer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,21 @@ def sales_team(self, record):
337337
team = self.options.storeview.team_id
338338
if team:
339339
return {'team_id': team.id}
340+
return {}
340341

341342
@mapping
342343
def analytic_account_id(self, record):
343344
analytic_account_id = self.options.storeview.account_analytic_id
344345
if analytic_account_id:
345346
return {'analytic_account_id': analytic_account_id.id}
347+
return {}
346348

347349
@mapping
348350
def fiscal_position(self, record):
349351
fiscal_position = self.options.storeview.fiscal_position_id
350352
if fiscal_position:
351353
return {'fiscal_position_id': fiscal_position.id}
354+
return {}
352355

353356
@mapping
354357
def warehouse_id(self, record):
@@ -358,6 +361,7 @@ def warehouse_id(self, record):
358361
'warehouse_id': warehouse.id,
359362
'company_id': warehouse.company_id.id,
360363
}
364+
return {}
361365

362366
# partner_id, partner_invoice_id, partner_shipping_id
363367
# are done in the importer
@@ -744,6 +748,10 @@ def discount_amount(self, record):
744748
discount = 100 * discount_value / row_total
745749
else:
746750
discount = 100 * discount_value / (row_total + discount_value)
751+
elif discount_value > 0 and row_total == 0:
752+
discount = 100
753+
754+
discount = min(discount, 100)
747755
result = {'discount': discount}
748756
return result
749757

0 commit comments

Comments
 (0)