58
58
journal_ids = self.pool.get('account.analytic.journal').search(cr, uid, [('code', '=', 'ENGI')], context=context)
59
59
to_be_deleted_ids = analytic_obj.search(cr, uid, [('imported_commitment', '=', True)], context=context)
60
60
functional_currency_obj = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id
61
default_founding_pool_id = self.pool.get('account.analytic.account').search(
62
cr, uid, [('category', '=', 'FUNDING'), ('code', '=', 'PF')], context=context)
63
if not default_founding_pool_id:
64
raise osv.except_osv(_('Error'), _('Default PF Funding Pool not found'))
65
default_founding_pool_id = default_founding_pool_id[0]
63
68
if len(journal_ids) > 0:
209
240
return {'type' : 'ir.actions.act_window_close'}
211
242
import_commitment_wizard()
245
class int_commitment_clear_wizard(osv.osv_memory):
246
_name = 'int.commitment.clear.wizard'
247
_description = 'Clear Intl Commitments Wizard'
249
def _get_to_del_ids(self, cr, uid, context=None, count=False):
251
('type', '=', 'engagement'),
252
('code', '=', 'ENGI'),
254
journal_ids = self.pool.get('account.analytic.journal').search(cr, uid,
255
domain, context=context)
260
('imported_commitment', '=', True),
261
('journal_id', 'in', journal_ids),
263
res_ids = self.pool.get('account.analytic.line').search(cr, uid, domain,
264
context=context, count=count)
268
'entries_count': fields.integer('Count Intl Commitments to delete'),
272
'entries_count': lambda s, cr, uid, context: s._get_to_del_ids(cr, uid, context=context, count=True),
275
def mass_delete(self, cr, uid, ids, context=None):
276
to_del_ids = self._get_to_del_ids(cr, uid, context=context, count=False)
278
self.pool.get('account.analytic.line').unlink(cr, uid, to_del_ids,
280
return {'type': 'ir.actions.act_window_close'}
282
int_commitment_clear_wizard()
285
class int_commitment_export_wizard(osv.osv_memory):
286
_name = 'int.commitment.export.wizard'
287
_description = 'Export Intl Commitments'
289
_csv_filename_pattern = 'Intl_Commitments_%s.csv'
291
_csv_header = ['Description', 'Ref', 'Document Date', 'Posting Date',
292
'General Account', 'Destination', 'Cost Center' , 'Funding Pool',
293
'Third Party', 'Booking Amount', 'Booking Currency', ]
296
'data': fields.binary('File', readonly=True),
297
'name': fields.char('File Name', 128, readonly=True),
298
'state': fields.selection((('choose','choose'), ('get','get'), ),
299
readonly=True, invisible=True),
303
'state': lambda *a: 'choose',
306
def button_export(self, cr, uid, ids, context=None):
307
aal_obj = self.pool.get('account.analytic.line')
309
instance_name = self.pool.get('res.users').browse(cr, uid, [uid],
310
context=context)[0].company_id.instance_id.name or ''
311
file_name = self._csv_filename_pattern % (instance_name, )
313
# csv prepare and header
314
csv_buffer = StringIO.StringIO()
315
csv_writer = csv.writer(csv_buffer, delimiter=self._csv_delimiter,
316
quoting=csv.QUOTE_MINIMAL)
317
csv_writer.writerow(self._csv_header)
321
('journal_id.type', '=', 'engagement'),
322
('journal_id.code', '=', 'ENGI'),
324
export_ids = aal_obj.search(cr, uid, domain, context=context)
325
for export_br in aal_obj.browse(cr, uid, export_ids, context=context):
326
csv_writer.writerow(self._export_entry(export_br))
331
'data': base64.encodestring(csv_buffer.getvalue()),
335
return self.write(cr, uid, ids, vals, context=context)
337
def _export_entry(self, item_br):
338
def decode_m2o(m2o, want_code=False):
341
res = m2o.code if want_code else m2o.name
345
# '%Y-%m-%d' orm -> '%d/%m/%Y' of import csv format
346
return dt and time.strftime('%d/%m/%Y', time.strptime(dt, '%Y-%m-%d')) or ''
356
decode_date(item_br.document_date),
359
decode_date(item_br.date),
362
decode_m2o(item_br.general_account_id, want_code=True),
365
decode_m2o(item_br.destination_id, want_code=True),
368
decode_m2o(item_br.cost_center_id, want_code=True),
371
decode_m2o(item_br.account_id, want_code=True),
374
item_br.partner_txt or '',
377
str(-1. * item_br.amount_currency),
380
decode_m2o(item_br.currency_id),
384
int_commitment_export_wizard()
212
385
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: