~therp-nl/openobject-server/ronald@therp.nl_fix_orm_lp1009014-trunk-revision2

« back to all changes in this revision

Viewing changes to openerp/addons/base/res/res_bank.py

  • Committer: Ronald Portier
  • Date: 2012-10-23 22:36:35 UTC
  • mfrom: (4185.1.318 trunk)
  • Revision ID: ronald@therp.nl-20121023223635-jxph07k7y1qf6bbx
[MERGE] Merge latest code from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
        'state': fields.many2one("res.country.state", 'Fed. State',
36
36
            domain="[('country_id', '=', country)]"),
37
37
        'country': fields.many2one('res.country', 'Country'),
38
 
        'email': fields.char('E-Mail', size=64),
 
38
        'email': fields.char('Email', size=64),
39
39
        'phone': fields.char('Phone', size=64),
40
40
        'fax': fields.char('Fax', size=64),
41
41
        'active': fields.boolean('Active'),
109
109
        if not context.get('address'):
110
110
            return value
111
111
 
112
 
        for address in self.pool.get('res.partner').resolve_o2m_commands_to_record_dicts(
 
112
        for address in self.pool.get('res.partner').resolve_2many_commands(
113
113
            cursor, user, 'address', context['address'], ['type', field], context=context):
114
114
 
115
115
            if address.get('type') == 'default':
172
172
                            ('required', field.required)]
173
173
        return res
174
174
 
 
175
    def _prepare_name_get(self, cr, uid, bank_dicts, context=None):
 
176
        """ Format the name of a res.partner.bank.
 
177
            This function is designed to be inherited to add replacement fields.
 
178
            :param bank_dicts: a list of res.partner.bank dicts, as returned by the method read()
 
179
            :return: [(id, name), ...], as returned by the method name_get()
 
180
        """
 
181
        # prepare a mapping {code: format_layout} for all bank types
 
182
        bank_type_obj = self.pool.get('res.partner.bank.type')
 
183
        bank_types = bank_type_obj.browse(cr, uid, bank_type_obj.search(cr, uid, []), context=context)
 
184
        bank_code_format = dict((bt.code, bt.format_layout) for bt in bank_types)
 
185
 
 
186
        res = []
 
187
        for data in bank_dicts:
 
188
            name = data['acc_number']
 
189
            if data['state'] and bank_code_format.get(data['state']):
 
190
                try:
 
191
                    if not data.get('bank_name'):
 
192
                        data['bank_name'] = _('BANK')
 
193
                    name = bank_code_format[data['state']] % data
 
194
                except Exception:
 
195
                    raise osv.except_osv(_("Formating Error"), _("Invalid Bank Account Type Name format."))
 
196
            res.append((data.get('id', False), name))
 
197
        return res
 
198
 
175
199
    def name_get(self, cr, uid, ids, context=None):
176
200
        if not len(ids):
177
201
            return []
178
 
        bank_type_obj = self.pool.get('res.partner.bank.type')
179
 
        res = []
180
 
        for val in self.browse(cr, uid, ids, context=context):
181
 
            result = val.acc_number
182
 
            if val.state:
183
 
                type_ids = bank_type_obj.search(cr, uid, [('code','=',val.state)])
184
 
                if type_ids:
185
 
                    t = bank_type_obj.browse(cr, uid, type_ids[0], context=context)
186
 
                    try:
187
 
                        # avoid the default format_layout to result in "False: ..."
188
 
                        if not val._data[val.id]['bank_name']:
189
 
                            val._data[val.id]['bank_name'] = _('BANK')
190
 
                        result = t.format_layout % val._data[val.id]
191
 
                    except:
192
 
                        result += ' [Formatting Error]'
193
 
                        raise
194
 
            res.append((val.id, result))
195
 
        return res
 
202
        bank_dicts = self.read(cr, uid, ids, context=context)
 
203
        return self._prepare_name_get(cr, uid, bank_dicts, context=context)
196
204
 
197
205
    def onchange_company_id(self, cr, uid, ids, company_id, context=None):
198
206
        result = {}