Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix al agrupar productos de varios pedidos. #24

Open
wants to merge 1 commit into
base: hackerspacebranch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions compras/orders/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,29 @@ def summary(self):
@property
def products_list(self):
products = []
grand_total = 0
for order in self.order_set.all():
for product in order.orderproduct_set.all():
p = {}
p["product"] = product.product
p["price"] = product.total
check_groupby_product = False
p["product"] = str(product.product).split('$')[0]
p["product"] = str(product.product).split('listing product ')[1]
p["price"] = float(str(product.product).split('$')[1])

for product_check in products:
if(p["product"] == product_check['product']):
product_check['amount'] += int(product.amount)
product_check['total'] += float(product.total)
check_groupby_product = True

p["order"] = product.order
p["amount"] = int(product.amount)
p["total"] = float(product.total)
products.append(p)

grand_total += float(product.total)

if not check_groupby_product:
p["amount"] = int(product.amount)
p["total"] = float(product.total)
products.append(p)
products.append(grand_total)
return products

@property
Expand Down Expand Up @@ -131,7 +144,7 @@ def tag(self):


def __str__(self):
return f"{self.product.name} ({self.presentation})"
return f"listing product {self.product.name} {self.presentation}${self.price}"

class Order(models.Model):
class Meta:
Expand Down
21 changes: 15 additions & 6 deletions compras/templates/admin/order/listing_summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
h1 { font-size: 24px; font-weight: bold }
th.total {text-align: center}
</style>
{% endblock %}

Expand All @@ -32,12 +33,20 @@
</thead>
<tbody>
{% for product in data.products %}
<tr>
<td>{{product.product}}</th>
<td>{{product.amount}}</th>
<td>${{product.price}}</th>
<td>${{product.total}}</th>
</tr>
{% if product.product %}
<tr>
<td>{{product.product}}</td>
<td>{{product.amount}}</td>
<td>${{product.price}}</td>
<td>${{product.total}}</td>
</tr>
{% else %}
<tr>
<th colspan="3" class="total">TOTAL</th>
<td>${{product}}</th>
</tr>
{% endif %}

{% endfor %}
</tbody>
</table>
Expand Down