Rename Product.weight to Product.unit

This commit is contained in:
Yohan Boniface 2019-04-13 11:02:10 +02:00
parent 5c12463bf7
commit d2cb557f8a
2 changed files with 4 additions and 5 deletions

View file

@ -48,7 +48,6 @@ class Base:
try:
setattr(self, name, self.cast(type_, value))
except (TypeError, ValueError):
raise
raise ValueError(f"Wrong value for field `{name}`: `{value}`")
def cast(self, type, value):
@ -92,7 +91,7 @@ class Product(Base):
name: str
ref: str
price: price_field
weight: str = ""
unit: str = ""
description: str = ""
url: str = ""
img: str = ""
@ -100,8 +99,8 @@ class Product(Base):
@property
def label(self):
out = self.name
if self.weight:
out += f" ({self.weight})"
if self.unit:
out += f" ({self.unit})"
return out

View file

@ -101,6 +101,6 @@ async def test_export_products(client, delivery):
resp = await client.get(f"/livraison/{delivery.id}/exporter/produits")
wb = load_workbook(filename=BytesIO(resp.body))
assert list(wb.active.values) == [
("name", "ref", "price", "weight", "description", "url", "img"),
("name", "ref", "price", "unit", "description", "url", "img"),
("Lait", "123", 1.5, None, None, None, None),
]