Skip to content

Commit

Permalink
Update weight funcs, add typing and doc string
Browse files Browse the repository at this point in the history
  • Loading branch information
IKarbowiak committed Jul 17, 2020
1 parent 9be84d0 commit 0bfa032
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions saleor/core/weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def zero_weight():
return Weight(kg=0)


def convert_weight(weight, unit):
def convert_weight(weight: Weight, unit: str) -> Weight:
# Weight amount from the Weight instance can be retrived in serveral units
# via its properties. eg. Weight(lb=10).kg
converted_weight = getattr(weight, unit)
Expand All @@ -49,10 +49,12 @@ def get_default_weight_unit():
return site.settings.default_weight_unit


def covert_weight_to_default_weight_unit(weight):
def covert_weight_to_default_weight_unit(weight: Weight) -> Weight:
"""Weight is kept in one unit, but should be returned in site default unit."""
default_unit = get_default_weight_unit()
if weight and weight.unit != default_unit:
weight = convert_weight(weight, default_unit)
elif weight:
weight.value = round(weight.value, 3)
if weight is not None:
if weight.unit != default_unit:
weight = convert_weight(weight, default_unit)
else:
weight.value = round(weight.value, 3)
return weight

0 comments on commit 0bfa032

Please sign in to comment.