Skip to content

Commit

Permalink
Merge pull request #81 from tarunbhardwaj/develop
Browse files Browse the repository at this point in the history
Added add_to method to copy sale_line to new sale #6889
  • Loading branch information
prakashpp committed Feb 13, 2015
2 parents 5c94536 + 69d4eb6 commit daa90bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 1 addition & 3 deletions cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,7 @@ def _login_event_handler(cls, user=None):
to_cart = cls.open_cart(True)
# Transfer lines from one cart to another
for from_line in guest_cart.sale.lines:
sale_line = to_cart.sale._add_or_update(
from_line.product.id, from_line.quantity
)
sale_line = from_line.add_to(to_cart.sale)
sale_line.save()

# Clear and delete the old cart
Expand Down
13 changes: 13 additions & 0 deletions sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,16 @@ def serialize(self, purpose=None):
),
})
return res

def add_to(self, sale):
"""
Copy sale_line to new sale.
Downstream modules can override this method to add change this behaviour
of copying.
:param sale: Sale active record.
:return: Newly created sale_line
"""
return sale._add_or_update(self.product.id, self.quantity)

0 comments on commit daa90bc

Please sign in to comment.