Commit b67393d3 by François C.

Ticket 1933 : In sales extraction, distingue Memmber and Associated People

parent 82ff458b
Pipeline #1741 passed with stage
in 1 minute 39 seconds
...@@ -14,28 +14,28 @@ class CagetteSales(models.Model): ...@@ -14,28 +14,28 @@ class CagetteSales(models.Model):
def get_sales(self, date_from, date_to): def get_sales(self, date_from, date_to):
res = [] res = []
# Get pos sessions # Get pos orders
cond = [['stop_at', '>=', date_from], ['stop_at', '<=', date_to], ['state', '=', "closed"]] cond = [['date_order', '>=', date_from], ['date_order', '<=', date_to]]
fields = [] fields = ['partner_id', 'statement_ids']
sessions = self.o_api.search_read('pos.session', 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 = []
for s in sessions: statements_partners = {}
statements = statements + s["statement_ids"] for o in orders:
statements = statements + o["statement_ids"]
for s in o["statement_ids"]:
statements_partners[s] = o["partner_id"][1]
# Get payment lines # Get payment lines
cond = [['statement_id', 'in', statements]] cond = [['id', 'in', statements]]
fields = ["partner_id", "amount", "journal_id", "create_date", "date"] fields = ["amount", "journal_id", "create_date", "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 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, ...) # POS session can contain payments from another day (closing session on next morning, ...)
if payment["date"] >= date_from and payment["date"] <= date_to: 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 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_id"][0] == payment["partner_id"][0] and item["date"] == payment["date"]: 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]["total_amount"] += round(float(payment["amount"]), 2)
res[len(res)-1]["payments"].append({ res[len(res)-1]["payments"].append({
"amount": round(float(payment["amount"]), 2), "amount": round(float(payment["amount"]), 2),
...@@ -43,7 +43,7 @@ class CagetteSales(models.Model): ...@@ -43,7 +43,7 @@ class CagetteSales(models.Model):
}) })
else: else:
item = { item = {
"partner_id": payment["partner_id"], "partner": statements_partners[payment["id"]],
"create_date": payment["create_date"], "create_date": payment["create_date"],
"date": payment["date"], "date": payment["date"],
"total_amount": round(float(payment["amount"]), 2), "total_amount": round(float(payment["amount"]), 2),
...@@ -51,12 +51,12 @@ class CagetteSales(models.Model): ...@@ -51,12 +51,12 @@ class CagetteSales(models.Model):
{ {
"amount": round(float(payment["amount"]), 2), "amount": round(float(payment["amount"]), 2),
"journal_id": payment["journal_id"] "journal_id": payment["journal_id"]
} }
] ]
} }
res.append(item) res.append(item)
except Exception as e: except Exception as e:
pass coop_logger.error("get_sales %s", str(e))
return res return res
...@@ -42,12 +42,9 @@ function display_orders(orders) { ...@@ -42,12 +42,9 @@ function display_orders(orders) {
width: "10%" width: "10%"
}, },
{ {
data:"partner_id", data:"partner",
title:"Membre", title:"Membre",
width: "50%", width: "50%"
render: function (data) {
return data[1];
}
}, },
{ {
data:"total_amount", data:"total_amount",
......
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