Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Catch cases where record['discount_amount'] = None #70

Merged
merged 2 commits into from
Dec 16, 2014
Merged

Catch cases where record['discount_amount'] = None #70

merged 2 commits into from
Dec 16, 2014

Conversation

mdietrichc2c
Copy link

Magento sometimes sends sales_order.items with the attributes 'discount_amount' set to None; this caused the float() function to fail with the error "TypeError: float() argument must be a string or a number".

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) when pulling bed82c6 on mdietrichc2c:fix-discount-sale-order into fb081b8 on OCA:7.0.

if record.get('discount_amount'):
discount_value = float(record.get('discount_amount', 0))
if self.backend_record.catalog_price_tax_included and \
record.get('row_total_incl_tax'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad indentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also do not put a \ but use parentheses

@guewen
Copy link
Member

guewen commented Dec 3, 2014

I propose to leave the existing code but just use this idiom value = float(record.get('field_amount') or 0) instead of value = float(record.get('field_amount', 0)) (also in the other amount fields).

@mdietrichc2c
Copy link
Author

@guewen , @pedrobaeza : yes, it's cleaner like this. I fixed it.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 83ffadb on mdietrichc2c:fix-discount-sale-order into fb081b8 on OCA:7.0.

@guewen
Copy link
Member

guewen commented Dec 16, 2014

Thanks!

👍

@pedrobaeza
Copy link
Member

👍

guewen added a commit that referenced this pull request Dec 16, 2014
Catch cases where record['discount_amount'] = None
@guewen guewen merged commit 0df0279 into OCA:7.0 Dec 16, 2014
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants