From c1c2c51745d66f110b926edc2c35b8f30066d5be Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Wed, 27 Nov 2024 20:45:16 +0100 Subject: [PATCH] [ADD] #377.1 implement ps-specific grouping on standard invoice report \#377.2 ps-specific name on standard invoice report --- ps_account/models/account_move.py | 33 +++++++++++++++++++++++++++- ps_account/report/report_invoice.xml | 7 ++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/ps_account/models/account_move.py b/ps_account/models/account_move.py index 5b48441..53fdf01 100644 --- a/ps_account/models/account_move.py +++ b/ps_account/models/account_move.py @@ -1,7 +1,9 @@ # Copyright 2014-2023 The Open Source Company (www.tosc.nl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from collections import OrderedDict + from odoo import api, fields, models -from odoo.tools import is_html_empty +from odoo.tools import frozendict, is_html_empty class AccountMove(models.Model): @@ -69,6 +71,35 @@ def group_by_analytic_acc(self, data_type, uom_hrs=False): result.setdefault(analytic_account, []).append(line) return result + def group_by_project_product_unit_price(self): + """ + Return synthesized account.move.line records implementing grouping required for + ps invoices + """ + grouped = OrderedDict() + + def key_func(line): + return ( + frozendict(line.analytic_distribution), + line.product_id, + line.price_unit, + ) + + for line in self.mapped("invoice_line_ids").sorted(key=key_func): + key = key_func(line) + if key not in grouped: + grouped[key] = line.new(line._cache) + grouped[key]["name"] = "%s%s" % ( + line.ps_invoice_id.project_id.name + and (line.ps_invoice_id.project_id.name + " - ") + or "", + line.product_id.name, + ) + else: + grouped[key].quantity += line.quantity + + return grouped.values() + def parse_invoice_description(self): res = not is_html_empty(self.invoice_description) return res diff --git a/ps_account/report/report_invoice.xml b/ps_account/report/report_invoice.xml index 0927368..c58199e 100644 --- a/ps_account/report/report_invoice.xml +++ b/ps_account/report/report_invoice.xml @@ -819,6 +819,13 @@ /> + + +