Browse Source

[ADD] account_export_csv - filter on journal_ids for export of journal entries

pull/597/head
Yannick Vaucher 11 years ago
committed by David Beal
parent
commit
51228e6826
  1. 3
      account_export_csv/__openerp__.py
  2. 45
      account_export_csv/wizard/account_export_csv.py
  3. 1
      account_export_csv/wizard/account_export_csv_view.xml

3
account_export_csv/__openerp__.py

@ -20,7 +20,7 @@
{ {
'name' : 'Account Export CSV', 'name' : 'Account Export CSV',
'version' : '1',
'version' : '1.1',
'depends' : [ 'depends' : [
'account', 'account',
], ],
@ -35,6 +35,7 @@
You can filter by period You can filter by period
TODO: rearange wizard view with only one button to generate file plus define a selection list to select report type
""", """,
'website': 'http://www.camptocamp.com', 'website': 'http://www.camptocamp.com',
'data': [ 'data': [

45
account_export_csv/wizard/account_export_csv.py

@ -85,7 +85,7 @@ class AccountCSVExport(orm.TransientModel):
'company_id': fields.many2one('res.company', 'Company', invisible=True), 'company_id': fields.many2one('res.company', 'Company', invisible=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', required=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'), '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'),
'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'),
'company_id': fields.many2one('res.company', 'Company', invisible=True), 'company_id': fields.many2one('res.company', 'Company', invisible=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', required=True), 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', required=True),
'export_filename': fields.char('Export CSV Filename', size=128), 'export_filename': fields.char('Export CSV Filename', size=128),
@ -136,7 +136,12 @@ class AccountCSVExport(orm.TransientModel):
_(u'BALANCE'), _(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 Return list to generate rows of the CSV file
""" """
@ -191,7 +196,12 @@ class AccountCSVExport(orm.TransientModel):
_(u'BALANCE'), _(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 Return list to generate rows of the CSV file
""" """
@ -222,9 +232,10 @@ class AccountCSVExport(orm.TransientModel):
We also write the data to the wizard with SQL query as write seams to use We also write the data to the wizard with SQL query as write seams to use
too much memory as well too much memory as well
Thos improvment permitted to improve the export from a 100k line to 400k lines
Thos improvment permitted to improve the export from a 100k line to 200k lines
with default `limit_memory_hard = 805306368` (768MB)
""" """
#XXX check why it still fail with more than 500k and when
#XXX check why it still fail with more than 200k line and when
this = self.browse(cr, uid, ids)[0] this = self.browse(cr, uid, ids)[0]
rows = self.get_data(cr, uid, ids, "journal_entries", context) rows = self.get_data(cr, uid, ids, "journal_entries", context)
with tempfile.TemporaryFile() as file_data: with tempfile.TemporaryFile() as file_data:
@ -279,7 +290,12 @@ class AccountCSVExport(orm.TransientModel):
] ]
def _get_rows_journal_entries(self, cr, uid, ids, fiscalyear_id, period_range_ids, company_id, context=None):
def _get_rows_journal_entries(self, cr, uid, ids,
fiscalyear_id,
period_range_ids,
journal_ids,
company_id,
context=None):
""" """
Return list to generate rows of the CSV file Return list to generate rows of the CSV file
""" """
@ -323,9 +339,10 @@ class AccountCSVExport(orm.TransientModel):
LEFT JOIN account_tax_code on (account_tax_code.id=account_move_line.tax_code_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) LEFT JOIN account_analytic_account on (account_analytic_account.id=account_move_line.analytic_account_id)
WHERE account_period.id IN %(period_ids)s WHERE account_period.id IN %(period_ids)s
AND account_journal.id IN %(journal_ids)s
ORDER BY account_move_line.date ORDER BY account_move_line.date
""", """,
{'period_ids': tuple(period_range_ids)}
{'period_ids': tuple(period_range_ids), 'journal_ids': tuple(journal_ids)}
) )
res = cr.fetchall() res = cr.fetchall()
rows = [] rows = []
@ -347,7 +364,19 @@ class AccountCSVExport(orm.TransientModel):
# If not period selected , we take all periods # If not period selected , we take all periods
p_obj = self.pool.get("account.period") p_obj = self.pool.get("account.period")
period_range_ids = p_obj.search(cr,uid,[('fiscalyear_id','=',fiscalyear_id)],context=context) 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 = []
rows.append(get_header_func(cr, uid, ids, context=context)) 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 return rows

1
account_export_csv/wizard/account_export_csv_view.xml

@ -14,6 +14,7 @@
</group> </group>
<group colspan="4" col="2"> <group colspan="4" col="2">
<field name="periods" domain="[('state', '=', 'draft'),('fiscalyear_id','=',fiscalyear_id)]"/> <field name="periods" domain="[('state', '=', 'draft'),('fiscalyear_id','=',fiscalyear_id)]"/>
<field name="journal_ids"/>
</group> </group>
<separator string ="" colspan="4"/> <separator string ="" colspan="4"/>
<group colspan="4" col="3"> <group colspan="4" col="3">

Loading…
Cancel
Save