def write(cls, *args): actions = iter(args) args = [] for numbers, values in zip(actions, actions): values = values.copy() if values.get('type') == 'cbu' and 'number' in values: values['number'] = cbu.format(values['number']) values['number_compact'] = cbu.compact(values['number']) args.extend((numbers, values)) super(AccountNumber, cls).write(*args) to_write = [] for number in sum(args[::2], []): if number.type == 'cbu': formated_number = cbu.format(number.number) compacted_number = cbu.compact(number.number) if ((formated_number != number.number) or (compacted_number != number.number_compact)): to_write.extend(([number], { 'number': formated_number, 'number_compact': compacted_number, })) if to_write: cls.write(*to_write)
def create(cls, vlist): vlist = [v.copy() for v in vlist] for values in vlist: if values.get('type') == 'cbu' and 'number' in values: values['number'] = cbu.format(values['number']) values['number_compact'] = cbu.compact(values['number']) return super(AccountNumber, cls).create(vlist)
def compact_cbu(self): return (cbu.compact(self.number) if self.type == 'cbu' else self.number)