Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3438][3894][IMP] account_move_obc_csv #55

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions account_move_obc_csv/report/report_account_move_obc_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import csv
from collections import defaultdict
from itertools import groupby

from odoo import _, models
from odoo.exceptions import UserError
Expand All @@ -14,6 +15,7 @@ class AccountMoveObcCsv(models.AbstractModel):

def _get_fields(self):
return [
"GL0010000", # asterisk
"GL0010001", # date
"GL0012002", # debit account
"GL0012101", # debit base amount
Expand Down Expand Up @@ -177,12 +179,24 @@ def _get_report_vals_dict(self, record):

def generate_csv_report(self, writer, data, records):
self._check_records(records)
# Sort records by date and then by picking_id
sorted_records = sorted(
records, key=lambda r: (r.date, r.stock_move_id.picking_id.id)
)
writer.writeheader()
for record in records:
vals_dict = self._get_report_vals_dict(record)
for _k, v in sorted(vals_dict.items()):
writer.writerow(v)
record.is_exported = True
# Group records by picking_id
for _p, grouped_records in groupby(
sorted_records, key=lambda r: r.stock_move_id.picking_id.id
):
first_record = True
for record in grouped_records:
vals_dict = self._get_report_vals_dict(record)
if first_record:
vals_dict[1]["GL0010000"] = "*"
first_record = False
for _k, v in sorted(vals_dict.items()):
writer.writerow(v)
record.is_exported = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to consider the non-inventory journal entries (e.g. those from vendor bills). The first line need to be marked with * for those as well.

Suggested change
# Group records by picking_id
for _p, grouped_records in groupby(
sorted_records, key=lambda r: r.stock_move_id.picking_id.id
):
first_record = True
for record in grouped_records:
vals_dict = self._get_report_vals_dict(record)
if first_record:
vals_dict[1]["GL0010000"] = "*"
first_record = False
for _k, v in sorted(vals_dict.items()):
writer.writerow(v)
record.is_exported = True
picking = self.env["stock.picking"]
for record in sorted_records:
vals_dict = self._get_report_vals_dict(record)
first_record = False
record_picking = record.stock_move_id.picking_id
if not record_picking:
first_record = True
elif picking != record_picking:
first_record = True
picking = record_picking
if first_record:
vals_dict[1]["GL0010000"] = "*"
for _k, v in sorted(vals_dict.items()):
writer.writerow(v)
record.is_exported = True


def csv_report_options(self):
res = super().csv_report_options()
Expand Down
Loading