Skip to content

Commit

Permalink
[14.0][IMP] account_invoice_report_grouped_by_picking: Show section a…
Browse files Browse the repository at this point in the history
…nd notes at the end of invoice
  • Loading branch information
manuelregidor committed Apr 3, 2024
1 parent b33a456 commit ae1a403
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
22 changes: 20 additions & 2 deletions account_invoice_report_grouped_by_picking/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ class AccountMove(models.Model):
@api.model
def _sort_grouped_lines(self, lines_dic):
min_date = datetime.datetime.min
return sorted(
dictionary = sorted(
lines_dic,
key=lambda x: (
(
x["picking"].date or min_date,
x["picking"].date_done or x["picking"].date or min_date,
x["line"].sequence
)
),
)
return dictionary

def _get_signed_quantity_done(self, invoice_line, move, sign):
"""Hook method. Usage example:
Expand Down Expand Up @@ -70,15 +72,29 @@ def lines_grouped_by_picking(self):
so_dict = {x.sale_id: x for x in self.picking_ids if x.sale_id}
# Now group by picking by direct link or via same SO as picking's one
previous_section = previous_note = False
last_section_notes = []
for line in self.invoice_line_ids.sorted(
lambda ln: (-ln.sequence, ln.date, ln.move_name, -ln.id), reverse=True
):
if line.display_type == "line_section":
previous_section = line
last_section_notes.append({

Check warning on line 81 in account_invoice_report_grouped_by_picking/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_report_grouped_by_picking/models/account_move.py#L80-L81

Added lines #L80 - L81 were not covered by tests
"picking": picking_obj,
"line": line,
"qty": 0.0,
"is_last_section_notes": True
})
continue

Check warning on line 87 in account_invoice_report_grouped_by_picking/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_report_grouped_by_picking/models/account_move.py#L87

Added line #L87 was not covered by tests
if line.display_type == "line_note":
previous_note = line
last_section_notes.append({

Check warning on line 90 in account_invoice_report_grouped_by_picking/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_report_grouped_by_picking/models/account_move.py#L89-L90

Added lines #L89 - L90 were not covered by tests
"picking": picking_obj,
"line": line,
"qty": 0.0,
"is_last_section_notes": True
})
continue

Check warning on line 96 in account_invoice_report_grouped_by_picking/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_report_grouped_by_picking/models/account_move.py#L96

Added line #L96 was not covered by tests
last_section_notes = []
has_returned_qty = False
remaining_qty = line.quantity
for move in line.move_line_ids:
Expand Down Expand Up @@ -135,4 +151,6 @@ def lines_grouped_by_picking(self):
{"picking": key[0], "line": key[1], "quantity": value}
for key, value in picking_dict.items()
]
return no_picking + self._sort_grouped_lines(with_picking)
return no_picking + self._sort_grouped_lines(
with_picking + last_section_notes
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
<t t-set="l" t-value="lines_group['line']" />
<t t-set="line" t-value="lines_group['line']" />
<t t-set="picking" t-value="lines_group['picking']" />
<t
t-set="next_line"
t-value="[lines_grouped[i + 1] for i, x in enumerate(lines_grouped) if x == lines_group and i &lt; len(lines_grouped) - 1] or [False]" />
<t
t-set="next_picking"
t-value="[lines_grouped[i + 1]['picking'] for i, x in enumerate(lines_grouped) if x == lines_group and i &lt; len(lines_grouped) - 1] or [False]"
/>
<!-- Avoid to show original subtotal -->
<t t-set="line_last" t-value="False" />
<t t-set="line_index" t-value="0" />

<t t-if="picking != last_picking">
<t t-set="last_picking" t-value="picking" />
<tr t-if="picking">
Expand Down Expand Up @@ -121,6 +123,22 @@
<t t-set="subtotal" t-value="0.0" />
</tr>
</xpath>
<!-- Append subtotal after notes and sections at the end of the invoice-->
<xpath
expr="//t[@name='account_invoice_line_accountable']/.."
position="after"
>
<tr t-if="lines_group.get('is_last_section_notes') and (not next_line or not next_line[0].get('is_last_section_notes')) and subtotal">
<td colspan="10" class="text-right">
<strong>Subtotal: </strong>
<strong
t-esc="subtotal"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'
/>
</td>
<t t-set="subtotal" t-value="0.0" />
</tr>
</xpath>
<xpath expr="//td/span[@t-field='line.price_total']" position="attributes">
<attribute name="t-if">lines_group['quantity'] == l.quantity</attribute>
</xpath>
Expand Down

0 comments on commit ae1a403

Please sign in to comment.