Commit 46d9ed42 by François C.

ticket #1890 : Change way of displaying members pos order payments

parent b67393d3
Pipeline #1742 passed with stage
in 1 minute 38 seconds
...@@ -16,36 +16,27 @@ class CagetteSales(models.Model): ...@@ -16,36 +16,27 @@ class CagetteSales(models.Model):
# Get pos orders # Get pos orders
cond = [['date_order', '>=', date_from], ['date_order', '<=', date_to]] cond = [['date_order', '>=', date_from], ['date_order', '<=', date_to]]
fields = ['partner_id', 'statement_ids'] fields = ['partner_id', 'statement_ids', 'name']
orders = self.o_api.search_read('pos.order', cond, fields) orders = self.o_api.search_read('pos.order', cond, fields)
# Get bank statements of these sessions # Get bank statements of these sessions
statements = [] statements = []
statements_partners = {} statements_partners = {}
statements_orders = {}
for o in orders: for o in orders:
statements = statements + o["statement_ids"] statements = statements + o["statement_ids"]
for s in o["statement_ids"]: for s in o["statement_ids"]:
statements_partners[s] = o["partner_id"][1] statements_partners[s] = o["partner_id"][1]
statements_orders[s] = o["name"]
# Get payment lines # Get payment lines
cond = [['id', 'in', statements]] cond = [['id', 'in', statements]]
fields = ["amount", "journal_id", "create_date", "date"] fields = ["amount", "journal_id", "create_date"]
payments = self.o_api.search_read('account.bank.statement.line', cond, fields, order="create_date ASC", limit=50000) payments = self.o_api.search_read('account.bank.statement.line', cond, fields, order="create_date ASC", limit=50000)
item = None
try: try:
for payment in payments: for payment in payments:
# POS session can contain payments from another day (closing session on next morning, ...) res.append({
if payment["date"] >= date_from and payment["date"] <= date_to:
# If the consecutive payment in the results is from the same partner on the same day, we consider it's the same basket
if item is not None and item["partner"] == statements_partners[payment["id"]] and item["date"] == payment["date"]:
res[len(res)-1]["total_amount"] += round(float(payment["amount"]), 2)
res[len(res)-1]["payments"].append({
"amount": round(float(payment["amount"]), 2),
"journal_id": payment["journal_id"]
})
else:
item = {
"partner": statements_partners[payment["id"]], "partner": statements_partners[payment["id"]],
"create_date": payment["create_date"], "create_date": payment["create_date"],
"date": payment["date"], "pos_order_name": statements_orders[payment["id"]],
"total_amount": round(float(payment["amount"]), 2), "total_amount": round(float(payment["amount"]), 2),
"payments": [ "payments": [
{ {
...@@ -53,9 +44,7 @@ class CagetteSales(models.Model): ...@@ -53,9 +44,7 @@ class CagetteSales(models.Model):
"journal_id": payment["journal_id"] "journal_id": payment["journal_id"]
} }
] ]
} })
res.append(item)
except Exception as e: except Exception as e:
coop_logger.error("get_sales %s", str(e)) coop_logger.error("get_sales %s", str(e))
......
...@@ -38,17 +38,23 @@ function display_orders(orders) { ...@@ -38,17 +38,23 @@ function display_orders(orders) {
columns:[ columns:[
{ {
data:"create_date", data:"create_date",
title:"Date de vente", title:"Date enregistrement",
width: "10%" width: "10%"
}, },
{ {
data:"pos_order_name",
title:"Ref. Caisse",
width: "10%"
},
{
data:"partner", data:"partner",
title:"Membre", title:"Membre",
width: "50%" width: "40%"
}, },
{ {
data:"total_amount", data:"total_amount",
title: "Montant du panier", title: "Montant dû",
className:"dt-body-center", className:"dt-body-center",
render: function (data) { render: function (data) {
return parseFloat(data).toFixed(2) + ' €'; return parseFloat(data).toFixed(2) + ' €';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment