diff --git a/account_export_csv/wizard/account_export_csv.py b/account_export_csv/wizard/account_export_csv.py
index 1612f83e..e9291ea7 100644
--- a/account_export_csv/wizard/account_export_csv.py
+++ b/account_export_csv/wizard/account_export_csv.py
@@ -80,6 +80,7 @@ class AccountCSVExport(orm.TransientModel):
'company_id': fields.many2one('res.company', 'Company', invisible=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', required=True),
'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'),
+ 'journal_ids': fields.many2many('account.journal','rel_wizard_journal','wizard_id','journal_id','Journals', help='If empty, use all journals, only used for journal entries'),
'export_filename': fields.char('Export CSV Filename', size=128),
}
@@ -128,7 +129,7 @@ class AccountCSVExport(orm.TransientModel):
_(u'BALANCE'),
]
- def _get_rows_account(self, cr, uid, ids, fiscalyear_id,period_range_ids,company_id,context=None):
+ def _get_rows_account(self, cr, uid, ids, fiscalyear_id,period_range_ids,journal_ids,company_id,context=None):
"""
Return list to generate rows of the CSV file
"""
@@ -138,6 +139,7 @@ class AccountCSVExport(orm.TransientModel):
from account_move_line as aml,account_account as ac
where aml.account_id = ac.id
and period_id in %(period_ids)s
+ and aml.company_id = %(company_id)s
group by ac.id,ac.code,ac.name
order by ac.code
""",
@@ -183,7 +185,7 @@ class AccountCSVExport(orm.TransientModel):
_(u'BALANCE'),
]
- def _get_rows_analytic(self, cr, uid, ids, fiscalyear_id,period_range_ids,company_id,context=None):
+ def _get_rows_analytic(self, cr, uid, ids, fiscalyear_id,period_range_ids,journal_ids,company_id,context=None):
"""
Return list to generate rows of the CSV file
"""
@@ -195,6 +197,7 @@ class AccountCSVExport(orm.TransientModel):
inner join account_account as ac
on account_move_line.account_id = ac.id
and account_move_line.period_id in %(period_ids)s
+ and account_move_line.company_id = %(company_id)s
group by aac.id,aac.code,aac.name,ac.id,ac.code,ac.name
order by aac.code
""",
@@ -207,6 +210,145 @@ class AccountCSVExport(orm.TransientModel):
rows.append(list(line))
return rows
+ def action_manual_export_journal_entries(self, cr, uid, ids, context=None):
+ """
+ Here we use TemporaryFile to avoid full filling the OpenERP worker Memory
+ We also write the data to the wizard with SQL query as write seams to use
+ too much memory as well.
+
+ Those improvements permitted to improve the export from a 100k line to 200k lines
+ with default `limit_memory_hard = 805306368` (768MB) with more lines,
+ you might encounter a MemoryError when trying to download the file even
+ if it has been generated.
+
+ To be able to export bigger volume of data, it is advised to set
+ limit_memory_hard to 2097152000 (2 GB) to generate the file and let
+ OpenERP load it in the wizard when trying to download it.
+
+ Tested with up to a generation of 700k entry lines
+ """
+ this = self.browse(cr, uid, ids)[0]
+ rows = self.get_data(cr, uid, ids, "journal_entries", context)
+ file_data = StringIO.StringIO()
+ try:
+ writer = AccountUnicodeWriter(file_data)
+ writer.writerows(rows)
+ file_value = file_data.getvalue()
+ self.write(cr, uid, ids,
+ {'data': base64.encodestring(file_value)},
+ context=context)
+ finally:
+ file_data.close()
+ return {
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'account.csv.export',
+ 'view_mode': 'form',
+ 'view_type': 'form',
+ 'res_id': this.id,
+ 'views': [(False, 'form')],
+ 'target': 'new',
+ }
+
+
+ def _get_header_journal_entries(self, cr, uid, ids, context=None):
+
+ return [
+ # Standard Sage export fields
+ _(u'DATE'),
+ _(u'JOURNAL CODE'),
+ _(u'ACCOUNT CODE'),
+ _(u'PARTNER NAME'),
+ _(u'REF'),
+ _(u'DESCRIPTION'),
+ _(u'DEBIT'),
+ _(u'CREDIT'),
+ _(u'FULL RECONCILE'),
+ _(u'PARTIAL RECONCILE'),
+ _(u'ANALYTIC ACCOUNT CODE'),
+
+ # Other fields
+ _(u'ENTRY NUMBER'),
+ _(u'ACCOUNT NAME'),
+ _(u'BALANCE'),
+ _(u'AMOUNT CURRENCY'),
+ _(u'CURRENCY'),
+ _(u'ANALYTIC ACCOUNT NAME'),
+ _(u'JOURNAL'),
+ _(u'MONTH'),
+ _(u'FISCAL YEAR'),
+ _(u'TAX CODE CODE'),
+ _(u'TAX CODE NAME'),
+ _(u'TAX AMOUNT'),
+ ]
+
+
+ def _get_rows_journal_entries(self, cr, uid, ids,
+ fiscalyear_id,
+ period_range_ids,
+ journal_ids,
+ company_id,
+ context=None):
+ print period_range_ids
+ print journal_ids
+ """
+ Create a generator of rows of the CSV file
+ """
+ cr.execute("""
+ SELECT
+ account_move_line.date AS date,
+ account_journal.name as journal,
+ account_account.code AS account_code,
+ res_partner.name AS partner_name,
+ account_move_line.ref AS ref,
+ account_move_line.name AS description,
+ account_move_line.debit AS debit,
+ account_move_line.credit AS credit,
+ account_move_reconcile.name as full_reconcile,
+ account_move_line.reconcile_partial_id AS partial_reconcile_id,
+ account_analytic_account.code AS analytic_account_code,
+
+ account_move.name AS entry_number,
+ account_account.name AS account_name,
+ account_move_line.debit - account_move_line.credit AS balance,
+ account_move_line.amount_currency AS amount_currency,
+ res_currency.name AS currency,
+ account_analytic_account.name AS analytic_account_name,
+ account_journal.name as journal,
+ account_period.code AS month,
+ account_fiscalyear.name as fiscal_year,
+ account_tax_code.code AS aml_tax_code_code,
+ account_tax_code.name AS aml_tax_code_name,
+ account_move_line.tax_amount AS aml_tax_amount
+ FROM
+ public.account_move_line
+ JOIN account_account on (account_account.id=account_move_line.account_id)
+ JOIN account_period on (account_period.id=account_move_line.period_id)
+ JOIN account_fiscalyear on (account_fiscalyear.id=account_period.fiscalyear_id)
+ JOIN account_journal on (account_journal.id = account_move_line.journal_id)
+ LEFT JOIN res_currency on (res_currency.id=account_move_line.currency_id)
+ LEFT JOIN account_move_reconcile on (account_move_reconcile.id = account_move_line.reconcile_id)
+ LEFT JOIN res_partner on (res_partner.id=account_move_line.partner_id)
+ LEFT JOIN account_move on (account_move.id=account_move_line.move_id)
+ LEFT JOIN account_tax on (account_tax.id=account_move_line.account_tax_id)
+ LEFT JOIN account_tax_code on (account_tax_code.id=account_move_line.tax_code_id)
+ LEFT JOIN account_analytic_account on (account_analytic_account.id=account_move_line.analytic_account_id)
+ WHERE account_period.id IN %(period_ids)s
+ AND account_journal.id IN %(journal_ids)s
+ AND account_move_line.company_id = %(company_id)s
+ ORDER BY account_move_line.date
+ """,
+ {'period_ids': tuple(period_range_ids), 'journal_ids': tuple(journal_ids), 'company_id': company_id}
+ )
+ while 1:
+ # http://initd.org/psycopg/docs/cursor.html#cursor.fetchmany
+ # Set cursor.arraysize to minimize network round trips
+ cr.arraysize=100
+ rows = cr.fetchmany()
+ if not rows:
+ break
+ for row in rows:
+ yield row
+
def get_data(self, cr, uid, ids,result_type,context=None):
get_header_func = getattr(self,("_get_header_%s"%(result_type)), None)
get_rows_func = getattr(self,("_get_rows_%s"%(result_type)), None)
@@ -220,7 +362,13 @@ class AccountCSVExport(orm.TransientModel):
# If not period selected , we take all periods
p_obj = self.pool.get("account.period")
period_range_ids = p_obj.search(cr,uid,[('fiscalyear_id','=',fiscalyear_id)],context=context)
+ journal_ids = None
+ if form.journal_ids:
+ journal_ids = [x.id for x in form.journal_ids]
+ else:
+ j_obj = self.pool.get("account.journal")
+ journal_ids = j_obj.search(cr, uid, [], context=context)
rows = []
rows.append(get_header_func(cr, uid, ids, context=context))
- rows.extend(get_rows_func(cr, uid, ids, fiscalyear_id,period_range_ids,company_id, context=context))
+ rows.extend(get_rows_func(cr, uid, ids, fiscalyear_id,period_range_ids,journal_ids,company_id, context=context))
return rows
diff --git a/account_export_csv/wizard/account_export_csv_view.xml b/account_export_csv/wizard/account_export_csv_view.xml
index 9cf4fb04..54389059 100644
--- a/account_export_csv/wizard/account_export_csv_view.xml
+++ b/account_export_csv/wizard/account_export_csv_view.xml
@@ -14,12 +14,14 @@
+
+