[IMP] account_financial_report: Open items groupy by salesman
TT49193
This commit is contained in:
committed by
Víctor Martínez
parent
c81cfc0f98
commit
e14373d995
@@ -1,5 +1,6 @@
|
||||
# © 2016 Julien Coux (Camptocamp)
|
||||
# Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# Copyright 2024 Tecnativa - Carolina Fernandez
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import operator
|
||||
@@ -66,6 +67,7 @@ class OpenItemsReport(models.AbstractModel):
|
||||
only_posted_moves,
|
||||
company_id,
|
||||
date_from,
|
||||
grouped_by,
|
||||
):
|
||||
domain = self._get_move_lines_domain_not_reconciled(
|
||||
company_id, account_ids, partner_ids, only_posted_moves, date_from
|
||||
@@ -75,7 +77,7 @@ class OpenItemsReport(models.AbstractModel):
|
||||
domain=domain, fields=ml_fields
|
||||
)
|
||||
journals_ids = set()
|
||||
partners_ids = set()
|
||||
group_ids = set()
|
||||
partners_data = {}
|
||||
if date_at_object < date.today():
|
||||
(
|
||||
@@ -119,29 +121,27 @@ class OpenItemsReport(models.AbstractModel):
|
||||
journals_ids.add(move_line["journal_id"][0])
|
||||
acc_id = move_line["account_id"][0]
|
||||
# Partners data
|
||||
if move_line["partner_id"]:
|
||||
prt_id = move_line["partner_id"][0]
|
||||
prt_name = move_line["partner_id"][1]
|
||||
partner = self.env["res.partner"]
|
||||
if move_line.get("partner_id"):
|
||||
partner = self.env["res.partner"].browse(move_line["partner_id"][0])
|
||||
if grouped_by == "salesperson":
|
||||
user = partner.user_id
|
||||
group_id = user.id or 0
|
||||
group_name = user.name or _("Missing Salesperson")
|
||||
else:
|
||||
prt_id = 0
|
||||
prt_name = _("Missing Partner")
|
||||
if prt_id not in partners_ids:
|
||||
partners_data.update({prt_id: {"id": prt_id, "name": prt_name}})
|
||||
partners_ids.add(prt_id)
|
||||
|
||||
group_id = partner.id or 0
|
||||
group_name = partner.name or _("Missing Partner")
|
||||
if group_id not in group_ids:
|
||||
partners_data.update({group_id: {"id": group_id, "name": group_name}})
|
||||
group_ids.add(group_id)
|
||||
# Move line update
|
||||
original = 0
|
||||
|
||||
if not float_is_zero(move_line["credit"], precision_digits=2):
|
||||
original = move_line["credit"] * (-1)
|
||||
if not float_is_zero(move_line["debit"], precision_digits=2):
|
||||
else:
|
||||
original = move_line["debit"]
|
||||
|
||||
if move_line["ref"] == move_line["name"]:
|
||||
if move_line["ref"]:
|
||||
ref_label = move_line["ref"]
|
||||
else:
|
||||
ref_label = ""
|
||||
ref_label = move_line["ref"] or ""
|
||||
elif not move_line["ref"]:
|
||||
ref_label = move_line["name"]
|
||||
elif not move_line["name"]:
|
||||
@@ -155,8 +155,8 @@ class OpenItemsReport(models.AbstractModel):
|
||||
"date_maturity": move_line["date_maturity"]
|
||||
and move_line["date_maturity"].strftime("%d/%m/%Y"),
|
||||
"original": original,
|
||||
"partner_id": prt_id,
|
||||
"partner_name": prt_name,
|
||||
"partner_id": partner.id or 0,
|
||||
"partner_name": partner.name or "",
|
||||
"ref_label": ref_label,
|
||||
"journal_id": move_line["journal_id"][0],
|
||||
"move_name": move_line["move_id"][1],
|
||||
@@ -172,12 +172,12 @@ class OpenItemsReport(models.AbstractModel):
|
||||
|
||||
# Open Items Move Lines Data
|
||||
if acc_id not in open_items_move_lines_data.keys():
|
||||
open_items_move_lines_data[acc_id] = {prt_id: [move_line]}
|
||||
open_items_move_lines_data[acc_id] = {group_id: [move_line]}
|
||||
else:
|
||||
if prt_id not in open_items_move_lines_data[acc_id].keys():
|
||||
open_items_move_lines_data[acc_id][prt_id] = [move_line]
|
||||
if group_id not in open_items_move_lines_data[acc_id].keys():
|
||||
open_items_move_lines_data[acc_id][group_id] = [move_line]
|
||||
else:
|
||||
open_items_move_lines_data[acc_id][prt_id].append(move_line)
|
||||
open_items_move_lines_data[acc_id][group_id].append(move_line)
|
||||
journals_data = self._get_journals_data(list(journals_ids))
|
||||
accounts_data = self._get_accounts_data(open_items_move_lines_data.keys())
|
||||
return (
|
||||
@@ -236,7 +236,9 @@ class OpenItemsReport(models.AbstractModel):
|
||||
move_lines = []
|
||||
for move_line in open_items_move_lines_data[acc_id][prt_id]:
|
||||
move_lines += [move_line]
|
||||
move_lines = sorted(move_lines, key=lambda k: (k["date"]))
|
||||
move_lines = sorted(
|
||||
move_lines, key=lambda k: (k["date"], k["partner_id"])
|
||||
)
|
||||
new_open_items[acc_id][prt_id] = move_lines
|
||||
return new_open_items
|
||||
|
||||
@@ -251,7 +253,7 @@ class OpenItemsReport(models.AbstractModel):
|
||||
date_from = data["date_from"]
|
||||
only_posted_moves = data["only_posted_moves"]
|
||||
show_partner_details = data["show_partner_details"]
|
||||
|
||||
grouped_by = data["grouped_by"]
|
||||
(
|
||||
move_lines_data,
|
||||
partners_data,
|
||||
@@ -265,6 +267,7 @@ class OpenItemsReport(models.AbstractModel):
|
||||
only_posted_moves,
|
||||
company_id,
|
||||
date_from,
|
||||
grouped_by,
|
||||
)
|
||||
|
||||
total_amount = self._calculate_amounts(open_items_move_lines_data)
|
||||
@@ -290,6 +293,7 @@ class OpenItemsReport(models.AbstractModel):
|
||||
"accounts_data": accounts_data,
|
||||
"total_amount": total_amount,
|
||||
"Open_Items": open_items_move_lines_data,
|
||||
"grouped_by": grouped_by,
|
||||
}
|
||||
|
||||
def _get_ml_fields(self):
|
||||
|
||||
Reference in New Issue
Block a user