[MERGE] l10n_be coda refactoring
authorAntony Lesuisse <al@openerp.com>
Tue, 11 Dec 2012 21:45:12 +0000 (22:45 +0100)
committerAntony Lesuisse <al@openerp.com>
Tue, 11 Dec 2012 21:45:12 +0000 (22:45 +0100)
bzr revid: al@openerp.com-20121211214512-aui7ptbdeynj0zgy

1  2 
addons/account/account_bank_statement.py
addons/l10n_be_coda/l10n_be_coda.py
addons/l10n_be_coda/wizard/account_coda_import.py

@@@ -546,7 -546,7 +546,7 @@@ class account_bank_statement_line(osv.o
      _name = "account.bank.statement.line"
      _description = "Bank Statement Line"
      _columns = {
-         'name': fields.char('Communication', size=64, required=True),
 -        'name': fields.char('Communication',size=64, required=True),
++        'name': fields.char('Communication', required=True),
          'date': fields.date('Date', required=True),
          'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
          'type': fields.selection([
@@@ -324,96 -26,53 +26,52 @@@ from osv import osv, field
  class account_bank_statement(osv.osv):
      _inherit = 'account.bank.statement'
      _columns = {
-         'coda_statement_id': fields.many2one('coda.bank.statement', 'Associated CODA Bank Statement'),
+         'coda_note': fields.text('CODA Notes'),
      }
  
-     def unlink(self, cr, uid, ids, context=None):
-         if context is None:
-             context = {}
-         context.update({'bank_statement_unlink': True})
-         coda_obj = self.pool.get('account.coda')
-         coda_st_obj = self.pool.get('coda.bank.statement')
-         # find all statements that are associated with the selected bank statements via a common CODA file
-         ids_plus = []
-         for statement in self.browse(cr, uid, ids, context=context):
-             if statement.coda_statement_id:
-                 for x in coda_obj.browse(cr, uid, statement.coda_statement_id.coda_id.id, context=context).statement_ids:
-                     if x.type == 'normal':
-                         ids_plus += [x.statement_id.id]
-         # unlink banks statements as well as associated CODA bank statements and CODA files
-         for statement in self.browse(cr, uid, ids_plus, context=context):
-             if not context.get('coda_statement_unlink', False):
-                 if statement.coda_statement_id and coda_st_obj.exists(cr, uid, statement.coda_statement_id.id, context=context):
-                     coda_st_obj.unlink(cr, uid, [statement.coda_statement_id.id], context=context)
-             if not context.get('coda_unlink', False):
-                 if statement.coda_statement_id \
-                     and coda_st_obj.exists(cr, uid, statement.coda_statement_id.id, context=context) \
-                     and statement.coda_statement_id.coda_id \
-                     and coda_obj.exists(cr, uid, statement.coda_statement_id.coda_id.id, context=context):
-                         coda_obj.unlink(cr, uid, [statement.coda_statement_id.coda_id.id], context=context)
-         context.update({'bank_statement_unlink': False})
-         new_ids = list(set(ids + ids_plus))
-         return super(account_bank_statement, self).unlink(cr, uid, new_ids, context=context)
  
- account_bank_statement()
- class coda_bank_statement_line(osv.osv):
-     _name = 'coda.bank.statement.line'
-     _order = 'sequence'
-     _description = 'CODA Bank Statement Line'
+ class account_bank_statement_line(osv.osv):
+     _inherit = 'account.bank.statement.line'
      _columns = {
-         'name': fields.char('Communication', size=268, required=True),
-         'sequence': fields.integer('Sequence'),
-         'date': fields.date('Entry Date', required=True),
-         'val_date': fields.date('Valuta Date'),
-         'account_id': fields.many2one('account.account','Account'),     # remove required=True
-         'type': fields.selection([
-             ('supplier','Supplier'),
-             ('customer','Customer'),
-             ('general','General'),
-             ('globalisation','Globalisation'),
-             ('information','Information'),
-             ('communication','Free Communication'),
-             ], 'Type', required=True),
-         'globalisation_level': fields.integer('Globalisation Level',
-                 help="The value which is mentioned (1 to 9), specifies the hierarchy level"
-                      " of the globalisation of which this record is the first."
-                      "\nThe same code will be repeated at the end of the globalisation."),
-         'globalisation_amount': fields.float('Globalisation Amount', digits_compute=dp.get_precision('Account')),
-         'globalisation_id': fields.many2one('account.bank.statement.line.global', 'Globalisation ID', readonly=True,
-             help="Code to identify transactions belonging to the same globalisation level within a batch payment"),
-         'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
-         'partner_id': fields.many2one('res.partner', 'Partner'),
-         'counterparty_name': fields.char('Counterparty Name', size=35),
-         'counterparty_bic': fields.char('Counterparty BIC', size=11),
-         'counterparty_number': fields.char('Counterparty Number', size=34),
-         'counterparty_currency': fields.char('Counterparty Currency', size=3),
-         'statement_id': fields.many2one('coda.bank.statement', 'CODA Bank Statement',
-             select=True, required=True, ondelete='cascade'),
-         'coda_bank_account_id': fields.related('statement_id', 'coda_bank_account_id', type='many2one', relation='coda.bank.account', string='Bank Account', store=True, readonly=True),
-         'ref': fields.char('Reference', size=32),
-         'note': fields.text('Notes'),
-         'company_id': fields.related('statement_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),
 -        'coda_account_number': fields.char('Account Number', size=64, help="The Counter Party Account Number")
++        'coda_account_number': fields.char('Account Number', help="The Counter Party Account Number")
      }
  
-     def unlink(self, cr, uid, ids, context=None):
-         if context is None:
-             context = {}
-         if context.get('block_statement_line_delete', False):
-             raise osv.except_osv('Warning', _('Delete operation not allowed.'))
-         return super(account_bank_statement_line, self).unlink(cr, uid, ids, context=context)
- coda_bank_statement_line()
- class account_bank_statement_line_global(osv.osv):
-     _inherit = 'account.bank.statement.line.global'
-     _columns = {
-         'coda_statement_line_ids': fields.one2many('coda.bank.statement.line', 'globalisation_id', 'CODA Bank Statement Lines', readonly=True),
-     }
+     def create(self, cr, uid, data, context=None):
 -      """
 -              This function creates a Bank Account Number if, for a bank statement line, 
 -              the partner_id field and the coda_account_number field are set, 
 -              and the account number does not exist in the database
 -      """
 -      if 'partner_id' in data and data['partner_id'] and 'coda_account_number' in data and data['coda_account_number']:
 -              acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', data['coda_account_number'])])
 -              if len(acc_number_ids) == 0:
 -                              try:
 -                                      type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
 -                                      type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
 -                                      self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': data['coda_account_number'], 'partner_id': data['partner_id'], 'state': type_id.code}, context=context)
 -                              except ValueError:
 -                                      pass
 -      return super(account_bank_statement_line, self).create(cr, uid, data, context=context)
++        """
++            This function creates a Bank Account Number if, for a bank statement line, 
++            the partner_id field and the coda_account_number field are set, 
++            and the account number does not exist in the database
++        """
++        if 'partner_id' in data and data['partner_id'] and 'coda_account_number' in data and data['coda_account_number']:
++            acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', data['coda_account_number'])])
++            if len(acc_number_ids) == 0:
++                try:
++                    type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
++                    type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
++                    self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': data['coda_account_number'], 'partner_id': data['partner_id'], 'state': type_id.code}, context=context)
++                except ValueError:
++                    pass
++        return super(account_bank_statement_line, self).create(cr, uid, data, context=context)
+     def write(self, cr, uid, ids, vals, context=None):
 -      super(account_bank_statement_line, self).write(cr, uid, ids, vals, context)
 -      """
 -                      Same as create function above, but for write function
 -      """
 -      if 'partner_id' in vals:
 -              for line in self.pool.get('account.bank.statement.line').browse(cr, uid, ids, context=context):
 -                      if line.coda_account_number:
 -                              acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', line.coda_account_number)])
 -                              if len(acc_number_ids) == 0:
 -                                      try:
 -                                          type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
 -                                          type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
 -                                          self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': line.coda_account_number, 'partner_id': vals['partner_id'], 'state': type_id.code}, context=context)
 -                                      except ValueError:
 -                                          pass
 -      return True
++        super(account_bank_statement_line, self).write(cr, uid, ids, vals, context)
++        """
++            Same as create function above, but for write function
++        """
++        if 'partner_id' in vals:
++            for line in self.pool.get('account.bank.statement.line').browse(cr, uid, ids, context=context):
++                if line.coda_account_number:
++                    acc_number_ids = self.pool.get('res.partner.bank').search(cr, uid, [('acc_number', '=', line.coda_account_number)])
++                    if len(acc_number_ids) == 0:
++                        try:
++                            type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal')
++                            type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context)
++                            self.pool.get('res.partner.bank').create(cr, uid, {'acc_number': line.coda_account_number, 'partner_id': vals['partner_id'], 'state': type_id.code}, context=context)
++                        except ValueError:
++                            pass
++        return True
  
- account_bank_statement_line_global()
 -account_bank_statement()
  
  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@@ -932,46 -375,12 +375,11 @@@ class account_coda_import(osv.osv_memor
              'context': context,
              'type': 'ir.actions.act_window',
          }
 -account_coda_import()
  
-     def action_open_coda_statements(self, cr, uid, ids, context=None):
-         if context is None:
-             context = {}
-         module, xml_id = 'l10n_be_coda', 'action_coda_bank_statements'
-         res_model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, module, xml_id)
-         action = self.pool.get('ir.actions.act_window').read(cr, uid, res_id, context=context)
-         domain = eval(action.get('domain') or '[]')
-         domain += [('coda_id', '=', context.get('coda_id', False))]
-         action.update({'domain': domain})
-         return action
-     def action_open_bank_statements(self, cr, uid, ids, context=None):
-         if context is None:
-             context = {}
-         module, xml_id = 'account', 'action_bank_statement_tree'
-         res_model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, module, xml_id)
-         action = self.pool.get('ir.actions.act_window').read(cr, uid, res_id, context=context)
-         domain = eval(action.get('domain') or '[]')
-         domain += [('id','in', context.get('bk_st_ids', False))]
-         action.update({'domain': domain})
-         return action
- account_coda_import()
  
- def str2date(date_str):
-     return time.strftime('%Y-%m-%d', time.strptime(date_str,'%d%m%y'))
+ def rmspaces(s):
+     return " ".join(s.split())
  
- def str2float(str):
-     try:
-         return float(str)
-     except:
-         return 0.0
  
- def list2float(lst):
-     try:
-         return str2float((lambda s : s[:-3] + '.' + s[-3:])(lst))
-     except:
-         return 0.0
  
  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: