summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-08-15 14:49:52 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-08-15 14:49:52 +0700
commit25225a6405147c40d51488e9ea2ec95b66e6ef28 (patch)
tree79c75bd93c608d0c91b3cedcd4924c8091fe61a4
parentb603e5eca682c7d42d259d3432316ed28b41737f (diff)
financial report fix
-rw-r--r--indoteknik_custom/models/account_financial_report.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/indoteknik_custom/models/account_financial_report.py b/indoteknik_custom/models/account_financial_report.py
index 315515f6..3adc1bd8 100644
--- a/indoteknik_custom/models/account_financial_report.py
+++ b/indoteknik_custom/models/account_financial_report.py
@@ -23,11 +23,15 @@ class AccountingReport(models.TransientModel):
output = io.BytesIO()
workbook = xlsxwriter.Workbook(output, {'in_memory': True})
-
+ journal_entries = self.env['account.move'].search([('move_type', '=', 'entry')], order='date asc', limit=1)
data = {}
data['form'] = obj.read([])[0]
-
- date_from = data['form']['date_from']
+
+ if obj.date_from:
+ date_from = data['form']['date_from']
+ else:
+ date_from = journal_entries.date
+
date_to = data['form']['date_to']
obj = self.search([('id', '=', options['form']['id'])])
@@ -61,7 +65,7 @@ class AccountingReport(models.TransientModel):
sheet.set_column('I:I', 10, format4)
sheet.set_column('J:J', 10, format4)
- date_ranges = self.generate_date_ranges(date_from, date_to)
+ date_ranges = self.generate_date_ranges(date_from, date_to, obj)
col_number = 0
balance_col_number = 4
@@ -158,21 +162,19 @@ class AccountingReport(models.TransientModel):
response.stream.write(output.read())
output.close()
- def generate_date_ranges(self, date_from, date_to):
+ def generate_date_ranges(self, date_from, date_to, obj):
current_date = date_from
date_ranges = []
while current_date <= date_to:
next_month = current_date.replace(day=1) + timedelta(days=32)
- end_of_month = next_month - timedelta(days=next_month.day)
- if end_of_month > date_to:
- end_of_month = date_to
+ end_of_month = min(next_month - timedelta(days=next_month.day), date_to)
date_ranges.append({
- "date_from": current_date,
+ "date_from": current_date if obj.date_from else date_from,
"date_to": end_of_month
})
current_date = end_of_month + timedelta(days=1)
- return date_ranges \ No newline at end of file
+ return date_ranges