Skip to content

Commit

Permalink
Merge pull request #61 from tosccolors/16.0-377-1-2-group-and-rename-…
Browse files Browse the repository at this point in the history
…lines

[ADD] #377.1 implement ps-specific grouping on standard invoice report
  • Loading branch information
Stephanvandenberg authored Dec 3, 2024
2 parents 0e7a232 + c1c2c51 commit dd4a09d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
33 changes: 32 additions & 1 deletion ps_account/models/account_move.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions ps_account/report/report_invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,13 @@
/>
</t>
</xpath>
<xpath expr="//t[@t-set='lines']" position="after">
<t
t-if="o.invoice_line_ids.mapped('ps_invoice_id')"
t-set="lines"
t-value="o.group_by_project_product_unit_price()"
/>
</xpath>
</template>
<!--<template id="ps_account.report_invoice_ps_account">
<t t-call="web.html_container">
Expand Down

0 comments on commit dd4a09d

Please # to comment.