Skip to content

Commit

Permalink
added update bag line support
Browse files Browse the repository at this point in the history
  • Loading branch information
tsilva committed May 16, 2016
1 parent bdfdc01 commit 8831c99
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/eadapters/budy_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,15 @@ def add_bag_line(self, product_id, quantity = 1, bag_id = None, *args, **kwargs)
quantity,
size = size,
scale = scale,
meta = meta,
meta = meta
)

def update_bag_line(self, bag_line, bag_id = None, *args, **kwargs):
self._ensure_bag()
bag_id = bag_id or self.bag_key
bag = models.BDBag.get_l(key = bag_id)
bag.update_line_s(bag_line)

def remove_bag_line(self, bag_line_id, bag_id = None, *args, **kwargs):
self._ensure_bag()
bag_id = bag_id or self.bag_key
Expand Down
7 changes: 7 additions & 0 deletions src/eadapters/models/bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class EBag(base.EBase):
)
)

@classmethod
def _build(cls, model, map):
super(EBag, cls)._build(model, map)

lines = model.get("lines", [])
model["quantity"] = sum([line["quantity"] for line in lines])

@property
def quantity(self):
return sum([line.quantity for line in self.lines])
13 changes: 13 additions & 0 deletions src/eadapters/models/budy/bd_bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ def add_line_s(
line = bd_bag_line.BDBagLine.wrap(line)
return line

@bd_common.handle_error
def update_line_s(self, line):
api = self._get_api()
item = bd_bag_line.BDBagLine(**line)
item = item.unwrap(default = True)
line = api.add_update_line_bag(
self.key,
line,
increment = False
)
line = bd_bag_line.BDBagLine.wrap(line)
return line

@bd_common.handle_error
def remove_line_s(self, line_id):
api = self._get_api()
Expand Down

0 comments on commit 8831c99

Please sign in to comment.